Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_name ('Tacos');
- session_start();
- require_once("../../config/configuration.php");
- require_once("../../config/text.php");
- require_once("../../utils/fonctions.php");
- require_once("../../utils/JsonRequest.php");
- // Verification que c'est bien une requête ajax
- if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')
- redirectIndex();
- ob_start();
- if(isset($_POST['day']) && isset($_POST['court']) && isset($_POST['place']) && isset($_POST['promo']) && isset($_POST['licence']) && isset($_POST['promoSolidaire']) && isset($_POST['bigMatch'])){
- $day = htmlspecialchars($_POST['day']);
- $court = htmlspecialchars($_POST['court']);
- $place = htmlspecialchars($_POST['place']);
- $promo = htmlspecialchars($_POST['promo']);
- $licence = htmlspecialchars($_POST['licence']);
- $promoSolidaire = htmlspecialchars($_POST['promoSolidaire']);
- $bigMatch = htmlspecialchars($_POST['bigMatch']);
- ?>
- <script>
- timerInterval = 0;
- Swal.fire({
- title: 'Redirection vers votre banque',
- html: 'Veuillez procéder au paiement',
- timer: 3000,
- timerProgressBar: true,
- onBeforeOpen: () => {
- Swal.showLoading()
- },
- onClose: () => {
- clearInterval(timerInterval)
- if(Swal.getTimerLeft() > 0){
- Swal.fire(
- 'Opération annulée',
- 'La paiement a été abandonné en cours',
- 'error'
- )
- }
- }
- }).then((result) => {
- if (
- result.dismiss === Swal.DismissReason.timer
- ) {
- $.ajax({
- url: "../../models/buy_billet.php",
- method: "POST",
- data: {
- 'day': <?= $day ?>,
- 'court': <?= $court ?>,
- 'place': '<?= $place ?>',
- 'promo': '<?= $promo ?>',
- 'licence': '<?= $licence ?>',
- 'promoSolidaire': '<?= $promo ?>',
- 'bigMatch': <?= $bigMatch ?>
- },
- dataType: "text",
- success: function (data) {
- console.log(data);
- }
- });
- /* if(data == 'error'){
- Swal.fire(
- 'Opération échoué',
- 'Il n\'y a pour le moment plus de billet de ce type',
- 'error'
- );
- }else{
- Swal.fire(
- 'Opération réussie',
- 'Votre billet a été réservé avec succès !',
- 'success'
- );
- } */
- <?php
- /* if($bigMatch == 0){ ?>
- Swal.fire(
- 'Opération réussie',
- 'Votre billet a été réservé avec succès !',
- 'success'
- );
- <?php } */
- // Pour avoir les dates du tournois
- $valid = true;
- $dates = getDefaultDate();
- $response = JsonRequest::getRequest(GET_ALL_DATES_TOURNOI);
- if($response->getCode() == 200)
- $dates = (array) json_decode($response->getJsonResponse());
- if(($jour = getAllDateWithDay($day, $dates)) != null){
- $response = JsonRequest::getRequest(GET_CAN_CREATE_BILLET, ['jour' => $jour, 'idCourt' => $court, 'place' => $place, 'licenceCode' => $licence,'promoCode' => $promo, 'promoSolidaireCode' => $promoSolidaire, 'bigMatch' => $bigMatch]);
- if($response->getCode() == 200){
- $preAchat = json_decode($response->getJsonResponse(), true);
- print_r($preAchat);
- $prix = $preAchat['prixAvant'];
- $reduc = 0;
- // TODO Test avec licence
- if($preAchat['licenceNum'] != ""){
- $response = JsonRequest::getRequest(GET_CONFIGURATION);
- if($response->getCode() == 200){
- $reduc = json_decode($response->getJsonResponse(), true)['reducLicencies'];
- }else{
- $valid = false;
- }
- }else if($preAchat['promoId'] > 0){
- $response = JsonRequest::getRequest(GET_GET_ONE_PROMO, ['id' => $preAchat['promoId']]);
- if($response->getCode() == 200){
- $reduc = json_decode($response->getJsonResponse(), true)['pourcentageReduc'];
- }else{
- $valid = false;
- }
- }
- if(isset($_SESSION['user']))
- $user = $_SESSION['user'];
- else
- $valid = false;
- if($valid){
- $prix = $prix - $prix*($reduc/100);
- // Avoir le TypeBillet
- $response = JsonRequest::getRequest(GET_ONE_TYPEBILLET_WITH_PARAMS, ['bigMatch' => $bigMatch, 'idCourt' => $court, 'jour' => $jour, 'place' =>$place]);
- if($response->getCode() == 200){
- $typeBillet = json_decode($response->getJsonResponse(), true);
- print_r($typeBillet);
- // Créer le Billet
- $response = JsonRequest::postRequest(POST_CREATE_BILLET, ['idTypeBillet' => $typeBillet['idTypeBillet'], 'nbPlace' => ($typeBillet['quantiteTotale'] - $typeBillet['quantiteVendue'])]);
- if($response->getCode() == 201){
- $billet = json_decode($response->getJsonResponse(), true);
- print($billet.'<br>');
- // Créer l'Achat
- $response = JsonRequest::postRequest(POST_CREATE_ACHAT, ['idBillet' => intval($billet), 'mailAcheteur' => $user, 'prixAvantPromo' => $preAchat['prixAvant'], 'prixAchat' => $prix, 'promoId' => $preAchat['promoId'], 'licenceNum' => $preAchat['licenceNum']]);
- if($response->getCode() == 201){
- if(intval($preAchat['promoId']) > 0){
- $response = JsonRequest::postRequest(POST_ADD_USE_PROMO, ['promoId' => 9]);
- if($response != 201){
- $valid = false;
- $response = JsonRequest::postRequest(POST_DELETE_ACHAT, ['idBillet' => intval($billet)]);
- }
- }
- }else{
- $response = JsonRequest::postRequest(POST_DELETE_BILLET, ['idBillet' => intval($billet)]);
- $valid = false;
- }
- // VERIFIER QUE LES CODES PROMOS SONT BIEN ADD +1
- // body.get("mailAcheteur"), Integer.parseInt(body.get("prixAvantPromo")), Integer.parseInt(body.get("prixAchat")), Integer.parseInt(body.get("promoId")), body.get("licenceNum")
- // get potencial billet OK
- // canBuyBillet OK
- // récupérer la promotion licence si licence OK
- // créer le billet (penser à son id) OK
- // créer l'achat (penser à idBillet, mailAcheteur, timestamp, prixApres)
- // mettre à jour le code promo
- }else{
- $valid = false;
- }
- }else{
- $valid = false;
- }
- }
- }else{
- $valid = false;
- } ?>
- <?php }
- if(!$valid){
- print("false");
- }
- /* var day = ;
- var court = ;
- var place = ;
- var pomoSolidaire = ;
- var promo = ;
- var licence = ;
- var bigMatch = ;
- var idUser = ;
- numerote */ ?>
- }
- })
- </script>
- <?php }
- echo ob_get_clean(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement