00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class Mage_Adminhtml_Permissions_UserController extends Mage_Adminhtml_Controller_Action
00027 {
00028
00029 protected function _initAction()
00030 {
00031 $this->loadLayout()
00032 ->_setActiveMenu('system/acl')
00033 ->_addBreadcrumb($this->__('System'), $this->__('System'))
00034 ->_addBreadcrumb($this->__('Permissions'), $this->__('Permissions'))
00035 ->_addBreadcrumb($this->__('Users'), $this->__('Users'))
00036 ;
00037 return $this;
00038 }
00039
00040 public function indexAction()
00041 {
00042 $this->_initAction()
00043 ->_addContent($this->getLayout()->createBlock('adminhtml/permissions_user'))
00044 ->renderLayout();
00045 }
00046
00047 public function newAction()
00048 {
00049 $this->_forward('edit');
00050 }
00051
00052 public function editAction()
00053 {
00054 $id = $this->getRequest()->getParam('user_id');
00055 $model = Mage::getModel('admin/user');
00056
00057 if ($id) {
00058 $model->load($id);
00059 if (! $model->getId()) {
00060 Mage::getSingleton('adminhtml/session')->addError($this->__('This user no longer exists'));
00061 $this->_redirect('*/*/');
00062 return;
00063 }
00064 }
00065
00066 $data = Mage::getSingleton('adminhtml/session')->getUserData(true);
00067 if (!empty($data)) {
00068 $model->setData($data);
00069 }
00070
00071 Mage::register('permissions_user', $model);
00072
00073 $this->_initAction()
00074 ->_addBreadcrumb($id ? $this->__('Edit User') : $this->__('New User'), $id ? $this->__('Edit User') : $this->__('New User'))
00075 ->_addContent($this->getLayout()->createBlock('adminhtml/permissions_user_edit')->setData('action', $this->getUrl('*/permissions_user/save')))
00076 ->_addLeft($this->getLayout()->createBlock('adminhtml/permissions_user_edit_tabs'));
00077
00078 $this->_addJs($this->getLayout()->createBlock('adminhtml/template')->setTemplate('permissions/user_roles_grid_js.phtml'));
00079 $this->renderLayout();
00080 }
00081
00082 public function saveAction()
00083 {
00084 if ($data = $this->getRequest()->getPost()) {
00085 $model = Mage::getModel('admin/user');
00086 $model->setData($data);
00087 try {
00088 $model->save();
00089 if ( $uRoles = $this->getRequest()->getParam('roles', false) ) {
00090
00091
00092 if ( 1 == sizeof($uRoles) ) {
00093 $model->setRoleIds($uRoles)
00094 ->setRoleUserId($model->getUserId())
00095 ->saveRelations();
00096 } else if ( sizeof($uRoles) > 1 ) {
00097
00098
00099 $rs = array();
00100 $rs[0] = $uRoles[0];
00101 $model->setRoleIds( $rs )->setRoleUserId( $model->getUserId() )->saveRelations();
00102 }
00103 }
00104 Mage::getSingleton('adminhtml/session')->addSuccess($this->__('User was successfully saved'));
00105 Mage::getSingleton('adminhtml/session')->setUserData(false);
00106 $this->_redirect('*/*/edit', array('user_id' => $model->getUserId()));
00107 return;
00108 } catch (Exception $e) {
00109 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00110 Mage::getSingleton('adminhtml/session')->setUserData($data);
00111 $this->_redirect('*/*/edit', array('user_id' => $model->getUserId()));
00112 return;
00113 }
00114 }
00115 $this->_redirect('*/*/');
00116 }
00117
00118 public function deleteAction()
00119 {
00120 $currentUser = Mage::getSingleton('admin/session')->getUser();
00121
00122 if ($id = $this->getRequest()->getParam('user_id')) {
00123 if ( $currentUser->getId() == $id ) {
00124 Mage::getSingleton('adminhtml/session')->addError($this->__('You cannot delete account of yourself'));
00125 $this->_redirect('*/*/edit', array('user_id' => $id));
00126 return;
00127 }
00128 try {
00129 $model = Mage::getModel('admin/user');
00130 $model->setId($id);
00131 $model->delete();
00132 Mage::getSingleton('adminhtml/session')->addSuccess($this->__('User was successfully deleted'));
00133 $this->_redirect('*/*/');
00134 return;
00135 }
00136 catch (Exception $e) {
00137 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00138 $this->_redirect('*/*/edit', array('user_id' => $this->getRequest()->getParam('user_id')));
00139 return;
00140 }
00141 }
00142 Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find a user to delete'));
00143 $this->_redirect('*/*/');
00144 }
00145
00146 public function rolesGridAction()
00147 {
00148 $id = $this->getRequest()->getParam('user_id');
00149 $model = Mage::getModel('admin/user');
00150
00151 if ($id) {
00152 $model->load($id);
00153 }
00154
00155 Mage::register('permissions_user', $model);
00156 $this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/permissions_user_edit_tab_roles')->toHtml());
00157 }
00158
00159 public function roleGridAction()
00160 {
00161 $this->getResponse()
00162 ->setBody($this->getLayout()
00163 ->createBlock('adminhtml/permissions_user_grid')
00164 ->toHtml()
00165 );
00166 }
00167
00168 protected function _isAllowed()
00169 {
00170 return Mage::getSingleton('admin/session')->isAllowed('system/acl/users');
00171 }
00172
00173 }