921 lines
26 KiB
PHP
Executable File
921 lines
26 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Description of Pictos
|
|
*
|
|
* @author Pierre Beaumont
|
|
* @company Antadis
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
include_once(dirname(__FILE__).'/classes/Picto.php');
|
|
|
|
class Pictos extends Module {
|
|
|
|
private $_html = '';
|
|
const _PICTOS_ALL_ = 1;
|
|
const _PICTOS_CHECKED_ = 2;
|
|
const _PICTOS_NOT_CHECKED_ = 3;
|
|
|
|
/**
|
|
*
|
|
* @param type $name
|
|
* @param Context $context
|
|
*/
|
|
public function __construct() {
|
|
|
|
$this->name = 'pictos';
|
|
$this->tab = 'front_office_features';
|
|
$this->version = '1.3.0';
|
|
$this->author = 'Antadis';
|
|
$this->bootstrap = true;
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Pictos');
|
|
$this->description = $this->l('It allows you to add pictos in product page and product listing.');
|
|
$this->confirmUninstall = $this->l('Are you sure you want to delete Pictos?');
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function install() {
|
|
|
|
if (!parent::install()
|
|
|| !$this->installDb()
|
|
// || !$this->dbUpgrade()
|
|
|| !$this->installTab()
|
|
// || !$this->addHookProductPictos()
|
|
|| !$this->registerHook('BackOfficeFooter')
|
|
|| !$this->registerHook('displayProductTabContent')
|
|
|| !$this->registerHook('displayAdminProductsExtra')
|
|
|| !$this->registerHook('actionAdminControllerSetMedia')
|
|
|| !$this->registerHook('productTab')
|
|
|| !$this->registerHook('dispolayroductTabContent')
|
|
|| !$this->registerHook('Header')
|
|
|| !$this->updateConfiguration()){
|
|
$this->uninstall();
|
|
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function updateConfiguration(){
|
|
return (
|
|
Configuration::updateValue('_PICTO_IMG_HEIGHT_', 50) &&
|
|
Configuration::updateValue('_PICTO_IMG_WIDTH_', 50)
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* @deprecated
|
|
* @param
|
|
* @return
|
|
*/
|
|
public function addHookProductPictos(){
|
|
if ( Hook::get('ProductPictos') ){
|
|
return true;
|
|
}
|
|
//create hook in DB
|
|
else{
|
|
$sql ='INSERT INTO ps_hook (name,title,position,live_edit) VALUES (\'productPictos\', \'Product Pictos\', 1, 0)';
|
|
return Db::getInstance()->execute($sql);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function uninstall() {
|
|
|
|
if(!parent::uninstall() || !$this->uninstallDb()){
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function installDb(){
|
|
|
|
$prefix = _DB_PREFIX_ ;
|
|
$engine = _MYSQL_ENGINE_;
|
|
|
|
$statements = array();
|
|
|
|
|
|
$statements[] = sprintf('CREATE TABLE IF NOT EXISTS `%spicto`(
|
|
`id_picto` int(11) NOT NULL AUTO_INCREMENT,
|
|
`date_add` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
|
|
`date_upd` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
|
|
PRIMARY KEY (`id_picto`)
|
|
) ENGINE=%s DEFAULT CHARSET=utf8 ;', $prefix, $engine );
|
|
|
|
$statements[] = sprintf('CREATE TABLE IF NOT EXISTS `%spicto_lang`(
|
|
`id_picto` int(11) NOT NULL,
|
|
`id_lang` int(11) NOT NULL,
|
|
`name` varchar(255),
|
|
`title` varchar(255),
|
|
`alt` varchar(255),
|
|
`link` varchar(255),
|
|
`description` text,
|
|
PRIMARY KEY (`id_picto`, `id_lang`)
|
|
) ENGINE=%s DEFAULT CHARSET=utf8 ;', $prefix, $engine );
|
|
|
|
$statements[] = sprintf('CREATE TABLE IF NOT EXISTS `%spicto_shop` (
|
|
`id_picto` int(11),
|
|
`id_shop` int(11),
|
|
PRIMARY KEY (`id_picto`,`id_shop`)
|
|
) ENGINE=%s DEFAULT CHARSET=utf8 ;', $prefix, $engine );
|
|
|
|
|
|
$statements[] = sprintf('CREATE TABLE IF NOT EXISTS `%spicto_product` (
|
|
`id_picto` int(11),
|
|
`id_product` int(11),
|
|
`order` int(11),
|
|
PRIMARY KEY (`id_picto`, `id_product`)
|
|
) ENGINE=%s DEFAULT CHARSET=utf8 ;', $prefix, $engine );
|
|
|
|
return $this->uninstallDb() && $this->updateDb($statements);
|
|
}
|
|
|
|
public function installTab(){
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function uninstallDb(){
|
|
|
|
$prefix = _DB_PREFIX_ ;
|
|
|
|
$statements = array();
|
|
|
|
$statements[] = sprintf('DROP TABLE IF EXISTS `%spicto`;', $prefix );
|
|
$statements[] = sprintf('DROP TABLE IF EXISTS `%spicto_lang`;', $prefix );
|
|
$statements[] = sprintf('DROP TABLE IF EXISTS `%spicto_product`;', $prefix );
|
|
|
|
$this->updateDb($statements);
|
|
|
|
return $this->updateDb($statements);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function truncateDb(){
|
|
|
|
$prefix = _DB_PREFIX_ ;
|
|
|
|
$statements = array();
|
|
|
|
$statements[] = sprintf('TRUNCATE TABLE `%spicto`;', $prefix );
|
|
$statements[] = sprintf('TRUNCATE TABLE `%spicto_lang`;', $prefix );
|
|
$statements[] = sprintf('TRUNCATE TABLE `%spicto_product`;', $prefix );
|
|
|
|
$this->updateDb($statements);
|
|
|
|
return $this->updateDb($statements);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param array $statements
|
|
* @return boolean
|
|
*/
|
|
public function updateDb($statements){
|
|
foreach($statements as $statement){
|
|
if( !Db::getInstance()->execute($statement)){
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
//Preparing data for the form
|
|
public function hookDisplayAdminProductsExtra($params) {
|
|
$ajax_redirect = __PS_BASE_URI__.'adm/index.php?controller=AdminModules&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules');
|
|
$id_product = Tools::getValue('id_product');
|
|
/*$id_category = Tools::getValue('id_category');*/
|
|
$product = new Product((int)$id_product);
|
|
$id_category = (Tools::getValue('id_category'))?Tools::getValue('id_category'):$product->getDefaultCategory();
|
|
$all_pictos = Picto::getAllPictos();
|
|
$product_pictos = Picto::getPictosForProduct((int)$id_product);
|
|
$checked_pictos = Picto::getAllPictoInfoChecked((int)$id_product);
|
|
$notChecked_pictos = Picto::getAllPictoInfoNotChecked((int)$id_product);
|
|
|
|
$this->context->smarty->assign(array(
|
|
'ajax_redirect' => $ajax_redirect,
|
|
'all_pictos' => $all_pictos,
|
|
'product_pictos' => $product_pictos,
|
|
'checked_pictos' => $checked_pictos,
|
|
'notChecked_pictos' => $notChecked_pictos,
|
|
'id_product' => (int)$id_product,
|
|
'id_category' => (int)$id_category
|
|
));
|
|
|
|
$this->_html = $this->display(__FILE__, 'views/templates/admin/product_pictos.tpl');
|
|
|
|
$this->_renderFormProduct();
|
|
|
|
// $this->_initList(self::_PICTOS_CHECKED_);
|
|
// $this->_initList(self::_PICTOS_NOT_CHECKED_);
|
|
|
|
|
|
return $this->_html;
|
|
|
|
}
|
|
|
|
private function _renderFormProduct(){
|
|
|
|
$languages = $this->context->controller->getLanguages();
|
|
|
|
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
|
|
|
$this->fields_form[0]['form'] = array(
|
|
'legend' => array(
|
|
'title' => $this->l('Duplicate picto'),
|
|
'icon' => 'icon-file',
|
|
),
|
|
'description' => $this->l('Duplicate to all product of current category and sub categories'),
|
|
'input' => array(
|
|
// array(
|
|
// 'type' => 'switch',
|
|
// 'label' => $this->l('All categories'),
|
|
// 'hint' => $this->l('Duplicate selected pictos to all sub-categories or just to current category'),
|
|
// 'name' => 'allcategories',
|
|
// 'class' => 't',
|
|
// 'form_group_class' => 'input_info',
|
|
// 'is_bool' => true,
|
|
// 'values' => array(
|
|
// array(
|
|
// 'id' => 'recursive_on',
|
|
// 'value' => 1
|
|
// ),
|
|
// array(
|
|
// 'id' => 'recursive_off',
|
|
// 'value' => 0
|
|
// )
|
|
// )
|
|
// ),
|
|
array(
|
|
'type' => 'hidden',
|
|
'name' => 'id_product',
|
|
'value' => Tools::getValue('id_product')
|
|
)
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->l('Duplicate')
|
|
)
|
|
);
|
|
|
|
$helper = new HelperForm();
|
|
$helper->show_toolbar = false;
|
|
$helper->default_form_language = $lang->id;
|
|
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
|
$helper->module = $this;
|
|
$helper->submit_action = 'submitDuplicatePicto';
|
|
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
|
|
foreach ($this->fields_form[0]['form']['input'] as $input) //fill all form fields
|
|
{
|
|
if ( $input['name'] == 'id_product' )
|
|
$helper->fields_value[$input['name']] = Tools::getValue('id_product');
|
|
}
|
|
|
|
|
|
$helper->tpl_vars = array(
|
|
'languages' => $this->context->controller->getLanguages(),
|
|
'id_language' => $this->context->language->id
|
|
);
|
|
|
|
$this->_html .= $helper->generateForm($this->fields_form);
|
|
}
|
|
|
|
public function hookActionAdminControllerSetMedia($params){
|
|
if($this->context->controller->controller_name == 'AdminProducts' && Tools::getValue('id_product'))
|
|
{
|
|
$this->context->controller->addJS(array(
|
|
__PS_BASE_URI__.'js/jquery/plugins/jquery.sortable.js',
|
|
_PS_MODULE_DIR_.'pictos/js/adminProduct.js'
|
|
));
|
|
|
|
$this->context->controller->addCSS(_PS_MODULE_DIR_.'pictos/css/adminProduct.css', 'all');
|
|
}
|
|
}
|
|
|
|
public function hookBackOfficeFooter($params){
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function hookHeader($params)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Called on product creation/duplication.
|
|
* When duplaicate a product, duplicate all product pictos.
|
|
* @deprecated Duplicate a product will no longer duplicate pictos
|
|
*/
|
|
public function hookAddProduct($params){
|
|
return false;
|
|
|
|
/*
|
|
if( !isset($params['id_product_old']) || !$params['id_product_old'] )
|
|
return false;
|
|
$new_product = $params['product'];
|
|
if ( !Validate::isLoadedObject($new_product) )
|
|
return false;
|
|
$id_product_old = (int)$params['id_product_old'];
|
|
|
|
// Get old products pictos
|
|
$pictos = PictosProduct::getPictosForProduct($id_product_old);
|
|
// Duplicate old product PictosProduct for new product
|
|
foreach ($pictos as $picto) {
|
|
// Duplicte old PictosProduct into new PictosProduct
|
|
$PictosProduct = new PictosProduct();
|
|
$PictosProduct->id_product = (int)$new_product->id;
|
|
$PictosProduct->name_pictos = pSQL($picto->name_pictos);
|
|
$PictosProduct->order_pictos = (int)$picto->order_pictos;
|
|
$PictosProduct->pictos_product_description = pSQL($picto->pictos_product_description);
|
|
$PictosProduct->save();
|
|
}
|
|
return true;
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* Called on product deletion
|
|
* Delete all product pictos after product deletion
|
|
*/
|
|
public function hookDeleteProduct($params){
|
|
if ( isset($params['product']) && Validate::isLoadedObject($params['product']) ){
|
|
$id_product = (int)$params['product']->id;
|
|
Picto::DelAllPictosForProduct((int)$id_product);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function hookProductPictos($params){
|
|
global $smarty;
|
|
if ( !Tools::getIsset('id_product') )
|
|
return;
|
|
$id_product = (int)Tools::getValue('id_product');
|
|
$pictos = Picto::getPictosForProduct((int)$id_product);
|
|
$smarty->assign('pictos', $pictos);
|
|
return $this->display(__FILE__, 'views/templates/hook/displayProductPictos.tpl');
|
|
}
|
|
|
|
public function hookDisplayProductTabContent($params){
|
|
return $this->hookProductPictos($params);
|
|
}
|
|
|
|
public function hookProductTab($params){
|
|
return;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function getContent(){
|
|
$this->_html = '';
|
|
|
|
$this->_postProcess();
|
|
|
|
$this->_renderForm();
|
|
$this->_initList();
|
|
$this->_settingForm();
|
|
|
|
return $this->_html;
|
|
}
|
|
|
|
private function _renderForm(){
|
|
|
|
|
|
$languages = $this->context->controller->getLanguages();
|
|
|
|
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
|
|
|
$img_path = __PS_BASE_URI__.'modules/pictos/img/';
|
|
if (Tools::isSubmit('id_picto')){
|
|
$picto = new Picto((int)Tools::getValue('id_picto'));
|
|
$urlpicto = $picto->name ;
|
|
}else{
|
|
$picto = new Picto();
|
|
$urlpicto = "noimg" ;
|
|
}
|
|
|
|
$this->fields_form[0]['form'] = array(
|
|
'legend' => array(
|
|
'title' => $this->l('Add picto'),
|
|
'icon' => 'icon-upload'
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Title'),
|
|
'name' => 'title',
|
|
'lang' => 'true'
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Alt'),
|
|
'name' => 'alt',
|
|
'lang' => 'true'
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Link'),
|
|
'name' => 'link',
|
|
'lang' => 'true'
|
|
),
|
|
array(
|
|
'type' => 'lang_file',
|
|
'label' => $this->l('Picto'),
|
|
'name' => 'name',
|
|
'lang' => 'true',
|
|
'url' => $urlpicto,
|
|
'img_path' => $img_path,
|
|
),
|
|
array(
|
|
'type' => 'textarea',
|
|
'label' => $this->l('Description'),
|
|
'name' => 'description',
|
|
'lang' => 'true'
|
|
),
|
|
array(
|
|
'type' => 'hidden',
|
|
'name' => 'id_picto',
|
|
'value' => ((Tools::isSubmit('id_picto'))?Tools::getValue('id_picto'):'')
|
|
)
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->l('Save')
|
|
)
|
|
);
|
|
|
|
$helper = new HelperForm();
|
|
$helper->show_toolbar = false;
|
|
$helper->table = $this->table;
|
|
$helper->default_form_language = $lang->id;
|
|
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
|
$helper->identifier = $this->identifier;
|
|
$helper->module = $this;
|
|
$helper->submit_action = 'submitAddPicto';
|
|
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->tpl_vars = array(
|
|
'languages' => $this->context->controller->getLanguages(),
|
|
'id_language' => $this->context->language->id
|
|
);
|
|
|
|
foreach ($this->fields_form[0]['form']['input'] as $input) //fill all form fields
|
|
{
|
|
$helper->fields_value[$input['name']] = $picto->{$input['name']};
|
|
}
|
|
|
|
$this->_html .= $helper->generateForm($this->fields_form);
|
|
}
|
|
|
|
private function _settingForm(){
|
|
|
|
$this->fields_form[0]['form'] = array(
|
|
'legend' => array(
|
|
'title' => $this->l('Picto Settings'),
|
|
'icon' => 'icon-cogs'
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Picto width'),
|
|
'name' => '_PICTO_IMG_WIDTH_'
|
|
// 'desc' => $this->l('Set to 0 to disable')
|
|
),
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Picto height'),
|
|
'name' => '_PICTO_IMG_HEIGHT_'
|
|
// 'desc' => $this->l('Set to 0 to disable')
|
|
)
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->l('Update Settings')
|
|
)
|
|
);
|
|
|
|
$helper = new HelperForm();
|
|
$helper->show_toolbar = false;
|
|
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
|
$helper->module = $this;
|
|
$helper->submit_action = 'submitUpdatePictoSettings';
|
|
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->tpl_vars = array(
|
|
'fields_value' => $this->_getSettingsVar()
|
|
);
|
|
|
|
foreach ($this->fields_form[0]['form']['input'] as $input) //fill all form fields
|
|
{
|
|
$helper->fields_value[$input['name']] = Configuration::get('{$input["name"]}');
|
|
}
|
|
|
|
$this->_html .= $helper->generateForm($this->fields_form);
|
|
}
|
|
|
|
private function _getSettingsVar(){
|
|
return array(
|
|
'_PICTO_IMG_HEIGHT_' => Configuration::get('_PICTO_IMG_HEIGHT_'),
|
|
'_PICTO_IMG_WIDTH_' => Configuration::get('_PICTO_IMG_WIDTH_')
|
|
);
|
|
}
|
|
|
|
|
|
private function _initList($select = self::_PICTOS_ALL_){
|
|
|
|
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
|
|
|
switch ($select) {
|
|
case self::_PICTOS_ALL_:
|
|
$pictos = Picto::getAllPictos();
|
|
break;
|
|
case self::_PICTOS_CHECKED_:
|
|
$pictos = Picto::getAllPictoInfoChecked();
|
|
break;
|
|
case self::_PICTOS_NOT_CHECKED_:
|
|
$pictos = Picto::getAllPictoInfoNotChecked();
|
|
break;
|
|
}
|
|
$pictosArray = array();
|
|
foreach ($pictos as $key => $picto) {
|
|
$pictosArray[] = array(
|
|
'id_picto' => $picto->id_picto,
|
|
'title' => $picto->title,
|
|
'name' => $picto->name,
|
|
'alt' => $picto->alt,
|
|
'link' => $picto->link,
|
|
'description' => $picto->description,
|
|
'order' => $key
|
|
);
|
|
}
|
|
|
|
$this->fields_list = array(
|
|
'id_picto' => array(
|
|
'title' => $this->l('ID')
|
|
),
|
|
'title' => array(
|
|
'title' => $this->l('Title'),
|
|
'type' => 'text'
|
|
),
|
|
'name' => array(
|
|
'title' => $this->l('Picto'),
|
|
'image_file' => '../modules/pictos/img/'.$lang->iso_code.'/'
|
|
),
|
|
'alt' => array(
|
|
'title' => $this->l('Alt'),
|
|
'type' => 'text',
|
|
),
|
|
'link' => array(
|
|
'title' => $this->l('Link'),
|
|
'type' => 'text',
|
|
),
|
|
'description' => array(
|
|
'title' => $this->l('Description'),
|
|
'type' => 'text',
|
|
),
|
|
);
|
|
$helper = new HelperList();
|
|
|
|
$helper->simple_header = true;
|
|
|
|
$helper->shopLinkType = '';
|
|
$helper->imageType = 'png';
|
|
|
|
// Actions to be displayed in the "Actions" column
|
|
switch ($select) {
|
|
case self::_PICTOS_ALL_:
|
|
$helper->actions = array('edit', 'delete');
|
|
$helper->title = $this->l('Pictos List');
|
|
$helper->icon = 'icon-list';
|
|
break;
|
|
case self::_PICTOS_CHECKED_:
|
|
$this->fields_list['order'] = array(
|
|
'title' => $this->l('position'),
|
|
'position' => 'order'
|
|
);
|
|
$helper->title = $this->l('Pictos Selected');
|
|
break;
|
|
case self::_PICTOS_NOT_CHECKED_:
|
|
$helper->title = $this->l('Pictos List');
|
|
break;
|
|
default:
|
|
$helper->title = $this->l('Pictos Available');
|
|
$helper->actions = array('edit', 'delete');
|
|
}
|
|
|
|
$helper->identifier = 'id_picto';
|
|
$helper->show_toolbar = false;
|
|
$helper->icon = 'icon-AdminCatalog';
|
|
$helper->table = $this->table;
|
|
$helper->module = $this;
|
|
|
|
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
|
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
|
|
|
|
|
|
$this->_html .= $helper->generateList($pictosArray, $this->fields_list);
|
|
}
|
|
|
|
private function _postProcess(){
|
|
if ( Tools::getValue('ajax') ){
|
|
$this->_ajaxProcess();
|
|
}
|
|
if ( Tools::isSubmit('submitAddPicto') ){
|
|
$errors = array();
|
|
if ( Tools::getValue('id_picto') ){
|
|
$id_picto = (int)Tools::getValue('id_picto');
|
|
$info = new Picto($id_picto);
|
|
}
|
|
else{
|
|
$id_picto = false;
|
|
$info = new Picto();
|
|
}
|
|
|
|
$languages = Language::getLanguages(false);
|
|
|
|
// set info values
|
|
foreach ($languages as $language){
|
|
$lang = new Language((int)$language['id_lang']);
|
|
|
|
//titles
|
|
if (isset($_POST['title_'.(int)($language['id_lang'])]))
|
|
$info->title[(int)($language['id_lang'])] = $_POST['title_'.(int)($language['id_lang'])];
|
|
// alts
|
|
if (isset($_POST['alt_'.(int)($language['id_lang'])]))
|
|
$info->alt[(int)($language['id_lang'])] = $_POST['alt_'.(int)($language['id_lang'])];
|
|
// links
|
|
if (isset($_POST['link_'.(int)($language['id_lang'])]))
|
|
$info->link[(int)($language['id_lang'])] = $_POST['link_'.(int)($language['id_lang'])];
|
|
// descriptions
|
|
if (isset($_POST['description_'.(int)($language['id_lang'])]))
|
|
$info->description[(int)($language['id_lang'])] = $_POST['description_'.(int)($language['id_lang'])];
|
|
|
|
|
|
//images
|
|
if ( isset($_FILES['name_'.(int)($language['id_lang'])]) && $_FILES['name_'.(int)($language['id_lang'])]['name'] ){
|
|
$file = $_FILES['name_'.(int)($language['id_lang'])];
|
|
/* Uploads image and sets slide */
|
|
$type = strtolower(substr(strrchr($file['name'], '.'), 1));
|
|
$imagesize = array();
|
|
$imagesize = @getimagesize($file['tmp_name']);
|
|
if (isset($file) &&
|
|
isset($file['tmp_name']) &&
|
|
!empty($file['tmp_name']) &&
|
|
!empty($imagesize) &&
|
|
in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('png', 'jpg', 'jpeg', 'gif')) &&
|
|
in_array($type, array('png', 'jpg', 'jpeg', 'gif')))
|
|
{
|
|
|
|
$img_height = Configuration::get('_PICTO_IMG_HEIGHT_');
|
|
$img_width = Configuration::get('_PICTO_IMG_WIDTH_');
|
|
|
|
if ( (int)$img_height == 0 )
|
|
$img_height = null;
|
|
if ( (int)$img_width == 0 )
|
|
$img_width = null;
|
|
|
|
$temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
|
|
$filename = Tools::encrypt($_FILES['name_'.(int)($language['id_lang'])]['name']).'_'.$language['id_lang'];
|
|
if ($error = ImageManager::validateUpload($_FILES['name_'.(int)($language['id_lang'])]))
|
|
$errors[] = $error;
|
|
elseif (!$temp_name || !move_uploaded_file($_FILES['name_'.(int)($language['id_lang'])]['tmp_name'], $temp_name))
|
|
return false;
|
|
elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/img/'.$lang->iso_code.'/'.$filename.'.'.$type, $img_width, $img_height, $type))
|
|
$errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
|
|
|
|
$info->name[(int)($language['id_lang'])] = $filename.'.'.$type;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( !count($errors) ){
|
|
$info->save();
|
|
// rename file with Picto->id_picto
|
|
// foreach ($languages as $language) {
|
|
// $lang = new Language((int)$language['id_lang']);
|
|
// $img_path = dirname(__FILE__).'/img/';
|
|
// $type = strtolower(substr(strrchr($file['name'], '.'), 1));
|
|
// $filename = Tools::encrypt($_FILES['name_'.(int)($language['id_lang'])]['name']).'_'.$language['id_lang'].$type;
|
|
// if ( is_file($img_path.'/'.$filename) ){
|
|
// rename($img_path.$filename, $img_path.$lang->iso_code.'/'.$info->id_picto.$type);
|
|
// }
|
|
// }
|
|
// $info->update();
|
|
}
|
|
if (isset($temp_name))
|
|
@unlink($temp_name);
|
|
}
|
|
|
|
// Update global picto settings
|
|
elseif ( Tools::isSubmit('submitUpdatePictoSettings') ){
|
|
$this->_updatePictoSettings();
|
|
}
|
|
|
|
// Dupolicate product picto
|
|
elseif( Tools::isSubmit('submitDuplicatePicto') ){
|
|
$id_product = (int)Tools::getValue('id_product');
|
|
$this->_duplicatePicto();
|
|
$redirect=__PS_BASE_URI__.'adm/index.php?controller=AdminProducts&id_product='.$id_product.'&updateproduct&token='.Tools::getAdminTokenLite('AdminProducts');
|
|
header('location:'.$redirect);
|
|
}
|
|
|
|
elseif ( Tools::isSubmit('deletemodule') ){
|
|
if ( Tools::getValue('id_picto') ){
|
|
$picto = new Picto((int)Tools::getValue('id_picto'));
|
|
$picto->delete();
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
/**
|
|
* Update pictos global settings
|
|
*/
|
|
private function _updatePictoSettings(){
|
|
if ( Validate::isInt(Tools::getValue('_PICTO_IMG_HEIGHT_')) )
|
|
Configuration::updateValue('_PICTO_IMG_HEIGHT_', Tools::getValue('_PICTO_IMG_HEIGHT_'));
|
|
if ( Validate::isInt(Tools::getValue('_PICTO_IMG_WIDTH_')) )
|
|
Configuration::updateValue('_PICTO_IMG_WIDTH_', Tools::getValue('_PICTO_IMG_WIDTH_'));
|
|
}
|
|
|
|
|
|
private function _duplicatePicto(){
|
|
|
|
// if ( !Tools::getValue('id_category') ){
|
|
// $this->displayError($this->l('You must sort product by category and choose your category in product list to duplicate pictos.'));
|
|
// return false;
|
|
// }
|
|
// $id_category = Tools::getValue('id_category');
|
|
$id_product = Tools::getValue('id_product');
|
|
$product = new Product((int)$id_product);
|
|
$id_category = $product->getDefaultCategory();
|
|
|
|
// $all_categories = Tools::getValue('allcategories');
|
|
|
|
Picto::duplicatePictosToCategory((int)$id_product, (int)$id_category, (int)$all_categories=true);
|
|
}
|
|
|
|
/**
|
|
* Remove image from directory
|
|
* @param $image Image name
|
|
*/
|
|
public function removeImages($image = NULL){
|
|
$filename = _PS_MODULE_DIR_.'pictos/img/';
|
|
if ( $image ){
|
|
$filename .= $image;
|
|
unlink($filename);
|
|
}else{
|
|
foreach (scandir($filename) as $item) {
|
|
if ($item == '.' || $item == '..') continue;
|
|
unlink($filename.$item);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private function _ajaxProcess(){
|
|
global $cookie;
|
|
|
|
$id_lang = Tools::getValue('id_lang');
|
|
if ($id_lang) {
|
|
$cookie->id_lang = (int)$id_lang;
|
|
}
|
|
|
|
|
|
$action = Tools::getValue('action');
|
|
$id_picto = Tools::getValue('id_picto');
|
|
$id_product = (int)Tools::getValue('id_product');
|
|
$id_category = (int)Tools::getValue('id_category');
|
|
|
|
if ( !$action )
|
|
die('Nothing to perform');
|
|
|
|
switch ($action) {
|
|
|
|
case 'suppPictos':
|
|
PictosProduct::DelAllPictoProduct($file);
|
|
unlink(dirname(__FILE__).'/../img/'.$file);
|
|
$info = PictosInfo::getPictoInfo($file);
|
|
$info->delete();
|
|
$output = '{"error":false}';
|
|
break;
|
|
|
|
// Add picto to product
|
|
case 'addToProduct':
|
|
if ( !$id_picto || !$id_product )
|
|
die ( Tools::jsonEncode('Bad parameters') );
|
|
|
|
if ( Picto::addToProduct((int)$id_picto, (int)$id_product) ){
|
|
die(Tools::jsonEncode(array(
|
|
'id_picto' => $id_picto
|
|
)));
|
|
}else{
|
|
die(Tools::jsonEncode(array(
|
|
'id_picto' => $id_picto,
|
|
'error' => true
|
|
)));
|
|
}
|
|
break;
|
|
|
|
case 'removeFromProduct':
|
|
if ( !$id_picto || !$id_product )
|
|
die ( Tools::jsonEncode('Bad parameters') );
|
|
|
|
$delete = Picto::removeFromProduct($id_picto, $id_product);
|
|
if($delete){
|
|
die(Tools::jsonEncode(array(
|
|
'id_picto' => $id_picto
|
|
)));
|
|
}else{
|
|
die(Tools::jsonEncode(array(
|
|
'id_picto' => $id_picto,
|
|
'error' => true
|
|
)));
|
|
}
|
|
break;
|
|
case 'updateOrder':
|
|
if ( !$id_picto || !$id_product || !Tools::getValue('compt') )
|
|
die ( Tools::jsonEncode('Bad parameters') );
|
|
$update = Picto::updateOrder($id_picto, $id_product, (int)Tools::getValue('compt'));
|
|
if($pictos){
|
|
if($update){
|
|
die(Tools::jsonEncode(array(
|
|
'id_info' => $info->id
|
|
)));
|
|
}else{
|
|
die(Tools::jsonEncode(array(
|
|
'PictosProduct' => $PictosProduct,
|
|
'error' => true
|
|
)));
|
|
}
|
|
}
|
|
break;
|
|
case 'assignPictoRecursive':
|
|
if ( !$id_product || !$id_category){
|
|
die ( Tools::jsonEncode('Bad parameters') );
|
|
}
|
|
$pictos = Picto::getPictosForProduct((int)$id_product);
|
|
$category = new Category((int)$id_category);
|
|
$products = $category->getProductsWs();
|
|
if ( $products ){
|
|
foreach ($products as $product) {
|
|
// Current product do nothing
|
|
if ( (int)$product['id'] == (int)$id_product )
|
|
continue;
|
|
// Delete pictos for product
|
|
Picto::DelAllPictosForProduct((int)$product['id']);
|
|
// Add picto to product
|
|
foreach ($pictos as $picto) {
|
|
// $n_picto = new PictosProduct();
|
|
// $n_picto->id_product = $product['id'];
|
|
// $n_picto->name_pictos = $picto->name_pictos;
|
|
// $n_picto->order_pictos = $picto->order_pictos;
|
|
// $n_picto->pictos_product_description = $picto->pictos_product_description;
|
|
// $n_picto->save();
|
|
}
|
|
}
|
|
}
|
|
echo json_encode('Pictogrammes assignés à tous les produits de la catégorie.');
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
} |