privilegedemarque/modules/antadismarketing/retroallocation_with_csv.php
Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

72 lines
2.3 KiB
PHP

<?php
/**
* Permet de resourcer et d'associer un tracking
* WITH CSV
* Historique retroallocation
*
* 21/01/2016
* id_tracking : id - cliclead-juillet15
* id_sponsor : 94440
*/
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/antadismarketing.php');
include(dirname(__FILE__).'/../referralprogram/referralprogram.php');
include(dirname(__FILE__).'/../referralprogram/ReferralProgramModule.php');
$tracking_name = "cliclead-juillet15";
$tracking = AntTracking::getTrackingInfo($tracking_name);
$id_sponsor = 94440;
$pathToFile = dirname(__FILE__).'/leads-DK.csv';
$delimiter = ';';
$errors = array();
if(Validate::isLoadedObject($tracking)) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$file_mime_type = finfo_file($finfo, $pathToFile);
finfo_close($finfo);
$gzipped = strcmp($file_mime_type, "application/x-gzip") == 0;
$handle = $gzipped ? gzopen($pathToFile, 'r') : fopen($pathToFile, 'r');
if ($handle === false) {
return [];
}
$customers = array();
while (($row = fgetcsv($handle, 0, $delimiter)) !== false) {
$customer = Db::getInstance()->getRow('
SELECT `id_customer`, `email`, `firstname`, `lastname`
FROM `'._DB_PREFIX_.'customer`
WHERE `email` = \''.pSQL($row[0]).'\'');
if (!$id_referralprogram = ReferralProgramModule::isEmailExists($customer['email'], true, false)){
$referralprogram = new ReferralProgramModule();
$referralprogram->id_sponsor = (int)$id_sponsor;
$referralprogram->firstname = $customer['firstname'];
$referralprogram->lastname = $customer['lastname'];
$referralprogram->email = $customer['email'];
if (!$referralprogram->validateFields(false))
$errors[] = $customer['email'];
else
$referralprogram->save();
} else {
$referralprogram = new ReferralProgramModule((int)$id_referralprogram);
}
if ($referralprogram->id_sponsor == $id_sponsor) {
$referralprogram->id_customer = (int)$customer['id_customer'];
$referralprogram->save();
}
//$tracking->addSubscribe((int)$customer['id_customer']);
}
fclose($handle);
}
echo $errors;
exit();