Advertisement
Guest User

Untitled

a guest
Nov 8th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. <?php
  2.  
  3. //for error display
  4. ini_set('display_errors', 1);
  5. ini_set('display_startup_errors', 1);
  6. error_reporting(E_ALL);
  7.  
  8.  
  9.  
  10. header('Access-Control-Allow-Origin: *');
  11. header('Content-Type: text/html; charset=utf-8');
  12.  
  13.  
  14.  
  15.  
  16. if (isset($_GET['InvoiceNo']) && isset($_GET['OrderNo']) && isset($_GET['InvoiceStatus']) )
  17. {
  18.  
  19. Update($_GET['InvoiceNo'],
  20. $_GET['OrderNo'],
  21. $_GET['InvoiceStatus']);
  22.  
  23. }
  24.  
  25. function Update($invoice_number,$id,$current_state)
  26.  
  27. {
  28.  
  29.  
  30. $servername = "localhost";
  31. $username = "xxx";
  32. $password = "xxx";
  33. $dbname = "xxxx";
  34.  
  35.  
  36. // Connecting, selecting database
  37. $conn = new mysqli($servername, $username, $password, $dbname);
  38. //mysql_set_charset('utf8', $conn);
  39. if ($conn->connect_error) {
  40. die("Connection failed: " . $conn->connect_error);
  41. }
  42.  
  43.  
  44.  
  45. $request = 'http://www.xxx.xxx/InvoiceUpdate/InvoiceUpdate.php';
  46.  
  47. //?InvoiceNo='.$_GET['InvoiceNo'].'&OrderNo='.$_GET['OrderNo'].'&InvoiceStatus='.$_GET['InvoiceStatus'];
  48.  
  49. $login = 'xxxx';
  50. $password = 'xxxx';
  51.  
  52. $ch = curl_init($request);
  53. curl_setopt($ch, CURLOPT_URL,$request);
  54. $parameters = array('InvoiceNo' => $_GET['InvoiceNo'], 'OrderNo' => $_GET['OrderNo'],'InvoiceStatus' => $_GET['InvoiceStatus']);
  55. $url = $request . '?' . http_build_query($parameters);
  56. curl_setopt($ch, CURLOPT_URL, $url);
  57. curl_setopt($ch, CURLOPT_HEADER, true);
  58. curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
  59. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  60. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  61. curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
  62. $result = curl_exec($ch);
  63.  
  64.  
  65. // decode
  66. $output =json_decode($result);
  67. echo $output;
  68. curl_close($ch);
  69.  
  70.  
  71.  
  72. //here the change of current state if there any change in the invoice state.
  73.  
  74. switch ($current_state) {
  75.  
  76. case 0:
  77.  
  78. $sql = "UPDATE ps_orders SET current_state=28 WHERE invoice_number = $invoice_number AND id_order =$id";
  79. echo "Invoice status updated successfully"; break;
  80.  
  81. case 1:
  82.  
  83. $sql = "UPDATE ps_orders SET current_state=25 WHERE invoice_number = $invoice_number AND id_order =$id";
  84. echo "Invoice status updated successfully";
  85. break;
  86. case 5:
  87.  
  88. $sql = "UPDATE ps_orders SET current_state=6 WHERE invoice_number = $invoice_number AND id_order =$id";
  89. echo "Invoice status updated successfully";
  90.  
  91. break;
  92.  
  93. }
  94.  
  95. $conn->query($sql);
  96.  
  97.  
  98. // Closing connection
  99. mysqli_close($conn);
  100.  
  101.  
  102.  
  103.  
  104.  
  105. }
  106.  
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement