Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. <?php
  2. session_name ('Tacos');
  3. session_start();
  4. require_once("../../config/configuration.php");
  5. require_once("../../config/text.php");
  6.  
  7. require_once("../../utils/fonctions.php");
  8. require_once("../../utils/JsonRequest.php");
  9.  
  10. // Verification que c'est bien une requête ajax
  11. if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')
  12. redirectIndex();
  13.  
  14. ob_start();
  15.  
  16. if(isset($_POST['day']) && isset($_POST['court']) && isset($_POST['place']) && isset($_POST['promo']) && isset($_POST['licence']) && isset($_POST['promoSolidaire']) && isset($_POST['bigMatch'])){
  17. $day = htmlspecialchars($_POST['day']);
  18. $court = htmlspecialchars($_POST['court']);
  19. $place = htmlspecialchars($_POST['place']);
  20. $promo = htmlspecialchars($_POST['promo']);
  21. $licence = htmlspecialchars($_POST['licence']);
  22. $promoSolidaire = htmlspecialchars($_POST['promoSolidaire']);
  23. $bigMatch = htmlspecialchars($_POST['bigMatch']);
  24. ?>
  25.  
  26.  
  27. <script>
  28. timerInterval = 0;
  29. Swal.fire({
  30. title: 'Redirection vers votre banque',
  31. html: 'Veuillez procéder au paiement',
  32. timer: 3000,
  33. timerProgressBar: true,
  34. onBeforeOpen: () => {
  35. Swal.showLoading()
  36. },
  37. onClose: () => {
  38. clearInterval(timerInterval)
  39. if(Swal.getTimerLeft() > 0){
  40. Swal.fire(
  41. 'Opération annulée',
  42. 'La paiement a été abandonné en cours',
  43. 'error'
  44. )
  45. }
  46. }
  47. }).then((result) => {
  48. if (
  49. result.dismiss === Swal.DismissReason.timer
  50. ) {
  51. $.ajax({
  52. url: "../../models/buy_billet.php",
  53. method: "POST",
  54. data: {
  55. 'day': <?= $day ?>,
  56. 'court': <?= $court ?>,
  57. 'place': '<?= $place ?>',
  58. 'promo': '<?= $promo ?>',
  59. 'licence': '<?= $licence ?>',
  60. 'promoSolidaire': '<?= $promo ?>',
  61. 'bigMatch': <?= $bigMatch ?>
  62. },
  63. dataType: "text",
  64. success: function (data) {
  65. console.log(data);
  66. }
  67. });
  68. /* if(data == 'error'){
  69. Swal.fire(
  70. 'Opération échoué',
  71. 'Il n\'y a pour le moment plus de billet de ce type',
  72. 'error'
  73. );
  74. }else{
  75. Swal.fire(
  76. 'Opération réussie',
  77. 'Votre billet a été réservé avec succès !',
  78. 'success'
  79. );
  80. } */
  81. <?php
  82. /* if($bigMatch == 0){ ?>
  83. Swal.fire(
  84. 'Opération réussie',
  85. 'Votre billet a été réservé avec succès !',
  86. 'success'
  87. );
  88. <?php } */
  89.  
  90. // Pour avoir les dates du tournois
  91. $valid = true;
  92.  
  93. $dates = getDefaultDate();
  94. $response = JsonRequest::getRequest(GET_ALL_DATES_TOURNOI);
  95. if($response->getCode() == 200)
  96. $dates = (array) json_decode($response->getJsonResponse());
  97.  
  98. if(($jour = getAllDateWithDay($day, $dates)) != null){
  99. $response = JsonRequest::getRequest(GET_CAN_CREATE_BILLET, ['jour' => $jour, 'idCourt' => $court, 'place' => $place, 'licenceCode' => $licence,'promoCode' => $promo, 'promoSolidaireCode' => $promoSolidaire, 'bigMatch' => $bigMatch]);
  100. if($response->getCode() == 200){
  101. $preAchat = json_decode($response->getJsonResponse(), true);
  102. print_r($preAchat);
  103.  
  104. $prix = $preAchat['prixAvant'];
  105. $reduc = 0;
  106.  
  107. // TODO Test avec licence
  108. if($preAchat['licenceNum'] != ""){
  109. $response = JsonRequest::getRequest(GET_CONFIGURATION);
  110. if($response->getCode() == 200){
  111. $reduc = json_decode($response->getJsonResponse(), true)['reducLicencies'];
  112. }else{
  113. $valid = false;
  114. }
  115. }else if($preAchat['promoId'] > 0){
  116. $response = JsonRequest::getRequest(GET_GET_ONE_PROMO, ['id' => $preAchat['promoId']]);
  117. if($response->getCode() == 200){
  118. $reduc = json_decode($response->getJsonResponse(), true)['pourcentageReduc'];
  119. }else{
  120. $valid = false;
  121. }
  122. }
  123.  
  124. if(isset($_SESSION['user']))
  125. $user = $_SESSION['user'];
  126. else
  127. $valid = false;
  128.  
  129. if($valid){
  130. $prix = $prix - $prix*($reduc/100);
  131. // Avoir le TypeBillet
  132. $response = JsonRequest::getRequest(GET_ONE_TYPEBILLET_WITH_PARAMS, ['bigMatch' => $bigMatch, 'idCourt' => $court, 'jour' => $jour, 'place' =>$place]);
  133. if($response->getCode() == 200){
  134. $typeBillet = json_decode($response->getJsonResponse(), true);
  135. print_r($typeBillet);
  136.  
  137. // Créer le Billet
  138. $response = JsonRequest::postRequest(POST_CREATE_BILLET, ['idTypeBillet' => $typeBillet['idTypeBillet'], 'nbPlace' => ($typeBillet['quantiteTotale'] - $typeBillet['quantiteVendue'])]);
  139. if($response->getCode() == 201){
  140. $billet = json_decode($response->getJsonResponse(), true);
  141. print($billet.'<br>');
  142.  
  143. // Créer l'Achat
  144. $response = JsonRequest::postRequest(POST_CREATE_ACHAT, ['idBillet' => intval($billet), 'mailAcheteur' => $user, 'prixAvantPromo' => $preAchat['prixAvant'], 'prixAchat' => $prix, 'promoId' => $preAchat['promoId'], 'licenceNum' => $preAchat['licenceNum']]);
  145. if($response->getCode() == 201){
  146. if(intval($preAchat['promoId']) > 0){
  147. $response = JsonRequest::postRequest(POST_ADD_USE_PROMO, ['promoId' => 9]);
  148. if($response != 201){
  149. $valid = false;
  150. $response = JsonRequest::postRequest(POST_DELETE_ACHAT, ['idBillet' => intval($billet)]);
  151. }
  152. }
  153. }else{
  154. $response = JsonRequest::postRequest(POST_DELETE_BILLET, ['idBillet' => intval($billet)]);
  155. $valid = false;
  156. }
  157.  
  158. // VERIFIER QUE LES CODES PROMOS SONT BIEN ADD +1
  159.  
  160. // body.get("mailAcheteur"), Integer.parseInt(body.get("prixAvantPromo")), Integer.parseInt(body.get("prixAchat")), Integer.parseInt(body.get("promoId")), body.get("licenceNum")
  161.  
  162. // get potencial billet OK
  163. // canBuyBillet OK
  164. // récupérer la promotion licence si licence OK
  165. // créer le billet (penser à son id) OK
  166. // créer l'achat (penser à idBillet, mailAcheteur, timestamp, prixApres)
  167. // mettre à jour le code promo
  168. }else{
  169. $valid = false;
  170. }
  171. }else{
  172. $valid = false;
  173. }
  174. }
  175. }else{
  176. $valid = false;
  177. } ?>
  178. <?php }
  179.  
  180. if(!$valid){
  181. print("false");
  182. }
  183.  
  184. /* var day = ;
  185. var court = ;
  186. var place = ;
  187. var pomoSolidaire = ;
  188. var promo = ;
  189. var licence = ;
  190. var bigMatch = ;
  191. var idUser = ;
  192. numerote */ ?>
  193. }
  194. })
  195. </script>
  196. <?php }
  197.  
  198. echo ob_get_clean(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement