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
00027 class Mage_Adminhtml_Block_Permissions_Tab_Rolesedit extends Mage_Adminhtml_Block_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface
00028 {
00029
00030
00031
00032
00033
00034 public function getTabLabel()
00035 {
00036 return Mage::helper('adminhtml')->__('Role Resources');
00037 }
00038
00039
00040
00041
00042
00043
00044 public function getTabTitle()
00045 {
00046 return $this->getTabLabel();
00047 }
00048
00049
00050
00051
00052
00053
00054 public function canShowTab()
00055 {
00056 return true;
00057 }
00058
00059
00060
00061
00062
00063
00064 public function isHidden()
00065 {
00066 return false;
00067 }
00068
00069 public function __construct()
00070 {
00071 parent::__construct();
00072
00073 $rid = Mage::app()->getRequest()->getParam('rid', false);
00074
00075 $resources = Mage::getModel('admin/roles')->getResourcesList();
00076
00077 $rules_set = Mage::getResourceModel('admin/rules_collection')->getByRoles($rid)->load();
00078
00079 $selrids = array();
00080
00081 foreach ($rules_set->getItems() as $item) {
00082 if (array_key_exists(strtolower($item->getResource_id()), $resources) && $item->getPermission() == 'allow') {
00083 $resources[$item->getResource_id()]['checked'] = true;
00084 array_push($selrids, $item->getResource_id());
00085 }
00086 }
00087
00088 $this->setSelectedResources($selrids);
00089
00090 $this->setTemplate('permissions/rolesedit.phtml');
00091
00092
00093 }
00094
00095 public function getEverythingAllowed()
00096 {
00097 return in_array('all', $this->getSelectedResources());
00098 }
00099
00100 public function getResTreeJson()
00101 {
00102 $rid = Mage::app()->getRequest()->getParam('rid', false);
00103 $resources = Mage::getModel('admin/roles')->getResourcesTree();
00104
00105 $rootArray = $this->_getNodeJson($resources->admin, 1);
00106
00107 $json = Zend_Json::encode(isset($rootArray['children']) ? $rootArray['children'] : array());
00108
00109 return $json;
00110 }
00111
00112 protected function _sortTree($a, $b)
00113 {
00114 return $a['sort_order']<$b['sort_order'] ? -1 : ($a['sort_order']>$b['sort_order'] ? 1 : 0);
00115 }
00116
00117
00118 protected function _getNodeJson($node, $level=0)
00119 {
00120 $item = array();
00121 $selres = $this->getSelectedResources();
00122
00123 if ($level != 0) {
00124 $item['text']= (string)$node->title;
00125 $item['sort_order']= isset($node->sort_order) ? (string)$node->sort_order : 0;
00126 $item['id'] = (string)$node->attributes()->aclpath;
00127
00128 if (in_array($item['id'], $selres))
00129 $item['checked'] = true;
00130 }
00131 if (isset($node->children)) {
00132 $children = $node->children->children();
00133 } else {
00134 $children = $node->children();
00135 }
00136 if (empty($children)) {
00137 return $item;
00138 }
00139
00140 if ($children) {
00141 $item['children'] = array();
00142
00143 foreach ($children as $child) {
00144 if ($child->getName()!='title' && $child->getName()!='sort_order') {
00145 if (!(string)$child->title) {
00146 continue;
00147 }
00148 if ($level != 0) {
00149 $item['children'][] = $this->_getNodeJson($child, $level+1);
00150 } else {
00151 $item = $this->_getNodeJson($child, $level+1);
00152 }
00153 }
00154 }
00155 if (!empty($item['children'])) {
00156 usort($item['children'], array($this, '_sortTree'));
00157 }
00158 }
00159 return $item;
00160 }
00161 }