* @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 AdminCMSCategories extends AdminTab { protected $maxImageSize = 300000; /** @var object CMSCategory() instance for navigation*/ private $_CMSCategory; public function __construct() { global $cookie; $this->table = 'cms_category'; $this->className = 'CMSCategory'; $this->lang = true; $this->edit = true; $this->view = true; $this->delete = true; $this->fieldsDisplay = array( 'id_cms_category' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 30), 'name' => array('title' => $this->l('Name'), 'width' => 100, 'callback' => 'hideCMSCategoryPosition'), 'description' => array('title' => $this->l('Description'), 'width' => 500, 'maxlength' => 90, 'orderby' => false), 'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'position', 'align' => 'center', 'position' => 'position'), 'active' => array('title' => $this->l('Displayed'), 'active' => 'status', 'align' => 'center', 'type' => 'bool', 'orderby' => false)); $this->_CMSCategory = AdminCMSContent::getCurrentCMSCategory(); $this->_filter = 'AND `id_parent` = '.(int)($this->_CMSCategory->id); $this->_select = 'position '; parent::__construct(); } 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); } public function display($token = NULL) { global $currentIndex, $cookie; $id_cms_category = (int)(Tools::getValue('id_cms_category', 1)); $this->getList((int)($cookie->id_lang), !$cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$cookie->__get($this->table.'Orderway') ? 'ASC' : NULL); echo '

'.(!$this->_listTotal ? ($this->l('There are no subcategories')) : ($this->_listTotal.' '.($this->_listTotal > 1 ? $this->l('subcategories') : $this->l('subCMS Category')))).' '.$this->l('in CMS Category').' "'.stripslashes(CMSCategory::hideCMSCategoryPosition($this->_CMSCategory->getName())).'"

'; echo ' '.$this->l('Add a new sub CMS Category').'
'; $this->displayList($token); echo '
'; } public function postProcess($token = NULL) { global $cookie, $currentIndex; $this->tabAccess = Profile::getProfileAccess($cookie->profile, $this->id); if (Tools::isSubmit('submitAdd'.$this->table)) { if ($id_cms_category = (int)(Tools::getValue('id_cms_category'))) { if (!CMSCategory::checkBeforeMove($id_cms_category, (int)(Tools::getValue('id_parent')))) { $this->_errors[] = Tools::displayError('CMS Category cannot be moved here'); return false; } } } /* Change object statuts (active, inactive) */ elseif (isset($_GET['statuscms_category']) AND Tools::getValue($this->identifier)) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->toggleStatus()) Tools::redirectAdmin($currentIndex.'&conf=5'.((int)$object->id_parent ? '&id_cms_category='.(int)$object->id_parent : '').'&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.'); } /* Delete object */ elseif (isset($_GET['delete'.$this->table])) { if ($this->tabAccess['delete'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject()) AND isset($this->fieldImageSettings)) { // check if request at least one object with noZeroObject if (isset($object->noZeroObject) AND sizeof($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1) $this->_errors[] = Tools::displayError('You need at least one object.').' '.$this->table.'
'.Tools::displayError('You cannot delete all of the items.'); else { $this->deleteImage($object->id); if ($this->deleted) { $object->deleted = 1; if ($object->update()) Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token')); } elseif ($object->delete()) Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token')); $this->_errors[] = Tools::displayError('An error occurred during deletion.'); } } else $this->_errors[] = Tools::displayError('An error occurred while deleting object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); } else $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } elseif (isset($_GET['position'])) { if ($this->tabAccess['edit'] !== '1') $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); elseif (!Validate::isLoadedObject($object = new CMSCategory((int)(Tools::getValue($this->identifier, Tools::getValue('id_cms_category_to_move', 1)))))) $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=5'.(($id_category = (int)(Tools::getValue($this->identifier, Tools::getValue('id_cms_category_parent', 1)))) ? ('&'.$this->identifier.'='.$id_category) : '').'&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_category = new CMSCategory(); $result = true; $result = $cms_category->deleteSelection(Tools::getValue($this->table.'Box')); if ($result) { $cms_category->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.'); } parent::postProcess(true); } public function displayForm($token=NULL) { global $currentIndex, $cookie; parent::displayForm(); if (!($obj = $this->loadObject(true))) return; $active = $this->getFieldValue($obj, 'active'); echo '
'.($obj->id ? '' : '').'
'.$this->l('CMS Category').'
'; foreach ($this->_languages as $language) echo '
id) ? ' onkeyup="copy2friendlyURL();"' : '').' /> * '.$this->l('Invalid characters:').' <>;=#{} 
'; echo '

'; foreach ($this->_languages as $language) echo '
'; echo '


'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; echo '

'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; echo '

'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; echo '

'; foreach ($this->_languages as $language) echo '
* '.$this->l('Only letters and the minus (-) character are allowed').' 
'; echo '

 
* '.$this->l('Required field').'

'; } }