Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //for error display
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- header('Access-Control-Allow-Origin: *');
- header('Content-Type: text/html; charset=utf-8');
- if (isset($_GET['InvoiceNo']) && isset($_GET['OrderNo']) && isset($_GET['InvoiceStatus']) )
- {
- Update($_GET['InvoiceNo'],
- $_GET['OrderNo'],
- $_GET['InvoiceStatus']);
- }
- function Update($invoice_number,$id,$current_state)
- {
- $servername = "localhost";
- $username = "xxx";
- $password = "xxx";
- $dbname = "xxxx";
- // Connecting, selecting database
- $conn = new mysqli($servername, $username, $password, $dbname);
- //mysql_set_charset('utf8', $conn);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $request = 'http://www.xxx.xxx/InvoiceUpdate/InvoiceUpdate.php';
- //?InvoiceNo='.$_GET['InvoiceNo'].'&OrderNo='.$_GET['OrderNo'].'&InvoiceStatus='.$_GET['InvoiceStatus'];
- $login = 'xxxx';
- $password = 'xxxx';
- $ch = curl_init($request);
- curl_setopt($ch, CURLOPT_URL,$request);
- $parameters = array('InvoiceNo' => $_GET['InvoiceNo'], 'OrderNo' => $_GET['OrderNo'],'InvoiceStatus' => $_GET['InvoiceStatus']);
- $url = $request . '?' . http_build_query($parameters);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
- $result = curl_exec($ch);
- // decode
- $output =json_decode($result);
- echo $output;
- curl_close($ch);
- //here the change of current state if there any change in the invoice state.
- switch ($current_state) {
- case 0:
- $sql = "UPDATE ps_orders SET current_state=28 WHERE invoice_number = $invoice_number AND id_order =$id";
- echo "Invoice status updated successfully"; break;
- case 1:
- $sql = "UPDATE ps_orders SET current_state=25 WHERE invoice_number = $invoice_number AND id_order =$id";
- echo "Invoice status updated successfully";
- break;
- case 5:
- $sql = "UPDATE ps_orders SET current_state=6 WHERE invoice_number = $invoice_number AND id_order =$id";
- echo "Invoice status updated successfully";
- break;
- }
- $conn->query($sql);
- // Closing connection
- mysqli_close($conn);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement