/**
  * generates an array with controller's data
  * @param string $where string for the getPathOfAlias yii method.
  * @param bool $module if check or not for module names in the controllers path
  * @param string $mode determinates what kind of array this method returns
  */
 private static function extractControllers($where, $module = false, $mode = 'dataProvider')
 {
     foreach (glob(Yii::getPathOfAlias($where) . "/*Controller.php") as $controller) {
         if ($module) {
             if (DIRECTORY_SEPARATOR === '/') {
                 // fix for windows machines
                 self::$_moduleName = preg_replace('/^.*\\/modules\\/(.*)\\/controllers.*$/', '$1', $controller);
             } else {
                 self::$_moduleName = preg_replace('/^.*\\\\modules\\\\(.*)\\\\controllers.*$/', '$1', $controller);
             }
         } else {
             self::$_moduleName = 'Basic';
         }
         $_controllerName = basename($controller, "Controller.php");
         // TODO when stop supporting php 5.2 use lcfirst
         $_controllerName[0] = strtolower($_controllerName[0]);
         self::$_controllerName = $_controllerName;
         $controller_class = ucfirst(self::$_controllerName . 'Controller');
         // extract the value of permission controller inside the controller
         if (!in_array($controller_class, self::$_alreadyIncluded)) {
             // use reflectionClass if a controller with the same class name was not previously included
             // add the controller class to the alreadyIncluded array
             self::$_alreadyIncluded[] = $controller_class;
             if (!in_array($controller_class, self::$_declaredClasses)) {
                 include $controller;
             }
             $class = new ReflectionClass($controller_class);
             if ($class->hasProperty('_permissionControl')) {
                 $permissionControl = $class->getStaticPropertyValue('_permissionControl');
             } else {
                 $permissionControl = NULL;
             }
         } else {
             // parse the file if a controller with the same class name was previously included
             // get the controller file content
             $controller_file = file_get_contents($controller, false, NULL, 0);
             // check if there is permissionControl inside it
             if (strpos($controller_file, 'permissionControl') !== false) {
                 // get portion of the file containing permissionControl
                 $controller_file = substr($controller_file, strpos($controller_file, 'permissionControl'));
                 $controller_file = substr($controller_file, 0, strpos($controller_file, ';'));
                 $permissionControl = eval('return $' . $controller_file . ';');
             } else {
                 $permissionControl = NULL;
             }
         }
         // check the value of permissionControl and skip this controller if necessary
         if ($permissionControl === false || count($permissionControl) === 1 && isset($permissionControl['label']) && $mode === 'dataProvider') {
             continue;
         }
         if ($mode === 'dataProvider') {
             self::$_rawData[] = array('id' => NULL, 'Module' => self::$_moduleName, 'Controller' => isset($permissionControl['label']) ? $permissionControl['label'] : self::$_controllerName, 'Read' => self::infoButton($permissionControl, 'read'), 'Write' => self::infoButton($permissionControl, 'write'), 'Admin' => self::infoButton($permissionControl, 'admin'));
         } else {
             if ($mode === 'homeList') {
                 self::$_rawData['/' . (self::$_moduleName === 'Basic' ? NULL : self::$_moduleName . '/') . self::$_controllerName] = (self::$_moduleName === 'Basic' ? NULL : self::$_moduleName . ': ') . (isset($permissionControl['label']) ? $permissionControl['label'] : self::$_controllerName);
             }
         }
     }
 }
 /**
  * parameters preparation after a select is executed
  */
 public function afterFind()
 {
     // retrieve the group name
     $this->group_name = $this->relUserGroupsGroup->groupname;
     // retrieve the user access permission's arra
     if ((int) $this->id === self::ROOT) {
         $this->access = self::ROOT_ACCESS;
     } else {
         $this->access = UserGroupsAccess::findRules(UserGroupsAccess::USER, $this->id);
     }
     // copy the level of it's own group
     $this->level = $this->relUserGroupsGroup->level;
     // copy the group home
     $this->group_home = $this->relUserGroupsGroup->home;
     // get the user readable home
     $home_array = UserGroupsAccess::homeList();
     if ($this->home) {
         $this->readable_home = isset($home_array[$this->home]) ? $home_array[$this->home] : $this->home;
     } else {
         $this->readable_home = isset($home_array[$this->group_home]) ? $home_array[$this->group_home] . ' - <i><b>Inherited from Group</b></i>' : $this->group_home;
     }
     parent::afterFind();
 }
