2016-01-04 12:49:26 +01:00
|
|
|
<?php
|
|
|
|
class LandingPages extends Module {
|
|
|
|
public function __construct() {
|
|
|
|
$this->name = 'landingpages';
|
|
|
|
$this->tab = 'advertising_marketing';
|
|
|
|
$this->version = '1.0';
|
|
|
|
$this->author = 'Antadis';
|
|
|
|
$this->need_instance = 0;
|
|
|
|
|
|
|
|
$this->displayName = $this->l('Landing Pages');
|
|
|
|
$this->description = $this->l('Landing pages management for Prestashop');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function install() {
|
|
|
|
# Install admin tab
|
|
|
|
$tab = Db::getInstance()->getRow('
|
|
|
|
SELECT `id_tab`
|
|
|
|
FROM `'._DB_PREFIX_.'tab`
|
|
|
|
WHERE `class_name` = "AdminCustomers"
|
|
|
|
');
|
|
|
|
|
|
|
|
Db::getInstance()->ExecuteS('
|
|
|
|
INSERT INTO `'._DB_PREFIX_.'tab`
|
|
|
|
VALUES (DEFAULT, '.(int) $tab['id_tab'].', "AdminLandingPages", "landingpages", 5)
|
|
|
|
');
|
|
|
|
$tab_id = Db::getInstance()->Insert_ID();
|
|
|
|
|
|
|
|
Db::getInstance()->ExecuteS('
|
|
|
|
INSERT INTO `'._DB_PREFIX_.'access`
|
|
|
|
VALUES (1, '.$tab_id.', 1, 1, 1, 1)
|
|
|
|
');
|
|
|
|
|
|
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
|
|
SELECT `id_profile`
|
|
|
|
FROM `'._DB_PREFIX_.'profile`
|
|
|
|
WHERE `id_profile` > 1
|
|
|
|
') as $profile) {
|
|
|
|
Db::getInstance()->ExecuteS('
|
|
|
|
INSERT INTO `'._DB_PREFIX_.'access`
|
|
|
|
VALUES ('.$profile['id_profile'].', '.$tab_id.', 0, 0, 0, 0)
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
$tabs_i18n = array(
|
|
|
|
'fr' => 'Landing pages',
|
|
|
|
'en' => 'Landing pages',
|
|
|
|
);
|
|
|
|
$langs = Db::getInstance()->ExecuteS('
|
|
|
|
SELECT `id_lang`, `iso_code`
|
|
|
|
FROM `'._DB_PREFIX_.'lang`
|
|
|
|
');
|
|
|
|
foreach($langs as $lang) {
|
|
|
|
if(isset($tabs_i18n[$lang['iso_code']])) {
|
|
|
|
Db::getInstance()->Execute('
|
|
|
|
INSERT INTO `'._DB_PREFIX_.'tab_lang`
|
|
|
|
VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n[$lang['iso_code']].'")
|
|
|
|
');
|
|
|
|
} else {
|
|
|
|
Db::getInstance()->Execute('
|
|
|
|
INSERT INTO `'._DB_PREFIX_.'tab_lang`
|
|
|
|
VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n['en'].'")
|
|
|
|
');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add tables
|
|
|
|
$query = '
|
|
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'landing_page` (
|
|
|
|
`id_landing_page` INTEGER NOT NULL AUTO_INCREMENT,
|
|
|
|
`enabled` BOOL NOT NULL,
|
2016-04-08 15:31:40 +02:00
|
|
|
`connect_button` BOOL NOT NULL,
|
2016-01-04 12:49:26 +01:00
|
|
|
`name` VARCHAR(255) NOT NULL,
|
|
|
|
`text1` VARCHAR(255) NOT NULL,
|
|
|
|
`text2` VARCHAR(255) NOT NULL,
|
|
|
|
PRIMARY KEY(`id_landing_page`)
|
|
|
|
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
|
|
|
';
|
|
|
|
if(!Db::getInstance()->Execute($query)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'landing_page_customer` (
|
|
|
|
`id_landing_page` INTEGER NOT NULL,
|
|
|
|
`id_customer` INTEGER NOT NULL,
|
|
|
|
PRIMARY KEY(`id_landing_page`, `id_customer`)
|
|
|
|
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
|
|
|
';
|
|
|
|
if(!Db::getInstance()->Execute($query)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Register hooks
|
|
|
|
if(!parent::install()
|
|
|
|
|| !$this->registerHook('adminCustomers')
|
|
|
|
|| !$this->registerHook('createAccountForm')
|
2016-04-08 15:31:40 +02:00
|
|
|
|| !$this->registerHook('createAccountFormBottom')
|
2016-01-04 12:49:26 +01:00
|
|
|
|| !$this->registerHook('createAccount')) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uninstall() {
|
|
|
|
$tab = Db::getInstance()->getRow('
|
|
|
|
SELECT `id_tab`
|
|
|
|
FROM `'._DB_PREFIX_.'tab`
|
|
|
|
WHERE `module` = "landingpages"
|
|
|
|
');
|
|
|
|
Db::getInstance()->Execute('
|
|
|
|
DELETE FROM `'._DB_PREFIX_.'tab_lang`
|
|
|
|
WHERE `id_tab` = '.$tab['id_tab']
|
|
|
|
);
|
|
|
|
Db::getInstance()->Execute('
|
|
|
|
DELETE FROM `'._DB_PREFIX_.'access`
|
|
|
|
WHERE `id_tab` = '.$tab['id_tab']
|
|
|
|
);
|
|
|
|
Db::getInstance()->Execute('
|
|
|
|
DELETE FROM `'._DB_PREFIX_.'tab`
|
|
|
|
WHERE `module` = "privatesales"
|
|
|
|
');
|
|
|
|
|
|
|
|
if(parent::uninstall() == FALSE) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'landing_page`');
|
|
|
|
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'landing_page_customer`');
|
|
|
|
|
|
|
|
$files = glob(dirname(__FILE__).'/img/*');
|
|
|
|
foreach($files as $file) {
|
|
|
|
unlink($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookCreateAccount($params) {
|
|
|
|
global $cookie;
|
|
|
|
|
|
|
|
$newCustomer = $params['newCustomer'];
|
|
|
|
if(!Validate::isLoadedObject($newCustomer)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($name = Tools::getValue('lp')) {
|
|
|
|
if($landing = Db::getInstance()->getRow('
|
|
|
|
SELECT `id_landing_page`
|
|
|
|
FROM `'._DB_PREFIX_.'landing_page`
|
|
|
|
WHERE `enabled` = 1
|
|
|
|
AND `name` = "'.pSQL($name).'"
|
|
|
|
')) {
|
|
|
|
$id_landing_page = (int) $landing['id_landing_page'];
|
|
|
|
|
|
|
|
Db::getInstance()->ExecuteS('
|
|
|
|
INSERT INTO `'._DB_PREFIX_.'landing_page_customer`
|
|
|
|
VALUES (
|
|
|
|
'.$id_landing_page.',
|
|
|
|
'.(int) $newCustomer->id.'
|
|
|
|
)
|
|
|
|
');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookAdminCustomers($params) {
|
|
|
|
global $cookie;
|
|
|
|
|
|
|
|
$customer = new Customer((int) $params['id_customer']);
|
|
|
|
|
|
|
|
if (!Validate::isLoadedObject($customer))
|
|
|
|
die (Tools::displayError('Incorrect object Customer.'));
|
|
|
|
|
|
|
|
if($landing_page = Db::getInstance()->getRow('
|
|
|
|
SELECT l.`id_landing_page`, l.`name`
|
|
|
|
FROM `'._DB_PREFIX_.'landing_page` l, `'._DB_PREFIX_.'landing_page_customer` c
|
|
|
|
WHERE c.`id_customer` = '.(int) $customer->id.'
|
|
|
|
AND l.`id_landing_page` = c.`id_landing_page`
|
|
|
|
')) {
|
|
|
|
echo '<div class="clear"> </div>
|
|
|
|
<h2>'.$this->l('Lead source').'</h2>
|
|
|
|
<strong>'.$this->l('Landing page:').'</strong>
|
|
|
|
<a href="/adm/index.php?tab=AdminLandingPages&token='.Tools::getAdminTokenLite('AdminLandingPages').'&edit_lp&id_lp='.$landing_page['id_landing_page'].'">'.$landing_page['name'].'</a>
|
|
|
|
<br />';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hookCreateAccountForm($params) {
|
|
|
|
global $smarty, $cookie;
|
|
|
|
$id_landing_page = 0;
|
|
|
|
$lp_text1 = '';
|
|
|
|
$lp_text2 = '';
|
|
|
|
|
|
|
|
if($name = Tools::getValue('lp')) {
|
|
|
|
if($landing = Db::getInstance()->getRow('
|
|
|
|
SELECT *
|
|
|
|
FROM `'._DB_PREFIX_.'landing_page`
|
|
|
|
WHERE `enabled` = 1
|
|
|
|
AND `name` = "'.pSQL($name).'"
|
|
|
|
')) {
|
|
|
|
$id_landing_page = $landing['id_landing_page'];
|
|
|
|
$lp_text1 = $landing['text1'];
|
|
|
|
$lp_text2 = $landing['text2'];
|
|
|
|
$tag = $landing['tag'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($id_landing_page > 0) {
|
|
|
|
if (file_exists(_PS_ROOT_DIR_.'/modules/landingpages/img/'.$id_landing_page.'_1_'.$cookie->id_lang.'.jpg')) {
|
|
|
|
$smarty->assign(array(
|
|
|
|
'landing' => 1,
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
$smarty->assign(array(
|
|
|
|
'landing' => 0,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
$smarty->assign(array(
|
|
|
|
'id_lp' => $id_landing_page,
|
|
|
|
'tag' => $tag,
|
|
|
|
'lp_text1' => $lp_text1,
|
|
|
|
'lp_text2' => $lp_text2,
|
|
|
|
));
|
|
|
|
return $this->display(__FILE__, 'authentication.tpl');
|
|
|
|
}
|
|
|
|
}
|
2016-04-08 15:31:40 +02:00
|
|
|
|
|
|
|
public function hookCreateAccountFormBottom($params) {
|
|
|
|
global $smarty, $cookie;
|
|
|
|
$connect_button = 0;
|
|
|
|
if($name = Tools::getValue('lp')) {
|
|
|
|
if($landing = Db::getInstance()->getRow('
|
|
|
|
SELECT `connect_button`
|
|
|
|
FROM `'._DB_PREFIX_.'landing_page`
|
|
|
|
WHERE `enabled` = 1
|
|
|
|
AND `name` = "'.pSQL($name).'"
|
|
|
|
')) {
|
|
|
|
$connect_button = $landing['connect_button'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$smarty->assign(array(
|
|
|
|
'connect_button' => $connect_button,
|
|
|
|
));
|
|
|
|
return $this->display(__FILE__, 'authentication_bottom.tpl');
|
|
|
|
}
|
2016-01-04 12:49:26 +01:00
|
|
|
}
|