table = 'category_family'; $this->className = 'CategoryFamilyCore'; $this->lang = true; $this->edit = true; $this->view = true; $this->delete = true; $this->fieldsDisplay = array( 'id_category_family' => array( 'title' => $this->l('ID'), 'align' => 'center', ), 'name' => array( 'title' => $this->l('Name'), 'width' => 100 ), 'id_parent' => array( 'title' => $this->l('Parent'), 'width' => 100, 'callback' => 'getParentName' ), ); parent::__construct(); } public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL) { global $cookie; /* Manage default params values */ if (empty($limit)) $limit = ((!isset($cookie->{$this->table.'_pagination'})) ? $this->_pagination[1] : $limit = $cookie->{$this->table.'_pagination'}); if (!Validate::isTableOrIdentifier($this->table)) die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"'); if (empty($orderBy)) $orderBy = $cookie->__get($this->table.'Orderby') ? $cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy; if (empty($orderWay)) $orderWay = $cookie->__get($this->table.'Orderway') ? $cookie->__get($this->table.'Orderway') : 'ASC'; $limit = (int)(Tools::getValue('pagination', $limit)); $cookie->{$this->table.'_pagination'} = $limit; /* Check params validity */ if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay) OR !is_numeric($start) OR !is_numeric($limit) OR !Validate::isUnsignedId($id_lang)) die(Tools::displayError('get list params is not valid')); /* Determine offset from current page */ if ((isset($_POST['submitFilter'.$this->table]) OR isset($_POST['submitFilter'.$this->table.'_x']) OR isset($_POST['submitFilter'.$this->table.'_y'])) AND !empty($_POST['submitFilter'.$this->table]) AND is_numeric($_POST['submitFilter'.$this->table])) $start = (int)($_POST['submitFilter'.$this->table] - 1) * $limit; /* Cache */ $this->_lang = (int)($id_lang); $this->_orderBy = $orderBy; $this->_orderWay = Tools::strtoupper($orderWay); /* SQL table : orders, but class name is Order */ $sqlTable = $this->table == 'order' ? 'orders' : $this->table; if (Tools::getIsset('viewcategory_family')) { if (Tools::getValue('id_category_family')) { $this->_where = ' AND id_parent = '. (int)Tools::getValue('id_category_family'); } } else { $this->_where = ' AND id_parent = 0'; } /* Query in order to get results with all fields */ $sql = 'SELECT SQL_CALC_FOUND_ROWS '.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').' '.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').' FROM `'._DB_PREFIX_.$sqlTable.'` a '.($this->lang ? 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'` AND b.`id_lang` = '.(int)($id_lang).')' : '').' '.(isset($this->_join) ? $this->_join.' ' : '').' WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').(isset($this->_filter) ? $this->_filter : '').' '.(isset($this->_group) ? $this->_group.' ' : '').' '.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').(isset($this->_having) ? $this->_having.' ' : '').' ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay). ($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').' LIMIT '.(int)($start).','.(int)($limit); $this->_list = Db::getInstance()->ExecuteS($sql); $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`'); } public function viewcategory_family() { global $cookie; $this->getList($cookie->id_lang); $this->displayList(); } public function postProcess() { if (Tools::isSubmit('addFamily')) { $family = new CategoryFamilyCore(); $family = $this->assocForm($family, $_POST); if ($family->add()) { return TRUE; } } elseif (Tools::isSubmit('editFamily')) { $id_category_family = Tools::getValue('id_category_family'); $family = new CategoryFamilyCore($id_category_family, $cookie->id_lang); $family = $this->assocForm($family, $_POST); $family->update(); } parent::postProcess(); } public function assocForm($obj, $data) { $obj->id_parent = ($data['parent'] ? $data['parent'] : 0); foreach (Language::getLanguages(FALSE) as $language) { $id_lang = $language['id_lang']; if ( isset($data['name_'.$id_lang]) ) { $obj->name[$id_lang] = $data['name_'.$id_lang]; } else { $obj->name[$id_lang] = ''; } } return $obj; } public function displayForm() { global $currentIndex, $cookie; parent::displayForm(); $parents = CategoryFamilyCore::getAll($cookie->id_lang); if (Tools::getIsset('updatecategory_family')) { $id_category_family = Tools::getValue('id_category_family'); $obj = new CategoryFamilyCore($id_category_family); if(!Validate::isLoadedObject($obj)) { echo '

This Category not exist

'; return FALSE; } } echo '
'.($obj->id ? '' : '').'
'.$this->l('Category Family').'
'; foreach ($this->_languages AS $language) echo '
* '.$this->l('Invalid characters:').' <>;=#{} 
'; echo '

'; echo '

id)? 'disabled=disabled' : '' ).' class="button" name="addFamily" value="'.$this->l('Save').'"/>'; if (isset($obj->id)) { echo ' '; } echo '
* '.$this->l('Required field').'
'; } }