108 lines
6.2 KiB
PHP
108 lines
6.2 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: jesse94
|
|
* Date: 14-07-01
|
|
* Time: 10:05
|
|
*/
|
|
|
|
// fonction qui récupère les options de paiement diisponibles pour un événement (JSP)
|
|
// param : id de l'événement, no de panier (pour éliminer les options ajoutées au panier)
|
|
// créé : 2014-06-30
|
|
function fxGetOptions($intEvenement = 0, $strNoPanier = '') {
|
|
global $objDatabase;
|
|
|
|
if ($intEvenement != 0) {
|
|
|
|
// info épreuves
|
|
$sqlEpreuves = "SELECT epr_id FROM inscriptions_panier_epreuves_commandees WHERE no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "' ORDER BY epr_id";
|
|
$tabEpreuves = $objDatabase->fxGetResults($sqlEpreuves);
|
|
|
|
if ($tabEpreuves != null) {
|
|
$strEpreuves = implode(',', array_map(function($tab) { return $tab['epr_id']; }, $tabEpreuves));
|
|
$strWhere = " AND opt_id IN(SELECT o.opt_id FROM inscriptions_options o, inscriptions_rabais r WHERE o.rab_id = r.rab_id AND r.rab_epreuves LIKE '%" . $strEpreuves . "%')";
|
|
} else
|
|
$strWhere = " AND opt_id IN(SELECT o.opt_id FROM inscriptions_options o, inscriptions_rabais r WHERE o.rab_id = r.rab_id AND (r.rab_epreuves = '' OR r.rab_epreuves IS NULL))";
|
|
|
|
$sqlOptions = "SELECT * FROM inscriptions_options WHERE opt_date_limite_offert >= '" . fxGetDate() . "' AND eve_id = " . intval($intEvenement) . " AND opt_id NOT IN(SELECT opt_id FROM inscriptions_panier_options WHERE no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "')" . $strWhere;
|
|
} else
|
|
$sqlOptions = "SELECT * FROM inscriptions_panier_options WHERE no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "'";
|
|
|
|
$tabOptions = $objDatabase->fxGetResults($sqlOptions);
|
|
|
|
return $tabOptions;
|
|
}
|
|
|
|
// fonction qui ajoute ou efface l'option et le rabais au panier
|
|
// param : action (add/del), no de panier, infos de l'événement, données post, langue d'affichage
|
|
// créé : 2014-07-01
|
|
function fxSetOptions($strAction, $strNoPanier, $tabEvenement, $tabData, $strLangue) {
|
|
global $objDatabase;
|
|
|
|
switch ($strAction) {
|
|
case 'add':
|
|
// vérifier si l'option est toujours valide
|
|
$sqlOption = "SELECT * FROM inscriptions_options WHERE opt_date_limite_offert >= '" . fxGetDate() . "' AND opt_actif = 1 AND opt_id = " . intval($tabData['opt_id']);
|
|
$tabOption = $objDatabase->fxGetRow($sqlOption);
|
|
|
|
if ($tabOption != null) { // ajouter l'option au panier
|
|
if ($tabOption['rab_id'] != 0) { // ajouter le rabais de l'option, s'il y a lieu
|
|
$intPanierRabais = fxCheckRabais($tabOption['rab_id']);
|
|
|
|
$sqlInsert = "INSERT INTO inscriptions_panier_rabais_acheteurs SET pra_id = " . intval($intPanierRabais) . ", no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "'";
|
|
$qryInsert = $objDatabase->fxQuery($sqlInsert);
|
|
|
|
// calculer le montant dans panier_epreuves_commandees
|
|
fxMajRabais($strNoPanier);
|
|
}
|
|
else
|
|
$intPanierRabais = 0;
|
|
|
|
$sqlInsert = "INSERT INTO inscriptions_panier_options SET opt_id = " . intval($tabData['opt_id']) . ", eve_id = " . intval($tabEvenement['general']['eve_id']) . ", opt_nom_fr = '" . $objDatabase->fxEscape($tabOption['opt_nom_fr']) . "', opt_nom_en = '" . $objDatabase->fxEscape($tabOption['opt_nom_en']) . "', opt_description_fr = '" . $objDatabase->fxEscape($tabOption['opt_description_fr']) . "', opt_description_en = '" . $objDatabase->fxEscape($tabOption['opt_description_en']) . "', opt_date_limite_paiement = '" . $objDatabase->fxEscape($tabOption['opt_date_limite_paiement']) . "', opt_prix = " . floatval($tabOption['opt_prix']) . ", opt_taxable = " . intval($tabOption['opt_taxable']) . ", rab_id = " . intval($tabOption['rab_id']) . ", pra_id = " . intval($intPanierRabais) . ", pop_maj = '" . fxGetDateTime() . "', no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "'";
|
|
$qryInsert = $objDatabase->fxQuery($sqlInsert);
|
|
|
|
// message de confirmation
|
|
if ($strLangue == 'fr')
|
|
$_SESSION['msg'] = 'p128';
|
|
else
|
|
$_SESSION['msg'] = 'p528';
|
|
}
|
|
else { // message d'erreur si option non valide
|
|
if ($strLangue == 'fr')
|
|
$_SESSION['msg'] = 'e127';
|
|
else
|
|
$_SESSION['msg'] = 'e527';
|
|
}
|
|
break;
|
|
|
|
case 'del':
|
|
// vérifier le id du rabais de l'option
|
|
$sqlOption = "SELECT pra_id FROM inscriptions_panier_options WHERE no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "' AND pop_id = " . intval($tabData['pop_id']);
|
|
$intPanierRabais = $objDatabase->fxGetVar($sqlOption);
|
|
|
|
$sqlDelete = "DELETE FROM inscriptions_panier_options WHERE no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "' AND pop_id = " . intval($tabData['pop_id']);
|
|
$qryDelete = $objDatabase->fxQuery($sqlDelete);
|
|
|
|
if ($intPanierRabais != 0) {
|
|
// effacer le montant du rabais
|
|
$sqlUpdate = "UPDATE inscriptions_panier_epreuves_commandees SET pra_id = 0, rab_priorite = 0, rab_montant = 0 WHERE no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "' AND pra_id = " . intval($intPanierRabais);
|
|
$qryUpdate = $objDatabase->fxQuery($sqlUpdate);
|
|
|
|
$sqlUpdate = "UPDATE inscriptions_panier_produits SET pra_id = 0, rab_priorite = 0, rab_montant = 0 WHERE no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "' AND pra_id = " . intval($intPanierRabais);
|
|
$qryUpdate = $objDatabase->fxQuery($sqlUpdate);
|
|
|
|
// effacer le rabais
|
|
$sqlDelete = "DELETE FROM inscriptions_panier_rabais_acheteurs WHERE no_panier = '" . $objDatabase->fxEscape($strNoPanier) . "' AND pra_id = " . intval($intPanierRabais);
|
|
$qryDelete = $objDatabase->fxQuery($sqlDelete);
|
|
}
|
|
}
|
|
|
|
// rediriger vers le panier
|
|
if ($strLangue == 'fr')
|
|
$strPage = 'panier';
|
|
else
|
|
$strPage = 'cart';
|
|
|
|
header("Location: " . $GLOBALS['vDomaine'] . '/' . $strPage . '/checkout/' . $tabEvenement['general']['eve_label_url']);
|
|
exit;
|
|
} |