* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7731 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminCategories extends AdminTab { protected $maxImageSize = 300000; /** @var object Category() instance for navigation*/ private $_category; public function __construct() { global $cookie; $this->table = 'category'; $this->className = 'Category'; $this->lang = true; $this->edit = true; $this->view = true; $this->delete = true; $this->fieldImageSettings = array('name' => 'image', 'dir' => 'c'); $this->fieldsDisplay = array( 'id_category' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 30), 'name' => array('title' => $this->l('Name'), 'width' => 100), '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->_category = AdminCatalog::getCurrentCategory(); $this->_filter = 'AND `id_parent` = '.(int)($this->_category->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; $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('subcategory')))).' '.$this->l('in category').' "'.stripslashes($this->_category->getName()).'"

'; if ($this->tabAccess['add'] === '1') echo ' '.$this->l('Add a new subcategory').''; echo '
'; $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_category = (int)(Tools::getValue('id_category'))) { if (!Category::checkBeforeMove($id_category, (int)(Tools::getValue('id_parent')))) { $this->_errors[] = Tools::displayError('Category cannot be moved here'); return false; } } } /* 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 { if ($this->deleted) { $object->deleteImage(); $object->deleted = 1; if ($object->update()) Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent)); } elseif ($object->delete()) Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent)); $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 Category((int)(Tools::getValue($this->identifier, Tools::getValue('id_category_to_move', 1)))))) $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); if (!$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_category_parent', 1)))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.Tools::getAdminTokenLite('AdminCatalog')); } /* Delete multiple objects */ elseif (Tools::getValue('submitDel'.$this->table)) { if ($this->tabAccess['delete'] === '1') { if (isset($_POST[$this->table.'Box'])) { $category = new Category(); $result = true; $result = $category->deleteSelection(Tools::getValue($this->table.'Box')); if ($result) { $category->cleanPositions((int)(Tools::getValue('id_category'))); Tools::redirectAdmin($currentIndex.'&conf=2&token='.Tools::getAdminTokenLite('AdminCatalog').'&id_category='.(int)(Tools::getValue('id_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.'); return; } parent::postProcess(); } protected function postImage($id) { $ret = parent::postImage($id); if (($id_category = (int)(Tools::getValue('id_category'))) AND isset($_FILES) AND sizeof($_FILES) AND $_FILES['image']['name'] != NULL AND file_exists(_PS_CAT_IMG_DIR_.$id_category.'.jpg')) { $imagesTypes = ImageType::getImagesTypes('categories'); foreach ($imagesTypes AS $k => $imageType) imageResize(_PS_CAT_IMG_DIR_.$id_category.'.jpg', _PS_CAT_IMG_DIR_.$id_category.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); } return $ret; } public function displayForm($token = NULL) { global $currentIndex, $cookie; parent::displayForm(); if (!($obj = $this->loadObject(true))) return; $active = $this->getFieldValue($obj, 'active'); $customer_groups = $obj->getGroups(); echo '
'.($obj->id ? '' : '').'
'.$this->l('Category').'
'; foreach ($this->_languages AS $language) echo '
id) ? ' onkeyup="copy2friendlyURL();"' : '').' /> * '.$this->l('Invalid characters:').' <>;=#{} 
'; echo '

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

'; echo $this->displayImage($obj->id, _PS_IMG_DIR_.'c/'.$obj->id.'.jpg', 350, NULL, Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)), true); echo '

'.$this->l('Upload category logo from your computer').'


'; 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 '

'; $groups = Group::getGroups((int)($cookie->id_lang)); if (sizeof($groups)) { echo ' '; $irow = 0; foreach ($groups AS $group) echo ' '; echo '
id) ? 'checked="checked" ' : '').' /> '.$this->l('ID').' '.$this->l('Group name').'
id))) ? 'checked="checked" ' : '').'/> '.$group['id_group'].'

'.$this->l('Mark all groups you want to give access to this category').'

'; } else echo '

'.$this->l('No group created').'

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

'; } }