﻿<?php 
session_start();
include_once('config.php');
$hl=ReturnHL();
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
\r\n"; ?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
<?php
$files = array(); $urls = array(); $mods = array(); $prio = array();
$basedir = realpath(".");
$filter = "|shtml|html|php|htm";
$redirs = array("index.html"=>"");
$postexc = array("index.html","indexES.html"); // No publicar (sí el seu redirect)


//afegim tots els models
$sql="SELECT * FROM projectors WHERE estat='A' or estat='P'";
$rs = $GLOBALS["DBConnection"]->ExecuteQuery($sql);
$error=$GLOBALS["DBConnection"]->getErrorDescription();
if($error!="") { echo $error; echo "<hr>\n\n" . $sql . "<hr>"; }
while($rs->Next()) {
	$link    = URLProjector($rs);
	$lastmod = $rs->GetField("Alta");
  array_push($urls,$link);
  array_push($mods,str_replace(" ","T",$lastmod)."+01:00");
  array_push($prio,"1.0");
}

// Afegim els links de lámpares: base de dades

// Per marques
$sql = "SELECT Marca, date_format(max(LastUpdate),'%Y-%m-%d %T') LastUpd, count(*) c FROM lamparas
	 		  WHERE Precio > 15
	 		  GROUP BY Marca
	      ORDER BY c DESC;";
$rs = $GLOBALS["DBConnection"]->ExecuteQuery($sql);
$error=$GLOBALS["DBConnection"]->getErrorDescription();
if($error!="") { echo $error; echo "<hr>\n\n" . $sql . "<hr>"; }
while($rs->Next()) {
	$link    = ML("lampara_proyector.php") . "?marca=".urlencode($rs->GetField("Marca"));
	$lastmod = $rs->GetField("LastUpd");
  array_push($urls,$link);
  array_push($mods,str_replace(" ","T",$lastmod)."+01:00");
  array_push($prio,"1.0");
}
// Tots els models de lámpares

$sql = "SELECT l.*, date_format(LastUpdate,'%Y-%m-%d %T') LastUpd FROM lamparas l
	 		  WHERE Precio > 15
	      ORDER BY Precio DESC;";
$rs = $GLOBALS["DBConnection"]->ExecuteQuery($sql);
$error=$GLOBALS["DBConnection"]->getErrorDescription();
if($error!="") { echo $error; echo "<hr>\n\n" . $sql . "<hr>"; }
while($rs->Next()) {
	$link    = GetLampUrl($rs);
	$lastmod = $rs->GetField("LastUpdate");
  array_push($urls,$link);
  array_push($mods,str_replace(" ","T",$lastmod."+01:00"));
  array_push($prio,"0.7");
}

// Tots els articles

$sql = "SELECT *, date_format(n.FechaAlta,'%Y-%m-%d %T') FechAlt FROM noticias n left join noticiamodelo m on n.idNoticia=m.idNoticia 
		   WHERE n.show='1' ".($hl!="ES" && $hl!="CA"?" and n.Titulo$hl!='' and n.Texto$hl!=''":"" )." group by n.idNoticia order by fechaalta DESC;";
$rs = $GLOBALS["DBConnection"]->ExecuteQuery($sql);
$error=$GLOBALS["DBConnection"]->getErrorDescription();
if($error!="") { echo $error; echo "<hr>\n\n" . $sql . "<hr>"; }
while($rs->Next()) {
	$link    = GetNoticiaUrl($rs);
	$lastmod = $rs->GetField("FechAlt");
  array_push($urls,$link);
  array_push($mods,str_replace(" ","T",$lastmod."+01:00"));
  array_push($prio,"0.7");
}

  array_push($urls,ML("soporte-proyector.html"));
  array_push($mods,str_replace(" ","T",$lastmod."+01:00"));
  array_push($prio,"1.0");

array_push($urls,ML("oferta-proyector.php"));
  array_push($mods,str_replace(" ","T",$lastmod."+01:00"));
  array_push($prio,"1.0");
// Imprimim els links en XML per sitemaps

foreach($urls as $i => $url) {
	if (array_search($url,$postexc)===false) {
		echo "<url>\r\n";
		if (strpos($url,"php",1)>0 || strpos($url,"?",1)>0)
		{
		  $url=urlencode($url);//htmlspecialchars($url);
		  $url = str_replace("%3F","?", $url);
		  $url = str_replace("%26","&amp;", $url);
		  $url = str_replace("%3D","=", $url);
		  echo "<loc>http://".$_SERVER['SERVER_NAME']."/".$url."</loc>\r\n";
		}else{
		  echo "<loc>http://".$_SERVER['SERVER_NAME']."/".$url."</loc>\r\n";
		}
		
		echo "<lastmod>".$mods[$i]."</lastmod>\r\n";
		echo "<priority>".$prio[$i]."</priority>";
		echo "</url>\r\n";
	
	}
  if (array_key_exists($url,$redirs)) {
  	echo "<url>\r\n";
	echo "<loc>http://".$_SERVER['SERVER_NAME']."/".$redirs[$url]."</loc>\r\n";
	echo "<lastmod>".$mods[$i]."</lastmod>\r\n";
		echo "<priority>1.0</priority>";
  	echo "</url>\r\n";
	}
}
?>
</urlset>
