* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision$ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminGenders extends AdminTab { public function __construct() { $this->table = 'gender'; $this->className = 'Gender'; $this->lang = true; $this->edit = true; $this->delete = true; $this->defaultImageHeight = 16; $this->defaultImageWidth = 16; $this->fieldImageSettings = array('name' => 'image', 'dir' => 'genders'); $this->fieldsDisplay = array( 'id_gender' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Name'), 'width' => 150, 'filter_key' => 'b!name'), 'type' => array( 'title' => $this->l('Type'), 'width' => 100, 'orderby' => false, 'type' => 'select', 'select' => array(0 => $this->l('Male'), 1 => $this->l('Female'), 2 => $this->l('Neutral')), 'filter_key' => 'a!type', 'callback' => 'displayGenderType', 'callback_object' => $this, ), 'image' => array('title' => $this->l('Image'), 'align' => 'center', 'image' => 'genders', 'orderby' => false, 'search' => false), ); parent::__construct(); } public function displayGenderType($value, $tr) { return $this->fieldsDisplay['type']['select'][$value]; } public function displayForm($isMainTab = true) { parent::displayForm(); if (!($obj = $this->loadObject(true))) return; echo '
'.($obj->id ? '' : '').'
'.$this->l('Gender').'
'; foreach ($this->_languages as $language) echo '
* '.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%: 
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'name', 'name'); echo '
 
'; echo '
getFieldValue($obj, 'type') == 0 ? 'checked="checked" ' : '').'/> getFieldValue($obj, 'type') == 1 ? 'checked="checked" ' : '').'/> getFieldValue($obj, 'type') == 2 ? 'checked="checked" ' : '').'/>
'; echo '
'; echo ' '; if ($obj->getImage()) echo ''; echo '

'.$this->l('Image width in pixel. "0" to use original size').'

'.$this->l('Image height in pixel. "0" to use original size').'

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

'; } protected function postImage($id) { if (isset($this->fieldImageSettings['name']) AND isset($this->fieldImageSettings['dir'])) { if(!Validate::isInt(Tools::getValue('img_width')) || !Validate::isInt(Tools::getValue('img_height'))) $this->_errors[] = Tools::displayError('Width and height must be a numeric'); else { if ((int)Tools::getValue('img_width') > 0 && (int)Tools::getValue('img_height') > 0) { $width = (int)Tools::getValue('img_width'); $height = (int)Tools::getValue('img_height'); } else { $width = NULL; $height = NULL; } return $this->uploadImage($id, $this->fieldImageSettings['name'], $this->fieldImageSettings['dir'].'/', false, $width, $height); } } return !sizeof($this->_errors) ? true : false; } }