예제 #3
0
 /**
  * parameters preparation after a select is executed
  */
 public function afterFind()
 {
     if (!$this->notUseAfrefind && Yii::app()->controller->action->id != 'NotSentEmails') {
         if (!$this->relProfile) {
             $this->relProfile = new Profile();
             $this->relProfile->ug_id = $this->id;
             $this->relProfile->save();
         }
         // retrieve the group name
         $this->group_name = $this->relUserGroupsGroup->groupname;
         // retrieve the user access permission's arra
         if ((int) $this->id === self::ROOT) {
             $this->access = self::ROOT_ACCESS;
         } else {
             $this->access = UserGroupsAccess::findRules(UserGroupsAccess::USER, $this->id);
         }
         // copy the level of it's own group
         $this->level = $this->relUserGroupsGroup->level;
         // copy the group home
         $this->group_home = $this->relUserGroupsGroup->home;
         //Получение параметров
         if ($this->params) {
             $this->params = unserialize($this->params);
         } else {
             $this->params = array_keys($this->ParamsFields);
         }
         // get the user readable home
         $home_array = UserGroupsAccess::homeList();
         if ($this->home) {
             $this->readable_home = isset($home_array[$this->home]) ? $home_array[$this->home] : $this->home;
         } else {
             $this->readable_home = isset($home_array[$this->group_home]) ? $home_array[$this->group_home] . ' - <i><b>Inherited from Group</b></i>' : $this->group_home;
         }
     }
     parent::afterFind();
 }
예제 #4
0
	<div class="form">

	<?php 
$form = $this->beginWidget('CActiveForm', array('id' => 'user-groups-misc-form', 'enableAjaxValidation' => true, 'enableClientValidation' => true));
?>
		<p class="note">Fields with <span class="required">*</span> are required.</p>

		<?php 
if (UserGroupsConfiguration::findRule('personal_home') || Yii::app()->user->pbac(array('user.admin', 'admin.admin'))) {
    ?>
		<div class="row">
			<?php 
    echo $form->labelEx($miscModel, 'home');
    ?>
			<?php 
    $home_lists = UserGroupsAccess::homeList();
    array_unshift($home_lists, Yii::t('userGroupsModule.admin', 'Group Home: {home}', array('{home}' => $miscModel->relUserGroupsGroup->home)));
    ?>
			<?php 
    echo $form->dropDownList($miscModel, 'home', $home_lists);
    ?>
			<?php 
    echo $form->error($miscModel, 'home');
    ?>
		</div>
		<?php 
}
?>
		<div class="row">
			<?php 
echo $form->labelEx($miscModel, 'email');
예제 #5
0
 /**
  * parameters preparation after a select is executed
  */
 public function afterFind()
 {
     // load the access permissions for the group
     $this->access = UserGroupsAccess::findRules(UserGroupsAccess::GROUP, $this->id);
     parent::afterFind();
 }
 /**
  * deletes the item from the database
  * @param Array $formData
  */
 private function itemDelete($formData)
 {
     // check if the user performing the action has the permission to do it
     if (!Yii::app()->user->pbac('admin')) {
         Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'You don\'t have the permission to delete any user/group'));
     } else {
         // check if the user is trying to delete a valid id
         if (Yii::app()->request->isPostRequest && $formData['id'] !== 'new' && (int) $formData['id'] !== UserGroupsUser::ROOT) {
             // load the item to delete
             if ((int) $formData['what'] === UserGroupsAccess::GROUP) {
                 $model = UserGroupsGroup::model()->findByPk((int) $formData['id']);
             } else {
                 if ((int) $formData['what'] === UserGroupsAccess::USER) {
                     $model = UserGroupsUser::model()->findByPk((int) $formData['id']);
                 }
             }
             if ($model) {
                 // check if your level is higher then the user/group you are about to delete
                 if ($model->level < Yii::app()->user->level) {
                     if ($model->delete() && UserGroupsAccess::model()->deleteAll('element = ' . $formData['what'] . ' AND element_id = ' . $formData['id'])) {
                         Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', '{what} deleted.', array('{what}' => ucfirst($formData['displayname']))));
                     } else {
                         Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'Impossible to delete the requested user/group. An Error Occurred'));
                     }
                 } else {
                     Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'You cannot delete a user/group with a higher level then yours.'));
                 }
             } else {
                 Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'The requested user/group does not exist and cannot be deleted.'));
             }
         } else {
             Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'Invalid Request.'));
         }
     }
     $this->redirect(Yii::app()->baseUrl . '/userGroups/admin');
 }