예제 #1
0
 public function uniquePair($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $rolesMenus = RolesMenus::model()->find('t.menu_id =' . $this->menu_id . ' AND t.role_id = ' . $this->role_id);
         if (!empty($rolesMenus)) {
             $this->addError('role_id', 'Role has been exist');
         }
     }
 }
예제 #2
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         /*
                     $menus = Menus::model()->findAll();
                     $idChild = Menus::model()->findAllChild($id,$menus);
                     if(count($idChild)>0)
                         Menus::model()->deleteByPk($idChild);
         */
         $this->loadModel($id)->delete();
         RolesMenus::model()->deleteAll(array('condition' => 'menu_id = ' . $id));
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         Yii::log('Invalid request. Please do not repeat this request again.');
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
예제 #3
0
 public function showMenu()
 {
     if (Yii::app()->session['LOGGED_USER'] != null) {
         $userObj = new Users();
         $userObj = Yii::app()->session['LOGGED_USER'];
         $value = '';
         $userRoleId = $userObj->role_id;
         $appicationId = Roles::getAppicationIdByRoleId($userRoleId);
         if ($appicationId != BE) {
             Yii::app()->user->logout();
             Yii::app()->controller->redirect(Yii::app()->createAbsoluteUrl('admin/site/login'));
         }
         $userRoleMenu = RolesMenus::model()->findAll(array('condition' => 'role_id=' . $userRoleId));
         $userRoleMenuId = array();
         if ($userRoleMenu) {
             foreach ($userRoleMenu as $u) {
                 $userRoleMenuId[] = $u->menu_id;
             }
         }
         $menusTemp = Menus::model()->findAll(array('condition' => 'show_in_menu="1"', 'order' => 'display_order asc'));
         // MAY 12, 2014 ANH DUNG ADD
         $menus = array();
         foreach ($menusTemp as $menuTemp) {
             if ($menuTemp->menu_link == '') {
                 $menus[] = $menuTemp;
                 continue;
             }
             $aLinks = explode('/', $menuTemp->menu_link);
             $c = '';
             // controller name
             $a = '';
             // action name
             if (count($aLinks) == 2) {
                 $c = $aLinks[1];
                 $a = 'Index';
             } elseif (count($aLinks) == 3) {
                 $c = $aLinks[1];
                 $a = ucfirst($aLinks[2]);
             }
             $aActionAllowed = ActionsUsers::getActionArrayAllowForCurrentUserByControllerName($c);
             $aActionAllowed = array_map('strtolower', $aActionAllowed);
             $aActionAllowed = array_map('trim', $aActionAllowed);
             // Now 14, 2014 ANH DUNG ADD
             if (in_array(strtolower($a), $aActionAllowed)) {
                 $menus[] = $menuTemp;
             }
         }
         // MAY 12, 2014 ANH DUNG ADD
         $this->str = "<ul class='nav'>";
         $this->str .= "<li class='nav_li'><a href='" . Yii::app()->createAbsoluteUrl('/admin') . "'>Home</a></li>";
         if ($menus != NULL) {
             $this->findchild(0, $menus, $value, $userRoleMenuId);
         }
         $this->str .= "</ul>";
         if (Yii::app()->user->id) {
             if (isset(Yii::app()->user->application_id) && Yii::app()->user->application_id == BE) {
                 return $this->str;
             } else {
                 return '';
             }
         } else {
             return '';
         }
     }
     return '';
 }
예제 #4
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = RolesMenus::model()->findByPk($id);
     if ($model === null) {
         Yii::log('The requested page does not exist.');
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #5
0
파일: Roles.php 프로젝트: jasonhai/onehome
 public function adminDelete()
 {
     // 1 delete foreign table Roles
     RolesMenus::model()->deleteAllByAttributes(array('role_id' => $this->id));
     // 2 delete foreign table Menus
     Users::model()->deleteAllByAttributes(array('role_id' => $this->id));
     // 4 delete table Applications
     $this->delete();
 }
예제 #6
0
 protected function checkControllerAccessRules($controller, $application)
 {
     if (empty($controller)) {
         $accessArray = array();
         $accessArray[] = array('deny', 'users' => array('*'));
     } else {
         $menu = Menus::model()->findAll(array('condition' => 'controller_name = "' . $controller . '" AND application_id =' . $application));
         if (!empty($menu)) {
             $list_menu_id = '';
             for ($i = 0; $i < count($menu); ++$i) {
                 $v = $menu[$i];
                 if ($i == count($menu) - 1) {
                     $list_menu_id .= $v->id;
                 } else {
                     $list_menu_id .= $v->id . ',';
                 }
             }
             //echo $list_menu_id;
             $list_menu = $list_menu_id;
             $list_menu_id = explode(",", $list_menu_id);
             $criteria = new CDbCriteria();
             $criteria->addInCondition('t.menu_id', $list_menu_id, 'AND');
             $criteria->group = 't.role_id';
             $menu_role = RolesMenus::model()->findAll($criteria);
             $accessArray = array();
             /*
             $accessArray[] = array('allow',  // allow all users to perform 'index' and 'view' actions
                 'actions'=>array('index','view'),
                 'users'=>array('*')
             );
             print_r($accessArray);
             */
             if (!empty($menu_role)) {
                 for ($i = 0; $i < count($menu_role); ++$i) {
                     $v = $menu_role[$i];
                     //echo $v->role_id;
                     $menuOfRole = RolesMenus::model()->findAll('menu_id IN (' . $list_menu . ') AND role_id=' . $v->role_id);
                     $action_name = '';
                     for ($t = 0; $t < count($menuOfRole); ++$t) {
                         $w = $menuOfRole[$t];
                         if ($t === count($menuOfRole) - 1) {
                             $action_name .= $w->actions;
                         } else {
                             if (!empty($w->actions)) {
                                 $action_name .= $w->actions . ",";
                             }
                         }
                     }
                     $action_name = explode(",", trim($action_name));
                     $accessArray[] = array('allow', 'actions' => $action_name, 'users' => array('@'), 'expression' => 'isset($user->role_id) && (Yii::app()->user->role_id == ' . $v->role_id . ')');
                 }
                 $accessArray[] = array('deny', 'users' => array('*'));
                 //print_r($accessArray);
             } else {
                 $accessArray = array();
                 $accessArray[] = array('allow', 'users' => array('*'));
             }
         } else {
             $accessArray = array();
             $accessArray[] = array('allow', 'users' => array('*'));
         }
     }
     //print_r($accessArray);
     return $accessArray;
 }