public function getContent() { $html = ''; $id_reassurance = (int) Tools::getValue('id_reassurance'); if (Tools::isSubmit('saveblockreassurance')) { if ($id_reassurance = Tools::getValue('id_reassurance')) { $reassurance = new reassuranceClass((int) $id_reassurance); } else { $reassurance = new reassuranceClass(); } $reassurance->copyFromPost(); $reassurance->id_shop = $this->context->shop->id; if ($reassurance->validateFields(false) && $reassurance->validateFieldsLang(false)) { $reassurance->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/reassurance-' . (int) $reassurance->id . '-' . (int) $reassurance->id_shop . '.jpg')) { return false; } unlink($tmpName); $reassurance->file_name = 'reassurance-' . (int) $reassurance->id . '-' . (int) $reassurance->id_shop . '.jpg'; $reassurance->save(); } $this->_clearCache('*'); } else { $html .= '<div class="conf error">' . $this->trans('An error occurred while attempting to save.', array(), 'Admin.Notifications.Error') . '</div>'; } } if (Tools::isSubmit('updateblockreassurance') || Tools::isSubmit('addblockreassurance')) { $helper = $this->initForm(); foreach (Language::getLanguages(false) as $lang) { if ($id_reassurance) { $reassurance = new reassuranceClass((int) $id_reassurance); $helper->fields_value['text'][(int) $lang['id_lang']] = $reassurance->text[(int) $lang['id_lang']]; $image = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $reassurance->file_name; $this->fields_form[0]['form']['input'][0]['image'] = '<img src="' . $this->getImageURL($reassurance->file_name) . '" />'; } else { $helper->fields_value['text'][(int) $lang['id_lang']] = Tools::getValue('text_' . (int) $lang['id_lang'], ''); } } if ($id_reassurance = Tools::getValue('id_reassurance')) { $this->fields_form[0]['form']['input'][] = array('type' => 'hidden', 'name' => 'id_reassurance'); $helper->fields_value['id_reassurance'] = (int) $id_reassurance; } return $html . $helper->generateForm($this->fields_form); } elseif (Tools::isSubmit('deleteblockreassurance')) { $reassurance = new reassuranceClass((int) $id_reassurance); if (file_exists(dirname(__FILE__) . '/img/' . $reassurance->file_name)) { unlink(dirname(__FILE__) . '/img/' . $reassurance->file_name); } $reassurance->delete(); $this->_clearCache('*'); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules')); } else { $content = $this->getListContent((int) Configuration::get('PS_LANG_DEFAULT')); $helper = $this->initList(); $helper->listTotal = count($content); return $html . $helper->generateList($content, $this->fields_list); } if (isset($_POST['submitModule'])) { Configuration::updateValue('BLOCKREASSURANCE_NBBLOCKS', isset($_POST['nbblocks']) && $_POST['nbblocks'] != '' ? (int) $_POST['nbblocks'] : ''); if ($this->removeFromDB() && $this->addToDB()) { $this->_clearCache('blockreassurance.tpl'); $output = '<div class="conf confirm">' . $this->trans('The block configuration has been updated.', array(), 'Modules.BlockReassurance') . '</div>'; } else { $output = '<div class="conf error"><img src="../img/admin/disabled.gif"/>' . $this->trans('An error occurred while attempting to save.', array(), 'Admin.Notifications.Error') . '</div>'; } } }