95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
include(dirname(__FILE__).'/../../config/config.inc.php');
|
|
include(dirname(__FILE__).'/classes/AntTrackingCategories.php');
|
|
include(dirname(__FILE__).'/classes/AntTracking.php');
|
|
// EtYBdzSkTIiB
|
|
|
|
if (!Tools::getValue('token') || Tools::getValue('token') != Configuration::get('ANT_TRACKING_CRONTOKEN') )
|
|
die();
|
|
|
|
$antTrackingCron = new AntTrackingCron();
|
|
$antTrackingCron->process();
|
|
exit;
|
|
|
|
class AntTrackingCron{
|
|
private $_nlTypes = array();
|
|
private $_parentCategoryId = 5;
|
|
private $_trackingCategoryAccess = 1;
|
|
private $_trackingCategoryId;
|
|
|
|
public function __construct(){
|
|
$this->_nlTypes = array(
|
|
/*'pro' => array(
|
|
'name' => 'PRO'
|
|
),*/
|
|
'part' => array(
|
|
'name' => 'PART'
|
|
),
|
|
'quot' => array(
|
|
'name' => 'QUOT'
|
|
),
|
|
'trihebdo' => array(
|
|
'name' => 'TRIHEBDO'
|
|
),
|
|
'hebdo' => array(
|
|
'name' => 'HEBDO'
|
|
),
|
|
);
|
|
}
|
|
|
|
public function process(){
|
|
$this->_time = mktime(0,0,0,date('n'),date('j')+1);
|
|
$this->_getCategory();
|
|
foreach ($this->_nlTypes as $type) {
|
|
$this->_generateTraking($type, $category);
|
|
}
|
|
}
|
|
|
|
private function _getCategory(){
|
|
setlocale(LC_TIME, "fr_FR.UTF-8");
|
|
|
|
$date = date('Y-m-d H:i:s', $this->_time);
|
|
$currMonth = strftime("%B", $this->_time);
|
|
|
|
$sql = 'SELECT atc.`id_tracking_categories`
|
|
FROM `'._DB_PREFIX_.'ant_marketing_tracking_categories` atc
|
|
LEFT JOIN `'._DB_PREFIX_.'ant_marketing_tracking_categories_lang` atcl
|
|
ON (atc.`id_tracking_categories` = atcl.`id_tracking_categories` AND `id_lang` = 1)
|
|
WHERE atcl.`name` LIKE \'NEWSLETTER ' . pSQL($currMonth) . ' ' . date('Y', $this->_time) .'\'';
|
|
if ($idCategory = (int)Db::getInstance()->getValue($sql))
|
|
return $this->_trackingCategoryId = (int)$idCategory;
|
|
|
|
$antTrackingCategory = new AntTrackingCategories();
|
|
$antTrackingCategory->id_parent_categories = $this->_parentCategoryId;
|
|
$antTrackingCategory->name = 'NEWSLETTER ' . $currMonth . ' ' . date('Y', $this->_time);
|
|
$antTrackingCategory->id_profile = $this->_trackingCategoryAccess;
|
|
$antTrackingCategory->save();
|
|
return $this->_trackingCategoryId = (int)$antTrackingCategory->id;
|
|
}
|
|
|
|
private function _generateTraking($type){
|
|
$trackingName = 'NL' . date('dmy', $this->_time) . '_' . $type['name'];
|
|
$tracking = new AntTracking();
|
|
$tracking->name = $trackingName;
|
|
$tracking->id_tracking_categories = $this->_trackingCategoryId;
|
|
$tracking->duree = 1;
|
|
$tracking->redirect = 0;
|
|
$tracking->redirect_page = '';
|
|
$tracking->subscribe_save = 0;
|
|
$tracking->subscribe_tag = '';
|
|
$tracking->redirection = '';
|
|
$tracking->cout = 0;
|
|
$tracking->utm_source = 'mailjet';
|
|
$tracking->utm_medium = $trackingName;
|
|
$tracking->utm_term = '';
|
|
$tracking->utm_content = '';
|
|
$tracking->utm_campaign = $trackingName;
|
|
$tracking->more_params = '';
|
|
|
|
foreach (Language::getLanguages() as $lang) {
|
|
$tracking->description[$lang['id_lang']] = $trackingName;
|
|
}
|
|
|
|
$tracking->save();
|
|
}
|
|
} |