<?php 
error_reporting(E_ALL);
header("Content-type: text/xml"); 
include("admin/connect.php");
$web = 'http://www.aurushotel.cz/';//doména webu!!!


if( isset($_GET['l'])){
    echo '<' . '?xml version="1.0" encoding="UTF-8"?' . '><' . '?xml-stylesheet type="text/xsl" href="sitemap_l.xsl"?' . '>';
    
    echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
    
    //echo $_SERVER['SERVER_NAME'];
    function getTree($root, $parent,$lang = 'en', $zanor = 0) {
        $ret = '';
    
        $querySection = "SELECT sec_id, IF(clon_url!='',clon_url,redirect_from) AS redirect_from, DATE(datum_editace) AS datum FROM section_tree WHERE sec_lang = '". mysql_real_escape_string($lang) ."' AND sec_parent_id = '".intval($parent)."' ORDER BY sec_id";
        $resSection = mysql_query($querySection);
        echo mysql_error();
        
        if (mysql_num_rows($resSection) > 0) {
    
          while( $row = mysql_fetch_array($resSection)) {
            //if( strpos($page['redirect_from'], 'http://')===true && strpos($page['redirect_from'], $root)!==true ){ continue; }
            
           $ret .= '<url>'."\n";
           $ret .= "<loc>";
                $ret .= $root.($row['redirect_from']=='homepage.htm' ? '' : $row['redirect_from']);
           $ret .= "</loc>\n";
           $ret .= "<lastmod>";
                  $ret .= $row['datum'];
           $ret .= "</lastmod>\n";
           $ret .= "<changefreq>";
                  $ret .= "weekly";
           $ret .= "</changefreq>\n";
           $ret .= "<priority>";
                  $ret .= 1 - ( $zanor * 0.1 );
           $ret .= "</priority>\n";
           $ret .= '</url>'."\n";
           $ret .=  getTree($root, $row['sec_id'],$lang, $zanor + 1);
          }
    
        }
        return $ret;
    }

    echo getTree($web, 0, $_GET['l']);//$lang
    
    echo '</urlset>';
}else{

    echo '<' . '?xml version="1.0" encoding="UTF-8"?' . '><' . '?xml-stylesheet type="text/xsl" href="sitemap.xsl"?' . '>';
    
    echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
    
    $sql = "SELECT lang FROM langs";
    $sqlq = mysql_query($sql);
    while( $sitemap = mysql_fetch_array($sqlq) ){

      echo '<sitemap>
              <loc>'.$web.'sitemap.xml?l='.$sitemap['lang'].'</loc>
            </sitemap>
      ';
    }
echo '</sitemapindex>';

}
?>



