* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7132 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminManufacturers extends AdminTab { protected $maxImageSize = 200000; /** @var array countries list */ private $countriesArray = array(); public function __construct() { global $cookie; $this->table = 'manufacturer'; $this->className = 'Manufacturer'; $this->lang = false; $this->edit = true; $this->delete = true; // Sub tab addresses $countries = Country::getCountries((int)($cookie->id_lang)); foreach ($countries AS $country) $this->countriesArray[$country['id_country']] = $country['name']; $this->fieldsDisplayAddresses = array( 'id_address' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'm!manufacturer_name' => array('title' => $this->l('Manufacturer'), 'width' => 100), 'firstname' => array('title' => $this->l('First name'), 'width' => 80), 'lastname' => array('title' => $this->l('Last name'), 'width' => 100, 'filter_key' => 'a!name'), 'postcode' => array('title' => $this->l('Postcode/ Zip Code'), 'align' => 'right', 'width' => 50), 'city' => array('title' => $this->l('City'), 'width' => 150), 'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'select' => $this->countriesArray, 'filter_key' => 'cl!id_country')); $this->_includeTabTitle = array($this->l('Manufacturers addresses')); $this->_joinAddresses = 'LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)($cookie->id_lang).') '; $this->_joinAddresses .= 'LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (a.`id_manufacturer` = m.`id_manufacturer`)'; $this->_selectAddresses = 'cl.`name` as country, m.`name` AS manufacturer_name'; $this->_includeTab = array('Addresses' => array('addressType' => 'manufacturer', 'fieldsDisplay' => $this->fieldsDisplayAddresses, '_join' => $this->_joinAddresses, '_select' => $this->_selectAddresses)); $this->view = true; $this->_select = 'COUNT(`id_product`) AS `products`, (SELECT COUNT(ad.`id_manufacturer`) as `addresses` FROM `'._DB_PREFIX_.'address` ad WHERE ad.`id_manufacturer` = a.`id_manufacturer` AND ad.`deleted` = 0 GROUP BY ad.`id_manufacturer`) as `addresses`'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (a.`id_manufacturer` = p.`id_manufacturer`)'; $this->_joinCount = false; $this->_group = 'GROUP BY a.`id_manufacturer`'; $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'm'); $this->fieldsDisplay = array( 'id_manufacturer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Name'), 'width' => 200), 'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 'm', 'orderby' => false, 'search' => false), 'addresses' => array('title' => $this->l('Addresses'), 'align' => 'right', 'tmpTableFilter' => true, 'width' => 20), 'products' => array('title' => $this->l('Products'), 'align' => 'right', 'tmpTableFilter' => true, 'width' => 20), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) ); parent::__construct(); } public function afterImageUpload() { /* Generate image with differents size */ if (($id_manufacturer = (int)(Tools::getValue('id_manufacturer'))) AND isset($_FILES) AND count($_FILES) AND file_exists(_PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg')) { $imagesTypes = ImageType::getImagesTypes('manufacturers'); foreach ($imagesTypes AS $k => $imageType) imageResize(_PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg', _PS_MANU_IMG_DIR_.$id_manufacturer.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); } } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); if (!($manufacturer = $this->loadObject(true))) return; $langtags = 'cdesc2¤cdesc¤mmeta_title¤mmeta_keywords¤mmeta_description'; echo '
'.($manufacturer->id ? '' : '').'
'.$this->l('Manufacturers').'
* '.$this->l('Invalid characters:').' <>;=#{} 
'; echo '
'; foreach ($this->_languages as $language) echo '
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'cdesc2'); echo '
'; echo '


'; foreach ($this->_languages as $language) echo '
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'cdesc'); echo '
'; // TinyMCE global $cookie; $iso = Language::getIsoById((int)($cookie->id_lang)); $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'); $ad = dirname($_SERVER["PHP_SELF"]); echo ' '; echo '


'; $this->displayImage($manufacturer->id, _PS_MANU_IMG_DIR_.$manufacturer->id.'.jpg', 350, NULL, NULL, true); echo '

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

'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'mmeta_title'); echo '
'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'mmeta_description'); echo '
'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'mmeta_keywords'); echo '
getFieldValue($manufacturer, 'active') ? 'checked="checked" ' : '').'/> getFieldValue($manufacturer, 'active') ? 'checked="checked" ' : '').'/>
* '.$this->l('Required field').'
'; } public function viewmanufacturer() { global $cookie; if (!($manufacturer = $this->loadObject())) return; echo '

'.$manufacturer->name.'

'; $products = $manufacturer->getProductsLite((int)($cookie->id_lang)); $addresses = $manufacturer->getAddresses((int)($cookie->id_lang)); echo '

'.$this->l('Total addresses:').' '.sizeof($addresses).'

'; echo '
'; foreach ($addresses AS $addresse) echo '

'.$addresse['firstname'].' '.$addresse['lastname'].'
'.$addresse['address1'].'
'.($addresse['address2'] ? $addresse['address2'].'
' : '').' '.$addresse['postcode'].' '.$addresse['city'].'
'.($addresse['state'] ? $addresse['state'].'
' : '').' '.$addresse['country'].'
'.($addresse['phone'] ? $addresse['phone'].'
' : '').' '.($addresse['phone_mobile'] ? $addresse['phone_mobile'].'
' : '').'
'.($addresse['other'] ? '

'.$addresse['other'].'
' : '').'
'; if (!sizeof($addresses)) echo 'No address for this manufacturer.'; echo '

'; echo '

'.$this->l('Total products:').' '.sizeof($products).'

'; foreach ($products AS $product) { $product = new Product($product['id_product'], false, (int)($cookie->id_lang)); echo '
'; if (!$product->hasAttributes()) { echo '
'.$this->l('Edit').' '.$this->l('Delete').'
'.(!empty($product->reference) ? '' : '').' '.(!empty($product->ean13) ? '' : '').' '.(!empty($product->upc) ? '' : '').' '.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').'
'.$product->name.''.$this->l('Ref:').' '.$product->reference.''.$this->l('EAN13:').' '.$product->ean13.''.$this->l('UPC:').' '.$product->upc.''.$this->l('Qty:').' '.$product->quantity.'
'; } else { echo '
'.$this->l('Edit').' '.$this->l('Delete').'

'.$product->name.'

'.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').' '; /* Build attributes combinaisons */ $combinaisons = $product->getAttributeCombinaisons((int)($cookie->id_lang)); foreach ($combinaisons AS $k => $combinaison) { $combArray[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference']; $combArray[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13']; $combArray[$combinaison['id_product_attribute']]['upc'] = $combinaison['upc']; $combArray[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity']; $combArray[$combinaison['id_product_attribute']]['attributes'][] = array($combinaison['group_name'], $combinaison['attribute_name'], $combinaison['id_attribute']); } $irow = 0; foreach ($combArray AS $id_product_attribute => $product_attribute) { $list = ''; foreach ($product_attribute['attributes'] AS $attribute) $list .= $attribute[0].' - '.$attribute[1].', '; $list = rtrim($list, ', '); echo ' '.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').' '; } unset($combArray); echo '
'.$this->l('Attribute name').' '.$this->l('Reference').' '.$this->l('EAN13').' '.$this->l('UPC').''.$this->l('Quantity').'
'.stripslashes($list).' '.$product_attribute['reference'].''.$product_attribute['ean13'].''.$product_attribute['upc'].''.$product_attribute['quantity'].'
'; } } } }