* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminModulesPositions extends AdminTab{ private $displayKey = 0; public function postProcess(){ global $currentIndex; // Getting key value for display if (Tools::getValue('show_modules') AND strval(Tools::getValue('show_modules')) != 'all'){ $this->displayKey = intval(Tools::getValue('show_modules')); } // Change position in hook if (array_key_exists('changePosition', $_GET)){ if ($this->tabAccess['edit'] === '1'){ $id_module = intval(Tools::getValue('id_module')); $id_hook = intval(Tools::getValue('id_hook')); $module = Module::getInstanceById($id_module); if (Validate::isLoadedObject($module)){ $module->updatePosition($id_hook, intval(Tools::getValue('direction'))); Tools::redirectAdmin($currentIndex.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); }else{ $this->_errors[] = Tools::displayError('module cannot be loaded'); } }else{ $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } }elseif (Tools::isSubmit('submitAddToHook')){// Add new module in hook if ($this->tabAccess['add'] === '1'){ // Getting vars... $id_module = intval(Tools::getValue('id_module')); $module = Module::getInstanceById($id_module); $id_hook = intval(Tools::getValue('id_hook')); $hook = new Hook($id_hook); $excepts = explode(',', str_replace(' ', '', Tools::getValue('exceptions'))); // Checking vars... foreach ($excepts AS $except) if (!Validate::isFileName($except)) $this->_errors[] = Tools::displayError('no valid value for field exceptions'); if (!$id_module OR !Validate::isLoadedObject($module)) $this->_errors[] = Tools::displayError('module cannot be loaded'); elseif (!$id_hook OR !Validate::isLoadedObject($hook)) $this->_errors[] = Tools::displayError('hook cannot be loaded'); elseif (Hook::getModuleFromHook($id_hook, $id_module)) $this->_errors[] = Tools::displayError('this module is already transplanted to this hook'); // Adding vars... elseif (!$module->registerHook($hook->name)) $this->_errors[] = Tools::displayError('an error occurred while transplanting module to hook'); elseif (!$module->registerExceptions($id_hook, $excepts)) $this->_errors[] = Tools::displayError('an error occurred while transplanting module to hook'); else Tools::redirectAdmin($currentIndex.'&conf=16'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); }else{ $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } }elseif (Tools::isSubmit('submitEditGraft')){// Edit module from hook if ($this->tabAccess['add'] === '1'){ // Getting vars... $id_module = intval(Tools::getValue('id_module')); $module = Module::getInstanceById($id_module); $id_hook = intval(Tools::getValue('id_hook')); $id_hook_old = intval(Tools::getValue('id_hook_old')); $hook = new Hook($id_hook); $excepts = explode(',', str_replace(' ', '', Tools::getValue('exceptions'))); // Checking vars... foreach ($excepts AS $except) if (!Validate::isFileName($except)) $this->_errors[] = Tools::displayError('no valid value for field exceptions'); if (!$id_module OR !Validate::isLoadedObject($module)) $this->_errors[] = Tools::displayError('module cannot be loaded'); elseif (!$id_hook OR !Validate::isLoadedObject($hook)) $this->_errors[] = Tools::displayError('hook cannot be loaded'); if (!$module->editHook($hook->name, $id_hook_old, $id_hook)){ $this->_errors[] = Tools::displayError('an error occurred while transplanting module to hook'); } // Adding vars... if (!$module->editExceptions($id_hook, $excepts)){ $this->_errors[] = Tools::displayError('an error occurred while transplanting module to hook'); }else{ Tools::redirectAdmin($currentIndex.'&conf=16'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); } }else{ $this->_errors[] = Tools::displayError('You do not have permission to add anything here.'); } } // Delete module from hook elseif (array_key_exists('deleteGraft', $_GET)) { if ($this->tabAccess['delete'] === '1') { $id_module = intval(Tools::getValue('id_module')); $module = Module::getInstanceById($id_module); $id_hook = intval(Tools::getValue('id_hook')); $hook = new Hook($id_hook); if (!Validate::isLoadedObject($module)) $this->_errors[] = Tools::displayError('module cannot be loaded'); elseif (!$id_hook OR !Validate::isLoadedObject($hook)) $this->_errors[] = Tools::displayError('hook cannot be loaded'); else { if (!$module->unregisterHook($id_hook) OR !$module->unregisterExceptions($id_hook)) $this->_errors[] = Tools::displayError('an error occurred while deleting module from hook'); else Tools::redirectAdmin($currentIndex.'&conf=17'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); } } else $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } public function display() { if (array_key_exists('addToHook', $_GET) OR array_key_exists('editGraft', $_GET) OR (Tools::isSubmit('submitAddToHook') AND $this->_errors)) $this->displayForm(); else $this->displayList(); } public function displayList() { global $currentIndex; echo ' '; echo ' '.$this->l('Transplant a module').'

'; // Print select list echo '
'.$this->l('Show').' :

 '.$this->l('Display non-positionnable hook').'
'; // Print hook list $irow = 0; $hooks = Hook::getHooks(!intval(Tools::getValue('hook_position'))); foreach ($hooks AS $hook) { $modules = array(); if (!$this->displayKey) $modules = Hook::getModulesFromHook($hook['id_hook']); elseif ($res = Hook::getModuleFromHook($hook['id_hook'], $this->displayKey)) $modules[0] = $res; $nbModules = sizeof($modules); echo ' '; // Print modules list if ($nbModules) { $instances = array(); foreach ($modules AS $module) if ($tmpInstance = Module::getInstanceById(intval($module['id_module']))) $instances[$tmpInstance->getPosition($hook['id_hook'])] = $tmpInstance; ksort($instances); foreach ($instances AS $position => $instance) { echo ' '; if (!$this->displayKey) { echo ' = 2? ' class="dragHandle"' : '').' id="td_'.$hook['id_hook'].'_'.$instance->id.'" width="40"> '.$this->l('Up').'
'.$this->l('Down').'
'; } } else echo ''; echo '
'.$hook['title'].' - '.$nbModules.' '.(($nbModules > 1) ? $this->l('modules') : $this->l('module')); if (!empty($hook['description'])) echo ' ['.$hook['description'].']'; echo '
'.intval($position).' '; } else echo ''; echo ' '.stripslashes($instance->name).' '.stripslashes($instance->displayName).' '.($instance->version ? ' v'.(intval($instance->version) == $instance->version? sprintf('%.1f', $instance->version) : floatval($instance->version)) : '').'
'.$instance->description.'
'.$this->l('Edit').' '.$this->l('Delete').'
'.$this->l('No module for this hook').'
'; } } public function displayForm($isMainTab = true) { global $currentIndex; parent::displayForm(); $id_module = intval(Tools::getValue('id_module')); $id_hook = intval(Tools::getValue('id_hook')); if ($id_module AND $id_hook AND Tools::isSubmit('editGraft')) { $slModule = Module::getInstanceById($id_module); $exceptsList = $slModule->getExceptions($id_hook); $excepts = ''; foreach ($exceptsList as $key => $except) $excepts .= ($key ? ',' : '').$except['file_name']; } $excepts = strval(Tools::getValue('exceptions', ((isset($slModule) AND Validate::isLoadedObject($slModule)) ? $excepts : ''))); $modules = Module::getModulesInstalled(0); $instances = array(); foreach ($modules AS $module) if ($tmpInstance = Module::getInstanceById($module['id_module'])) $instances[$tmpInstance->displayName] = $tmpInstance; ksort($instances); $modules = $instances; $hooks = Hook::getHooks(0); echo '
'; if ($this->displayKey) echo ''; echo '
'.$this->l('Transplant a module').'
*
*

Ex: identity.php, history.php, order.php, product.php

'.$this->l('Please specify those files in which you do not want the module to be displayed').'.
'.$this->l('These files are located in your base directory').', '.$this->l('e.g., ').' identity.php.
'.$this->l('Please type each filename separated by a comma').'.

'; if (Tools::isSubmit('editGraft')){ echo ' '; } echo '
* '.$this->l('Required field').'
'; } } ?>