public function postProcess()
 {
     if (Tools::isSubmit('viewcms') && ($id_cms = (int) Tools::getValue('id_cms')) && ($cms = new CMS($id_cms, $this->context->language->id)) && Validate::isLoadedObject($cms)) {
         $redir = $this->context->link->getCMSLink($cms);
         if (!$cms->active) {
             $admin_dir = dirname($_SERVER['PHP_SELF']);
             $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
             $redir .= '?adtoken=' . Tools::getAdminTokenLite('AdminCmsContent') . '&ad=' . $admin_dir . '&id_employee=' . (int) $this->context->employee->id;
         }
         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 the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
         } else {
             Tools::redirectAdmin(self::$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 (Tools::isSubmit($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'));
                     $token = Tools::getAdminTokenLite('AdminCmsContent');
                     Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . $token . '&id_cms_category=' . (int) Tools::getValue('id_cms_category'));
                 }
                 $this->errors[] = Tools::displayError('An error occurred while deleting this 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 this.');
         }
     } elseif (Tools::isSubmit('submitAddcms') || Tools::isSubmit('submitAddcmsAndPreview')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         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 an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         } else {
             $cms = new CMS($id_cms);
             $this->copyFromPost($cms, 'cms');
             if (!$cms->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         }
         if (Tools::isSubmit('submitAddcmsAndPreview')) {
             $alias = $this->getFieldValue($cms, 'link_rewrite', $this->context->language->id);
             $preview_url = $this->context->link->getCMSLink($cms, $alias, $this->context->language->id);
             if (!$cms->active) {
                 $admin_dir = dirname($_SERVER['PHP_SELF']);
                 $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
                 $params = http_build_query(array('adtoken' => Tools::getAdminTokenLite('AdminCmsContent'), 'ad' => $admin_dir, 'id_employee' => (int) $this->context->employee->id));
                 if (Configuration::get('PS_REWRITING_SETTINGS')) {
                     $params = '?' . $params;
                 } else {
                     $params = '&' . $params;
                 }
                 $preview_url .= $cms->active ? '' : $params;
             }
             Tools::redirectAdmin($preview_url);
         } elseif (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . $cms->id . '&conf=4&update' . $this->table . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=4&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('way') && Tools::isSubmit('id_cms') && Tools::isSubmit('position')) {
         if ($this->tabAccess['edit'] !== '1') {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         } elseif (!Validate::isLoadedObject($object = $this->loadObject())) {
             $this->errors[] = Tools::displayError('An error occurred while updating the status for an 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(self::$currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=4&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('statuscms') && Tools::isSubmit($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Tools::redirectAdmin(self::$currentIndex . '&conf=5&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getValue('token'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitBulkdeletecms')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'bulkdelete';
             $this->boxes = Tools::getValue($this->table . 'Box');
             if (is_array($this->boxes) && array_key_exists(0, $this->boxes)) {
                 $firstCms = new CMS((int) $this->boxes[0]);
                 $id_cms_category = (int) $firstCms->id_cms_category;
                 if (!($res = parent::postProcess(true))) {
                     return $res;
                 }
                 Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . Tools::getAdminTokenLite('AdminCmsContent') . '&id_cms_category=' . $id_cms_category);
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } else {
         parent::postProcess(true);
     }
 }
 public function postProcess()
 {
     if (Tools::isSubmit('viewcms') && ($id_cms = (int) Tools::getValue('id_cms'))) {
         parent::postProcess();
         if (($cms = new CMS($id_cms, $this->context->language->id)) && Validate::isLoadedObject($cms)) {
             $this->redirect_after = $this->getPreviewUrl($cms);
             Tools::redirectAdmin($this->redirect_after);
         }
     } 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 the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
         } else {
             Tools::redirectAdmin(self::$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 (Tools::isSubmit($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'));
                     $token = Tools::getAdminTokenLite('AdminCmsContent');
                     Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . $token . '&id_cms_category=' . (int) Tools::getValue('id_cms_category'));
                 }
                 $this->errors[] = Tools::displayError('An error occurred while deleting this 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 this.');
         }
     } elseif (Tools::isSubmit('submitAddcms') || Tools::isSubmit('submitAddcmsAndPreview')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         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 an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         } else {
             $cms = new CMS($id_cms);
             $this->copyFromPost($cms, 'cms');
             if (!$cms->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         }
         if (Tools::isSubmit('view' . $this->table)) {
             $this->redirect_after = $this->getPreviewUrl($cms);
             Tools::redirectAdmin($this->redirect_after);
         } elseif (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . $cms->id . '&conf=4&update' . $this->table . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=4&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('way') && Tools::isSubmit('id_cms') && Tools::isSubmit('position')) {
         if ($this->tabAccess['edit'] !== '1') {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         } elseif (!Validate::isLoadedObject($object = $this->loadObject())) {
             $this->errors[] = Tools::displayError('An error occurred while updating the status for an 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(self::$currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=4&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('statuscms') && Tools::isSubmit($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Tools::redirectAdmin(self::$currentIndex . '&conf=5&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getValue('token'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitBulkdeletecms')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'bulkdelete';
             $this->boxes = Tools::getValue($this->table . 'Box');
             if (is_array($this->boxes) && array_key_exists(0, $this->boxes)) {
                 $firstCms = new CMS((int) $this->boxes[0]);
                 $id_cms_category = (int) $firstCms->id_cms_category;
                 if (!($res = parent::postProcess(true))) {
                     return $res;
                 }
                 Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . Tools::getAdminTokenLite('AdminCmsContent') . '&id_cms_category=' . $id_cms_category);
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } else {
         parent::postProcess(true);
     }
 }
Beispiel #3
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);
     }
 }
Beispiel #4
0
$filter = array();
if (intval(Tools::G('delete')) > 0) {
    $object = new CMS(intval(Tools::G('delete')));
    if (Validate::isLoadedObject($object)) {
        $object->delete();
    }
    if (is_array($object->_errors) and count($object->_errors) > 0) {
        $errors = $object->_errors;
    } else {
        UIAdminAlerts::conf('文章已删除');
    }
} elseif (Tools::isSubmit('subDelete')) {
    $select_cat = Tools::getRequest('cmsBox');
    $cms = new CMS();
    if (is_array($select_cat)) {
        if ($cms->deleteSelection($select_cat)) {
            UIAdminAlerts::conf('文章已删除');
        }
    }
} elseif (Tools::isSubmit('subActiveON') or Tools::isSubmit('subActiveOFF')) {
    $select_cat = Tools::P('itemBox');
    $action = Tools::isSubmit('subActiveON') ? 1 : 0;
    $object = new CMS();
    if (is_array($select_cat)) {
        if ($object->statusSelection($select_cat, $action)) {
            UIAdminAlerts::conf('文章已更新');
        }
    }
}
$table = new UIAdminTable('cms', 'CMS', 'id_cms');
$table->header = array(array('sort' => false, 'isCheckAll' => 'itemBox[]'), array('name' => 'id_cms', 'title' => 'ID', 'filter' => 'string'), array('name' => 'title', 'title' => '名称', 'filter' => 'string'), array('name' => 'rewrite', 'title' => '静态链接', 'filter' => 'string'), array('name' => 'active', 'title' => '状态', 'filter' => 'bool'), array('name' => 'is_top', 'title' => '置顶', 'filter' => 'bool'), array('name' => 'add_date', 'title' => '添加时间'), array('sort' => false, 'title' => '操作', 'class' => 'text-right', 'isAction' => array('edit', 'view', 'delete')));