395 lines
10 KiB
PHP
Executable File
395 lines
10 KiB
PHP
Executable File
<?php
|
|
|
|
/*
|
|
* 2007-2012 PrestaShop
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
*
|
|
* DISCLAIMER *
|
|
* *************************************** */
|
|
/* Do not edit or add to this file if you wish to upgrade Prestashop to newer
|
|
* versions in the future.
|
|
* ****************************************************
|
|
* @category Belvg
|
|
* @package belvg_blockconstructor
|
|
* @author Dzianis Yurevich (dzianis.yurevich@gmail.com)
|
|
* @copyright Copyright (c) 2010 - 2012 BelVG LLC. (http://www.belvg.com)
|
|
* @license http://store.belvg.com/BelVG-LICENSE-COMMUNITY.txt
|
|
*/
|
|
|
|
include_once(_PS_MODULE_DIR_ . 'belvg_blockconstructor/belvg_blockconstructor.php');
|
|
|
|
class AdminBlockConstructorController extends ModuleAdminController {
|
|
|
|
protected $position_identifier = 'id_belvg_blockconstructor';
|
|
|
|
protected $_js = '
|
|
<script>
|
|
$(".multishop_toolbar").hide();
|
|
</script>
|
|
';
|
|
|
|
protected $_module = null;
|
|
|
|
public function mod_l($string)
|
|
{
|
|
if (is_null($this->_module)) {
|
|
$this->_module = new belvg_blockconstructor;
|
|
}
|
|
|
|
return $this->_module->l($string, __CLASS__);
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
$this->bootstrap = true;
|
|
$this->table = 'belvg_blockconstructor';
|
|
$this->identifier = 'id_belvg_blockconstructor';
|
|
$this->className = 'BelvgBlockConstructor';
|
|
$this->lang = TRUE;
|
|
$this->addRowAction('edit');
|
|
$this->addRowAction('delete');
|
|
|
|
$this->fields_list = array(
|
|
'id_belvg_blockconstructor' => array(
|
|
'title' => $this->l('ID'),
|
|
'align' => 'center',
|
|
'width' => 30
|
|
),
|
|
'title' => array(
|
|
'title' => $this->l('Block Title'),
|
|
'width' => 100
|
|
),
|
|
'classbloc' => array(
|
|
'title' => $this->l('Link'),
|
|
'width' => 200,
|
|
),
|
|
'status' => array(
|
|
'title' => $this->l('Status'),
|
|
'width' => 40,
|
|
'active' => 'update',
|
|
'align' => 'center',
|
|
'type' => 'bool',
|
|
'orderby' => FALSE
|
|
),
|
|
/*'date_from' => array(
|
|
'title' => $this->mod_l('Date start'),
|
|
'width' => 150,
|
|
'type' => 'date',
|
|
'align' => 'right'
|
|
),
|
|
'date_to' => array(
|
|
'title' => $this->mod_l('Date end'),
|
|
'width' => 150,
|
|
'type' => 'date',
|
|
'align' => 'right'
|
|
)*/
|
|
);
|
|
|
|
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) {
|
|
$this->_where .= ' AND a.' . $this->identifier . ' IN (
|
|
SELECT sa.' . $this->identifier . '
|
|
FROM `' . _DB_PREFIX_ . $this->table . '_shop` sa
|
|
WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
|
|
)';
|
|
}
|
|
|
|
$this->identifiersDnd = array('id_belvg_blockconstructor' => 'id_sslide_to_move');
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
public function renderForm()
|
|
{
|
|
$this->display = 'edit';
|
|
$this->initToolbar();
|
|
if (!$obj = $this->loadObject(TRUE)) {
|
|
return;
|
|
}
|
|
|
|
$hook = array(
|
|
array(
|
|
"id_hook" => 136,
|
|
"title" => 'Panier bloc gauche haut',
|
|
),
|
|
/*array(
|
|
"id_hook" => 144,
|
|
"title" => 'Accueil bloc centre',
|
|
),
|
|
array(
|
|
"id_hook" => 145,
|
|
"title" => 'Accueil bloc droite',
|
|
),
|
|
array(
|
|
"id_hook" => 146,
|
|
"title" => 'Accueil bloc bas gauche',
|
|
),
|
|
array(
|
|
"id_hook" => 147,
|
|
"title" => 'Accueil bloc bas droit',
|
|
),*/
|
|
);
|
|
|
|
$categories = array();
|
|
$tab = array();
|
|
$tab['id'] = 0 ;
|
|
$tab['name'] = "Select Category";
|
|
$categories[] = $tab;
|
|
foreach(Category::getCategories((int) $this->context->cookie->id_lang) as $c) {
|
|
foreach($c as $d){
|
|
$tab = array();
|
|
$tab['id'] = $d['infos']['id_category'] ;
|
|
$tab['name'] = $d['infos']['id_category'] ." - " . $d['infos']['name'] ;
|
|
$categories[] = $tab;
|
|
}
|
|
}
|
|
|
|
if (Tools::isSubmit('id_belvg_blockconstructor')){
|
|
$id_belvg_blockconstructor = (int)Tools::getValue('id_belvg_blockconstructor');
|
|
$url = __PS_BASE_URI__.'modules/belvg_blockconstructor/img/'.$id_belvg_blockconstructor ;
|
|
}else{
|
|
$url = "noimg" ;
|
|
}
|
|
|
|
$this->fields_form = array(
|
|
'tinymce' => TRUE,
|
|
'legend' => array(
|
|
'title' => $this->l('Blocks Constructor'),
|
|
'image' => '../img/admin/tab-categories.gif'
|
|
),
|
|
'input' => array(
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Block Title:'),
|
|
'name' => 'title',
|
|
'id' => 'title',
|
|
'lang' => TRUE,
|
|
'required' => TRUE,
|
|
'size' => 50,
|
|
'maxlength' => 50,
|
|
),
|
|
/*array(
|
|
'type' => 'text',
|
|
'label' => $this->mod_l('Block Subtitle:'),
|
|
'name' => 'subtitle',
|
|
'id' => 'subtitle',
|
|
'size' => 50,
|
|
'maxlength' => 50,
|
|
),*/
|
|
array(
|
|
'type' => 'text',
|
|
'label' => $this->l('Link:'),
|
|
'name' => 'classbloc',
|
|
'id' => 'classbloc',
|
|
'lang' => TRUE,
|
|
'size' => 50,
|
|
'maxlength' => 100,
|
|
),
|
|
/*array(
|
|
'type' => 'text',
|
|
'label' => $this->mod_l('Block Link:'),
|
|
'name' => 'linkA',
|
|
'id' => 'linkA',
|
|
'lang' => true,
|
|
'size' => 50,
|
|
'maxlength' => 50,
|
|
),*/
|
|
array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Hook:'),
|
|
'name' => 'id_hook',
|
|
'id' => 'id_hook',
|
|
'options' => array(
|
|
'query' => $hook,
|
|
'id' => 'id_hook',
|
|
'name' => 'title',
|
|
'default' => array('label' => $this->mod_l('Select hook'), 'value' => 0))
|
|
),
|
|
/*array(
|
|
'type' => 'select',
|
|
'label' => $this->l('Category'),
|
|
'name' => 'id_category',
|
|
'options' => array(
|
|
'query' => $categories,
|
|
'id' => 'id',
|
|
'name' => 'name'
|
|
)
|
|
), */
|
|
array(
|
|
'type' => 'radio',
|
|
'label' => $this->l('Status:'),
|
|
'name' => 'status',
|
|
'class' => 't',
|
|
'is_bool' => TRUE,
|
|
'values' => array(
|
|
array(
|
|
'id' => 'active_on',
|
|
'value' => 1,
|
|
'label' => $this->l('Enabled')
|
|
),
|
|
array(
|
|
'id' => 'active_off',
|
|
'value' => 0,
|
|
'label' => $this->l('Disabled')
|
|
)
|
|
),
|
|
),
|
|
array(
|
|
'type' => 'file',
|
|
'label' => $this->l('Select a file FR'),
|
|
'name' => 'imagelogo_1',
|
|
'lang' => true,
|
|
'url' => $url
|
|
),
|
|
array(
|
|
'type' => 'file',
|
|
'label' => $this->l('Select a file EN'),
|
|
'name' => 'imagelogo_2',
|
|
'lang' => true,
|
|
'url' => $url
|
|
),
|
|
/*array(
|
|
'type' => 'date',
|
|
'label' => $this->mod_l('Date from:'),
|
|
'name' => 'date_from',
|
|
'id' => 'date_from',
|
|
'size' => 50,
|
|
'maxlength' => 50,
|
|
),
|
|
array(
|
|
'type' => 'date',
|
|
'label' => $this->mod_l('Date to:'),
|
|
'name' => 'date_to',
|
|
'id' => 'date_to',
|
|
'size' => 50,
|
|
'maxlength' => 50,
|
|
),
|
|
array(
|
|
'type' => 'textarea',
|
|
'label' => $this->mod_l('Content:'),
|
|
'name' => 'content',
|
|
'autoload_rte' => TRUE,
|
|
'lang' => TRUE,
|
|
'rows' => 5,
|
|
'cols' => 40,
|
|
),*/
|
|
),
|
|
'submit' => array(
|
|
'title' => $this->mod_l(' Save '),
|
|
'class' => 'button'
|
|
)
|
|
);
|
|
|
|
if (Shop::isFeatureActive()) {
|
|
$this->fields_form['input'][] = array(
|
|
'type' => 'shop',
|
|
'label' => $this->mod_l('Shop association:'),
|
|
'name' => 'checkBoxShopAsso',
|
|
);
|
|
}
|
|
|
|
$this->tpl_form_vars = array(
|
|
'status' => $this->object->status
|
|
);
|
|
|
|
return parent::renderForm() . $this->_js;
|
|
}
|
|
|
|
protected function updateAssoShop($id_object)
|
|
{
|
|
if (!Shop::isFeatureActive()) {
|
|
return;
|
|
}
|
|
|
|
$assos_data = $this->getSelectedAssoShop($this->table, $id_object);
|
|
|
|
$exclude_ids = $assos_data;
|
|
foreach (Db::getInstance()->executeS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'shop') as $row) {
|
|
if (!$this->context->employee->hasAuthOnShop($row['id_shop'])) {
|
|
$exclude_ids[] = $row['id_shop'];
|
|
}
|
|
}
|
|
|
|
Db::getInstance()->delete($this->table . '_shop', '`' . $this->identifier . '` = ' . (int) $id_object . ($exclude_ids ? ' AND id_shop NOT IN (' . implode(', ', $exclude_ids) . ')' : ''));
|
|
|
|
$insert = array();
|
|
foreach ($assos_data as $id_shop) {
|
|
$insert[] = array(
|
|
$this->identifier => $id_object,
|
|
'id_shop' => (int) $id_shop,
|
|
);
|
|
}
|
|
|
|
return Db::getInstance()->insert($this->table . '_shop', $insert, FALSE, TRUE, Db::INSERT_IGNORE);
|
|
}
|
|
|
|
protected function getSelectedAssoShop($table)
|
|
{
|
|
if (!Shop::isFeatureActive()) {
|
|
return array();
|
|
}
|
|
|
|
$shops = Shop::getShops(TRUE, NULL, TRUE);
|
|
if (count($shops) == 1 && isset($shops[0])) {
|
|
return array($shops[0], 'shop');
|
|
}
|
|
|
|
$assos = array();
|
|
if (Tools::isSubmit('checkBoxShopAsso_' . $table)) {
|
|
foreach (Tools::getValue('checkBoxShopAsso_' . $table) as $id_shop => $value) {
|
|
$assos[] = (int) $id_shop;
|
|
}
|
|
} else if (Shop::getTotalShops(FALSE) == 1) {
|
|
// if we do not have the checkBox multishop, we can have an admin with only one shop and being in multishop
|
|
$assos[] = (int) Shop::getContextShopID();
|
|
}
|
|
|
|
return $assos;
|
|
}
|
|
|
|
public function processSave()
|
|
{
|
|
$save = parent::processSave();
|
|
if(Validate::isLoadedObject($this->object)){
|
|
$languages = Language::getLanguages(false);
|
|
foreach ($languages as $language) {
|
|
if(Validate::isLoadedObject($this->object)){
|
|
|
|
$tabimgs = array(
|
|
"logo",
|
|
);
|
|
foreach($tabimgs as $tabimg){
|
|
|
|
$namePost = 'image'.$tabimg.'_'.$language['id_lang'];
|
|
if (isset($_FILES[$namePost]) && isset($_FILES[$namePost]['tmp_name']) && !empty($_FILES[$namePost]['tmp_name']))
|
|
{
|
|
if (file_exists(dirname(__FILE__).'/../../img/'.$this->object->id.'_'.(int)$language['id_lang'].'.jpg'))
|
|
unlink(dirname(__FILE__).'/../../img/'.$this->object->id.'_'.(int)$language['id_lang'].'.jpg');
|
|
if ($error = ImageManager::validateUpload($_FILES[$namePost]))
|
|
$errors .= $error;
|
|
elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES[$namePost]['tmp_name'], $tmpName))
|
|
return false;
|
|
elseif (!ImageManager::resize($tmpName, dirname(__FILE__).'/../../img/'.$this->object->id.'_'.$language['id_lang'].'.jpg'))
|
|
$errors .= $this->displayError($this->l('An error occurred while attempting to upload the image.'));
|
|
if (isset($tmpName))
|
|
unlink($tmpName);
|
|
}
|
|
else
|
|
$errors = "File cannot be uploaded";
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
return $save;
|
|
}
|
|
|
|
} |