<?php require_once('admin/setari.php');

$criteriu = $_GET['mag'];

$xml = simplexml_load_file('xml/'.$criteriu.'.xml') or die("Error: Cannot create object");
if($criteriu != ''){$nr_produse = ($xml->count());}
// ===== start arata 12 produse /pagina
if ($_GET['pag'] == ''){$i = (1);}else{$i = ($_GET['pag']-1);}

$nr_max_produse_listate = ($i+$nr_produse);  

if($_GET['mag'] != ''){

for ($i; $i<$nr_max_produse_listate; $i++) {

	$item = $_GET['produs'];
	$titlu1 = $xml->item[$i]->title;
	$titlu = str_ireplace(array("'", '"'), ' ' ,$titlu1);
	$pret = $xml->item[$i]->price;
	$pret_old = $xml->item[$i]->old_price;
	$brand = $xml->item[$i]->brand;
	$product_active = $xml->item[$i]->product_active;
	$category = $xml->item[$i]->category; 
	$subcategory = $xml->item[$i]->subcategory;
	$other_data = $xml->item[$i]->other_data;
	$short_message1 = $xml->item[$i]->short_message;
	$short_message = str_ireplace(array("'", '"'), ' ' ,$short_message1);
	$image_urls1 = $xml->item[$i]->image_urls;
	$image_urls = explode(', ', $image_urls1);
	$description = $xml->item[$i]->description;
	$link_aff = $xml->item[$i]->aff_code;   
	$titlu_url1 = str_ireplace(array(' ', ',', '+', '/', '@', '#', '\\', '%28', '%29', '(', ')', '"', '&', '*', '.', '~', '|', '--', '®', '™', ';', ':'), '-' ,$titlu);
	$titlu_url = str_ireplace(array('--', '---', '----', ' ', '!', '\'', '?'), '-' ,$titlu_url1);
	
	if($description == ''){$description = $titlu;}	
	if($image_urls == ''){$image_urls ='img/click.jpeg';}
	
echo $i.' - '.$titlu.'<br />';	
//print_r ($xml); 

$adauga_produse = mysql_query ("INSERT INTO produse 
	(`id`, `vanzator`, `brand`, `category`, `subcategory`, `title`, `short_message`, `description`, `other_data`, `price`, `old_price`, `product_active`, `aff_code`, `image_urls`) VALUES 
	('', '".addslashes($criteriu)."', '".addslashes($brand)."', '".addslashes($category)."', '".addslashes($subcategory)."', '".addslashes(trim($titlu))."', '".htmlentities($short_message)."', '".addslashes($description)."', '".addslashes($other_data)."', '".addslashes($pret)."', '".addslashes($pret_old)."', '".addslashes($product_active)."', '".$link_aff."', '".$image_urls['0']."');") or die(mysql_error());
	
	}
}
// ===== end arata 12 produse /pagina
?>