Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. // Recuperation des variables
  5. $date = $_POST['order_time'];
  6. $payment_method = $_POST['payment_method'];
  7.  
  8. echo $details = $_POST['panel'];
  9. $details = json_decode($details, true);
  10. $id = $details['id_restau'];
  11. $contenu_cmd = $details['order'];
  12. $total_price1 = substr($_POST['total'],0,5);
  13. $total_price = floatval(str_replace(',', '.', $total_price1));
  14. $order = $_POST['order_type'];
  15. if(isset($_POST['adresse'])) {
  16. $numero = $_POST['numero'];
  17. $adresse = $_POST['adresse'];
  18. $ville = $_POST['ville'];
  19. $codepostal = $_POST['codepostal'];
  20. $codeentre = $_POST['codeentre'];
  21. $interphone = $_POST['interphone'];
  22. $batiment = $_POST['batiment'];
  23. $escalier = $_POST['escalier'];
  24. $etage = $_POST['etage'];
  25. $numappartement = $_POST['numappartement'];
  26. $societe = $_POST['societe'];
  27. $infossupp = $_POST['infossupp'];
  28. }
  29.  
  30. // Conversion en JSON et envoi
  31. if(isset($_SESSION['user'])) {
  32.  
  33. // Type de commande
  34. switch($order) {
  35. case 'available_on_the_spot' : $order_type = 1; break;
  36. case 'available_takeaway' : $order_type = 2; break;
  37. case 'available_delivery': $order_type = 3; break;
  38. }
  39.  
  40. // Creation du tableau de la commande
  41. $commande = array( "idApp"=> $id,
  42. "idCard"=> "",
  43. "order_type"=> $order_type,
  44. "order_ready" => $date,
  45. "total_price"=> $total_price,
  46. "guid"=> "web_".$_SESSION['user']['infos_user']['email'],
  47. "payment_method"=> $payment_method,
  48. "order" => $contenu_cmd,
  49. "device_type" => "web" );
  50.  
  51. if($order_type == 3) {
  52. $commande["delivery_data"]["customer_name"] = $_SESSION['user']['infos_user']['first_name']." ".$_SESSION['user']['infos_user']['last_name'];
  53. $commande["delivery_data"]["customer_phone"] = $_SESSION['user']['infos_user']['telephone'];
  54. $commande["delivery_data"]["customer_address"] = array(
  55. "entryCode"=> $codeentre,
  56. "building"=> $batiment,
  57. "level"=> $etage,
  58. "stairs" => $escalier,
  59. "extra"=> $infossupp,
  60. "company"=> $societe,
  61. "zipcode"=> $codepostal,
  62. "flatNumber" => $numappartement,
  63. "interphone" => $interphone,
  64. "city" => $ville,
  65. "main" => $numero.", ".$adresse);
  66. }
  67.  
  68. // Requete
  69. include('../requires/url.dist.php');
  70. $ACCESS_TOKEN = $_SESSION['user']['infos_connexion']['access_token'];
  71. $REFRESH_TOKEN = $_SESSION['user']['infos_connexion']['refresh_token'];
  72. $url = $urlWebService.$urlAddCommande.$ACCESS_TOKEN ;
  73. echo $data = json_encode($commande);
  74. $options = array(
  75. 'http' => array(
  76. 'header' => "Content-type: application/json",
  77. 'method' => 'POST',
  78. 'content' => $data,
  79. ),
  80. );
  81. $context = stream_context_create($options);
  82. $result = file_get_contents($url, false, $context);
  83. $result = json_decode($result, true);
  84.  
  85. // Traitement de la reponse
  86. if($result['error'] == 'OK') {
  87. echo json_encode($result);
  88. //initialiser le panier
  89. // $tab_php = $_SESSION['infos_restaurant_php'];
  90. // $_SESSION['panier'][$id] = array();
  91. // $_SESSION['panier'][$id]['items'] = array();
  92. // $_SESSION['panier'][$id]['menus'] = array();
  93. // $_SESSION['panier'][$id]['total_price'] = 0;
  94. } else {
  95. if($result['error'] == 'invalid_grant' && $result['error_description'] == "The access token provided has expired."){
  96. $infos_user_cnx = refreshToken($REFRESH_TOKEN);
  97. if($infos_user_cnx != false){
  98. $_SESSION['user']['infos_connexion'] = $infos_user_cnx;
  99. $url = $urlWebService.$urlAddCommande.$_SESSION['user']['infos_connexion']['access_token'];
  100. $context = stream_context_create($options);
  101. $result = file_get_contents($url, false, $context);
  102. $result = json_decode($result, true);
  103. if($result['error']== 'OK'){
  104. echo 'OK';
  105. $idOrder = $result['data']->idOrder;
  106. $_SESSION['idOrder'] = $idOrder;
  107. //initialiser le panier
  108. // $tab_php = $_SESSION['infos_restaurant_php'];
  109. // $_SESSION['panier'][$id] = array();
  110. // $_SESSION['panier'][$id]['items'] = array();
  111. // $_SESSION['panier'][$id]['menus'] = array();
  112. // $_SESSION['panier'][$id]['total_price'] = 0;
  113. }
  114. }
  115. echo $result['error'];
  116. } else {
  117. echo $result['error']; // Switch dans le JS
  118. }
  119. }
  120. } else {
  121. echo '<div class="alert alert-warning text-center"><p><i class="fa fa-exclamation-triangle fa-2x"></i></p><p>Connectez-vous avant de commander !</p></div>';
  122. }
  123.  
  124.  
  125. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement