isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; } /* public function getOddzial(){ if($this->isGuest) return false; $oddzial = Users::model()->findByPk((int)$this->id); return $oddzial->oddzial_id; } public function getOddzialName(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->nazwa; } public function getOddzialRodzaj(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->rodzaj; } public function getOddzialTyp(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->typ; } public function getOddzialSkrot(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->skrot; } public function getOddzialCechaId(){ if($this->isGuest) return false; $oddzial = Users::model()->with('oddzialy')->findByPk((int)$this->id); return $oddzial->oddzialy->cechy_id; } */ public function getZmianaHasla(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->zmiana_hasla; } public function hasClient(){ if($this->isGuest){ return false; } $klienci = KliKlienci::model()->findAllByAttributes(array('user_id'=>(int)$this->id)); if($klienci){ return true; } else{ return false; } } //Robal end /* * Retrieves the role and permission info from the database and stores them for further usage */ private function setupPermissions() { $this->roles = array(); $this->permissions = array(); // do not setup permissions if user is a guest if($this->isGuest) return; // retrieve roles from the database // $userRoles = Role::model()->with('role')->findAll('user_id = ' . $this->getId()); /*$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); //$userRoles = global_user_has_role::model()->with('role')->findAll('user_id = ' . $this->getId()); foreach($userRoles as $role) { $this->roles[$role->role->id] = $role->role->name; }*/ // retrieve permissions from the database $userPermissions = UsersPermissions::model()->with('permission')->findAll('user_id = ' . $this->getId()); // PAWEŁ $userPermissions = RolesPermissions::model()->with('permission')->findAll('role_id = '.$this->getRole()); foreach($userPermissions as $permission) { if($permission->permission){ $this->permissions[$permission->permission_id] = $permission->permission->name; } } } public function getMemuName($name) { $back = ''; /// echo $name; $menu = Menu::model()->findByAttributes(array('name'=>$name)); if($menu == null ){ $back = $name; }else { if(isset($_GET['lang']) && ($_GET['lang'] == 'en')){ $back = $menu->menu_en; }else { $back = $menu->menu_pl; } } return $back; } } isGuest) $this->setupPermissions(); } public function getUrlAdress() { } /* public function getUsersByOddzial($oddzial = NULL, $param=null) { if ($param == 'urlopy') { return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny_urlopy="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } elseif($oddzial == NULL){ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } else{ return CHtml::listData(Users::model()->findAllBySQL('select *, concat(last_name, " ",first_name) as first_name from sys_users users left join sys_oddzial oddzialy on users.oddzial_id = oddzialy.oddzial_id where widoczny="tak" and oddzialy.oddzial_id = "'.$oddzial.'" order by oddzialy.nazwa, last_name'),'user_id','first_name', 'oddzialy.nazwa'); } }*/ public function getUserModel() { $user = Users::model()->findByPk((int)$this->id); if($user !== NULL){ return $user; } return false; } /* * Checks wether the user has the given role * @param Mixed the role identifier, string or integer * @return Bool true if the user possesses the given role, false otherwise */ public function checkRole($identifier) { return $this->performCheck($identifier, 'roles'); } /* * Checks wether the user has the given permission * @param Mixed the permission identifier, string or integer * @return Bool true if the user possesses the given permission, false otherwise */ public function checkPermission($identifier) { $arrayIdentifier = explode('|',$identifier); $arrayIdentifierResults = array_map(array($this,'performCheck'),$arrayIdentifier,array_fill(0,count($arrayIdentifier),'permissions')); return array_sum($arrayIdentifierResults) > 0 ? true : false; } /* * Internal function, invoked after calling checkPermission or checkRole * Checks wether the user has the given role or permission * @param Mixed role or permission identifier, string or integer * @param String type to check, role or permission * @return Bool true if the user possesses the given role or permission, false otherwise */ private function performCheck($identifier, $type = 'permissions') { $varName = in_array($type, array('permissions','roles')) ? strtolower($type) : 'permissions'; $identifier = strtolower($identifier); return is_numeric($identifier) ? isset($this->{$varName}[$identifier]) : (array_search($identifier, $this->{$varName}) !== false); } /** * @param mixed the name of the inaccessible member variable * @return mixed the customized value for a inaccessible variable */ public function __get($name) { if(!in_array(strtolower($name),array('isguest','isinitialized')) && substr(strtolower($name),0,2) == 'is') { if($this->isGuest) return false; $checkRole = substr(strToLower($name),2); foreach($this->roles as $role) { if(strtolower(str_replace(array(" ","_"),"",$role)) == $checkRole) { return true; } } return false; } return parent::__get($name); } public function getRole(){ $user = Users::model()->findByPk((int)$this->id); return isset($user->role_id) ? $user->role_id : 0 ; } public function getRoleURL(){ $user = Users::model()->findByPk((int)$this->id); return $user->users->url; } public function getImie(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->first_name; } public function getNazwisko(){ if($this->isGuest) return false; $user = Users::model()->findByPk((int)$this->id); return $user->last_name; } //Robal start public function getRoleName(){ if($this->isGuest) return false; $role = Users::model()->with('users')->findByPk((int)$this->id); return $role->users->name; }