// Normalize
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12746 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -28,12 +28,12 @@
|
||||
if (!defined('_CAN_LOAD_FILES_'))
|
||||
exit;
|
||||
|
||||
class blockreinsurance extends Module
|
||||
class Blockreinsurance extends Module
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'blockreinsurance';
|
||||
if(version_compare(_PS_VERSION_, '1.4.0.0') >= 0)
|
||||
if (version_compare(_PS_VERSION_, '1.4.0.0') >= 0)
|
||||
$this->tab = 'front_office_features';
|
||||
else
|
||||
$this->tab = 'Blocks';
|
||||
@@ -47,7 +47,7 @@ class blockreinsurance extends Module
|
||||
|
||||
public function install()
|
||||
{
|
||||
return (parent::install() AND $this->installDB() AND Configuration::updateValue('blockreinsurance_nbblocks', 5) AND $this->registerHook('footer'));
|
||||
return (parent::install() && $this->installDB() && Configuration::updateValue('blockreinsurance_nbblocks', 5) && $this->registerHook('footer'));
|
||||
}
|
||||
|
||||
public function installDB()
|
||||
@@ -63,8 +63,8 @@ class blockreinsurance extends Module
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
//Delete configuration
|
||||
return (Configuration::deleteByName('blockreinsurance_nbblocks') AND $this->uninstallDB() AND parent::uninstall());
|
||||
// Delete configuration
|
||||
return (Configuration::deleteByName('blockreinsurance_nbblocks') && $this->uninstallDB() && parent::uninstall());
|
||||
}
|
||||
|
||||
public function uninstallDB()
|
||||
@@ -75,24 +75,24 @@ class blockreinsurance extends Module
|
||||
|
||||
public function addToDB()
|
||||
{
|
||||
if(isset($_POST['nbblocks']))
|
||||
if (isset($_POST['nbblocks']))
|
||||
{
|
||||
for($i = 1; $i <= (int)$_POST['nbblocks']; $i++)
|
||||
for ($i = 1; $i <= (int)$_POST['nbblocks']; $i++)
|
||||
{
|
||||
$filename = explode('.', $_FILES['info'.$i.'_file']['name']);
|
||||
if (isset($_FILES['info'.$i.'_file']) AND isset($_FILES['info'.$i.'_file']['tmp_name']) AND !empty($_FILES['info'.$i.'_file']['tmp_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') OR !move_uploaded_file($_FILES['info'.$i.'_file']['tmp_name'], $tmpName))
|
||||
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`)
|
||||
VALUES ("'.((isset($filename[0]) AND $filename[0] != '') ? pSQL($filename[0]) : '').
|
||||
'", "'.((isset($_POST['info'.$i.'_text']) AND $_POST['info'.$i.'_text'] != '') ? pSQL($_POST['info'.$i.'_text']) : '').'")');
|
||||
VALUES ("'.((isset($filename[0]) && $filename[0] != '') ? pSQL($filename[0]) : '').
|
||||
'", "'.((isset($_POST['info'.$i.'_text']) && $_POST['info'.$i.'_text'] != '') ? pSQL($_POST['info'.$i.'_text']) : '').'")');
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
@@ -105,10 +105,8 @@ class blockreinsurance extends Module
|
||||
while (false !== ($file = readdir($dir)))
|
||||
{
|
||||
$path = dirname(__FILE__).'/img/'.$file;
|
||||
if ($file != ".." AND $file != "." AND !is_dir($file))
|
||||
{
|
||||
if ($file != '..' && $file != '.' && !is_dir($file))
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
@@ -125,8 +123,8 @@ class blockreinsurance extends Module
|
||||
// If we try to update the settings
|
||||
if (isset($_POST['submitModule']))
|
||||
{
|
||||
Configuration::updateValue('blockreinsurance_nbblocks', ((isset($_POST['nbblocks']) AND $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : ''));
|
||||
if($this->removeFromDB() && $this->addToDB())
|
||||
Configuration::updateValue('blockreinsurance_nbblocks', ((isset($_POST['nbblocks']) && $_POST['nbblocks'] != '') ? (int)$_POST['nbblocks'] : ''));
|
||||
if ($this->removeFromDB() && $this->addToDB())
|
||||
echo '<div class="conf confirm"><img src="../img/admin/ok.gif"/>'.$this->l('Configuration updated').'</div>';
|
||||
else
|
||||
echo '<div class="conf error"><img src="../img/admin/disabled.gif"/>'.$this->l('An error occurred during the save').'</div>';
|
||||
@@ -165,22 +163,20 @@ class blockreinsurance extends Module
|
||||
<fieldset class="width2">
|
||||
<select name="nbblocks">';
|
||||
// Show by default 5 blocks maximum
|
||||
for($i = 1; $i <= 5; $i++)
|
||||
{
|
||||
for ($i = 1; $i <= 5; $i++)
|
||||
$content .= '<option value="'.$i.'" '.(($i == $nb_blocks) ? 'selected="selected"' : '').'>'.$i.' '.$this->l('block(s)').'</option>';
|
||||
}
|
||||
$content .= '</select>
|
||||
<div class="clear"> </div>';
|
||||
// Show by default 5 blocks maximum
|
||||
for($i = 1; $i <= 5; $i++)
|
||||
for ($i = 1; $i <= 5; $i++)
|
||||
{
|
||||
$content .= '<div id="container_infos'.$i.'" class="container_infos"><h3>'.$this->l('Block number').' '.$i.'</h3>'.
|
||||
((!empty($infos[$i-1]) && $infos[$i-1]['filename'] != '') ? '<img src="'.Tools::getHttpHost(true)._MODULE_DIR_.$this->name.'/img/'.$infos[$i-1]['filename'].'.jpg" />' : '').
|
||||
((!empty($infos[$i - 1]) && $infos[$i - 1]['filename'] != '') ? '<img src="'.Tools::getHttpHost(true)._MODULE_DIR_.$this->name.'/img/'.$infos[$i - 1]['filename'].'.jpg" />' : '').
|
||||
'<div class="clear"> </div>
|
||||
<p><label for="info'.$i.'_file">'.$this->l('Image for this block').' :</label>
|
||||
<input type="file" name="info'.$i.'_file" /></p>
|
||||
<p><label for="info'.$i.'_text">'.$this->l('Alternative text for this block').' :</label>
|
||||
<input type="text" id="info'.$i.'_text" name="info'.$i.'_text" value="'.((!empty($infos[$i-1]) && $infos[$i-1]['text'] != '') ? $infos[$i-1]['text'] : '').'" /></p></div>';
|
||||
<input type="text" id="info'.$i.'_text" name="info'.$i.'_text" value="'.((!empty($infos[$i - 1]) && $infos[$i - 1]['text'] != '') ? $infos[$i - 1]['text'] : '').'" /></p></div>';
|
||||
}
|
||||
$content .= '<div class="clear"> </div>
|
||||
<br /><center><input type="submit" name="submitModule" value="'.$this->l('Update settings').'" class="button" /></center>
|
||||
|
||||
Reference in New Issue
Block a user