File: /home4/cca63905/public_html/nueva/modules/corewhatsapp/corewhatsapp.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
* @license Prestashop Commercial Module License
*/
if (!defined('_PS_VERSION_'))
exit;
header('X-Frame-Options: GOFORIT');
if ( _PS_VERSION_ >= '1.7') {
require_once _PS_MODULE_DIR_.'/corewhatsapp/classes/Corewhatsapp.php';
}
class Corewhatsapp extends Module {
public function __construct() {
$this->bootstrap = true;
$this->name = 'corewhatsapp';
$this->tab = 'administration';
$this->version = '3.0.0';
$this->author = 'Corecreativo';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('WhatsApp para tu tienda Prestashop');
$this->description = $this->l('Este módulo te proporciona el chat de whatsapp en tu tienda prestashop');
$this->confirmUninstall = $this->l('¿Estás seguro que quieres eliminar este módulo?');
}
public function install() {
// New Tab
if (_PS_VERSION_ >= '1.7') {
$parentTabID = Tab::getIdFromClassName('AdminAdmin');
$tab = new Tab();
$tab->active = 1;
$tab->id_parent = $parentTabID;
} else {
// $parentTabID = Tab::getIdFromClassName('AdminAdmin');
$tab = new Tab();
$tab->active = 1;
$tab->id_parent = 0;
}
$tab->class_name = "AdminCorewhatsapp";
$tab->name = array();
foreach (Language::getLanguages() as $lang){
$tab->name[$lang['id_lang']] = "WhatsApp Corecreativo";
}
// $tab->id_parent = $parentTabID;
$tab->module = 'corewhatsapp';
$tab->add();
if (Validate::isLoadedObject($tab))
Configuration::updateValue('PS_COREWHATSAPP_MODULE_IDTAB', (int)$tab->id);
else
return $this->_abortInstall($this->l('Unable to load the "AdminCorewhatsapp" tab'));
Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'corewhatsapp` (
`id_corewhatsapp` int(11) NOT NULL AUTO_INCREMENT,
`core_corewhatsapp_number` varchar(500) DEFAULT NULL,
`core_corewhatsapp_message` text DEFAULT NULL,
`core_language` varchar(500) DEFAULT NULL,
`core_dates` date DEFAULT NULL,
`core_status` int(11) DEFAULT 0,
`created_date` date DEFAULT NULL,
`active` int(11) DEFAULT 0,
`type` int(11) DEFAULT 0,
PRIMARY KEY (`id_corewhatsapp`)
) ENGINE=' . _MYSQL_ENGINE_ . ' default CHARSET=utf8');
Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'corewhatsapp_lang` (
`id_corewhatsapp` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_corewhatsapp`,`id_lang`),
KEY `id_corewhatsapp` (`id_corewhatsapp`)
) ENGINE=' . _MYSQL_ENGINE_ . ' default CHARSET=utf8');
if (parent::install()) {
/* Register left column hook */
$this->registerHook('displayFooter');
Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'tab` SET module=NULL WHERE class_name="AdminCorewhatsapp" ');
//Move class and controllers files - Permission required on Linux machine.
Tools::copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . '/controllers/admin/AdminCorewhatsappController.php', _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'controllers' .
DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'AdminCorewhatsappController.php');
Tools::copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . '/classes/Corewhatsapp.php', _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'classes' .
DIRECTORY_SEPARATOR . 'Corewhatsapp.php');
// Copy Images
Tools::copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . '/views/img/admin/tab-corewhatsapp.gif', _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'img' .
DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'tab-corewhatsapp.gif');
Tools::copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . '/views/img/admin/AdminCorewhatsapp.gif', _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'img' .
DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'AdminCorewhatsapp.gif');
// Clear cache
include_once(_PS_ROOT_DIR_.'/config/config.inc.php');
include_once(_PS_ROOT_DIR_.'/init.php');
Tools::clearSmartyCache();
Tools::clearXMLCache();
Media::clearCache();
Tools::generateIndex();
$get_url = Db::getInstance()->ExecuteS('SELECT domain,physical_uri FROM '._DB_PREFIX_.'shop_url ');
$protocol = (isset($_SERVER['HTTPS']) ? "https" : "http") ;
$site_url = "$protocol://".$get_url[0]['domain'].$get_url[0]['physical_uri'];
$this->context->smarty->assign('SITEURL',$site_url);
$to = "modulo@corecreativo.es";
$subject = "Módulo WhatsApp instalado";
$message = "
<html>
<head>
<title>Módulo Whatsapp instalado</title>
</head>
<body>
<p>Módulo Whatsapp instalado</p>
<table>
<tr>
<th>URL => $site_url </th>
</tr>
<tr>
<td>Corecreativo</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);
return true;
} else
return false;
//return parent::install();
}
public function uninstall() {
if ($id_tab = Tab::getIdFromClassName('AdminCorewhatsapp')) {
$tab = new Tab((int) $id_tab);
$tab->delete();
}
Db::getInstance()->Execute(' DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'corewhatsapp`, `' . _DB_PREFIX_ . 'corewhatsapp_lang`; ');
return parent::uninstall();
}
public function showData()
{
$CORENumber = NULL;
$COREMessage = NULL;
$id_lang = $this->context->language->id;
$result = Db::getInstance()->ExecuteS("SELECT * FROM "._DB_PREFIX_."corewhatsapp WHERE core_status=1 AND FIND_IN_SET('".pSQL($id_lang)."', `core_language`) LIMIT 0,1 ");
foreach ($result as $row)
{
$CORENumber = $row['core_corewhatsapp_number'];
$COREMessage = $row['core_corewhatsapp_message'];
}
$this->context->smarty->assign('CORENUMBER',$CORENumber);
$this->context->smarty->assign('COREMESSAGE',rawurlencode($COREMessage));
$get_url = Db::getInstance()->ExecuteS('SELECT domain,physical_uri FROM '._DB_PREFIX_.'shop_url ');
$protocol = (isset($_SERVER['HTTPS']) ? "https" : "http") ;
$image_url = "$protocol://".$get_url[0]['domain'].'/'.$get_url[0]['physical_uri']."modules/corewhatsapp/views/img/whatsapp.png";
$this->context->smarty->assign('COREIMAGEPATH',$image_url);
if (_PS_VERSION_ >= '1.7') {
$this->context->smarty->assign('PS7_FLAG',"YES");
} else {
$this->context->smarty->assign('PS7_FLAG',"");
}
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
$this->context->smarty->assign('DEVICE',"api");
} else {
$this->context->smarty->assign('DEVICE',"web");
}
return $this->display(__FILE__, './views/templates/front/corewhatsapp.tpl');
}
public function hookDisplayFooter()
{
return $this->showData();
}
/**
* 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);
}
}
}
?>