File: /home4/cca63905/www/nueva/controllers/admin/AdminCorewhatsappController.php
<?php
/**
* The module helps to add whats app chat support on online store and turn visitors into customers.This helps to build relationship with customers,provide personalized service and increase in sales.
*
* NOTICE OF LICENSE
*
* Each copy of the software must be used for only one production website, it may be used on additional
* test servers. You are not permitted to make copies of the software without first purchasing the
* appropriate additional licenses. This license does not grant any reseller privileges.
*
* @author Corecreativo
* @copyright 2007-2023 Corecreativo
* @license Prestashop Commercial Module License
*/
class AdminCorewhatsappControllerCore extends AdminController {
public function __construct()
{
$this->bootstrap = true;
$this->table = 'corewhatsapp';
$this->className = 'Corewhatsapp';
$this->lang = false;
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->context = Context::getContext();
if (!Tools::getValue('realedit'))
$this->deleted = false;
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
)
);
$this->fields_list = array(
'id_corewhatsapp' => array(
'title' => $this->l('ID'),
'align' => 'left',
'width' => 'auto'
),
'core_corewhatsapp_number' =>
array(
'title' => $this->l('WhatsApp'), 'filter_key' => 'core_corewhatsapp_number', 'align' => 'left', 'width' => 'auto'),
'core_dates' => array('title' => $this->l('Fecha'), 'filter_key' => 'core_dates', 'align' => 'left', 'width' => 'auto')
);
if(!$this->ajax && !isset($this->display)){
$this->context->smarty->assign(array(
'modules_dir' => _MODULE_DIR_
));
$this->content .= $this->context->smarty->fetch(_PS_MODULE_DIR_.'corewhatsapp/views/templates/admin/corewhatsapp.tpl');
}
parent::__construct();
}
public function renderForm()
{
$languages = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'lang WHERE active=1 ');
if (_PS_VERSION_ < '1.6') {
$type = 'radio' ;
} else {
$type = 'switch' ;
}
$this->fields_form = array(
'legend' => array(
'title' => $this->l('WhatsApp Corecreativo Management'),
'image' => '../img/admin/tab-corewhatsapp.gif'
),
'input' => array
(
array(
'type' => 'text',
'label' => $this->l('Número de Whatsapp:'),
'name' => 'core_corewhatsapp_number',
'lang' => false,
'size' => 33,
'required' => true,
'desc' => $this->l('El teléfono debe escribirse con el prefijo. Ejemplo: +34XXXXXXXXX')
),
array(
'type' => 'textarea',
'label' => $this->l('Mensaje inicial que recibirás:'),
'name' => 'core_corewhatsapp_message',
'lang' => false,
'cols' => 50,
'rows' => 10,
'required' => true,
'desc' => $this->l('El mensaje inicial cuando el cliente escriba por Whatsapp.')
),
array(
'type' => 'select',
'label' => $this->l('Idioma'),
'name' => 'core_language[]',
'required' => false,
'multiple' => true,
'expanded' => true,
'desc' => $this->l('ATENCIÓN: Selecciona Español para que funcione el módulo. Solo Español, la segunda lengua materna del mundo por número de hablantes.'),
'options' => array(
'query' => $languages,
'id' => 'id_lang',
'name' => 'name'
)
),
array(
'type' => "$type",
'label' => $this->l('Activo:'),
'name' => 'core_status',
'is_bool' => true,
'values' => array(
array(
'id' => 'core_status_on',
'value' => 1,
'label' => $this->l('Si')
),
array(
'id' => 'core_status_off',
'value' => 0,
'label' => $this->l('No')
)
),
'required' => false,
'desc' => $this->l('Activar o no este Whatsapp')
),
array(
'type' => 'date',
'label' => $this->l('Fecha:'),
'name' => 'core_dates',
'size' => 20,
'search' => false,
'desc' => $this->l('Fecha en la que lo has creado o actualizado.')
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default'
)
);
if(isset($_REQUEST['id_corewhatsapp']))
{
$id_corewhatsapp = (trim($_REQUEST['id_corewhatsapp']));
}
if(!empty($id_corewhatsapp))
{
$core_language = Db::getInstance()->getValue('SELECT core_language FROM '._DB_PREFIX_.'corewhatsapp WHERE
id_corewhatsapp='.pSQL($id_corewhatsapp).' ');
$this->fields_value['core_language[]'] = explode(',',$core_language);
}
return parent::renderForm();
}
public function postProcess()
{
$multiple_languages = array();
$multiple_languages = Tools::getValue('core_language');
$_POST['core_language'] = implode(',',(array)$multiple_languages);
parent::postProcess();
}
/**
* Surcharge de la fonction de traduction sur PS 1.7 et supérieur.
* La fonction globale ne fonctionne pas
* @param type $string
* @param type $class
* @param type $addslashes
* @param type $htmlentities
* @return type
*/
public function l($string, $class = null, $addslashes = false, $htmlentities = true)
{
if (_PS_VERSION_ >= '1.7') {
return Context::getContext()->getTranslator()->trans($string);
} else {
return parent::l($string, $class, $addslashes, $htmlentities);
}
}
}