Files
le-matelot/web/benefits/customerBenefits.php
2020-01-27 08:56:08 +01:00

187 lines
8.4 KiB
PHP

<?php
$link = mysqli_connect('localhost', 'root', '#M6BxrtFh@KuXBh5Qz$$', 'c0lematelotv2');
if (!$link) {
die('Erreur de connexion (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
/*
if ($result = mysqli_query($link, "SELECT DATABASE()")) {
$row = mysqli_fetch_row($result);
printf("La base de donn&eacute;es courante est %s.\n", $row[0]);
mysqli_free_result($result);
}
*/
function geneCode($numchar)
{
$word = "A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z,2,3,4,5,6,7,8,9";
$array=explode(",",$word);
shuffle($array);
$newstring = implode($array,"");
$codereduc = substr($newstring, 0, $numchar);
return $codereduc;
}
$benefits = mysqli_real_escape_string($link, $_POST["benefits"]);
if($benefits !== 'generate'){
exit();
}
$customerId = mysqli_real_escape_string($link, $_POST["cref"]);
if(!is_numeric($customerId)){
exit();
}
$customerLang = mysqli_real_escape_string($link, $_POST["clang"]);
if($customerLang === 'de'){
$copy = "Kopie";
$copied = "Kopiert";
}else if($customerLang === 'en'){
$copy = "Copy";
$copied = "Copied";
}else if($customerLang === 'es'){
$copy = "Copia";
$copied = "Copiado";
}else if($customerLang === 'fr'){
$copy = "Copier";
$copied = "Copié";
}else if($customerLang === 'it'){
$copy = "Copia";
$copied = "Copiato";
}
?>
<script src="benefits/clipboard.min.js"></script>
<?php
/*
echo "REF CLIENT: ";
echo $customerId;
echo "<br />";
echo "CODE AVANTAGES CLIENT: <h3>";
echo geneCode(6);
echo "</h3>";
echo $customerLang;
*/
$sql = mysqli_query($link, "SELECT coupon_code FROM `coupon_customer_for_life` WHERE `customer_ref`='".$customerId."'");
if(mysqli_num_rows($sql) !== 0){
$codeav = mysqli_fetch_row($sql);
if($customerLang === 'de'){
echo "<h5>CODE KUNDENNUTZEN: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codeav[0]."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}else if($customerLang === 'en'){
echo "<h5>CUSTOMER ADVANTAGE CODE: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codeav[0]."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}else if($customerLang === 'es'){
echo "<h5>VENTAJAS CLIENTE CÓDIGO: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codeav[0]."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}else if($customerLang === 'fr'){
echo "<h5>CODE AVANTAGES CLIENT: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codeav[0]."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}else if($customerLang === 'it'){
echo "<h5>VANTAGGI CLIENTE CODICE: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codeav[0]."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}
/*
echo $futuredate = date("Y")+100;
echo "-";
echo $suitdate = date("m-d H:i:s");
*/
}else{
$codegen = geneCode(6);
if($customerLang === 'de'){
echo "<h5>CODE KUNDENNUTZEN: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codegen."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}else if($customerLang === 'en'){
echo "<h5>CUSTOMER ADVANTAGE CODE: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codegen."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}else if($customerLang === 'es'){
echo "<h5>VENTAJAS CLIENTE CÓDIGO: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codegen."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}else if($customerLang === 'fr'){
echo "<h5>CODE AVANTAGES CLIENT: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codegen."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}else if($customerLang === 'it'){
echo "<h5>VANTAGGI CLIENTE CODICE: <input type=\"text\" id=\"custCode\" onfocus=\"select_all_and_copy(this)\" value=\"".$codegen."\"><button class=\"btn\" onclick=\"select_all_and_copy(document.getElementById('custCode'))\">".$copy."</button></h5>";
}
$futuredate = date("Y")+100;
$suitdate = date("m-d H:i:s");
//Fix percent
if($customerLang === 'fr'){
$percent = "10";
}else{
$percent = "7";
}
$serial = array("percentage" => $percent);
$outserial = json_encode($serial);
mysqli_query($link, "INSERT INTO `coupon` (`id`, `code`, `type`, `serialized_effects`, `is_enabled`, `start_date`, `expiration_date`, `max_usage`, `is_cumulative`, `is_removing_postage`, `is_available_on_special_offers`, `is_used`, `serialized_conditions`, `per_customer_usage_count`, `created_at`, `updated_at`, `version`, `version_created_at`, `version_created_by`) VALUES
(NULL,
'".$codegen."',
'thelia.coupon.type.remove_x_percent',
'".$outserial."',
1,
'".date("Y-m-d H:i:s")."',
'".$futuredate."-".$suitdate."',
-1,
1,
0,
1,
0,
'W3siY29uZGl0aW9uU2VydmljZUlkIjoidGhlbGlhLmNvbmRpdGlvbi5tYXRjaF9mb3JfZXZlcnlvbmUiLCJvcGVyYXRvcnMiOltdLCJ2YWx1ZXMiOltdfV0=',
0,
'".date("Y-m-d H:i:s")."',
'".date("Y-m-d H:i:s")."',
1,
'".date("Y-m-d H:i:s")."',
NULL);");
mysqli_query($link, "SET FOREIGN_KEY_CHECKS=0");
$sqlast = mysqli_query($link, "SELECT * FROM `coupon` ORDER BY `id` DESC LIMIT 1");
$rowlast = mysqli_fetch_row($sqlast);
//echo $rowlast[0];
mysqli_query($link, "INSERT INTO `coupon_version` (`id`, `code`, `type`, `serialized_effects`, `is_enabled`, `start_date`, `expiration_date`, `max_usage`, `is_cumulative`, `is_removing_postage`, `is_available_on_special_offers`, `is_used`, `serialized_conditions`, `per_customer_usage_count`, `created_at`, `updated_at`, `version`, `version_created_at`, `version_created_by`) VALUES
($rowlast[0],
'".$codegen."',
'thelia.coupon.type.remove_x_percent',
'".$outserial."',
1,
'".date("Y-m-d H:i:s")."',
'".$futuredate."-".$suitdate."',
-1,
1,
0,
1,
0,
'W3siY29uZGl0aW9uU2VydmljZUlkIjoidGhlbGlhLmNvbmRpdGlvbi5tYXRjaF9mb3JfZXZlcnlvbmUiLCJvcGVyYXRvcnMiOltdLCJ2YWx1ZXMiOltdfV0=',
0,
'".date("Y-m-d H:i:s")."',
'".date("Y-m-d H:i:s")."',
1,
'".date("Y-m-d H:i:s")."',
NULL);");
mysqli_query($link, "INSERT INTO `coupon_i18n` (`id`, `locale`, `title`, `short_description`, `description`) VALUES
(".$rowlast[0].", 'de_DE', 'Kundennutzen', '', ''),
(".$rowlast[0].", 'en_US', 'Customer benefits', '', ''),
(".$rowlast[0].", 'es_ES', 'Beneficios cliente', '', ''),
(".$rowlast[0].", 'fr_FR', 'Avantages client', '', ''),
(".$rowlast[0].", 'it_IT', 'Vantaggi cliente', '', '');");
mysqli_query($link, "SET FOREIGN_KEY_CHECKS=1");
mysqli_query($link, "INSERT INTO `coupon_customer_for_life` (`id`, `customer_ref`, `coupon_code`) VALUES (NULL, '".$customerId."', '".$codegen."');");
//echo base64_decode('W3siY29uZGl0aW9uU2VydmljZUlkIjoidGhlbGlhLmNvbmRpdGlvbi5tYXRjaF9mb3JfZXZlcnlvbmUiLCJvcGVyYXRvcnMiOltdLCJ2YWx1ZXMiOltdfV0=');
//===
//echo base64_encode('[{"conditionServiceId":"thelia.condition.match_for_everyone","operators":[],"values":[]}]');
/*
{literal}
INSERT INTO `coupon` (`id`, `code`, `type`, `serialized_effects`, `is_enabled`, `start_date`, `expiration_date`, `max_usage`, `is_cumulative`, `is_removing_postage`, `is_available_on_special_offers`, `is_used`, `serialized_conditions`, `per_customer_usage_count`, `created_at`, `updated_at`, `version`, `version_created_at`, `version_created_by`) VALUES
(1, 'A5FT8B', 'thelia.coupon.type.remove_x_percent', '{"percentage":"7"}', 1, '2017-05-22 00:17:33', '2117-07-22 00:17:33', -1, 1, 0, 1, 0, 'W3siY29uZGl0aW9uU2VydmljZUlkIjoidGhlbGlhLmNvbmRpdGlvbi5tYXRjaF9mb3JfZXZlcnlvbmUiLCJvcGVyYXRvcnMiOltdLCJ2YWx1ZXMiOltdfV0=', 0, '2017-05-22 00:20:28', '2017-05-22 00:21:22', 4, '2017-05-22 00:21:22', NULL);
<br /><br />
INSERT INTO `coupon_customer_for_life` (`id`,`customer_ref`, `coupon_code`) VALUES (NULL, '1210290112001461', 'A5FT8B');
{/literal}
*/
}
mysqli_close($link);
?>