Beezkit Posted June 7, 2017 Share Posted June 7, 2017 (edited) Bonjour à vous, J'ai 2 petit soucis sur mon override du block réinssurance. Dans mon override j'ai ajouté un champs lien, pour donner une url en plus a mes réinssurance. Lorsque je crée un nouveau réinsurrance pas de soucis, mais lorsque je le modifie il ne marche plus. Voici mon code : <?php /* * 2007-2016 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2016 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class BlockreinsuranceOverride extends Blockreinsurance { public function installDB() { $return = true; $return &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reinsurance` ( `id_reinsurance` INT UNSIGNED NOT NULL AUTO_INCREMENT, `id_shop` int(10) unsigned NOT NULL , `file_name` VARCHAR(100) NOT NULL, PRIMARY KEY (`id_reinsurance`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); $return &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reinsurance_lang` ( `id_reinsurance` INT UNSIGNED NOT NULL AUTO_INCREMENT, `id_lang` int(10) unsigned NOT NULL , `text` VARCHAR(300) NOT NULL, `lien` VARCHAR(300) NOT NULL, PRIMARY KEY (`id_reinsurance`, `id_lang`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); return $return; } public function hookDisplayHome($params) { return $this->hookFooter($params); } public function addToDB() { if (isset($_POST['nbblocks'])) { for ($i = 1; $i <= (int)$_POST['nbblocks']; $i++) { $filename = explode('.', $_FILES['info'.$i.'_file']['name']); if (isset($_FILES['info'.$i.'_file']) && isset($_FILES['info'.$i.'_file']['tmp_name']) && !empty($_FILES['info'.$i.'_file']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['info'.$i.'_file'])) return false; elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['info'.$i.'_file']['tmp_name'], $tmpName)) return false; elseif (!ImageManager::resize($tmpName, dirname(__FILE__).'/img/'.$filename[0].'.jpg')) return false; unlink($tmpName); } Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'reinsurance` (`filename`,`text`,`lien`) VALUES ("'.((isset($filename[0]) && $filename[0] != '') ? pSQL($filename[0]) : '').'", "'.((isset($_POST['info'.$i.'_text']) && $_POST['info'.$i.'_text'] != '') ? pSQL($_POST['info'.$i.'_text']) : '').'", "'.((isset($_POST['info'.$i.'_lien']) && $_POST['info'.$i.'_lien'] != '') ? pSQL($_POST['info'.$i.'_lien']) : '').'")'); } return true; } else return false; } public function getContent() { $html = ''; $id_reinsurance = (int)Tools::getValue('id_reinsurance'); if (Tools::isSubmit('saveblockreinsurance')) { if ($id_reinsurance = Tools::getValue('id_reinsurance')) $reinsurance = new reinsuranceClass((int)$id_reinsurance); else $reinsurance = new reinsuranceClass(); $reinsurance->copyFromPost(); $reinsurance->id_shop = $this->context->shop->id; if ($reinsurance->validateFields(false) && $reinsurance->validateFieldsLang(false)) { $reinsurance->save(); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['image'])) return false; elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) return false; elseif (!ImageManager::resize($tmpName, dirname(__FILE__).'/img/reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg')) return false; unlink($tmpName); $reinsurance->file_name = 'reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg'; $reinsurance->save(); } $this->_clearCache('blockreinsurance.tpl'); } else $html .= '<div class="conf error">'.$this->l('An error occurred while attempting to save.').'</div>'; } if (Tools::isSubmit('updateblockreinsurance') || Tools::isSubmit('addblockreinsurance')) { $helper = $this->initForm(); foreach (Language::getLanguages(false) as $lang) if ($id_reinsurance) { $reinsurance = new reinsuranceClass((int)$id_reinsurance); $helper->fields_value['text'][(int)$lang['id_lang']] = $reinsurance->text[(int)$lang['id_lang']]; $helper->fields_value['lien'][(int)$lang['id_lang']] = $reinsurance->lien[(int)$lang['id_lang']]; } else $helper->fields_value['text'][(int)$lang['id_lang']] = Tools::getValue('text_'.(int)$lang['id_lang'], ''); $helper->fields_value['lien'][(int)$lang['id_lang']] = Tools::getValue('lien_'.(int)$lang['id_lang'], ''); if ($id_reinsurance = Tools::getValue('id_reinsurance')) { $this->fields_form[0]['form']['input'][] = array('type' => 'hidden', 'name' => 'id_reinsurance'); $helper->fields_value['id_reinsurance'] = (int)$id_reinsurance; } return $html.$helper->generateForm($this->fields_form); } else if (Tools::isSubmit('deleteblockreinsurance')) { $reinsurance = new reinsuranceClass((int)$id_reinsurance); if (file_exists(dirname(__FILE__).'/img/'.$reinsurance->file_name)) unlink(dirname(__FILE__).'/img/'.$reinsurance->file_name); $reinsurance->delete(); $this->_clearCache('blockreinsurance.tpl'); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } else { $helper = $this->initList(); return $html.$helper->generateList($this->getListContent((int)Configuration::get('PS_LANG_DEFAULT')), $this->fields_list); } if (isset($_POST['submitModule'])) { Configuration::updateValue('BLOCKREINSURANCE_NBBLOCKS', ((isset($_POST['nbblocks']) && $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : '')); if ($this->removeFromDB() && $this->addToDB()) { $this->_clearCache('blockreinsurance.tpl'); $output = '<div class="conf confirm">'.$this->l('The block configuration has been updated.').'</div>'; } else $output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>'.$this->l('An error occurred while attempting to save.').'</div>'; } } protected function getListContent($id_lang) { return Db::getInstance()->executeS(' SELECT r.`id_reinsurance`, r.`id_shop`, r.`file_name`, rl.`text`, rl.`lien` FROM `'._DB_PREFIX_.'reinsurance` r LEFT JOIN `'._DB_PREFIX_.'reinsurance_lang` rl ON (r.`id_reinsurance` = rl.`id_reinsurance`) WHERE `id_lang` = '.(int)$id_lang.' '.Shop::addSqlRestrictionOnLang()); } protected function initForm() { $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $this->fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('New reassurance block'), ), 'input' => array( array( 'type' => 'file', 'label' => $this->l('Image'), 'name' => 'image', 'value' => true ), array( 'type' => 'textarea', 'label' => $this->l('Text'), 'lang' => true, 'name' => 'text', 'cols' => 40, 'rows' => 10 ), array( 'type' => 'textarea', 'label' => $this->l('Lien'), 'lang' => true, 'name' => 'lien' ) ), 'submit' => array( 'title' => $this->l('Save'), ) ); $helper = new HelperForm(); $helper->module = $this; $helper->name_controller = 'blockreinsurance'; $helper->identifier = $this->identifier; $helper->token = Tools::getAdminTokenLite('AdminModules'); foreach (Language::getLanguages(false) as $lang) $helper->languages[] = array( 'id_lang' => $lang['id_lang'], 'iso_code' => $lang['iso_code'], 'name' => $lang['name'], 'is_default' => ($default_lang == $lang['id_lang'] ? 1 : 0) ); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; $helper->toolbar_scroll = true; $helper->title = $this->displayName; $helper->submit_action = 'saveblockreinsurance'; $helper->toolbar_btn = array( 'save' => array( 'desc' => $this->l('Save'), 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), ), 'back' => array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Back to list') ) ); return $helper; } protected function initList() { $this->fields_list = array( 'id_reinsurance' => array( 'title' => $this->l('ID'), 'width' => 120, 'type' => 'text', 'search' => false, 'orderby' => false ), 'text' => array( 'title' => $this->l('Text'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false ), 'lien' => array( 'title' => $this->l('Lien'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false ), ); if (Shop::isFeatureActive()) $this->fields_list['id_shop'] = array('title' => $this->l('ID Shop'), 'align' => 'center', 'width' => 25, 'type' => 'int'); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = false; $helper->identifier = 'id_reinsurance'; $helper->actions = array('edit', 'delete'); $helper->show_toolbar = true; $helper->imageType = 'jpg'; $helper->toolbar_btn['new'] = array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Add new') ); $helper->title = $this->displayName; $helper->table = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; return $helper; } } <?php /* * 2007-2016 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2016 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class reinsuranceClass extends ObjectModel { /** @var integer reinsurance id*/ public $id; /** @var integer reinsurance id shop*/ public $id_shop; /** @var string reinsurance file name icon*/ public $file_name; /** @var string reinsurance text*/ public $text; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'reinsurance', 'primary' => 'id_reinsurance', 'multilang' => true, 'fields' => array( 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true), 'file_name' => array('type' => self::TYPE_STRING, 'validate' => 'isFileName'), // Lang fields 'text' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), ) ); public function copyFromPost() { /* Classical fields */ foreach ($_POST AS $key => $value) if (array_key_exists($key, $this) AND $key != 'id_'.$this->table) $this->{$key} = $value; /* Multilingual fields */ if (sizeof($this->fieldsValidateLang)) { $languages = Language::getLanguages(false); foreach ($languages AS $language) foreach ($this->fieldsValidateLang AS $field => $validation) if (isset($_POST[$field.'_'.(int)($language['id_lang'])])) $this->{$field}[(int)($language['id_lang'])] = $_POST[$field.'_'.(int)($language['id_lang'])]; } } } Mon autre soucis est que depuis que l'override est en place, les images ne vont plus dans mon module mais dans le dossier de mon override. Derniere question, peut on overrider le reinsuranceClass ? si oui ou le mettre ? Edited June 7, 2017 by Beezkit (see edit history) Link to comment Share on other sites More sharing options...
Beezkit Posted June 7, 2017 Author Share Posted June 7, 2017 Pas d'idée du pourquoi du comment ? En cherchant un peu cela viendrais du fait que validateFieldsLang me renvoie rien Link to comment Share on other sites More sharing options...
Beezkit Posted June 8, 2017 Author Share Posted June 8, 2017 Merci pour les images, c'était tout simple. Je suis un grand débutant en dev et encore plus en dev prestashop, que souhaite tu dire par définition ? Link to comment Share on other sites More sharing options...
Beezkit Posted June 8, 2017 Author Share Posted June 8, 2017 Je l'avais ajouté dans les définitions, je ne vous ai pas partagé le bon script, le voici : <?php /* * 2007-2016 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2016 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class reinsuranceClass extends ObjectModel { /** @var integer reinsurance id*/ public $id; /** @var integer reinsurance id shop*/ public $id_shop; /** @var string reinsurance file name icon*/ public $file_name; /** @var string reinsurance text*/ public $text; /** @var string reinsurance text*/ public $lien; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'reinsurance', 'primary' => 'id_reinsurance', 'multilang' => true, 'fields' => array( 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => true), 'file_name' => array('type' => self::TYPE_STRING, 'validate' => 'isFileName'), // Lang fields 'text' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), 'lien' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), ) ); public function copyFromPost() { /* Classical fields */ foreach ($_POST AS $key => $value) if (array_key_exists($key, $this) AND $key != 'id_'.$this->table) $this->{$key} = $value; /* Multilingual fields */ if (sizeof($this->fieldsValidateLang)) { $languages = Language::getLanguages(false); foreach ($languages AS $language) foreach ($this->fieldsValidateLang AS $field => $validation) if (isset($_POST[$field.'_'.(int)($language['id_lang'])])) $this->{$field}[(int)($language['id_lang'])] = $_POST[$field.'_'.(int)($language['id_lang'])]; } } } Link to comment Share on other sites More sharing options...
Beezkit Posted June 8, 2017 Author Share Posted June 8, 2017 Non effectivement elle ne l'est pas car je ne sais pas comment l'overrider celle ci, mais je constate que ma traduction "lien" n'est pas présente dans les traductions, et c'est a cause de cela que je ne peu pas mettre a jours un réinsurance. Mais je ne comprend pas pourquoi Link to comment Share on other sites More sharing options...
Beezkit Posted June 8, 2017 Author Share Posted June 8, 2017 Bon j'ai trouvé, je me suis planté dans mon code, j'ai enlevé des lignes par erreur. Voici la correction pour ceux qui serait interressé : <?php /* * 2007-2016 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2016 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class BlockreinsuranceOverride extends Blockreinsurance { public function installDB() { $return = true; $return &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reinsurance` ( `id_reinsurance` INT UNSIGNED NOT NULL AUTO_INCREMENT, `id_shop` int(10) unsigned NOT NULL , `file_name` VARCHAR(100) NOT NULL, PRIMARY KEY (`id_reinsurance`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); $return &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'reinsurance_lang` ( `id_reinsurance` INT UNSIGNED NOT NULL AUTO_INCREMENT, `id_lang` int(10) unsigned NOT NULL , `text` VARCHAR(300) NOT NULL, `lien` VARCHAR(300) NOT NULL, PRIMARY KEY (`id_reinsurance`, `id_lang`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); return $return; } public function hookDisplayHome($params) { return $this->hookFooter($params); } public function addToDB() { if (isset($_POST['nbblocks'])) { for ($i = 1; $i <= (int)$_POST['nbblocks']; $i++) { $filename = explode('.', $_FILES['info'.$i.'_file']['name']); if (isset($_FILES['info'.$i.'_file']) && isset($_FILES['info'.$i.'_file']['tmp_name']) && !empty($_FILES['info'.$i.'_file']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['info'.$i.'_file'])) return false; elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['info'.$i.'_file']['tmp_name'], $tmpName)) return false; elseif (!ImageManager::resize($tmpName, _PS_MODULE_DIR_.$this->name.'/img/reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg')) return false; unlink($tmpName); } Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'reinsurance` (`filename`,`text`,`lien`) VALUES ("'.((isset($filename[0]) && $filename[0] != '') ? pSQL($filename[0]) : '').'", "'.((isset($_POST['info'.$i.'_text']) && $_POST['info'.$i.'_text'] != '') ? pSQL($_POST['info'.$i.'_text']) : '').'", "'.((isset($_POST['info'.$i.'_lien']) && $_POST['info'.$i.'_lien'] != '') ? pSQL($_POST['info'.$i.'_lien']) : '').'")'); } return true; } else return false; } /*public function getContent() { $html = ''; $id_reinsurance = (int)Tools::getValue('id_reinsurance'); if (Tools::isSubmit('saveblockreinsurance')) { if ($id_reinsurance = Tools::getValue('id_reinsurance')) $reinsurance = new reinsuranceClass((int)$id_reinsurance); else $reinsurance = new reinsuranceClass(); $reinsurance->copyFromPost(); $reinsurance->id_shop = $this->context->shop->id; if ($reinsurance->validateFields(false) && $reinsurance->validateFieldsLang(false)) { $reinsurance->save(); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['image'])) return false; elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) return false; elseif (!ImageManager::resize($tmpName, _PS_MODULE_DIR_.$this->name.'/img/reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg')) return false; unlink($tmpName); $reinsurance->file_name = 'reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg'; $reinsurance->save(); } $this->_clearCache('blockreinsurance.tpl'); } else $html .= '<div class="conf error">'.$this->l('An error occurred while attempting to save.').'</div>'; } if (Tools::isSubmit('updateblockreinsurance') || Tools::isSubmit('addblockreinsurance')) { $helper = $this->initForm(); foreach (Language::getLanguages(false) as $lang) if ($id_reinsurance) { $reinsurance = new reinsuranceClass((int)$id_reinsurance); $helper->fields_value['text'][(int)$lang['id_lang']] = $reinsurance->text[(int)$lang['id_lang']]; $helper->fields_value['lien'][(int)$lang['id_lang']] = $reinsurance->lien[(int)$lang['id_lang']]; } else { $helper->fields_value['text'][(int)$lang['id_lang']] = Tools::getValue('text_'.(int)$lang['id_lang'], ''); $helper->fields_value['lien'][(int)$lang['id_lang']] = Tools::getValue('lien_'.(int)$lang['id_lang'], ''); } if ($id_reinsurance = Tools::getValue('id_reinsurance')) { $this->fields_form[0]['form']['input'][] = array('type' => 'hidden', 'name' => 'id_reinsurance'); $helper->fields_value['id_reinsurance'] = (int)$id_reinsurance; } return $html.$helper->generateForm($this->fields_form); } else if (Tools::isSubmit('deleteblockreinsurance')) { $reinsurance = new reinsuranceClass((int)$id_reinsurance); if (file_exists(dirname(__FILE__).'/img/'.$reinsurance->file_name)) unlink(dirname(__FILE__).'/img/'.$reinsurance->file_name); $reinsurance->delete(); $this->_clearCache('blockreinsurance.tpl'); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } else { $helper = $this->initList(); return $html.$helper->generateList($this->getListContent((int)Configuration::get('PS_LANG_DEFAULT')), $this->fields_list); } if (isset($_POST['submitModule'])) { Configuration::updateValue('BLOCKREINSURANCE_NBBLOCKS', ((isset($_POST['nbblocks']) && $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : '')); if ($this->removeFromDB() && $this->addToDB()) { $this->_clearCache('blockreinsurance.tpl'); $output = '<div class="conf confirm">'.$this->l('The block configuration has been updated.').'</div>'; } else $output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>'.$this->l('An error occurred while attempting to save.').'</div>'; } }*/ public function getContent() { $html = ''; $id_reinsurance = (int)Tools::getValue('id_reinsurance'); if (Tools::isSubmit('saveblockreinsurance')) { if ($id_reinsurance = Tools::getValue('id_reinsurance')) $reinsurance = new reinsuranceClass((int)$id_reinsurance); else $reinsurance = new reinsuranceClass(); $reinsurance->copyFromPost(); $reinsurance->id_shop = $this->context->shop->id; if ($reinsurance->validateFields(false) && $reinsurance->validateFieldsLang(false)) { $reinsurance->save(); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { if ($error = ImageManager::validateUpload($_FILES['image'])) return false; elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmpName)) return false; elseif (!ImageManager::resize($tmpName, _PS_MODULE_DIR_.$this->name.'/img/reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg')) return false; unlink($tmpName); $reinsurance->file_name = 'reinsurance-'.(int)$reinsurance->id.'-'.(int)$reinsurance->id_shop.'.jpg'; $reinsurance->save(); } $this->_clearCache('blockreinsurance.tpl'); } else $html .= '<div class="conf error">'.$this->l('An error occurred while attempting to save.').'</div>'; } if (Tools::isSubmit('updateblockreinsurance') || Tools::isSubmit('addblockreinsurance')) { $helper = $this->initForm(); foreach (Language::getLanguages(false) as $lang) if ($id_reinsurance) { $reinsurance = new reinsuranceClass((int)$id_reinsurance); $helper->fields_value['text'][(int)$lang['id_lang']] = $reinsurance->text[(int)$lang['id_lang']]; $helper->fields_value['lien'][(int)$lang['id_lang']] = $reinsurance->lien[(int)$lang['id_lang']]; } else { $helper->fields_value['text'][(int)$lang['id_lang']] = Tools::getValue('text_'.(int)$lang['id_lang'], ''); $helper->fields_value['lien'][(int)$lang['id_lang']] = Tools::getValue('lien_'.(int)$lang['id_lang'], ''); } if ($id_reinsurance = Tools::getValue('id_reinsurance')) { $this->fields_form[0]['form']['input'][] = array('type' => 'hidden', 'name' => 'id_reinsurance'); $helper->fields_value['id_reinsurance'] = (int)$id_reinsurance; } return $html.$helper->generateForm($this->fields_form); } else if (Tools::isSubmit('deleteblockreinsurance')) { $reinsurance = new reinsuranceClass((int)$id_reinsurance); if (file_exists(dirname(__FILE__).'/img/'.$reinsurance->file_name)) unlink(dirname(__FILE__).'/img/'.$reinsurance->file_name); $reinsurance->delete(); $this->_clearCache('blockreinsurance.tpl'); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } else { $helper = $this->initList(); return $html.$helper->generateList($this->getListContent((int)Configuration::get('PS_LANG_DEFAULT')), $this->fields_list); } if (isset($_POST['submitModule'])) { Configuration::updateValue('BLOCKREINSURANCE_NBBLOCKS', ((isset($_POST['nbblocks']) && $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : '')); if ($this->removeFromDB() && $this->addToDB()) { $this->_clearCache('blockreinsurance.tpl'); $output = '<div class="conf confirm">'.$this->l('The block configuration has been updated.').'</div>'; } else $output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>'.$this->l('An error occurred while attempting to save.').'</div>'; } } protected function getListContent($id_lang) { return Db::getInstance()->executeS(' SELECT r.`id_reinsurance`, r.`id_shop`, r.`file_name`, rl.`text`, rl.`lien` FROM `'._DB_PREFIX_.'reinsurance` r LEFT JOIN `'._DB_PREFIX_.'reinsurance_lang` rl ON (r.`id_reinsurance` = rl.`id_reinsurance`) WHERE `id_lang` = '.(int)$id_lang.' '.Shop::addSqlRestrictionOnLang()); } protected function initForm() { $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $this->fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('New reassurance block'), ), 'input' => array( array( 'type' => 'file', 'label' => $this->l('Image'), 'name' => 'image', 'value' => true ), array( 'type' => 'textarea', 'label' => $this->l('Text'), 'lang' => true, 'name' => 'text', 'cols' => 40, 'rows' => 10 ), array( 'type' => 'textarea', 'label' => 'Lien', 'lang' => true, 'name' => 'lien' ) ), 'submit' => array( 'title' => $this->l('Save'), ) ); $helper = new HelperForm(); $helper->module = $this; $helper->name_controller = 'blockreinsurance'; $helper->identifier = $this->identifier; $helper->token = Tools::getAdminTokenLite('AdminModules'); foreach (Language::getLanguages(false) as $lang) $helper->languages[] = array( 'id_lang' => $lang['id_lang'], 'iso_code' => $lang['iso_code'], 'name' => $lang['name'], 'is_default' => ($default_lang == $lang['id_lang'] ? 1 : 0) ); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; $helper->toolbar_scroll = true; $helper->title = $this->displayName; $helper->submit_action = 'saveblockreinsurance'; $helper->toolbar_btn = array( 'save' => array( 'desc' => $this->l('Save'), 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), ), 'back' => array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Back to list') ) ); return $helper; } protected function initList() { $this->fields_list = array( 'id_reinsurance' => array( 'title' => $this->l('ID'), 'width' => 120, 'type' => 'text', 'search' => false, 'orderby' => false ), 'text' => array( 'title' => $this->l('Text'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false ), 'lien' => array( 'title' => $this->l('Lien'), 'width' => 140, 'type' => 'text', 'search' => false, 'orderby' => false ), ); if (Shop::isFeatureActive()) $this->fields_list['id_shop'] = array('title' => $this->l('ID Shop'), 'align' => 'center', 'width' => 25, 'type' => 'int'); $helper = new HelperList(); $helper->shopLinkType = ''; $helper->simple_header = false; $helper->identifier = 'id_reinsurance'; $helper->actions = array('edit', 'delete'); $helper->show_toolbar = true; $helper->imageType = 'jpg'; $helper->toolbar_btn['new'] = array( 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&add'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Add new') ); $helper->title = $this->displayName; $helper->table = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; return $helper; } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now