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
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Adminhtml_Block_System_Config_Tabs extends Mage_Adminhtml_Block_Widget
00036 {
00037
00038
00039
00040
00041
00042
00043 protected $_tabs;
00044
00045
00046
00047
00048
00049 protected function _construct()
00050 {
00051 $this->setId('system_config_tabs');
00052 $this->setTitle(Mage::helper('adminhtml')->__('Configuration'));
00053 $this->setTemplate('system/config/tabs.phtml');
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063 protected function _sort($a, $b)
00064 {
00065 return (int)$a->sort_order < (int)$b->sort_order ? -1 : ((int)$a->sort_order > (int)$b->sort_order ? 1 : 0);
00066 }
00067
00068
00069
00070
00071
00072 public function initTabs()
00073 {
00074 $current = $this->getRequest()->getParam('section');
00075 $websiteCode = $this->getRequest()->getParam('website');
00076 $storeCode = $this->getRequest()->getParam('store');
00077
00078 $url = Mage::getModel('adminhtml/url');
00079
00080 $configFields = Mage::getSingleton('adminhtml/config');
00081 $sections = $configFields->getSections($current);
00082 $tabs = (array)$configFields->getTabs()->children();
00083
00084
00085 $sections = (array)$sections;
00086
00087 usort($sections, array($this, '_sort'));
00088 usort($tabs, array($this, '_sort'));
00089
00090 foreach ($tabs as $tab) {
00091 $helperName = $configFields->getAttributeModule($tab);
00092 $label = Mage::helper($helperName)->__((string)$tab->label);
00093
00094 $this->addTab($tab->getName(), array(
00095 'label' => $label,
00096 'class' => (string) $tab->class
00097 ));
00098 }
00099
00100
00101 foreach ($sections as $section) {
00102
00103 $hasChildren = $configFields->hasChildren($section, $websiteCode, $storeCode);
00104
00105
00106 $code = $section->getName();
00107
00108 $sectionAllowed = $this->checkSectionPermissions($code);
00109 if ((empty($current) && $sectionAllowed)) {
00110
00111 $current = $code;
00112 $this->getRequest()->setParam('section', $current);
00113 }
00114
00115 $helperName = $configFields->getAttributeModule($section);
00116
00117 $label = Mage::helper($helperName)->__((string)$section->label);
00118
00119 if ($code == $current) {
00120 if (!$this->getRequest()->getParam('website') && !$this->getRequest()->getParam('store')) {
00121 $this->_addBreadcrumb($label);
00122 } else {
00123 $this->_addBreadcrumb($label, '', $url->getUrl('*/*/*', array('section'=>$code)));
00124 }
00125 }
00126 if ( $sectionAllowed && $hasChildren) {
00127 $this->addSection($code, (string)$section->tab, array(
00128 'class' => (string)$section->class,
00129 'label' => $label,
00130 'url' => $url->getUrl('*/*/*', array('_current'=>true, 'section'=>$code)),
00131 ));
00132 }
00133
00134 if ($code == $current) {
00135 $this->setActiveTab($section->tab);
00136 $this->setActiveSection($code);
00137 }
00138 }
00139
00140
00141
00142
00143 foreach ($this->getTabs() as $tab) {
00144 $sections = $tab->getSections();
00145 if ($sections) {
00146 $sections->getLastItem()->setIsLast(true);
00147 }
00148 }
00149
00150 Mage::helper('adminhtml')->addPageHelpUrl($current.'/');
00151
00152 return $this;
00153 }
00154
00155 public function addTab($code, $config)
00156 {
00157 $tab = new Varien_Object($config);
00158 $tab->setId($code);
00159 $this->_tabs[$code] = $tab;
00160 return $this;
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 public function getTab($code)
00170 {
00171 if(isset($this->_tabs[$code])) {
00172 return $this->_tabs[$code];
00173 }
00174
00175 return null;
00176 }
00177
00178 public function addSection($code, $tabCode, $config)
00179 {
00180 if($tab = $this->getTab($tabCode)) {
00181 if(!$tab->getSections()) {
00182 $tab->setSections(new Varien_Data_Collection());
00183 }
00184 $section = new Varien_Object($config);
00185 $section->setId($code);
00186 $tab->getSections()->addItem($section);
00187 }
00188 return $this;
00189 }
00190
00191 public function getTabs()
00192 {
00193 return $this->_tabs;
00194 }
00195
00196
00197
00198
00199
00200
00201 public function getStoreSelectOptions()
00202 {
00203 $section = $this->getRequest()->getParam('section');
00204
00205 $curWebsite = $this->getRequest()->getParam('website');
00206 $curStore = $this->getRequest()->getParam('store');
00207
00208 $storeModel = Mage::getSingleton('adminhtml/system_store');
00209
00210
00211 $url = Mage::getModel('adminhtml/url');
00212
00213 $options = array();
00214 $options['default'] = array(
00215 'label' => Mage::helper('adminhtml')->__('Default Config'),
00216 'url' => $url->getUrl('*/*/*', array('section'=>$section)),
00217 'selected' => !$curWebsite && !$curStore,
00218 'style' => 'background:#ccc; font-weight:bold;',
00219 );
00220
00221 foreach ($storeModel->getWebsiteCollection() as $website) {
00222 $websiteShow = false;
00223 foreach ($storeModel->getGroupCollection() as $group) {
00224 if ($group->getWebsiteId() != $website->getId()) {
00225 continue;
00226 }
00227 $groupShow = false;
00228 foreach ($storeModel->getStoreCollection() as $store) {
00229 if ($store->getGroupId() != $group->getId()) {
00230 continue;
00231 }
00232 if (!$websiteShow) {
00233 $websiteShow = true;
00234 $options['website_' . $website->getCode()] = array(
00235 'label' => $website->getName(),
00236 'url' => $url->getUrl('*/*/*', array('section'=>$section, 'website'=>$website->getCode())),
00237 'selected' => !$curStore && $curWebsite == $website->getCode(),
00238 'style' => 'padding-left:16px; background:#DDD; font-weight:bold;',
00239 );
00240 }
00241 if (!$groupShow) {
00242 $groupShow = true;
00243 $options['group_' . $group->getId() . '_open'] = array(
00244 'is_group' => true,
00245 'is_close' => false,
00246 'label' => $group->getName(),
00247 'style' => 'padding-left:32px;'
00248 );
00249 }
00250 $options['store_' . $store->getCode()] = array(
00251 'label' => $store->getName(),
00252 'url' => $url->getUrl('*/*/*', array('section'=>$section, 'website'=>$website->getCode(), 'store'=>$store->getCode())),
00253 'selected' => $curStore == $store->getCode(),
00254 'style' => '',
00255 );
00256 }
00257 if ($groupShow) {
00258 $options['group_' . $group->getId() . '_close'] = array(
00259 'is_group' => true,
00260 'is_close' => true,
00261 );
00262 }
00263 }
00264 }
00265
00266 return $options;
00267 }
00268
00269
00270
00271
00272
00273
00274 public function getStoreButtonsHtml()
00275 {
00276 $curWebsite = $this->getRequest()->getParam('website');
00277 $curStore = $this->getRequest()->getParam('store');
00278
00279 $html = '';
00280
00281 if (!$curWebsite && !$curStore) {
00282 $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
00283 'label' => Mage::helper('adminhtml')->__('New Website'),
00284 'onclick' => "location.href='".$this->getUrl('*/system_website/new')."'",
00285 'class' => 'add',
00286 ))->toHtml();
00287 } elseif (!$curStore) {
00288 $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
00289 'label' => Mage::helper('adminhtml')->__('Edit Website'),
00290 'onclick' => "location.href='".$this->getUrl('*/system_website/edit', array('website'=>$curWebsite))."'",
00291 ))->toHtml();
00292 $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
00293 'label' => Mage::helper('adminhtml')->__('New Store View'),
00294 'onclick' => "location.href='".$this->getUrl('*/system_store/new', array('website'=>$curWebsite))."'",
00295 'class' => 'add',
00296 ))->toHtml();
00297 $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
00298 'label' => Mage::helper('adminhtml')->__('Delete Website'),
00299 'onclick' => "location.href='".$this->getUrl('*/system_website/delete', array('website'=>$curWebsite))."'",
00300 'class' => 'delete',
00301 ))->toHtml();
00302 } else {
00303 $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
00304 'label' => Mage::helper('adminhtml')->__('Edit Store View'),
00305 'onclick' => "location.href='".$this->getUrl('*/system_store/edit', array('store'=>$curStore))."'",
00306 ))->toHtml();
00307 $html .= $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
00308 'label' => Mage::helper('adminhtml')->__('Delete Store View'),
00309 'onclick' => "location.href='".$this->getUrl('*/system_store/delete', array('store'=>$curStore))."'",
00310 'class' => 'delete',
00311 ))->toHtml();
00312 }
00313
00314 return $html;
00315 }
00316
00317
00318
00319
00320
00321
00322
00323 public function checkSectionPermissions($code=null)
00324 {
00325 static $permissions;
00326
00327 if (!$code or trim($code) == "") {
00328 return false;
00329 }
00330
00331 if (!$permissions) {
00332 $permissions = Mage::getSingleton('admin/session');
00333 }
00334
00335 $showTab = false;
00336 if ( $permissions->isAllowed('system/config/'.$code) ) {
00337 $showTab = true;
00338 }
00339 return $showTab;
00340 }
00341
00342 }