* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); 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, 'callback' => 'hideCategoryPosition'), 'description' => array('title' => $this->l('Description'), 'width' => 560, 'maxlength' => 90, 'orderby' => false), 'active' => array('title' => $this->l('Displayed'), 'active' => 'status', 'align' => 'center', 'type' => 'bool', 'orderby' => false)); $this->_category = AdminCatalog::getCurrentCategory(); $this->_filter = 'AND `id_parent` = '.intval($this->_category->id); 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(intval($cookie->id_lang), !$cookie->__get($this->table.'Orderby') ? 'name' : 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(Category::hideCategoryPosition($this->_category->getName())).'"

'; echo ' '.$this->l('Add a new subcategory').'
'; $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 = intval(Tools::getValue('id_category'))) { if (!Category::checkBeforeMove($id_category, intval(Tools::getValue('id_parent')))) { $this->_errors[] = Tools::displayError('category cannot be moved here'); return false; } // Updating customer's group if ($this->tabAccess['edit'] !== '1') $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); else { $object = new $this->className($id_category); if (Validate::isLoadedObject($object)) $object->updateGroup(Tools::getValue('groupBox')); else $this->_errors[] = Tools::displayError('an error occurred while updating object').' '.$this->table.' '.Tools::displayError('(cannot load object)'); } } } /* Change object statuts (active, inactive) */ elseif (isset($_GET['status']) AND Tools::getValue($this->identifier)) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->toggleStatus()) Tools::redirectAdmin($currentIndex.'&conf=5'.((($id_category = intval(Tools::getValue('id_category'))) AND Tools::getValue('id_product')) ? '&id_category='.$id_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 anything 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 them'); 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.'); } parent::postProcess(); } protected function postImage($id) { $ret = parent::postImage($id); if (($id_category = intval(Tools::getValue('id_category'))) AND isset($_FILES) AND sizeof($_FILES) 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', intval($imageType['width']), intval($imageType['height'])); } return $ret; } public function displayForm($token=NULL) { global $currentIndex, $cookie; parent::displayForm(); $obj = $this->loadObject(true); $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'.intval(Tab::getIdFromClassName('AdminCatalog')).intval($cookie->id_employee))); 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(intval($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').'

'; } }