public function selectAllByUserId($id) { $criteria = new CDbCriteria(); $criteria->condition = 'user_id=:id'; $criteria->params = array(':id' => $id); return UserRole::model()->findAll($criteria); }
public static function itemAlias($type, $code = NULL) { $_items = array('UserStatus' => array(self::STATUS_NOACTIVE => UserModule::t('Not active'), self::STATUS_ACTIVE => UserModule::t('Active'), self::STATUS_BANNED => UserModule::t('Banned')), 'AdminStatus' => array('0' => UserModule::t('No'), '1' => UserModule::t('Yes')), 'UserRoleStatus' => [CHtml::listData(UserRole::model()->findAll(array('select' => 'id, user_role', 'order' => 'user_role')), 'id', 'user_role')]); if (isset($code)) { return isset($_items[$type][$code]) ? $_items[$type][$code] : false; } else { return isset($_items[$type]) ? $_items[$type] : false; } }
public function testUserSavesRolesOnSave() { $model = $this->getModel(); $model->use_username = self::USERNAME; $model->roles = $roles = UserRole::model()->findAll(); $model->save(false); /** @var $model User */ $model = User::model()->findByPk($model->use_id); $this->assertTrue(is_array($model->roles)); $this->assertEquals(count($roles), count($model->roles)); }
public function loggedIn($record) { ## set id and role $this->id = $record->id; ## set role $role = UserRole::model()->findByAttributes(['user_id' => $this->id, 'is_default_role' => 'Yes']); $this->setState('fullRole', $role->role['role_name']); $rootRole = Helper::explodeFirst(".", $role->role['role_name']); $this->setState('role', $rootRole); $this->setState('roleId', $role->id); ## reset error code $this->errorCode = self::ERROR_NONE; }
/** * Правила доступа к backend */ public function accessRules() { $rolesAdm = array('admin'); //по умолчанию //Получаем админов $model_adm = UserRole::model()->findAll('access_level=10'); if ($model_adm) { foreach ($model_adm as $adm_key) { $rolesAdm[] = $adm_key->name; } } return array(array('allow', 'roles' => $rolesAdm), array('allow', 'actions' => array('login', 'logout', 'access', 'error', 'recover'), 'users' => array('*')), array('deny', 'users' => array('*'))); }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { // find user record by email address (username) $UserLogin = UserLogin::model()->findByAttributes(array('LoginEmail' => $this->username, 'IsActive' => 1)); if ($UserLogin === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($UserLogin->UserPassword !== md5($this->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->errorCode = self::ERROR_NONE; // set user login ID $this->userLoginID = $UserLogin->UserLoginID; // assign user role in auth manager $userRole = UserRole::model()->findByPk($UserLogin->UserRoleID)->RoleType; $currentRoles = Yii::app()->authManager->getRoles($this->userLoginID); if (!array_key_exists($userRole, $currentRoles)) { // remove old role if role changes if (!empty($currentRoles)) { AuthAssignment::model()->deleteAll('userid = :userid', array('userid' => $this->userLoginID)); } Yii::app()->authManager->assign($userRole, $this->userLoginID); Yii::app()->authManager->save(); } // UserProfile //$UserProfile = UserProfile::model()->findByAttributes(array('UserLoginID'=>$UserLogin->UserLoginID)); $UserProfile = UserProfile::model()->with('companies')->findByAttributes(array('UserLoginID' => $UserLogin->UserLoginID)); // echo '<pre>'; // print_r($UserProfile); // die(); // create session variables $this->setState('fullName', sprintf('%s %s', $UserProfile->FirstName, $UserProfile->LastName)); // full user name $this->setState('companyID', $UserProfile->CompanyID); // user email $this->setState('userProfileID', $UserProfile->UserProfileID); // user email $this->setState('email', $UserLogin->LoginEmail); // user email $this->setState('companyName', $UserProfile->companies->CompanyName); // user email $this->setState('agreeToTerms', $UserProfile->AgreeToTerms); // user email $this->setState('isFacilitator', $UserProfile->IsFacilitator); // user email $this->setState('UserRoleID', $UserLogin->UserRoleID); // user email } } return !$this->errorCode; }
public function init() { if (Yii::app()->user->isGuest) { $this->redirect('/'); } $modleRole = UserRole::model()->find('name LIKE "' . Yii::app()->user->role . '"')->id; $modelSiteModel = SiteModule::model()->find('templates LIKE "' . $this->module_template_name . '"'); if ($modleRole && $modelSiteModel) { $modelRule = UserGroupRule::model()->find('user_role_id = ' . $modleRole . ' AND module_id=' . $modelSiteModel->id); if ($modelRule) { $this->rule = $modelRule->access_type; } } }
public function testUserCreate() { $this->deleteUser(); $this->login(); $this->url('admin4/user/create'); $this->assertRegExp('/admin v4 - create user/i', $this->title()); $this->byId('User_use_username')->value(self::USERNAME); $this->byId('User_use_password')->value(self::PASSWORD); $this->byId('User_use_fname')->value(self::SURNAME); $this->byId('User_use_sname')->value(self::EMAIL); $this->byId('User_use_email')->value(self::EMAIL); /** @var $roles UserRole[] */ $roles = UserRole::model()->findAll(); foreach ($roles as $role) { $this->byId('User_role_' . $role->rol_id)->click(); } $this->byId('user-form')->submit(); $this->assertRegExp('/admin4\\/user\\/update/i', $this->url()); $this->getBrowser(); // $this->assertRegExp('/succesfully created/i', $this->source()); }
public function afterLogin($fromCookie) { if ($fromCookie) { Yii::app()->user =& $this; } $oUser = User::model()->findByPk($this->id); $this->roleid = $oUser->roleid; $this->rolename = $oUser->Role->name; $this->roletype = $oUser->Role->type; $this->realname = $oUser->realname; $this->status = $oUser->status; $this->lang = $oUser->lang; $this->view_all = $oUser->view_all; $model = UserRole::model()->findByPk($this->roleid); if ($oUser->Role->purview == 'admin') { $this->perm = Module::getUserPerm('admin'); } else { $this->perm = Module::getUserPerm(json_decode($model->purview, true)); } $this->publishers = UserResource::getUserPublisher(); }
/** * Возращает скидку на товар. * Входные параметры: $count - количество заказаного товара, $model - модель скидки (таблица tbl_catalog_elements_discount) * Выходные параметры - возращает размер скидки (ИЗ ЦЕНЫ СКИДКА НЕ ВЫЧИТАЕТСЯ) */ public function returnDiscount($price, $count, $model) { $discount = 0; //Проверяем права на получение скитки if (($model->user_role_id == 0 || UserRole::model()->returnUserRule(Yii::app()->user->id) == $model->user_role_id) && $count >= $model->count) { switch ($model->type) { case 1: //Фиксированая $discount = $model->values; break; case 2: //В процентах $discount = $price * ($model->values / 100); break; } } return $discount; }
public function actionSaveuserrole() { $organid = $this->Getorganid(); $roleids = $_POST['roleids']; $employeeID = $_POST['userid']; $findmodel = UserRole::model()->findAll("EmployeeID=:userid", array(':userid' => $employeeID)); if (!empty($employeeID)) { if (!empty($roleids)) { $roleids = substr($roleids, 0, strlen($roleids) - 1); $roleids = explode(',', $roleids); if (count($findmodel) == 0) { $i = 0; foreach ($roleids as $roleid) { $model = new UserRole(); $model->RoleID = $roleid; $model->EmployeeID = $employeeID; $model->OrganID = $organid['OrganID']; $model->UserID = $organid['id']; $model->CreateTime = time(); $result = $model->save(); if ($result) { $i++; } } if ($i == count($roleids)) { $message = "保存成功"; } else { $message = "保存失败"; } } else { foreach ($findmodel as $key => $val) { if (!in_array($val->RoleID, $roleids)) { $delcount = UserRole::model()->deleteByPk($val->ID); } } foreach ($roleids as $roleid) { $findmodel = UserRole::model()->findAll("RoleID=:roleid and EmployeeID=:urid", array(':roleid' => $roleid, ':urid' => $employeeID)); if (empty($findmodel)) { $model = new UserRole(); $model->RoleID = $roleid; $model->EmployeeID = $employeeID; $model->OrganID = $organid['OrganID']; $model->UserID = $organid['id']; $model->CreateTime = time(); $result = $model->save(); } } $findmodel = UserRole::model()->findAll("EmployeeID=:userid", array(':userid' => $employeeID)); if (count($roleids) == count($findmodel)) { $message = "保存成功"; } else { $message = "保存失败"; } } } else { $result = UserRole::model()->deleteAll("EmployeeID=:userid", array(":userid" => $employeeID)); if ($result > 0) { $message = "保存成功"; } else { $message = "保存失败"; } } } else { $message = "保存失败"; } echo json_encode($message); }
?> <h4 class='alert alert-success centered hide-on-click'> <?php echo Yii::t("UserAdminModule.admin", "Saved"); ?> </h4> <?php } ?> <?php $roleForm = $this->beginWidget('CActiveForm'); ?> <?php echo $roleForm->checkBoxList($model, 'roleIds', CHtml::listData(UserRole::model()->findAll(), 'code', 'name'), array('template' => "<label class='checkbox'>{input} {label}</label>", 'separator' => '')); ?> <br> <?php echo CHtml::htmlButton('<i class="icon-ok icon-white"></i> ' . Yii::t("UserAdminModule.admin", "Save"), array('class' => 'btn btn-info', 'type' => 'submit')); ?> <?php $this->endWidget(); ?> </td> <td style='padding:0 10px;'> <?php if (Yii::app()->user->getFlash('taskSaved')) {
public function actionEdit() { // check permissions if (!Yii::app()->user->checkAccess('manageUser')) { Helper::authException(); } // make sure a user login id is defined $userLoginId = Helper::verifyId($_GET['id'], 'UserLogin'); // models $UserLogin = UserLogin::model()->findByPk($userLoginId); $UserProfile = UserProfile::model()->findByAttributes(array('UserLoginID' => $userLoginId)); // role array for select $userRoles = UserRole::model()->findAll(); $rolesArray = array(); foreach ($userRoles as $UserRole) { if ($UserRole->RoleType != 'godAdministrator') { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } elseif (Helper::hasRole('godAdministrator') || $UserLogin->UserRoleID == $UserRole->UserRoleID) { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } } // add default (empty value) to front of array $rolesArray = array('' => '') + $rolesArray; // make sure associated rows were found in our models if ($UserLogin == null || $UserProfile == null) { throw new CHttpException(404, 'A User with the specified ID could not be found.'); } // form processing if (isset($_POST['UserLogin'], $_POST['UserProfile'])) { // redirect to the dashboard if 'Cancel' button clicked if (isset($_POST['button-cancel'])) { $this->redirect($this->createUrl('user/dashboard')); } // set UserLogin attributes and scenario $UserLogin->attributes = $_POST['UserLogin']; $UserLogin->scenario = 'edit'; // set UserProfile attributes $UserProfile->attributes = $_POST['UserProfile']; // validate form submission $valid = $UserLogin->validate(); $valid = $UserProfile->validate() && $valid; if ($valid) { // save UserLogin if (!$UserLogin->save(false)) { throw new CHttpException(400, 'Error when trying to save user changes.'); } // save UserProfile if (!$UserProfile->save(false)) { throw new CHttpException(400, 'Error when trying to save user changes.'); } // set success message for user Yii::app()->user->setFlash('success', 'User successfully updated.'); // redirect to user dashboard $this->redirect($this->createUrl('user/dashboard')); } } // clear password $UserLogin->UserPassword = null; // render view $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray, 'isEdit' => true)); }
<?php //echo $form->error($model,'superuser'); ?> </div> </div> --> <div class="row form-group"> <div class="col-md-3 control-label"> <?php echo $form->labelEx($model, 'user_role'); ?> </div> <div class="col-md-4"> <?php //echo $form->dropDownList($model,'user_role',User::itemAlias('AdminStatus')); echo $form->dropDownList($model, 'user_role', CHtml::listData(UserRole::model()->findAll(array('select' => 'id, user_role', 'order' => 'user_role')), 'id', 'user_role'), array('empty' => '- Select -', 'class' => 'form-control input-md')); ?> <?php echo $form->error($model, 'user_role'); ?> </div> </div> <div class="row form-group"> <div class="col-md-3 control-label"> <?php echo $form->labelEx($model, 'status'); ?> </div> <div class="col-md-4"> <?php
/** * 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 $id the ID of the model to be loaded * @return UserRole the loaded model * @throws CHttpException */ public function loadModel($id) { $model = UserRole::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'user-form', 'enableAjaxValidation' => false, 'enableClientValidation' => false, 'type' => 'horizontal')); ?> <?php echo $form->errorSummary($model); ?> <?php echo $form->textFieldRow($model, 'description', array('class' => 'span5', 'maxlength' => 32)); ?> <?php echo $form->textFieldRow($model, 'name', array('class' => 'span5', 'maxlength' => 254)); ?> <?php echo $form->dropDownListRow($model, 'access_level', UserRole::model()->getLvlAccess(), array('class' => 'span5')); ?> <div class="form-actions"> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'htmlOptions' => array('style' => 'margin-right: 20px'), 'label' => $model->isNewRecord ? Yii::t('Bootstrap', 'PHRASE.BUTTON.CREATE') : Yii::t('Bootstrap', 'PHRASE.BUTTON.SAVE'))); ?> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'htmlOptions' => array('name' => 'go_to_list', 'style' => 'margin-right: 20px'), 'label' => $model->isNewRecord ? Yii::t('Bootstrap', 'PHRASE.BUTTON.CREATE_RETURN') : Yii::t('Bootstrap', 'PHRASE.BUTTON.SAVE_RETURN'))); ?> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'link', 'label' => Yii::t('Bootstrap', 'PHRASE.BUTTON.RETURN'), 'url' => $this->listUrl('role')));
public function deleteRolesOfUser($user_id) { UserRole::model()->deleteAll('user_id =' . $user_id); //return number affected line }
public function actionDelemployee() { $employeeid = $_GET['employeeid']; $resule = Profile::model()->deleteAll("user_id =:id", array(":id" => $employeeid)); $resule = UserDepart::model()->deleteAll("EmployeeID=:id", array(":id" => $employeeid)); $resule = UserRole::model()->deleteAll("EmployeeID=:id", array(":id" => $employeeid)); $resule = User::model()->deleteAll("id =:id", array(":id" => $employeeid)); echo $resule; }
public function getStatus_diagnostic_order($id) { $model = Order::model()->findByPk($id); if ($model->technician_order_id == Yii::app()->user->id) { if ($model->status_order_id == 4) { //si la orden esta en diagnóstico finalizado return false; } $modelUserRole = UserRole::model()->find('user_id=:user_id AND role_id=:role_id', array(':user_id' => $model->technician_order_id, ':role_id' => 2)); if (!empty($modelUserRole)) { if ($model->status_order_id == 2 || $model->status_order_id == 3) { return true; } else { return false; } } else { return false; } } else { return false; } }
public function addRoleByUsers($id, $roleId, $change) { if ($change == '1') { $userRole = new UserRole(); $userRole->role_id = $roleId; $userRole->user_id = $id; $userRole->save(); } elseif ($change == '2') { $criteria = new CDbCriteria(); $criteria->condition = 'user_id=:userId AND role_id=:roleId'; $criteria->params = array(':userId' => $id, ':roleId' => $roleId); $userRole = UserRole::model()->find($criteria); //error_log(print_r($userRole,1)); $userRole->delete(); } }
<?php /** * @var $model User[] * @var $roles UserRole[] */ ?> <?php $roles = UserRole::model()->findAll(); foreach ($roles as $role) { ?> <div class="control-group"> <label class="control-label" for="<?php echo 'User_role_' . $role->rol_id; ?> "><?php echo $role->rol_title; ?> </label> <div class="controls"> <?php echo CHtml::checkBox('User[role][' . $role->rol_id . ']', $model->userBelongsToRole($role->rol_id)); ?> </div> </div> <?php }
$this->menu = array(array('label' => UserModule::t('Create User'), 'url' => array('create')), array('label' => UserModule::t('Manage Users'), 'url' => array('admin')), array('label' => UserModule::t('List User'), 'url' => array('/user'))); Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n \$('.search-form').toggle();\n return false;\n});\t\n\$('.search-form form').submit(function(){\n \$.fn.yiiGridView.update('user-grid', {\n data: \$(this).serialize()\n });\n return false;\n});\n"); ?> <h1><?php echo UserModule::t("Manage Users"); ?> </h1> <p><?php echo UserModule::t("You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b> or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done."); ?> </p> <?php echo CHtml::link(UserModule::t('Advanced Search'), '#', array('class' => 'search-button')); ?> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> <?php $this->widget('bootstrap.widgets.TbGridView', array('id' => 'user-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'template' => "{items}\n{pager}{summary}", 'enablePagination' => true, 'type' => TbHtml::GRID_TYPE_BORDERED, 'columns' => array(array('name' => 'username', 'type' => 'raw', 'value' => 'CHtml::link(UHtml::markSearch($data,"username"),array("admin/view","id"=>$data->id))'), array('name' => 'email', 'type' => 'raw', 'value' => 'CHtml::link(UHtml::markSearch($data,"email"), "mailto:".$data->email)'), 'create_at', 'lastvisit_at', array('name' => 'user_role', 'value' => function ($data) { $ss = UserRole::model()->findByAttributes(array("id" => $data->user_role)); if ($ss) { return $ss->user_role; } else { return '-'; } }), array('name' => 'status', 'value' => 'User::itemAlias("UserStatus",$data->status)', 'filter' => User::itemAlias("UserStatus")), array('class' => 'CButtonColumn', 'htmlOptions' => array('width' => '200px')))));
<div class="content"> <div class="title"><h5>Danh sách thành viên</h5></div> <div class="table"> <?php $this->widget('zii.widgets.grid.CGridView', array('dataProvider' => $model->search(), 'filter' => $model, 'itemsCssClass' => 'display', 'filterCssClass' => 'ui-state-default', 'summaryCssClass' => 'head', 'summaryText' => '<h5 class="iFrames">Danh sách thành viên</h5><label>Hiển thị từ {start} đến {end} trên {count} bản ghi</label>', 'rowCssClass' => array('gradeA odd', 'gradeA even'), 'pagerCssClass' => 'dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers', 'columns' => array(array('name' => 'user_id', 'value' => '1 + $row + ($this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize)', 'filter' => false), 'first_name', 'last_name', array('name' => 'email', 'type' => 'raw', 'value' => 'CHtml::link(CHtml::encode($data->email), $data->getAdminUrl())'), 'created_date', array('name' => 'state', 'filter' => array(1 => 'Active', 0 => 'Non Active'), 'value' => '$data->getState()'), array('name' => 'state', 'filter' => CHtml::listData(UserRole::model()->findAll(), 'user_role_id', 'role_name'), 'value' => '$data->getUserRole()'), array('class' => 'CButtonColumn')))); ?> </div> </div>
public function deleteRole($id) { $criteria = new CDbCriteria(); //$criteria->addInCondition('role_id',$id); $criteria->condition = 'role_id=:roleId'; $criteria->params = array(':roleId' => $id); UserRole::model()->deleteAll($criteria); //UserRole::model()->deleteByPk(14); Role::model()->deleteByPk($id); }
public function actionEdit() { // check permissions if (!Yii::app()->user->checkAccess('manageUser')) { // Helper::authException(); } // make sure a user login id is defined // $userLoginId = Helper::verifyId($_GET['id'], 'UserLogin'); $userLoginId = $_GET['id']; // models $UserLogin = UserLogin::model()->findByPk($userLoginId); $UserProfile = UserProfile::model()->findByAttributes(array('UserLoginID' => $userLoginId)); $criteria3 = new CDbCriteria(); $criteria3->condition = '(companyID = :companyID AND IsActive=1)'; $criteria3->params = array(':companyID' => Yii::app()->user->companyID); $criteria3->order = 'Email'; $userManagers = UserProfile::model()->with('userLogin')->findAllByAttributes(array(), $criteria3); $managersArray = array(); $managersArray[0] = "Please Select..."; foreach ($userManagers as $UserManager) { if (!$UserManager) { if ($UserManager->ManagerEmail == '') { $managersArray[$UserManager->Email] = $UserManager->Email; } } } // add default (empty value) to front of array $managerArray = $managersArray; // role array for select $userRoles = UserRole::model()->findAll(); $rolesArray = array(); foreach ($userRoles as $UserRole) { if ($UserRole->RoleType != 'lacekAdministrator') { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } elseif (Helper::hasRole('lacekAdministrator') || $UserLogin->UserRoleID == $UserRole->UserRoleID) { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } } // add default (empty value) to front of array $rolesArray = array('' => '') + $rolesArray; // make sure associated rows were found in our models if ($UserLogin == null || $UserProfile == null) { throw new CHttpException(404, 'A User with the specified ID could not be found.'); } // form processing if (isset($_POST['UserLogin'], $_POST['UserProfile'])) { // redirect to the dashboard if 'Cancel' button clicked if (isset($_POST['button-cancel'])) { $this->redirect($this->createUrl('user/dashboard')); } // set UserLogin attributes and scenario $UserLogin->attributes = $_POST['UserLogin']; $UserLogin->scenario = 'edit'; // set UserProfile attributes $UserProfile->attributes = $_POST['UserProfile']; // validate form submission $valid = $UserLogin->validate(); $valid = $UserProfile->validate() && $valid; //TODO /* if($UserProfile->ManagerEmail){ $UserProfilex = UserProfile::model()->findByAttributes(array( 'Email' => $UserProfile->ManagerEmail, )); $candidateModel = new Candidate(); $candidateModel->CompanyID=$UserProfile->CompanyID; $candidateModel->FirstName=$UserProfile->FirstName; $candidateModel->MiddleName=$UserProfile->MiddleName; $candidateModel->LastName=$UserProfile->LastName; $candidateModel->Title=$UserProfile->Title; $candidateModel->Email=$UserProfile->Email; $candidateModel->CompanyPositionID=1; $candidateModel->HireDate=date("Y-m-d"); $candidateModel->PositionDate=date("Y-m-d"); $candidateModel->IsActive=1; $candidateModel->UserProfileID=$UserProfilex->UserProfileID; //print_r($candidateModel); // die($UserProfilex->UserProfileID); if ($candidateModel->validate()) { $candidateModel->save(); } else { $errores = $candidateModel->getErrors(); print_r($errores); die(); } } */ if ($valid) { // save UserLogin if (!$UserLogin->save(false)) { throw new CHttpException(400, 'Error when trying to save user changes.'); } // save UserProfile if (!$UserProfile->save(false)) { throw new CHttpException(400, 'Error when trying to save user changes.'); } // set success message for user Yii::app()->user->setFlash('success', 'User successfully updated.'); // redirect to user dashboard $this->redirect($this->createUrl('user/dashboard')); } } // clear password $UserLogin->UserPassword = null; // render view $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray, 'managersArray' => $managerArray, 'isEdit' => true)); }
<?php $this->breadcrumbs = ['Ledgers' => ['admin'], 'Manage']; $baseUrl = Yii::app()->theme->baseUrl; // foreach(Yii::app()->user->getFlashes() as $key => $message) { // echo '<div class="alert alert-info span5"><div class="flash-' . $key . '">' . $message . "</div></div>\n"; // } $id = Yii::app()->user->id; $user_data = Users::model()->findByPk($id); $user_role_id = $user_data->user_role; //$access_level = 5; $access_buttons = ''; $ledgar_access = ''; if ($user_role_id > 0) { $user_rols = UserRole::model()->findByPk($user_role_id); if ($user_rols) { //$access_level = json_decode($user_rols->ledger_access_level); $ledger_create = 0; $ledger_edit = 0; $ledger_delete = 0; $ledger_status_change = 0; if (isset($user_rols->ledger_access_level) && $user_rols->ledger_access_level !== '') { $ledgar_access = json_decode($user_rols->ledger_access_level); $ledger_create = $ledgar_access->create; $ledger_edit = $ledgar_access->edit; $ledger_delete = $ledgar_access->delete; $ledger_status_change = $ledgar_access->status_change; } } } $access_buttons = '';
/** * Возращает роль пользователя по его, пользователя, ID * type - тип возращаемого значения. 1-вернет ID записи таблицы tbl_user_role, 2-вернет name записи таблицы tbl_user_role */ public function returnUserRule($id, $type = 1) { if ($model = User::model()->findByPk($id)) { if ($modelRole = UserRole::model()->find('name LIKE "' . $model->role_id . '"')) { return $type == 1 ? $modelRole->id : $modelRole->name; } } return false; }
<?php //Роли по умолчанию $default = array('guest' => array('type' => CAuthItem::TYPE_ROLE, 'description' => 'Гость', 'bizRule' => null, 'data' => null), 'user' => array('type' => CAuthItem::TYPE_ROLE, 'description' => 'Пользователь', 'children' => array('guest'), 'bizRule' => null, 'data' => null), 'manager' => array('type' => CAuthItem::TYPE_ROLE, 'description' => 'Менеджер', 'children' => array('user'), 'bizRule' => null, 'data' => null), 'admin' => array('type' => CAuthItem::TYPE_ROLE, 'description' => 'Администратор', 'children' => array('manager'), 'bizRule' => null, 'data' => null)); $result = array(); foreach (UserRole::model()->findAll() as $data) { $result[$data->name] = array('type' => CAuthItem::TYPE_ROLE, 'description' => $data->description, 'bizRule' => null, 'data' => null); } return !empty($result) ? $result : $default;
<?php $this->breadcrumbs = ['Counterparties' => ['admin'], 'Manage']; $baseUrl = Yii::app()->theme->baseUrl; $id = Yii::app()->user->id; $user_data = Users::model()->findByPk($id); $client_id = $user_data->client_id; //$access_level = 5; $access_buttons = ''; $counterpart_access = ''; if (isset(Yii::app()->user->user_role)) { $user_rols = UserRole::model()->findByPk(Yii::app()->user->user_role); if ($user_rols) { //$access_level = json_decode($user_rols->counterparties_access_level); $counterpart_create = 0; $counterpart_edit = 0; $counterpart_delete = 0; //$counterpart_status_change = 0; if (isset($user_rols->counterparties_access_level) && $user_rols->counterparties_access_level !== '') { $counterpart_access = json_decode($user_rols->counterparties_access_level); $counterpart_create = $counterpart_access->create; $counterpart_edit = $counterpart_access->edit; $counterpart_delete = $counterpart_access->delete; //$counterpart_status_change = $counterpart_access->status_change; } } } $access_buttons = ''; if ($counterpart_create == 1) { $access_buttons .= '{ extend: "create", editor: editor }, '; }
$pageSize = Yii::app()->user->getState("pageSize", 20); ?> <h2><?php echo Yii::t('UserAdminModule.admin', 'User management'); ?> </h2> <?php echo CHtml::link('<i class="icon-plus-sign icon-white"></i> ' . Yii::t('UserAdminModule.admin', 'Create'), array('create'), array('class' => 'btn btn-info')); ?> <?php $form = $this->beginWidget("CActiveForm"); ?> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'user-grid', 'dataProvider' => $model->search(), 'ajaxUpdate' => false, 'filter' => $model, 'columns' => array(array('header' => '№', 'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)', 'htmlOptions' => array('width' => '25', 'class' => 'centered')), array('name' => 'login', 'value' => 'CHtml::link($data->login, array("view", "id"=>$data->id))', 'type' => 'raw'), array('name' => 'findByRole', 'filter' => CHtml::listData(UserRole::model()->findAll(), 'code', 'name'), 'value' => 'User::getRoles($data->roles)'), array('name' => 'is_superadmin', 'filter' => User::getIsSuperAdminList(false), 'value' => 'User::getIsSuperAdminValue($data->is_superadmin)', 'type' => 'raw', 'visible' => User::checkRole('isSuperAdmin'), 'htmlOptions' => array('width' => '55', 'style' => 'text-align:center')), array('name' => 'active', 'filter' => array(1 => 'On', 0 => 'Off'), 'value' => 'UHelper::attributeToggler($data, "active")', 'type' => 'raw', 'htmlOptions' => array('width' => '55', 'style' => 'text-align:center')), array('id' => 'autoId', 'class' => 'CCheckBoxColumn', 'selectableRows' => 2), array('class' => 'CButtonColumn', 'buttons' => array('delete' => array('visible' => '($data->id != Yii::app()->user->id)')), 'header' => CHtml::dropDownList('pageSize', $pageSize, array(20 => 20, 50 => 50, 100 => 100, 200 => 200), array('onchange' => "\$.fn.yiiGridView.update('user-grid',{ data:{pageSize: \$(this).val() }})", 'style' => 'width:50px')))), 'itemsCssClass' => 'table table-hover table-striped table-bordered table-condensed')); ?> <script> function reloadGrid(data) { $.fn.yiiGridView.update('user-grid'); } </script> <?php echo CHtml::ajaxSubmitButton("", array(), array(), array("style" => "visibility:hidden;")); echo CHtml::ajaxSubmitButton(Yii::t("UserAdminModule.admin", "Delete selected"), array("deleteSelected"), array("success" => "reloadGrid"), array("class" => "btn btn-small pull-right", "confirm" => Yii::t("UserAdminModule.admin", "Delete selected elements ?"))); $this->endWidget();