* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminCMS extends AdminTab { private $_category; public function __construct() { $this->table = 'cms'; $this->className = 'CMS'; $this->lang = true; $this->edit = true; $this->view = true; $this->delete = true; $this->fieldsDisplay = array( 'id_cms' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'link_rewrite' => array('title' => $this->l('URL'), 'width' => 200), 'meta_title' => array('title' => $this->l('Title'), 'width' => 300), 'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'position', 'align' => 'center', 'position' => 'position'), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) ); $this->_category = AdminCMSContent::getCurrentCMSCategory(); $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'cms_category` c ON (c.`id_cms_category` = a.`id_cms_category`)'; $this->_select = 'a.position '; $this->_filter = 'AND c.id_cms_category = '.(int)($this->_category->id); parent::__construct(); } private function _displayDraftWarning($active) { return '

'.$this->l('Your CMS page will be saved as a draft').'

'; } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); $obj = $this->loadObject(true); $iso = Language::getIsoById((int)($cookie->id_lang)); $divLangName = 'meta_title¤meta_description¤meta_keywords¤ccontent¤link_rewrite'; echo '
'.($obj->id ? '' : '').' '.$this->_displayDraftWarning($obj->active).'
'.$this->l('CMS page').''; // META TITLE echo '
'; foreach ($this->_languages as $language) echo '
*
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'meta_title'); echo '
 
'; // META DESCRIPTION echo '
'; foreach ($this->_languages as $language) echo '
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'meta_description'); echo '
 
'; // META KEYWORDS echo '
'; foreach ($this->_languages as $language) echo '
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'meta_keywords'); echo '
 
'; // LINK REWRITE echo '
'; foreach ($this->_languages as $language) echo ' '; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'link_rewrite'); echo '
 
'; // CONTENT echo '
'; foreach ($this->_languages as $language) echo '
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'ccontent'); echo '
 
getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
'; // SUBMIT echo '
* '.$this->l('Required field').'

'.$this->_displayDraftWarning($obj->active).'
'; // TinyMCE global $cookie; $iso = Language::getIsoById((int)($cookie->id_lang)); $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'); $ad = dirname($_SERVER["PHP_SELF"]); echo ' '; } public function display($token = NULL) { global $currentIndex, $cookie; if (($id_cms_category = (int)Tools::getValue('id_cms_category'))) $currentIndex .= '&id_cms_category='.$id_cms_category; $this->getList((int)($cookie->id_lang), !$cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$cookie->__get($this->table.'Orderway') ? 'ASC' : NULL); //$this->getList((int)($cookie->id_lang)); if (!$id_cms_category) $id_cms_category = 1; echo '

'.(!$this->_listTotal ? ($this->l('No pages found')) : ($this->_listTotal.' '.($this->_listTotal > 1 ? $this->l('pages') : $this->l('page')))).' '. $this->l('in category').' "'.stripslashes(CMSCategory::hideCMSCategoryPosition($this->_category->getName())).'"

'; echo ' '.$this->l('Add a new page').'
'; $this->displayList($token); echo '
'; } public function displayList($token = NULL) { global $currentIndex; /* Display list header (filtering, pagination and column names) */ $this->displayListHeader($token); if (!sizeof($this->_list)) echo ''.$this->l('No items found').''; /* Show the content of the table */ $this->displayListContent($token); /* Close list table and submit button */ $this->displayListFooter($token); } 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.').' '.$this->table.' ('.mysql_error().')'; else Tools::redirectAdmin($currentIndex.'&id_cms_category='.$cms->id_cms_category.'&conf=1&token='.Tools::getAdminTokenLite('AdminCMSContent')); }/* Delete multiple objects */ 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.').' '.$this->table.' ('.mysql_error().')'; 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.').' '.$this->table.' ('.mysql_error().')'; 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.').' '.$this->table.' '.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')); } /* Change object statuts (active, inactive) */ 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.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } else parent::postProcess(true); } }