// fixed homeSlider

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11554 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone
2011-12-21 20:29:21 +00:00
parent f303dabffc
commit 76a270ab66
3 changed files with 21 additions and 16 deletions
+7 -7
View File
@@ -104,15 +104,17 @@ class HomeSlide extends ObjectModel
public function delete() public function delete()
{ {
$res = null; $res = true;
$images = $this->image; $images = $this->image;
foreach ($images as $image) foreach ($images as $image)
{ {
if (file_exists(dirname(__FILE__).'/images/'.$image)) if ($image && file_exists(dirname(__FILE__).'/images/'.$image))
$res &= @unlink(dirname(__FILE__).'/images/'.$image); $res &= @unlink(dirname(__FILE__).'/images/'.$image);
} }
$res &= $this->reOrderPositions(); $res &= $this->reOrderPositions();
$res &= Db::getInstance()->execute(' $res &= Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'homeslider` DELETE FROM `'._DB_PREFIX_.'homeslider`
WHERE `id_homeslider_slides` = '.(int)$this->id WHERE `id_homeslider_slides` = '.(int)$this->id
@@ -139,13 +141,11 @@ class HomeSlide extends ObjectModel
$rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hss.`position` as position, hss.`id_homeslider_slides` as id_slide SELECT hss.`position` as position, hss.`id_homeslider_slides` as id_slide
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs FROM `'._DB_PREFIX_.'homeslider_slides` hss
WHERE hss.`id_homeslider_slides` = hs.`id_homeslider_slides` AND hs.`id_shop` = '.(int)$id_shop.' AND hss.`position` > '.(int)$this->position LEFT JOIN `'._DB_PREFIX_.'homeslider` hs ON (hss.`id_homeslider_slides` = hs.`id_homeslider_slides`)
WHERE hs.`id_shop` = '.(int)$id_shop.' AND hss.`position` > '.(int)$this->position
); );
if (!$rows)
return false;
foreach ($rows as $row) foreach ($rows as $row)
{ {
$current_slide = new HomeSlide($row['id_slide']); $current_slide = new HomeSlide($row['id_slide']);
+1 -1
View File
@@ -44,7 +44,7 @@ if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slid
{ {
$res = Db::getInstance()->execute(' $res = Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'homeslider_slides` SET `position` = '.(int)$position.' UPDATE `'._DB_PREFIX_.'homeslider_slides` SET `position` = '.(int)$position.'
WHERE `id_slide` = '.(int)$id_slide WHERE `id_homeslider_slides` = '.(int)$id_slide
); );
} }
+13 -8
View File
@@ -258,7 +258,7 @@ class HomeSlider extends Module
$defaultLanguage = (int)Configuration::get('PS_LANG_DEFAULT'); $defaultLanguage = (int)Configuration::get('PS_LANG_DEFAULT');
$languages = Language::getLanguages(false); $languages = Language::getLanguages(false);
$divLangName = 'image¤title¤url¤legend¤description'; $divLangName = 'image¤title¤url¤legend¤description';
$this->_html = '<script type="text/javascript">id_language = Number('.$defaultLanguage.');</script>'; $this->_html .= '<script type="text/javascript">id_language = Number('.$defaultLanguage.');</script>';
/* Form */ /* Form */
$this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="POST" enctype="multipart/form-data">'; $this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="POST" enctype="multipart/form-data">';
@@ -466,7 +466,7 @@ class HomeSlider extends Module
$res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int)Tools::getValue('HOMESLIDER_PAUSE')); $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int)Tools::getValue('HOMESLIDER_PAUSE'));
if (!$res) if (!$res)
$errors .= $this->displayError($this->l('Configuration could not be updated')); $errors .= $this->displayError($this->l('Configuration could not be updated'));
$this->_html = $this->displayConfirmation($this->l('Configuration updated')); $this->_html .= $this->displayConfirmation($this->l('Configuration updated'));
} /* Process Slide status */ } /* Process Slide status */
else if (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) else if (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide'))
{ {
@@ -476,7 +476,7 @@ class HomeSlider extends Module
else else
$slide->active = 0; $slide->active = 0;
$res = $slide->update(); $res = $slide->update();
$this->_html = ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayErro($this->l('Configuration could not be updated'))); $this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayErro($this->l('Configuration could not be updated')));
} }
/* Processes Slide */ /* Processes Slide */
else if (Tools::isSubmit('submitSlide')) else if (Tools::isSubmit('submitSlide'))
@@ -487,7 +487,7 @@ class HomeSlider extends Module
$slide = new HomeSlide((int)Tools::getValue('id_slide')); $slide = new HomeSlide((int)Tools::getValue('id_slide'));
if (!Validate::isLoadedObject($slide)) if (!Validate::isLoadedObject($slide))
{ {
$this->_html = $this->displayError($this->l('Invalid id_slide')); $this->_html .= $this->displayError($this->l('Invalid id_slide'));
return; return;
} }
} }
@@ -511,20 +511,24 @@ class HomeSlider extends Module
if (Tools::getValue('description_'.$language['id_lang']) != '') if (Tools::getValue('description_'.$language['id_lang']) != '')
$slide->description[$language['id_lang']] = pSQL(Tools::getValue('description_'.$language['id_lang'])); $slide->description[$language['id_lang']] = pSQL(Tools::getValue('description_'.$language['id_lang']));
/* Uploads image and sets slide */ /* Uploads image and sets slide */
$type = strtolower(substr(strrchr($_FILES['image_'.$language['id_lang']]['name'], '.'), 1));
if (isset($_FILES['image_'.$language['id_lang']]) && if (isset($_FILES['image_'.$language['id_lang']]) &&
isset($_FILES['image_'.$language['id_lang']]['tmp_name']) && isset($_FILES['image_'.$language['id_lang']]['tmp_name']) &&
!empty($_FILES['image_'.$language['id_lang']]['tmp_name'])) !empty($_FILES['image_'.$language['id_lang']]['tmp_name']) &&
in_array(strtolower(substr(strrchr($_FILES['image_'.$language['id_lang']]['type'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) &&
in_array($type, array('jpg', 'gif', 'jpeg', 'png')))
{ {
$temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
$salt = sha1(microtime());
if ($error = checkImage($_FILES['image_'.$language['id_lang']])) if ($error = checkImage($_FILES['image_'.$language['id_lang']]))
$errors .= $error; $errors .= $error;
else if (!$temp_name || !move_uploaded_file($_FILES['image_'.$language['id_lang']]['tmp_name'], $temp_name)) else if (!$temp_name || !move_uploaded_file($_FILES['image_'.$language['id_lang']]['tmp_name'], $temp_name))
return false; return false;
else if (!imageResize($temp_name, dirname(__FILE__).'/images/'.Tools::encrypt($_FILES['image_'.$language['id_lang']]['name']).'.jpg')) else if (!imageResize($temp_name, dirname(__FILE__).'/images/'.Tools::encrypt($_FILES['image_'.$language['id_lang']]['name'].$salt).$type))
$errors .= $this->displayError($this->l('An error occurred during the image upload.')); $errors .= $this->displayError($this->l('An error occurred during the image upload.'));
if (isset($temp_name)) if (isset($temp_name))
unlink($temp_name); unlink($temp_name);
$slide->image[$language['id_lang']] = pSQL(Tools::encrypt($_FILES['image_'.($language['id_lang'])]['name']).'.jpg'); $slide->image[$language['id_lang']] = pSQL(Tools::encrypt($_FILES['image_'.($language['id_lang'])]['name'].$salt).$type);
} }
if (Tools::getValue('image_old_'.$language['id_lang']) != '') if (Tools::getValue('image_old_'.$language['id_lang']) != '')
$slide->image[$language['id_lang']] = pSQL(Tools::getValue('image_old_'.$language['id_lang'])); $slide->image[$language['id_lang']] = pSQL(Tools::getValue('image_old_'.$language['id_lang']));
@@ -545,7 +549,8 @@ class HomeSlider extends Module
$res = $slide->delete(); $res = $slide->delete();
if (!$res) if (!$res)
$this->_html .= $this->displayError('Could not delete'); $this->_html .= $this->displayError('Could not delete');
$this->_html = $this->displayConfirmation($this->l('Slide deleted')); else
$this->_html .= $this->displayConfirmation($this->l('Slide deleted'));
} }
/* Display errors if needed */ /* Display errors if needed */