Пример #1
0
 public function checkRole($userID)
 {
     if (Session::get('role') == null) {
         $file = MODEL_PATH . 'AclModel.php';
         if (file_exists($file)) {
             include_once $file;
         }
         $acl = new AclModel();
         $role = $acl->selectAllUserAcl($userID);
         if (empty($role)) {
             $this->error(true);
             return false;
         } else {
             $aclUserId = array();
             foreach ($role as $id) {
                 $aclUserId[] = $id['acl_id'];
             }
             $aclId = implode(',', $aclUserId);
             $roles = $acl->selectAll($aclId);
             $module = array('');
             $controllAction = array('');
             foreach ($roles as $value) {
                 $module[] = trim($value['module']);
                 $temp = explode('|', $value['action']);
                 foreach ($temp as $ac) {
                     $controllAction[] = $value['module'] . '-' . trim($ac);
                 }
             }
             $setRole = array();
             $setRole['module'] = $module;
             $setRole['controllAction'] = $controllAction;
             Session::set('role', $setRole);
         }
     }
     if (Router::$controller != 'index') {
         if (in_array(Router::$controller, Session::get('role')['module']) != 1) {
             $this->error(true);
             return false;
         }
         if (Router::$action != 'default') {
             $check = Router::$controller . '-' . Router::$action;
             echo in_array($check, Session::get('role')['controllAction']) . '<br />';
             if (in_array($check, Session::get('role')['controllAction']) != 1) {
                 $this->error(true);
                 return false;
             }
         }
     }
     $this->index();
 }