public function actionUpdatePrivilege($id)
 {
     if (Yii::app()->user->getIsSuperUser() == false && Yii::app()->user->checkAccess('updateManagerRolePrivilege') == false) {
         throw new CHttpException(403);
     }
     if ($id <= 0) {
         throw new CHttpException(404, '无效ID');
     }
     $managerRole = ManagerRole::model()->findByPk($id);
     if (empty($managerRole)) {
         throw new CHttpException(404, '没有找到 "' . $id . '" 管理员角色数据');
     }
     $form = new UpdateManagerRolePrivilegeForm();
     if (isset($_POST['UpdateManagerRolePrivilegeForm'])) {
         $form->setAttributes(Yii::app()->request->getPost('UpdateManagerRolePrivilegeForm'));
         if ($form->validate()) {
             $privileges = array();
             foreach ($form->privileges as $privilege) {
                 if (empty($privilege) == false) {
                     $privileges[] = $privilege;
                 }
             }
             $managerRole->privileges = implode(',', $privileges);
             if ($managerRole->save(true, array('privileges'))) {
                 $this->setFlashMessage(strtr('管理员角色<b>{name}</b> 权限已更新 {link}', array('{name}' => $managerRole->name, '{link}' => CHtml::link('查看', array('updatePrivilege', 'id' => $managerRole->manager_role_id)))));
                 $this->redirect($this->getReturnUrl());
             } else {
                 $this->setFlashMessage('更新管理员角色数据失败');
             }
         }
     } else {
         $form->privileges = $managerRole->getPrivilegeArray();
     }
     $privileges = ManagerRole::$privileges;
     $this->breadcrumbs = array('管理员角色' => $this->createUrl('index'), '权限');
     $this->render('updatePrivilege', array('managerRole' => $managerRole, 'form' => $form, 'privileges' => $privileges, 'returnUrl' => $this->getReturnUrl()));
 }
 public function actionUpdate($id)
 {
     if (Yii::app()->user->getIsSuperUser() == false && Yii::app()->user->checkAccess('updateManager') == false) {
         throw new CHttpException(403);
     }
     $manager = Manager::model()->findByPk($id);
     if (is_null($manager)) {
         throw new CHttpException(404);
     }
     $isAdmin = $manager->is_admin;
     if (isset($_POST['Manager'])) {
         $manager->attributes = Yii::app()->request->getPost('Manager');
         if ($isAdmin == true) {
             unset($manager->manager_role_id);
         }
         if ($manager->validate() && $manager->validate()) {
             if ($manager->login_password) {
                 $manager->login_password = md5($manager->login_password);
             } else {
                 unset($manager->login_password);
             }
             if ($manager->save()) {
                 $this->setFlashMessage(strtr('<strong>{link}</strong> 管理员修改成功', array('{link}' => CHtml::link($manager->login_name, array('view', 'id' => $manager->primaryKey)))));
                 ManagerLog::logCurrentUserAction(1, '修改管理员', $manager->login_name);
                 $this->redirect($this->getReturnUrl());
             } else {
                 $this->setFlashMessage('管理员修改失败', 'err');
             }
         }
     } else {
         $manager->login_password = '';
     }
     $managerRoleOptions = ManagerRole::model()->getOptions();
     $this->breadcrumbs = array('管理员' => array('index'), '修改');
     $this->render('create', array('manager' => $manager, 'managerRoleOptions' => $managerRoleOptions, 'returnUrl' => $this->getReturnUrl()));
 }
Example #3
0
</script>
<?php 
$this->endClip();
?>

<div class="heading">
	<h1><?php 
echo CHtml::image(Yii::app()->baseUrl . '/image/user-group.png');
?>
管理员角色</h1>
	<div class="buttons">
		<?php 
if (Yii::app()->user->checkAccess('createManagerRole')) {
    ?>
		<?php 
    echo CHtml::link('<span>添加</span>', array('create', 'returnUrl' => Yii::app()->request->url), array('class' => 'button'));
    ?>
		<?php 
}
?>
	</div>
</div>

<div class="content">

	<?php 
$this->widget('zii.widgets.grid.CGridView', array('pager' => array('cssFile' => false), 'cssFile' => false, 'htmlOptions' => array('class' => 'list-view'), 'itemsCssClass' => 'list tree-table', 'loadingCssClass' => 'list-view-loading', 'dataProvider' => $dataProvider, 'selectableRows' => 2, 'columns' => array(array('name' => 'manager_role_id', 'headerHtmlOptions' => array('class' => 'id-column', 'style' => 'width:80px;'), 'htmlOptions' => array('class' => 'idcolumn', 'align' => 'center')), array('name' => 'name'), array('name' => 'create_time', 'htmlOptions' => array('align' => 'center', 'width' => '150px')), array('name' => 'update_time', 'htmlOptions' => array('align' => 'center', 'width' => '150px')), array('class' => 'CButtonColumn', 'header' => ManagerRole::model()->getAttributeLabel('privileges'), 'headerHtmlOptions' => array('style' => 'width:100px;'), 'htmlOptions' => array('align' => 'center'), 'template' => '{privileges}', 'buttons' => array('privileges' => array('label' => '设置权限', 'url' => 'array("updatePrivilege", "id" => $data->primaryKey, "return_url" => Yii::app()->request->url)')), 'visible' => Yii::app()->user->checkAccess('updateManagerRolePrivilege')), array('class' => 'CButtonColumn', 'header' => '操作', 'headerHtmlOptions' => array('style' => 'width:100px;'), 'htmlOptions' => array('align' => 'center'), 'template' => '{view} {update} {delete}', 'buttons' => array('view' => array('url' => 'array("view", "id" => $data->primaryKey, "return_url" => Yii::app()->request->url)'), 'update' => array('url' => 'array("update", "id" => $data->primaryKey, "return_url" => Yii::app()->request->url)', 'visible' => 'Yii::app()->user->checkAccess("updateManagerRole")'), 'delete' => array('visible' => '$data->is_admin ? false : Yii::app()->user->checkAccess("deleteManagerRole")'))))));
?>

</div>