203 lines
8.1 KiB
PHP
203 lines
8.1 KiB
PHP
<?php
|
|
function fxGetSerial($debut_code='MS1') {
|
|
$strTemplate = '9X9XX9X9';
|
|
$intMax = strlen($strTemplate);
|
|
$strSerial = $debut_code;
|
|
|
|
for ($intCtr = 0; $intCtr < $intMax; $intCtr++) {
|
|
switch($strTemplate[$intCtr]) {
|
|
case 'X':
|
|
$strSerial .= chr(rand(65, 90));
|
|
break;
|
|
|
|
case '9':
|
|
$strSerial .= rand(0, 9);
|
|
break;
|
|
|
|
case '-':
|
|
$strSerial .= '-';
|
|
}
|
|
}
|
|
|
|
return $strSerial;
|
|
}
|
|
|
|
// fonction qui vérifie si une aleur d'un champ existe dans une table (JSP)
|
|
// param : table, champ, valeur
|
|
// créé : 2013-02-08
|
|
function fxCheckValue($strTable, $strField, $strValue) {
|
|
global $objDatabase;
|
|
|
|
$sqlSelect = "SELECT COUNT(*) AS nb FROM " . $objDatabase->fxEscape($strTable) . " WHERE " . $objDatabase->fxEscape($strField) . " = '" . $objDatabase->fxEscape($strValue) . "'";
|
|
$nbSelect = $objDatabase->fxGetVar($sqlSelect);
|
|
|
|
if ($nbSelect > 0)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
// fonction qui retourne un numéro de confirmation unique pour les certificats-cadeaux (JSP)
|
|
// créé : 2013-02-08
|
|
|
|
|
|
function fxCreerRabais() {
|
|
global $objDatabase;
|
|
|
|
$strUniqueId = uniqid('', true);
|
|
|
|
for ($intCtr = 1; $intCtr <= $_POST['txt_nb']; $intCtr++) {
|
|
$strCodeRabais = fxGetNoConfimation();
|
|
$strEpreuves = $strProduits = '';
|
|
|
|
if (isset($_POST['epr_id']))
|
|
$strEpreuves = implode(',', $_POST['epr_id']);
|
|
if (isset($_POST['pro_id']))
|
|
$strProduits = implode(',', $_POST['pro_id']);
|
|
|
|
$sqlInsert = "INSERT INTO inscriptions_rabais SET eve_id = " . intval($_POST['sel_evenement']) . ", rab_description_fr = '" . $objDatabase->fxEscape($_POST['txt_description_fr']) . "', rab_description_en = '" . $objDatabase->fxEscape($_POST['txt_description_en']) . "', rab_pourcent = " . intval($_POST['txt_pourcent']) . ", rab_montant = " . floatval($_POST['txt_montant']) . ", rab_priorite = " . floatval($_POST['txt_priorite']) . ", rab_date_limite = '" . $objDatabase->fxEscape($_POST['txt_date_limite']) . "', rab_date_limite_debut = '" . $objDatabase->fxEscape($_POST['txt_date_limite_debut']) . "', rab_heure_limite_fin = '" . $objDatabase->fxEscape($_POST['txt_heure_limite_fin']) . "', rab_heure_limite_debut = '" . $objDatabase->fxEscape($_POST['txt_heure_limite_debut']) . "', rab_code_manuel = 1, rab_code = '" . $strCodeRabais . "', rab_condition = '', rab_qte_limitee = 1, rab_qte = " . intval($_POST['txt_qte']) . ", rab_effacable = 1, rab_actif = 1, rab_ajoute_par = '" . $objDatabase->fxEscape($_POST['txt_ajoute_par']) . "', rab_adresse_ip = '" . $_SERVER['REMOTE_ADDR'] . "', rab_ajout = '" . fxGetDateTime() . "', rab_epreuves = '" . $strEpreuves . "', rab_produits = '" . $strProduits . "', rab_plus_moins_cher = " . intval($_POST['rab_plus_moins_cher']) . ", rab_nb_epr_diff2 = " . intval($_POST['rab_nb_epr_diff2']) . ", rab_key = '" . $strUniqueId . "'";
|
|
$qryInsert = $objDatabase->fxQuery($sqlInsert);
|
|
|
|
//echo $strCodeRabais . '<br />';
|
|
}
|
|
|
|
return $strUniqueId;
|
|
}
|
|
|
|
function fxShowBatchRabais($strNoBatch) {
|
|
global $objDatabase;
|
|
$arrResultat['existant'] = array();
|
|
$arrResultat['non_existant'] = array();
|
|
|
|
if (isset($_POST['btn_push'])) {
|
|
$arrRabais = explode(',', $_POST['rab_id']);
|
|
|
|
foreach ($arrRabais as $rab_id) {
|
|
$arrRetour2[] = fxInsertInfosProd('inscriptions_rabais', 'rab_id', $rab_id, 'DEV');
|
|
}
|
|
}
|
|
|
|
$sqlRabais = "SELECT * FROM inscriptions_rabais WHERE rab_key = '" . $strNoBatch . "'";
|
|
$arrRabais = $objDatabase->fxGetResults($sqlRabais);
|
|
|
|
if ($arrRabais != null) {
|
|
?>
|
|
<h1>Codes rabais :</h1>
|
|
<div class="resume">
|
|
<p><strong>Événement:</strong> <?php echo $arrRabais[1]['eve_id'] . ' - ' . fxShowEvenement($arrRabais[1]['eve_id']); ?></p>
|
|
<?php
|
|
if (trim($arrRabais[1]['rab_date_limite_debut']) != '') {
|
|
?>
|
|
<p><strong>Débutant le:</strong>
|
|
<?php
|
|
echo fxShowDate($arrRabais[1]['rab_date_limite_debut'], 'fr');
|
|
|
|
if (trim($arrRabais[1]['rab_heure_limite_debut']) != '') {
|
|
echo ' @ ' . fxShowTime($arrRabais[1]['rab_heure_limite_debut'], 'fr');
|
|
}
|
|
?>
|
|
</p>
|
|
<?php
|
|
}
|
|
?>
|
|
<p><strong>Expirant le:</strong>
|
|
<?php
|
|
echo fxShowDate($arrRabais[1]['rab_date_limite'], 'fr');
|
|
|
|
if (trim($arrRabais[1]['rab_heure_limite_fin']) != '') {
|
|
echo ' @ ' . fxShowTime($arrRabais[1]['rab_heure_limite_fin'], 'fr');
|
|
}
|
|
?>
|
|
</p>
|
|
<p><strong>Nombre d'utilisation:</strong> <?php echo $arrRabais[1]['rab_qte']; ?></p>
|
|
<p><strong>Valeur:</strong> <?php if ($arrRabais[1]['rab_pourcent'] > 0) { echo $arrRabais[1]['rab_pourcent'] . '%'; } else { echo $arrRabais[1]['rab_montant'] . ' $'; } ?></p>
|
|
</div>
|
|
<div class="codes">
|
|
<?php
|
|
for ($intCtr = 1; $intCtr <= count($arrRabais); $intCtr++) {
|
|
$arrStatut = fxGetStatutProd('inscriptions_rabais', 'rab_id', $arrRabais[$intCtr]['rab_id']);
|
|
|
|
if ($arrStatut['statut'] == 'existant') {
|
|
$arrResultat['existant'][] = $arrRabais[$intCtr]['rab_id'];
|
|
$strClass = 'color: #008000;';
|
|
} else {
|
|
$arrResultat['non_existant'][] = $arrRabais[$intCtr]['rab_id'];
|
|
$strClass = 'color: red;';
|
|
}
|
|
|
|
echo '<span style="' . $strClass . '">' . $arrRabais[$intCtr]['rab_code'] . '</span></br>';
|
|
}
|
|
?>
|
|
</div>
|
|
<br>
|
|
<h2>Bilan:</h2>
|
|
<span style="color: red;"><?php echo count($arrResultat['non_existant']); ?> non en PROD</span>
|
|
<br>
|
|
<span style="color: #008000;"><?php echo count($arrResultat['existant']); ?> en PROD</span>
|
|
<br>
|
|
<?php
|
|
if (count($arrResultat['non_existant']) > 0) {
|
|
?>
|
|
<form action="../maj_rabais.php?batch=<?php echo $_GET['batch']; ?>" method="post" id="frm_rabais" name="frm_rabais">
|
|
<input type="hidden" id="rab_id" name="rab_id" value="<?php echo implode(',', $arrResultat['non_existant']); ?>">
|
|
<button type="submit" id="btn_push" name="btn_push">Pousser en PROD</button>
|
|
</form>
|
|
<?php
|
|
}
|
|
} else {
|
|
?>
|
|
<h1>Rabais introuvables!</h1>
|
|
<?php
|
|
}
|
|
}
|
|
|
|
function fxShowEvenement($intEvenement) {
|
|
global $objDatabase;
|
|
|
|
$sqlEvenement = "SELECT eve_nom_fr FROM inscriptions_evenements WHERE eve_id = " . intval($intEvenement);
|
|
$strEvenement = $objDatabase->fxGetVar($sqlEvenement);
|
|
|
|
echo $strEvenement;
|
|
}
|
|
|
|
// récupérer les événements
|
|
function fxGetEvenementsRabais() {
|
|
global $objDatabase;
|
|
|
|
$sqlEvenements = "SELECT eve_id, eve_nom_fr FROM inscriptions_evenements WHERE eve_actif = 1 AND eve_date_fin >= '" . fxGetDate() . "' ORDER BY eve_nom_fr";
|
|
$tabEvenements = $objDatabase->fxGetResults($sqlEvenements);
|
|
|
|
return $tabEvenements;
|
|
}
|
|
|
|
// récupérer les épreuves
|
|
function fxGetEpreuvesRabais($intEvenement) {
|
|
global $objDatabase;
|
|
|
|
$sqlEpreuves = "SELECT epr_id, epr_type_fr, epr_nom_fr FROM inscriptions_epreuves WHERE epr_actif = 1 AND eve_id = " . intval($intEvenement) . " ORDER BY epr_tri";
|
|
$tabEpreuves = $objDatabase->fxGetResults($sqlEpreuves);
|
|
|
|
return $tabEpreuves;
|
|
}
|
|
|
|
// récupérer les produits
|
|
function fxGetProduitsRabais($intEvenement) {
|
|
global $objDatabase;
|
|
|
|
$sqlProduits = "SELECT pro_id, pro_nom_fr FROM inscriptions_produits_new WHERE pro_actif = 1 AND eve_id = " . intval($intEvenement) . " ORDER BY pro_nom_fr";
|
|
$tabProduits = $objDatabase->fxGetResults($sqlProduits);
|
|
|
|
return $tabProduits;
|
|
}
|
|
function fxGetNoConfimation($debut_code="ms")
|
|
{
|
|
|
|
do {
|
|
$strSerial = fxGetSerial($debut_code);
|
|
|
|
} while (fxCheckValue('inscriptions_rabais', 'rab_code', $strSerial) != true);
|
|
|
|
return $strSerial;
|
|
}
|
|
|