<?php
include_once('connect.php');
include_once('functions.php');
include_once('modules/payment/payment.classes.php');
//echo date('Y-m-d H:i:s', time()-4*60*60);


$handle = fopen("iit_tools.csv", "r");

if($handle){
	$index = 0;
    $banned = ["21620", "38092", "18005","16410","10040","17450", "90015","17340","16709","17375","99085","17315"];
	
	while (($row = fgetcsv($handle)) !== false) {
        $item = new Item("%", "%", $row[6]);
        //var_dump($item);
        if($item->Line !== null && !in_array($item->SKU, $banned)){
            
            $filename = "img/catalog/" . $item->Line . " " . $item->SKU . ".jpg";
            if(!file_exists($filename)){
                $url = $row[8];
                if($url != "null"){
                    // Function to write image into file 
                    file_put_contents($filename, file_get_contents($url)); 
                    //echo "<img src=\"$url\" />" . $item->SKU . "---" . $item->Description . "<br><br>";
                
    
                }	
    
            }else{
                $query = "INSERT INTO PRODUCT_UPC (`Line`, `SKU`, `UPC`, `Qty`) VALUES ('$item->Line', '$item->SKU', $row[7], 1);";
                mysqli_query($con, $query);

                $query = "INSERT INTO CATALOG_DETAIL (`Line`, `SKU`, `CategoryID`) VALUES ('$item->Line', '$item->SKU', $row[9]);";
                mysqli_query($con, $query);
            }
        }
		//$filename = "img/catalog/" . $row[2] . ".jpg";
		
		
		
		
		

			
        $index++;
    }
}else{
	echo "Cannot open file";
}


?>

<?php
/**
 * Author: Abu Ashraf Masnun
 * URL: http://masnun.me
 */
 /*
class WorkerThreads extends Thread
{
    private $workerId;

    public function __construct($id)
    {
        $this->workerId = $id;
    }

    public function run()
    {
        sleep(rand(0, 3));
        echo "Worker {$this->workerId} ran" . PHP_EOL;
    }
}

// Worker pool
$workers = [];

// Initialize and start the threads
foreach (range(0, 5) as $i) {
    $workers[$i] = new WorkerThreads($i);
    $workers[$i]->start();
}

// Let the threads come back
foreach (range(0, 5) as $i) {
    $workers[$i]->join();
}
*/
 //var_dump(sendEstimate(10028));



?>
