示例#1
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_ . 'homeslider_slides` hss, `' . _DB_PREFIX_ . 'homeslider` hs
			WHERE hss.`id_homeslider_slides` = hs.`id_homeslider_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_homeslider_slides` as id_slide
			FROM `' . _DB_PREFIX_ . 'homeslider_slides` hss
			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);
        foreach ($rows as $row) {
            $current_slide = new HomeSlide($row['id_slide']);
            --$current_slide->position;
            $current_slide->update();
            unset($current_slide);
        }
        return true;
    }
示例#2
0
 public function renderList()
 {
     $slides = $this->getSlides();
     foreach ($slides as $key => $slide) {
         $slides[$key]['status'] = $this->displayStatus($slide['id_slide'], $slide['active']);
         $associated_shop_ids = HomeSlide::getAssociatedIdsShop((int) $slide['id_slide']);
         if ($associated_shop_ids && count($associated_shop_ids) > 1) {
             $slides[$key]['is_shared'] = true;
         } else {
             $slides[$key]['is_shared'] = false;
         }
     }
     $this->context->smarty->assign(array('link' => $this->context->link, 'slides' => $slides, 'image_baseurl' => $this->_path . 'images/'));
     return $this->display(__FILE__, 'list.tpl');
 }
示例#3
0
 private function _postProcess()
 {
     $errors = array();
     /* Processes Slider */
     if (Tools::isSubmit('submitSlider')) {
         $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'));
         $res &= Configuration::updateValue('HOMESLIDER_HEIGHT', (int) Tools::getValue('HOMESLIDER_HEIGHT'));
         $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'));
         $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'));
         $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_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 HomeSlide((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 HomeSlide((int) Tools::getValue('id_slide'));
             if (!Validate::isLoadedObject($slide)) {
                 $this->_html .= $this->displayError($this->l('Invalid id_slide'));
                 return;
             }
         } else {
             $slide = new HomeSlide();
         }
         /* Sets position */
         $slide->position = (int) Tools::getValue('position');
         /* Sets active */
         $slide->active = (int) Tools::getValue('active_slide');
         /* 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 HomeSlide((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'));
     }
 }
示例#4
0
 private function _postProcess()
 {
     $errors = array();
     $shop_context = Shop::getContext();
     /* Processes Slider */
     if (Tools::isSubmit('submitSlider')) {
         $shop_groups_list = array();
         $shops = Shop::getContextListShopID();
         foreach ($shops as $shop_id) {
             $shop_group_id = (int) Shop::getGroupFromShop($shop_id, true);
             if (!in_array($shop_group_id, $shop_groups_list)) {
                 $shop_groups_list[] = $shop_group_id;
             }
             $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id, $shop_id);
             $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id, $shop_id);
             $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id, $shop_id);
             $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id, $shop_id);
         }
         /* Update global shop context if needed*/
         switch ($shop_context) {
             case Shop::CONTEXT_ALL:
                 $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'));
                 $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'));
                 $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'));
                 $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'));
                 if (count($shop_groups_list)) {
                     foreach ($shop_groups_list as $shop_group_id) {
                         $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id);
                     }
                 }
                 break;
             case Shop::CONTEXT_GROUP:
                 if (count($shop_groups_list)) {
                     foreach ($shop_groups_list as $shop_group_id) {
                         $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id);
                     }
                 }
                 break;
         }
         $this->clearCache();
         if (!$res) {
             $errors[] = $this->displayError($this->l('The configuration could not be updated.'));
         } else {
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=6&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
         }
     } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) {
         $slide = new HomeSlide((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 HomeSlide((int) Tools::getValue('id_slide'));
             if (!Validate::isLoadedObject($slide)) {
                 $this->_html .= $this->displayError($this->l('Invalid slide ID'));
                 return false;
             }
         } else {
             $slide = new HomeSlide();
         }
         /* Sets position */
         $slide->position = (int) Tools::getValue('position');
         /* Sets active */
         $slide->active = (int) Tools::getValue('active_slide');
         /* 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 = Tools::strtolower(Tools::substr(strrchr($_FILES['image_' . $language['id_lang']]['name'], '.'), 1));
             $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(Tools::strtolower(Tools::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/' . $salt . '_' . $_FILES['image_' . $language['id_lang']]['name'], 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']] = $salt . '_' . $_FILES['image_' . $language['id_lang']]['name'];
             } 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 HomeSlide((int) Tools::getValue('delete_id_slide'));
         $res = $slide->delete();
         $this->clearCache();
         if (!$res) {
             $this->_html .= $this->displayError('Could not delete.');
         } else {
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=1&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
         }
     }
     /* Display errors if needed */
     if (count($errors)) {
         $this->_html .= $this->displayError(implode('<br />', $errors));
     } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) {
         Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
     } elseif (Tools::isSubmit('submitSlide')) {
         Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
     }
 }
示例#5
0
文件: Page.php 项目: krissihall/sm_ss
 public function HomeSlides()
 {
     $homeSlide = HomeSlide::get();
     return $homeSlide;
 }
 protected function importHomeSlides()
 {
     if (!(int) Validate::isLoadedObject(Module::getInstanceByName('homeslider')) || !Module::isEnabled('homeslider') || !Module::isInstalled('homeslider')) {
         return;
     }
     $new_path = new Sampledatainstall();
     $sfile = $new_path->sendPath() . 'input/home_slides.csv';
     if (!is_file($sfile) && !is_readable($sfile)) {
         return;
     }
     $this->truncateTables(array('homeslider', 'homeslider_slides', 'homeslider_slides_lang'));
     $handle = $this->openCsvFile('home_slides.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('HomeSlide', $this->home_slide_fields, $line);
         if (!isset($fields['id'])) {
             $slide = new HomeSlide($line[0]);
             $slide->id = $line[0];
         } else {
             $slide = new HomeSlide($fields['id']);
         }
         foreach ($fields as $key => $field) {
             if ($key == 'description' || $key == 'title' || $key == 'legend' || $key == 'url' || $key == 'image') {
                 $slide->{$key} = $this->multilFild($field);
             } else {
                 $slide->{$key} = $field;
             }
         }
         $slide->force_id = true;
         if (!$res) {
             $res = $slide->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }