Ejemplo n.º 1
0
    public function reOrderPositions()
    {
        $id_test = $this->id;
        $context = Context::getContext();
        $id_shop = $context->shop->id;
        $max = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT MAX(pt.`position`) as pos
			FROM `' . _DB_PREFIX_ . 'ptsbttestimonials` pt, `' . _DB_PREFIX_ . 'ptsbttestimonials_shop` pts
			WHERE pt.`id_ptsbttestimonials` = pts.`id_ptsbttestimonials` AND pts.`id_shop` = ' . (int) $id_shop);
        if ((int) $max == (int) $id_test) {
            return true;
        }
        $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT pt.`position` as pos, pt.`id_ptsbttestimonials` as id_test
			FROM `' . _DB_PREFIX_ . 'ptsbttestimonials` pt
			LEFT JOIN `' . _DB_PREFIX_ . 'ptsbttestimonials_shop` pts ON (pt.`id_ptsbttestimonials` = pts.`id_ptsbttestimonials`)
			WHERE pts.`id_shop` = ' . (int) $id_shop . ' AND pt.`position` > ' . (int) $this->position);
        foreach ($rows as $row) {
            $current_test = new PtsTestimonial($row['id_test']);
            --$current_test->position;
            $current_test->update();
            unset($current_test);
        }
        return true;
    }
Ejemplo n.º 2
0
 public function postProcess()
 {
     $errors = array();
     if (Tools::isSubmit('submitPtsBtTestimonials')) {
         $this->makeFormConfigs();
         $res = $this->batchUpdateConfigs();
         $this->clearCache();
         if ($res) {
             $this->_html .= $this->displayConfirmation($this->l('Configuration updated successfully.'));
         } else {
             $errors[] = $this->displayError($this->l('The configuration could not be updated.'));
         }
     } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_test')) {
         $test = new PtsTestimonial((int) Tools::getValue('id_test'));
         if ($test->active == 0) {
             $test->active = 1;
         } else {
             $test->active = 0;
         }
         $res = $test->update();
         $this->clearCache();
         $this->_html .= $res ? $this->displayConfirmation($this->l('Configuration updated successfully')) : $this->displayError($this->l('The configuration could not be updated.'));
     } elseif (Tools::isSubmit('submitTestimonial')) {
         if (Tools::getValue('id_test')) {
             $test = new PtsTestimonial((int) Tools::getValue('id_test'));
             if (!Validate::isLoadedObject($test)) {
                 $this->_html .= $this->displayError($this->l('Invalid Id_testimonial'));
                 return false;
             }
         } else {
             $test = new PtsTestimonial();
         }
         $type = Tools::strtolower(Tools::substr(strrchr($_FILES['image']['name'], '.'), 1));
         $imagesize = getimagesize($_FILES['image']['tmp_name']);
         if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['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'])) {
                 $errors[] = $error;
             } elseif (!$temp_name || !move_uploaded_file($_FILES['image']['tmp_name'], $temp_name)) {
                 return false;
             } elseif (!ImageManager::resize($temp_name, dirname(__FILE__) . '/views/img/' . Tools::encrypt($_FILES['image']['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);
             }
             $test->avatar = Tools::encrypt($_FILES['image']['name'] . $salt) . '.' . $type;
         } elseif (Tools::getValue('image_old') != '') {
             $test->avatar = Tools::getValue('image_old');
         }
         $test->name = Tools::getValue('name');
         $test->email = Tools::getValue('email');
         $test->company = Tools::getValue('company');
         $test->address = Tools::getValue('address');
         $url = Tools::getValue('url');
         if (isset($url)) {
             $values = $this->getMediaLinkIdAndType($url);
             $test->media_id = $values['id_link'];
             $test->media_type = $values['type'];
             $test->media_code = $url;
         }
         $id_test = Tools::getValue('id_test');
         if (!empty($id_test)) {
             $test->position = $this->getOldPosition($id_test);
         } else {
             $test->position = $this->handlePosition();
         }
         $test->active = (int) Tools::getValue('active_test');
         foreach ($this->languages() as $lang) {
             $test->content[$lang['id_lang']] = Tools::getValue('content_' . $lang['id_lang']);
             $test->note[$lang['id_lang']] = Tools::getValue('note_' . $lang['id_lang']);
         }
         /* Processes if no errors  */
         if (!$errors) {
             /* Adds */
             if (!Tools::getValue('id_test')) {
                 if (!$test->add()) {
                     $errors[] = $this->displayError($this->l('The Testimonial could not be added.'));
                 }
             } elseif (!$test->update()) {
                 $errors[] = $this->displayError($this->l('The Testimonial could not be updated.'));
             }
             $this->clearCache();
         }
     } elseif (Tools::isSubmit('delete_id_test')) {
         $test = new PtsTestimonial((int) Tools::getValue('delete_id_test'));
         $res = $test->delete();
         $this->clearCache();
         if (!$res) {
             $this->_html .= $this->displayError('Could not delete.');
         } else {
             $admin_url = $this->context->link->getAdminLink('AdminModules', true);
             $admin_url .= '&conf=1&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
             Tools::redirectAdmin($admin_url);
         }
     }
     if (count($errors)) {
         $this->_html .= $this->displayError(implode('<br />', $errors));
     } elseif (Tools::isSubmit('submitTestimonial') && Tools::getValue('id_test')) {
         $admin_url = $this->context->link->getAdminLink('AdminModules', true);
         $admin_url .= '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
         Tools::redirectAdmin($admin_url);
     } elseif (Tools::isSubmit('submitTestimonial')) {
         $admin_url = $this->context->link->getAdminLink('AdminModules', true);
         $admin_url .= '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
         Tools::redirectAdmin($admin_url);
     }
 }