Example #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(et.`position`) as position
			FROM `' . _DB_PREFIX_ . 'extra_tabs` et, `' . _DB_PREFIX_ . 'extra_tabs_shop` ets
			WHERE et.`id_tab` = ets.`id_tab` AND ets.`id_shop` = ' . (int) $id_shop);
        if ((int) $max == (int) $id_slide) {
            return true;
        }
        $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT et.`position` as position, et.`id_tab` as id_slide
			FROM `' . _DB_PREFIX_ . 'extra_tabs` et
			LEFT JOIN `' . _DB_PREFIX_ . 'extra_tabs_shop` ets ON (et.`id_tab` = ets.`id_tab`)
			WHERE ets.`id_shop` = ' . (int) $id_shop . ' AND et.`position` > ' . (int) $this->position);
        foreach ($rows as $row) {
            $current_tab = new Extratabs($row['id_tab']);
            --$current_tab->position;
            $current_tab->update();
            unset($current_tab);
        }
        return true;
    }
Example #2
0
 public function getContent()
 {
     $output = '';
     $errors = array();
     if (Tools::isSubmit('submitSaveTab')) {
         if (Tools::isSubmit('id_tab')) {
             $extra_tab = new Extratabs((int) Tools::getValue('id_tab'));
             if (!Validate::isLoadedObject($extra_tab)) {
                 $errors[] = $this->displayError($this->l('Invalid id_slide'));
                 return;
             }
         } else {
             $extra_tab = new Extratabs();
         }
         /* Sets position */
         $extra_tab->position = (int) Tools::getValue('position');
         /* Sets active */
         $extra_tab->active = (int) Tools::getValue('active');
         $extra_tab->category = Tools::getValue('category');
         $extra_tab->product = Tools::getValue('product');
         $languages = Language::getLanguages(false);
         foreach ($languages as $language) {
             $extra_tab->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']);
             $extra_tab->content[$language['id_lang']] = Tools::getValue('tabcontent_' . $language['id_lang']);
         }
         if (!$errors) {
             /* Adds */
             if (!Tools::isSubmit('id_tab')) {
                 if (!$extra_tab->add()) {
                     $errors[] = $this->displayError($this->l('The tab could not be added.'));
                 }
             } elseif (!$extra_tab->update()) {
                 $errors[] = $this->displayError($this->l('The tab could not be updated.'));
             }
             Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
         }
     } elseif (Tools::isSubmit('removetab')) {
         if (Tools::isSubmit('id_tab')) {
             $extra_tab = new Extratabs((int) Tools::getValue('id_tab'));
             if (!$extra_tab->delete()) {
                 $errors[] = $this->displayError('Could not delete');
             }
         }
     } elseif (Tools::isSubmit('changeactive')) {
         if (Tools::isSubmit('id_tab')) {
             $extra_tab = new Extratabs((int) Tools::getValue('id_tab'));
             $extra_tab->active = !$extra_tab->active;
             if (!$extra_tab->update()) {
                 $errors[] = $this->displayError('Could not change');
             } else {
                 Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'));
             }
         }
     }
     $this->context->smarty->assign(array('postAction' => AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'), 'ajaxurl' => $this->_path . 'ajax.php'));
     if (count($errors)) {
         $output .= $this->displayError(implode('<br />', $errors));
     }
     if (Tools::isSubmit('itemsubmit')) {
         return $output . $this->displayItemForm();
     } else {
         return $output . $this->displayForm();
     }
 }