<?php
        require_once("../../config/connect.php");

	$timestamp = time();
	$datum = date("d.m.Y - H:i", $timestamp);

	echo "____________________ 658 Orders _____________________<br>";

	echo "____________________ Start Zeit _____________________<br>";
	echo $datum;
	echo "____________________ ENDE Start Zeit _____________________<br>";


        $sql = "SELECT woo_order_id FROM abgeschlossener_bon WHERE bon_id=2059";

	$Q1 = mysql_query($sql);
	if (!$Q1) {
		echo "MySql Error: " . mysql_error();
		echo "Befehl :" . $sql;
	}

	$token = FILIALSYSTEM_TOKEN;
	$url = FILIALSYSTEM_URL_ZENTRALSYSTEM;

        while ($row = mysql_fetch_assoc($Q1)) {
        
		echo "Delete Order ID: ".$row['woo_order_id']."<br>";
	    	$strurl = "orders/".$row['woo_order_id'].".json";
            	
       
			

			try {
					
					
					$abpad = $url . $strurl;
					echo $abpad . "<br>";

					delete_table_api_shopify_url($abpad);

					

			} catch (Exception $e) {
					echo 'Exception abgefangen: ',  $e->getMessage(), "<br>";
			}

  
			
		}

       // $sql2 = "UPDATE abgeschlossener_bon_produkte SET filialsystem_sync_done=0;";
       // $Q2 = mysql_query($sql2);
       // if (!$Q2) echo "Fehler " . mysql_error();

	$timestamp2 = time();
	$datum2 = date("d.m.Y - H:i", $timestamp2);

	echo "____________________ End Zeit _____________________<br>";
	echo $datum2;
	echo "____________________ ENDE End Zeit _____________________<br>";

function delete_table_api_shopify_url($url)
{

	$token = FILIALSYSTEM_TOKEN;

	ini_set('max_execution_time', -1);
	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	//curl_setopt( $ch, CURLOPT_POST, 1 ); 
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
	curl_setopt($ch, CURLOPT_HEADER, TRUE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			"Content-Type: application/json",
			"X-Shopify-Access-Token: $token"
	));

	$response = curl_exec($ch);
	if ($response === false) echo 'Curl-Fehler: ' . curl_error($ch);
	//$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
	curl_close($ch);
	
	echo "<pre>";
	print_r($response);
	echo "</pre>";

}

?>