Beispiel #1
0
 function postProcess()
 {
     global $cookie, $link, $currentIndex;
     if (Tools::isSubmit('viewcms') and $id_cms = (int) Tools::getValue('id_cms') and $cms = new CMS($id_cms, (int) $cookie->id_lang) and Validate::isLoadedObject($cms)) {
         $redir = $link->getCMSLink($cms);
         if (!$cms->active) {
             $admin_dir = dirname($_SERVER['PHP_SELF']);
             $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
             $redir .= '?adtoken=' . Tools::encrypt('PreviewCMS' . $cms->id) . '&ad=' . $admin_dir;
         }
         Tools::redirectAdmin($redir);
     } elseif (Tools::isSubmit('deletecms')) {
         if (Tools::getValue('id_cms') == Configuration::get('PS_CONDITIONS_CMS_ID')) {
             Configuration::updateValue('PS_CONDITIONS', 0);
             Configuration::updateValue('PS_CONDITIONS_CMS_ID', 0);
         }
         $cms = new CMS((int) Tools::getValue('id_cms'));
         $cms->cleanPositions($cms->id_cms_category);
         if (!$cms->delete()) {
             $this->_errors[] = Tools::displayError('An error occurred while deleting object.') . ' <b>' . $this->table . ' (' . mysql_error() . ')</b>';
         } else {
             Tools::redirectAdmin($currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=1&token=' . Tools::getAdminTokenLite('AdminCMSContent'));
         }
     } elseif (Tools::getValue('submitDel' . $this->table)) {
         if ($this->tabAccess['delete'] === '1') {
             if (isset($_POST[$this->table . 'Box'])) {
                 $cms = new CMS();
                 $result = true;
                 $result = $cms->deleteSelection(Tools::getValue($this->table . 'Box'));
                 if ($result) {
                     $cms->cleanPositions((int) Tools::getValue('id_cms_category'));
                     Tools::redirectAdmin($currentIndex . '&conf=2&token=' . Tools::getAdminTokenLite('AdminCMSContent') . '&id_category=' . (int) Tools::getValue('id_cms_category'));
                 }
                 $this->_errors[] = Tools::displayError('An error occurred while deleting selection.');
             } else {
                 $this->_errors[] = Tools::displayError('You must select at least one element to delete.');
             }
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
         }
     } elseif (Tools::isSubmit('submitAddcms') or Tools::isSubmit('submitAddcmsAndPreview')) {
         parent::validateRules();
         if (!sizeof($this->_errors)) {
             if (!($id_cms = (int) Tools::getValue('id_cms'))) {
                 $cms = new CMS();
                 $this->copyFromPost($cms, 'cms');
                 if (!$cms->add()) {
                     $this->_errors[] = Tools::displayError('An error occurred while creating object.') . ' <b>' . $this->table . ' (' . mysql_error() . ')</b>';
                 } elseif (Tools::isSubmit('submitAddcmsAndPreview')) {
                     $preview_url = $link->getCMSLink($cms, $this->getFieldValue($object, 'link_rewrite', $this->_defaultFormLanguage), (int) $cookie->id_lang);
                     if (!$cms->active) {
                         $admin_dir = dirname($_SERVER['PHP_SELF']);
                         $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
                         $token = Tools::encrypt('PreviewCMS' . $cms->id);
                         $preview_url .= $object->active ? '' : '&adtoken=' . $token . '&ad=' . $admin_dir;
                     }
                     Tools::redirectAdmin($preview_url);
                 } else {
                     Tools::redirectAdmin($currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=3&token=' . Tools::getAdminTokenLite('AdminCMSContent'));
                 }
             } else {
                 $cms = new CMS($id_cms);
                 $this->copyFromPost($cms, 'cms');
                 if (!$cms->update()) {
                     $this->_errors[] = Tools::displayError('An error occurred while updating object.') . ' <b>' . $this->table . ' (' . mysql_error() . ')</b>';
                 } elseif (Tools::isSubmit('submitAddcmsAndPreview')) {
                     $preview_url = $link->getCMSLink($cms, $this->getFieldValue($object, 'link_rewrite', $this->_defaultFormLanguage), (int) $cookie->id_lang);
                     if (!$cms->active) {
                         $admin_dir = dirname($_SERVER['PHP_SELF']);
                         $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
                         $token = Tools::encrypt('PreviewCMS' . $cms->id);
                         $preview_url .= $object->active ? '' : '&adtoken=' . $token . '&ad=' . $admin_dir;
                     }
                     Tools::redirectAdmin($preview_url);
                 } else {
                     Tools::redirectAdmin($currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=4&token=' . Tools::getAdminTokenLite('AdminCMSContent'));
                 }
             }
         }
     } elseif (Tools::getValue('position')) {
         if ($this->tabAccess['edit'] !== '1') {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         } elseif (!Validate::isLoadedObject($object = $this->loadObject())) {
             $this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
         } elseif (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) {
             $this->_errors[] = Tools::displayError('Failed to update the position.');
         } else {
             Tools::redirectAdmin($currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=4' . (($id_category = (int) Tools::getValue('id_cms_category')) ? '&id_cms_category=' . $id_category : '') . '&token=' . Tools::getAdminTokenLite('AdminCMSContent'));
         }
     } elseif (Tools::isSubmit('status') and Tools::isSubmit($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Tools::redirectAdmin($currentIndex . '&conf=5' . ((int) Tools::getValue('id_cms_category') ? '&id_cms_category=' . (int) Tools::getValue('id_cms_category') : '') . '&token=' . Tools::getValue('token'));
                 } else {
                     $this->_errors[] = Tools::displayError('An error occurred while updating status.');
                 }
             } else {
                 $this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } else {
         parent::postProcess(true);
     }
 }