1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Adminhtml_Block_System_Config_Tabs extends Mage_Adminhtml_Block_Widget
36: {
37:
38: 39: 40: 41: 42:
43: protected $_tabs;
44:
45: 46: 47: 48:
49: protected function _construct()
50: {
51: $this->setId('system_config_tabs');
52: $this->setTitle(Mage::helper('adminhtml')->__('Configuration'));
53: $this->setTemplate('system/config/tabs.phtml');
54: }
55:
56: 57: 58: 59: 60: 61: 62:
63: protected function _sort($a, $b)
64: {
65: return (int)$a->sort_order < (int)$b->sort_order ? -1 : ((int)$a->sort_order > (int)$b->sort_order ? 1 : 0);
66: }
67:
68: 69: 70: 71:
72: public function initTabs()
73: {
74: $current = $this->getRequest()->getParam('section');
75: $websiteCode = $this->getRequest()->getParam('website');
76: $storeCode = $this->getRequest()->getParam('store');
77:
78: $url = Mage::getModel('adminhtml/url');
79:
80: $configFields = Mage::getSingleton('adminhtml/config');
81: $sections = $configFields->getSections($current);
82: $tabs = (array)$configFields->getTabs()->children();
83:
84:
85: $sections = (array)$sections;
86:
87: usort($sections, array($this, '_sort'));
88: usort($tabs, array($this, '_sort'));
89:
90: foreach ($tabs as $tab) {
91: $helperName = $configFields->getAttributeModule($tab);
92: $label = Mage::helper($helperName)->__((string)$tab->label);
93:
94: $this->addTab($tab->getName(), array(
95: 'label' => $label,
96: 'class' => (string) $tab->class
97: ));
98: }
99:
100:
101: foreach ($sections as $section) {
102: Mage::dispatchEvent('adminhtml_block_system_config_init_tab_sections_before', array('section' => $section));
103: $hasChildren = $configFields->hasChildren($section, $websiteCode, $storeCode);
104:
105:
106: $code = $section->getName();
107:
108: $sectionAllowed = $this->checkSectionPermissions($code);
109: if ((empty($current) && $sectionAllowed)) {
110:
111: $current = $code;
112: $this->getRequest()->setParam('section', $current);
113: }
114:
115: $helperName = $configFields->getAttributeModule($section);
116:
117: $label = Mage::helper($helperName)->__((string)$section->label);
118:
119: if ($code == $current) {
120: if (!$this->getRequest()->getParam('website') && !$this->getRequest()->getParam('store')) {
121: $this->_addBreadcrumb($label);
122: } else {
123: $this->_addBreadcrumb($label, '', $url->getUrl('*/*/*', array('section'=>$code)));
124: }
125: }
126: if ( $sectionAllowed && $hasChildren) {
127: $this->addSection($code, (string)$section->tab, array(
128: 'class' => (string)$section->class,
129: 'label' => $label,
130: 'url' => $url->getUrl('*/*/*', array('_current'=>true, 'section'=>$code)),
131: ));
132: }
133:
134: if ($code == $current) {
135: $this->setActiveTab($section->tab);
136: $this->setActiveSection($code);
137: }
138: }
139:
140: 141: 142:
143: foreach ($this->getTabs() as $tab) {
144: $sections = $tab->getSections();
145: if ($sections) {
146: $sections->getLastItem()->setIsLast(true);
147: }
148: }
149:
150: Mage::helper('adminhtml')->addPageHelpUrl($current.'/');
151:
152: return $this;
153: }
154:
155: public function addTab($code, $config)
156: {
157: $tab = new Varien_Object($config);
158: $tab->setId($code);
159: $this->_tabs[$code] = $tab;
160: return $this;
161: }
162:
163: 164: 165: 166: 167: 168:
169: public function getTab($code)
170: {
171: if(isset($this->_tabs[$code])) {
172: return $this->_tabs[$code];
173: }
174:
175: return null;
176: }
177:
178: public function addSection($code, $tabCode, $config)
179: {
180: if($tab = $this->getTab($tabCode)) {
181: if(!$tab->getSections()) {
182: $tab->setSections(new Varien_Data_Collection());
183: }
184: $section = new Varien_Object($config);
185: $section->setId($code);
186: $tab->getSections()->addItem($section);
187: }
188: return $this;
189: }
190:
191: public function getTabs()
192: {
193: return $this->_tabs;
194: }
195:
196: 197: 198: 199: 200:
201: public function getStoreSelectOptions()
202: {
203: $section = $this->getRequest()->getParam('section');
204:
205: $curWebsite = $this->getRequest()->getParam('website');
206: $curStore = $this->getRequest()->getParam('store');
207:
208: $storeModel = Mage::getSingleton('adminhtml/system_store');
209:
210:
211: $url = Mage::getModel('adminhtml/url');
212:
213: $options = array();
214: $options['default'] = array(
215: 'label' => Mage::helper('adminhtml')->__('Default Config'),
216: 'url' => $url->getUrl('*/*/*', array('section'=>$section)),
217: 'selected' => !$curWebsite && !$curStore,
218: 'style' => 'background:#ccc; font-weight:bold;',
219: );
220:
221: foreach ($storeModel->getWebsiteCollection() as $website) {
222: $websiteShow = false;
223: foreach ($storeModel->getGroupCollection() as $group) {
224: if ($group->getWebsiteId() != $website->getId()) {
225: continue;
226: }
227: $groupShow = false;
228: foreach ($storeModel->getStoreCollection() as $store) {
229: if ($store->getGroupId() != $group->getId()) {
230: continue;
231: }
232: if (!$websiteShow) {
233: $websiteShow = true;
234: $options['website_' . $website->getCode()] = array(
235: 'label' => $website->getName(),
236: 'url' => $url->getUrl('*/*/*', array('section'=>$section, 'website'=>$website->getCode())),
237: 'selected' => !$curStore && $curWebsite == $website->getCode(),
238: 'style' => 'padding-left:16px; background:#DDD; font-weight:bold;',
239: );
240: }
241: if (!$groupShow) {
242: $groupShow = true;
243: $options['group_' . $group->getId() . '_open'] = array(
244: 'is_group' => true,
245: 'is_close' => false,
246: 'label' => $group->getName(),
247: 'style' => 'padding-left:32px;'
248: );
249: }
250: $options['store_' . $store->getCode()] = array(
251: 'label' => $store->getName(),
252: 'url' => $url->getUrl('*/*/*', array('section'=>$section, 'website'=>$website->getCode(), 'store'=>$store->getCode())),
253: 'selected' => $curStore == $store->getCode(),
254: 'style' => '',
255: );
256: }
257: if ($groupShow) {
258: $options['group_' . $group->getId() . '_close'] = array(
259: 'is_group' => true,
260: 'is_close' => true,
261: );
262: }
263: }
264: }
265:
266: return $options;
267: }
268:
269: 270: 271: 272: 273:
274: public function getStoreButtonsHtml()
275: {
276: $curWebsite = $this->getRequest()->getParam('website');
277: $curStore = $this->getRequest()->getParam('store');
278:
279: $html = '';
280:
281: if (!$curWebsite && !$curStore) {
282: $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
283: 'label' => Mage::helper('adminhtml')->__('New Website'),
284: 'onclick' => "location.href='".$this->getUrl('*/system_website/new')."'",
285: 'class' => 'add',
286: ))->toHtml();
287: } elseif (!$curStore) {
288: $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
289: 'label' => Mage::helper('adminhtml')->__('Edit Website'),
290: 'onclick' => "location.href='".$this->getUrl('*/system_website/edit', array('website'=>$curWebsite))."'",
291: ))->toHtml();
292: $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
293: 'label' => Mage::helper('adminhtml')->__('New Store View'),
294: 'onclick' => "location.href='".$this->getUrl('*/system_store/new', array('website'=>$curWebsite))."'",
295: 'class' => 'add',
296: ))->toHtml();
297: $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
298: 'label' => Mage::helper('adminhtml')->__('Delete Website'),
299: 'onclick' => "location.href='".$this->getUrl('*/system_website/delete', array('website'=>$curWebsite))."'",
300: 'class' => 'delete',
301: ))->toHtml();
302: } else {
303: $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
304: 'label' => Mage::helper('adminhtml')->__('Edit Store View'),
305: 'onclick' => "location.href='".$this->getUrl('*/system_store/edit', array('store'=>$curStore))."'",
306: ))->toHtml();
307: $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
308: 'label' => Mage::helper('adminhtml')->__('Delete Store View'),
309: 'onclick' => "location.href='".$this->getUrl('*/system_store/delete', array('store'=>$curStore))."'",
310: 'class' => 'delete',
311: ))->toHtml();
312: }
313:
314: return $html;
315: }
316:
317: 318: 319: 320: 321: 322:
323: public function checkSectionPermissions($code=null)
324: {
325: static $permissions;
326:
327: if (!$code or trim($code) == "") {
328: return false;
329: }
330:
331: if (!$permissions) {
332: $permissions = Mage::getSingleton('admin/session');
333: }
334:
335: $showTab = false;
336: if ( $permissions->isAllowed('system/config/'.$code) ) {
337: $showTab = true;
338: }
339: return $showTab;
340: }
341:
342: }
343: