<?php

require ("progressbar.php");
date_default_timezone_set('America/Bogota');

$mysql_hostname = "localhost"; // Example : localhost
$mysql_user     = "root";
$mysql_password = "";
$mysql_database = "sistemageneral";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");

mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");
mysql_query("SET NAMES 'utf8'");
mysql_query('delete from temporalespecificosboton where 1;');
mysql_query('ALTER TABLE temporalespecificosboton AUTO_INCREMENT=1');


$xml1=new SimpleXMLElement(file_get_contents("https://6QW5T3HTWPMREMYZQ8TW8FH3JY45YGGZ@esferos.com/site/api/specific_prices"));



// get product line with xpath for example
$specificprices1=$xml1->xpath("/prestashop/specific_prices/specific_price");
$totalregistros2 = count($specificprices1);

echo "Precios Especificos Boton Promo //";
$HoraInicio = date('h:i:s') . " - ";
echo $HoraInicio;
$i2=0;
if ($specificprices1) {
 // loop over each product node
 foreach ($specificprices1 as $specificprice1) {
	 $i2=$i2+1;
$porcentaje1 = $i2 * 100 /$totalregistros2;
echo "<script>callprogress(".round($porcentaje2).")</script>";
flush();
ob_flush();
	  
	 
	 
	 $idspecificprice1=$specificprice1["id"];
     //$xmlprecio=new SimpleXMLElement(file_get_contents("https://6QW5T3HTWPMREMYZQ8TW8FH3JY45YGGZ@esferos.com/site/api/specific_prices/18"));
$xmlprecio=new SimpleXMLElement(file_get_contents("https://6QW5T3HTWPMREMYZQ8TW8FH3JY45YGGZ@esferos.com/site/api/specific_prices/".$idspecificprice1));
 		$id=$xmlprecio->specific_price->id;
		$id_product=$xmlprecio->specific_price->id_product;
	 	$id_product_attribute=$xmlprecio->specific_price->id_product_attribute;
	 	$price=$xmlprecio->specific_price->price;
	 	$from_quantity=$xmlprecio->specific_price->from_quantity;
	 	$reduction=$xmlprecio->specific_price->reduction;
	 	$reduction_type=$xmlprecio->specific_price->reduction_type;
	 	$from_date=$xmlprecio->specific_price->from;
	 	$to_date=$xmlprecio->specific_price->to;
	 
 $sql = "INSERT INTO `temporalespecificosboton` (id, id_product,id_product_attribute, price,from_quantity, reduction,reduction_type, from_date, to_date) VALUES ('$id','$id_product','$id_product_attribute','$price','$from_quantity','$reduction','$reduction_type','$from_date','$$to_date')";
mysqli_query($bd,$sql);
 
 
 }
}
$HoraFin = date('h:i:s') . "\n";
echo $HoraFin;

