* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class BlockSupplier extends Module { function __construct() { $this->name = 'blocksupplier'; $this->tab = 'front_office_features'; $this->version = 1.0; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Suppliers block'); $this->description = $this->l('Adds a block displaying suppliers.'); } function install() { if (!parent::install()) return false; if (!$this->registerHook('leftColumn')) return false; if (!$this->registerHook('header')) return false; Configuration::updateValue('SUPPLIER_DISPLAY_TEXT', true); Configuration::updateValue('SUPPLIER_DISPLAY_TEXT_NB', 5); Configuration::updateValue('SUPPLIER_DISPLAY_FORM', true); return true; } function hookLeftColumn($params) { global $smarty, $link; $smarty->assign(array( 'suppliers' => Supplier::getSuppliers(false), 'link' => $link, 'text_list' => Configuration::get('SUPPLIER_DISPLAY_TEXT'), 'text_list_nb' => Configuration::get('SUPPLIER_DISPLAY_TEXT_NB'), 'form_list' => Configuration::get('SUPPLIER_DISPLAY_FORM'), 'display_link_supplier' => Configuration::get('PS_DISPLAY_SUPPLIERS') )); return $this->display(__FILE__, 'blocksupplier.tpl'); } function getContent() { $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitBlockSuppliers')) { $text_list = (int)(Tools::getValue('text_list')); $text_nb = (int)(Tools::getValue('text_nb')); $form_list = (int)(Tools::getValue('form_list')); if ($text_list AND !Validate::isUnsignedInt($text_nb)) $errors[] = $this->l('Invalid number of elements'); elseif (!$text_list AND !$form_list) $errors[] = $this->l('Please activate at least one system list.'); else { Configuration::updateValue('SUPPLIER_DISPLAY_TEXT', $text_list); Configuration::updateValue('SUPPLIER_DISPLAY_TEXT_NB', $text_nb); Configuration::updateValue('SUPPLIER_DISPLAY_FORM', $form_list); } if (isset($errors) AND sizeof($errors)) $output .= $this->displayError(implode('
', $errors)); else $output .= $this->displayConfirmation($this->l('Settings updated')); } return $output.$this->displayForm(); } public function displayForm() { $output = '
'.$this->l('Settings').'
   '.$this->l('Display').' '.$this->l('elements').'

'.$this->l('To display suppliers as a plain-text list').'

'.$this->l('To display suppliers as a drop-down list').'

'; return $output; } function hookRightColumn($params) { return $this->hookLeftColumn($params); } function hookHeader($params) { Tools::addCSS(($this->_path).'blocksupplier.css', 'all'); } }