private function _postProcess() { $errors = array(); /* Processes Slider */ if (Tools::isSubmit('submitSlider')) { $res = $this->getParams()->batchUpdate($this->_configs); $this->getParams()->refreshConfig(); if (!$res) { $errors .= $this->displayError($this->l('Configuration could not be updated')); } $this->_html .= $this->displayConfirmation($this->l('Configuration updated')); } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) { $slidemini = new leobtsliderminiControl((int) Tools::getValue('id_slide')); if ($slidemini->active == 0) { $slidemini->active = 1; } else { $slidemini->active = 0; } $res = $slidemini->update(); $this->_html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('Configuration could not be updated')); } elseif (Tools::isSubmit('submitSlide')) { /* Sets ID if needed */ if (Tools::getValue('id_slide')) { $slidemini = new leobtsliderminiControl((int) Tools::getValue('id_slide')); if (!Validate::isLoadedObject($slidemini)) { $this->_html .= $this->displayError($this->l('Invalid id_slide')); return; } } else { $slidemini = new leobtsliderminiControl(); } /* Sets position */ $slidemini->position = (int) Tools::getValue('position'); /* Sets active */ $slidemini->active = (int) Tools::getValue('active_slide'); /* Sets each langue fields */ $languages = Language::getLanguages(false); foreach ($languages as $language) { if (Tools::getValue('title_' . $language['id_lang']) != '') { $slidemini->title[$language['id_lang']] = pSQL(Tools::getValue('title_' . $language['id_lang'])); } if (Tools::getValue('url_' . $language['id_lang']) != '') { $slidemini->url[$language['id_lang']] = pSQL(Tools::getValue('url_' . $language['id_lang'])); } if (Tools::getValue('legend_' . $language['id_lang']) != '') { $slidemini->legend[$language['id_lang']] = pSQL(Tools::getValue('legend_' . $language['id_lang'])); } if (Tools::getValue('description_' . $language['id_lang']) != '') { $slidemini->description[$language['id_lang']] = pSQL(Tools::getValue('description_' . $language['id_lang'])); } /* Uploads image and sets slide */ $type = strtolower(substr(strrchr($_FILES['image_' . $language['id_lang']]['name'], '.'), 1)); $imagesize = array(); $imagesize = @getimagesize($_FILES['image_' . $language['id_lang']]['tmp_name']); if (isset($_FILES['image_' . $language['id_lang']]) && isset($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($imagesize) && in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); $salt = sha1(microtime()); if ($error = ImageManager::validateUpload($_FILES['image_' . $language['id_lang']])) { $errors .= $error; } elseif (!$temp_name || !move_uploaded_file($_FILES['image_' . $language['id_lang']]['tmp_name'], $temp_name)) { return false; } elseif (!ImageManager::resize($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.')); } if (isset($temp_name)) { @unlink($temp_name); } $slidemini->image[$language['id_lang']] = pSQL(Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type); } elseif (Tools::getValue('image_old_' . $language['id_lang']) != '') { $slidemini->image[$language['id_lang']] = pSQL(Tools::getValue('image_old_' . $language['id_lang'])); } } /* Processes if no errors */ if (!$errors) { /* Adds */ if (!Tools::getValue('id_slide')) { if (!$slidemini->add()) { $errors .= $this->displayError($this->l('Slide could not be added')); } } elseif (!$slidemini->update()) { $errors .= $this->displayError($this->l('Slide could not be updated')); } } } elseif (Tools::isSubmit('delete_id_slide')) { $slidemini = new leobtsliderminiControl((int) Tools::getValue('delete_id_slide')); $res = $slidemini->delete(); if (!$res) { $this->_html .= $this->displayError('Could not delete'); } else { $this->_html .= $this->displayConfirmation($this->l('Slide deleted')); } } /* Display errors if needed */ if (count($errors)) { $this->_html .= $this->displayError(implode('<br />', $errors)); } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) { $this->_html .= $this->displayConfirmation($this->l('Slide updated')); } elseif (Tools::isSubmit('submitSlide')) { $this->_html .= $this->displayConfirmation($this->l('Slide added')); } }
public function reOrderPositions() { $id_slide = $this->id; $context = Context::getContext(); $id_shop = $context->shop->id; $max = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(hss.`position`) as position FROM `' . _DB_PREFIX_ . 'leobtslidermini_slides` hss, `' . _DB_PREFIX_ . 'leobtslidermini` hs WHERE hss.`id_leobtslidermini_slides` = hs.`id_leobtslidermini_slides` AND hs.`id_shop` = ' . (int) $id_shop); if ((int) $max == (int) $id_slide) { return true; } $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT hss.`position` as position, hss.`id_leobtslidermini_slides` as id_slide FROM `' . _DB_PREFIX_ . 'leobtslidermini_slides` hss LEFT JOIN `' . _DB_PREFIX_ . 'leobtslidermini` hs ON (hss.`id_leobtslidermini_slides` = hs.`id_leobtslidermini_slides`) WHERE hs.`id_shop` = ' . (int) $id_shop . ' AND hss.`position` > ' . (int) $this->position); foreach ($rows as $row) { $current_slide = new leobtsliderminiControl($row['id_slide']); --$current_slide->position; $current_slide->update(); unset($current_slide); } return true; }