Exemplo n.º 1
0
 private function _postProcess()
 {
     $errors = array();
     /* Processes Slider */
     if (Tools::isSubmit('submitSlider')) {
         $res = Configuration::updateValue('CATESLIDER_WIDTH', (int) Tools::getValue('slide_width'));
         $res &= Configuration::updateValue('CATESLIDER_HEIGHT', (int) Tools::getValue('slide_height'));
         $res &= Configuration::updateValue('CATESLIDER_SPEED', (int) Tools::getValue('slide_speed'));
         $res &= Configuration::updateValue('CATESLIDER_PAUSE', (int) Tools::getValue('slide_pause'));
         $res &= Configuration::updateValue('CATESLIDER_LOOP', (int) Tools::getValue('slide_loop'));
         $this->clearCache();
         if (!$res) {
             $errors[] = $this->displayError($this->l('The configuration could not be updated.'));
         }
         $this->_html .= $this->displayConfirmation($this->l('Configuration updated'));
     } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) {
         $slide = new CategorySlide((int) Tools::getValue('id_slide'));
         if ($slide->active == 0) {
             $slide->active = 1;
         } else {
             $slide->active = 0;
         }
         $res = $slide->update();
         $this->clearCache();
         $this->_html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.'));
     } elseif (Tools::isSubmit('submitSlide')) {
         /* Sets ID if needed */
         if (Tools::getValue('id_slide')) {
             $slide = new CategorySlide((int) Tools::getValue('id_slide'));
             if (!Validate::isLoadedObject($slide)) {
                 $this->_html .= $this->displayError($this->l('Invalid id_slide'));
                 return;
             }
         } else {
             $slide = new CategorySlide();
         }
         /* Sets position */
         $slide->position = (int) Tools::getValue('position');
         /* Sets active */
         $slide->active = (int) Tools::getValue('active_slide');
         $slide->id_category = (int) Tools::getValue('id_category');
         /* Sets each langue fields */
         $languages = Language::getLanguages(false);
         foreach ($languages as $language) {
             $slide->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']);
             $slide->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']);
             $slide->legend[$language['id_lang']] = Tools::getValue('legend_' . $language['id_lang']);
             $slide->description[$language['id_lang']] = 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, null, null, $type)) {
                     $errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
                 }
                 if (isset($temp_name)) {
                     @unlink($temp_name);
                 }
                 $slide->image[$language['id_lang']] = Tools::encrypt($_FILES['image_' . $language['id_lang']]['name'] . $salt) . '.' . $type;
             } elseif (Tools::getValue('image_old_' . $language['id_lang']) != '') {
                 $slide->image[$language['id_lang']] = Tools::getValue('image_old_' . $language['id_lang']);
             }
         }
         /* Processes if no errors  */
         if (!$errors) {
             /* Adds */
             if (!Tools::getValue('id_slide')) {
                 if (!$slide->add()) {
                     $errors[] = $this->displayError($this->l('The slide could not be added.'));
                 }
             } elseif (!$slide->update()) {
                 $errors[] = $this->displayError($this->l('The slide could not be updated.'));
             }
             $this->clearCache();
         }
     } elseif (Tools::isSubmit('delete_id_slide')) {
         $slide = new CategorySlide((int) Tools::getValue('delete_id_slide'));
         $res = $slide->delete();
         $this->clearCache();
         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'));
     }
 }
Exemplo n.º 2
0
    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_ . 'categoryslider_slides` hss, `' . _DB_PREFIX_ . 'categoryslider` hs
			WHERE hss.`id_categoryslider_slides` = hs.`id_categoryslider_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_categoryslider_slides` as id_slide
			FROM `' . _DB_PREFIX_ . 'categoryslider_slides` hss
			LEFT JOIN `' . _DB_PREFIX_ . 'categoryslider` hs ON (hss.`id_categoryslider_slides` = hs.`id_categoryslider_slides`)
			WHERE hs.`id_shop` = ' . (int) $id_shop . ' AND hss.`position` > ' . (int) $this->position);
        foreach ($rows as $row) {
            $current_slide = new CategorySlide($row['id_slide']);
            --$current_slide->position;
            $current_slide->update();
            unset($current_slide);
        }
        return true;
    }