public function importGroup()
 {
     $type = Tools::strtolower(Tools::substr(strrchr($_FILES['import_file']['name'], '.'), 1));
     if (isset($_FILES['import_file']) && $type == 'txt' && isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) {
         include_once _PS_MODULE_DIR_ . 'pssliderlayer/grouplayer.php';
         include_once _PS_MODULE_DIR_ . 'pssliderlayer/sliderlayer.php';
         $content = Tools::file_get_contents($_FILES['import_file']['tmp_name']);
         $content = Tools::jsonDecode(PsSliderSlide::base64Decode($content), true);
         $languageField = array('title', 'link', 'image', 'thumbnail', 'video', 'layersparams');
         $languages = Language::getLanguages();
         $langList = array();
         foreach ($languages as $lang) {
             $langList[$lang['iso_code']] = $lang['id_lang'];
         }
         $override_group = Tools::getValue('override_group');
         //override or edit
         if ($override_group && PsSliderGroup::groupExists($content['id_pssliderlayer_groups'])) {
             $group = new PsSliderGroup($content['id_pssliderlayer_groups']);
             //edit group
             $group = $this->setDataForGroup($group, $content);
             if (!$group->update()) {
                 return false;
             }
             PsSliderGroup::deleteAllSlider($content['id_pssliderlayer_groups']);
             foreach ($content['sliders'] as $slider) {
                 $obj = new PsSliderSlide();
                 foreach ($slider as $key => $val) {
                     if (in_array($key, $languageField)) {
                         foreach ($val as $keyLang => $valLang) {
                             $obj->{$key}[$langList[$keyLang]] = $valLang;
                         }
                     } else {
                         $obj->{$key} = $val;
                     }
                 }
                 $obj->id_group = $group->id;
                 if (isset($slider['id']) && $slider['id'] && PsSliderSlide::sliderExist($slider['id'])) {
                     $obj->update();
                 } else {
                     $obj->add();
                 }
             }
         } else {
             $group = new PsSliderGroup();
             $group = $this->setDataForGroup($group, $content);
             if (!$group->add()) {
                 return false;
             }
             foreach ($content['sliders'] as $slider) {
                 $obj = new PsSliderSlide();
                 foreach ($slider as $key => $val) {
                     if (in_array($key, $languageField)) {
                         foreach ($val as $keyLang => $valLang) {
                             $obj->{$key}[$langList[$keyLang]] = $valLang;
                         }
                     } else {
                         $obj->{$key} = $val;
                     }
                 }
                 $obj->id_group = $group->id;
                 $obj->id = 0;
                 $obj->add();
             }
         }
         //add new
         //return true;
     }
     Tools::redirectAdmin('index.php?controller=AdminModules&token=' . Tools::getAdminTokenLite('AdminModules') . '&configure=pssliderlayer&tab_module=prestabrain&module_name=pssliderlayer&conf=4');
     //return false;
 }
Example #2
0
 public function postValidation()
 {
     $errors = array();
     if (Tools::isSubmit('submitGroup')) {
         if (Tools::isSubmit('id_group')) {
             if (!Validate::isInt(Tools::getValue('id_group')) && !PsSliderGroup::groupExists(Tools::getValue('id_group'))) {
                 $errors[] = $this->l('Invalid id_group');
             }
         }
         $groupValue = Tools::getValue('group');
         /* Checks state (active) */
         if (!Tools::getValue('title_group')) {
             $errors[] = $this->l('Invalid title group');
         }
         if (!Validate::isInt(Tools::getValue('active_group')) || Tools::getValue('active_group') != 0 && Tools::getValue('active_group') != 1) {
             $errors[] = $this->l('Invalid group state');
         }
         if (!Validate::isInt($groupValue['touch_mobile']) || $groupValue['touch_mobile'] != 0 && $groupValue['touch_mobile'] != 1) {
             $errors[] = $this->l('Invalid touch mobile state');
         }
         if (!Validate::isInt($groupValue['stop_on_hover']) || $groupValue['stop_on_hover'] != 0 && $groupValue['stop_on_hover'] != 1) {
             $errors[] = $this->l('Invalid stop on hover state');
         }
         if (!Validate::isInt($groupValue['shuffle_mode']) || $groupValue['shuffle_mode'] != 0 && $groupValue['shuffle_mode'] != 1) {
             $errors[] = $this->l('Invalid Shuffle Mode state');
         }
         if (!Validate::isInt($groupValue['image_cropping']) || $groupValue['image_cropping'] != 0 && $groupValue['image_cropping'] != 1) {
             $errors[] = $this->l('Invalid Image Cropping state');
         }
         if (!Validate::isInt($groupValue['show_time_line']) || $groupValue['show_time_line'] != 0 && $groupValue['show_time_line'] != 1) {
             $errors[] = $this->l('Invalid Show Time Line state');
         }
         if (!Validate::isInt($groupValue['background_image']) || $groupValue['background_image'] != 0 && $groupValue['background_image'] != 1) {
             $errors[] = $this->l('Invalid Show Background Image state');
         }
         if (!Validate::isInt($groupValue['show_navigator']) || $groupValue['show_navigator'] != 0 && $groupValue['show_navigator'] != 1) {
             $errors[] = $this->l('Invalid Always Show Navigator state');
         }
         //check interger isUnsignedInt
         $intArray = array('delay' => $this->l('Invalid Delay value'), 'start_with_slide' => $this->l('Invalid Start With Slide value'), 'width' => $this->l('Invalid Width value'), 'height' => $this->l('Invalid Height value'), 'offset_horizontal' => $this->l('Invalid Offset Horizontal value'), 'offset_vertical' => $this->l('Invalid Offset Vertical value'), 'hide_navigator_after' => $this->l('Invalid Hide Navigator After value'), 'thumbnail_width' => $this->l('Invalid Thumbnail Width value'), 'thumbnail_height' => $this->l('Invalid Thumbnail Height value'), 'thumbnail_amount' => $this->l('Invalid Thumbnail Amount value'));
         foreach ($intArray as $key => $value) {
             if (!Validate::isInt($groupValue[$key]) && $groupValue[$key] != '') {
                 $errors[] = $value;
             }
         }
         if (!Validate::isColor(Tools::getValue('background_color'))) {
             $errors[] = $this->l('Invalid Background color value');
         }
     }
     /* Display errors if needed */
     if (count($errors)) {
         $this->_error_text .= implode('<br>', $errors);
         $this->_html .= $this->displayError(implode('<br />', $errors));
         return false;
     }
     /* Returns if validation is ok */
     return true;
 }