<?

//18/01/2008 : ajout des annonces immobilières + petites annonces
if (strpos($_SERVER['HTTP_HOST'],"fasilaweb.fr") && strpos($_SERVER["REQUEST_URI"],"sitemap.php?PHPSESSID=")) {
    header("Status: 301 Moved Permanently", false, 301);
    header("Location: http://www.fasilaweb.fr/sitemap.php");
    exit();
}

/**********************************************************/
/*
* Fichier		sitemap.php
* Description	génère le site map dynamiquement (Google)
* Création		04/02/2006
*/
/**********************************************************/
include("_includes/mdl_correspondance.inc.php");
include("_includes/globals.inc.php");
include("_includes/connexion.inc.php");
include("_includes/sql.inc.php");
include("_includes/affichage.inc.php");
include("_includes/page.inc.php");

/* claude 2026-07-29 : assainir la SORTIE du sitemap, sans jamais le rediriger.
   1) URL CANONIQUES : SITE_URL est figee sur $_SERVER['HTTP_HOST'] a l'inclusion de
      globals.inc.php, et mkHref() bati dessus. Appele sans www, ce sitemap listait des
      URL sans www, toutes vouees a une 301. Meme source de verite qu'index.php :
      dd_domaine, domaine principal non redirige.
   2) BLOCS <url> VIDES : 5 endroits impriment <url> puis ne posent le <loc> que si
      l'URL n'est pas la racine nue (garde contre les pages non resolues). Quand la
      garde joue, il reste un <url> sans <loc> - invalide, <loc> etant obligatoire.
   Les deux corrections passent par un seul filtre de tampon : une insertion, pas de
   fermeture a poser, PHP vide le tampon en fin de script. */
$__urlCanon = '';
if (defined('DMN_FORCER_REDIR301') && DMN_FORCER_REDIR301) {
    $__rsCanon = @mysql_query("select str_dmn_host from dd_domaine"
        . " where bln_dmn_is_principal = 1 and bln_forcer_redir301 = 0"
        . " and str_sit_code = '" . STR_SITE_CODE . "'", $GLOBALS['bdd']);
    if ($__rsCanon && ($__rowCanon = mysql_fetch_assoc($__rsCanon)) && !empty($__rowCanon['str_dmn_host'])) {
        $__c = SITE_HTTP . $__rowCanon['str_dmn_host'];
        if ($__c !== SITE_URL) { $__urlCanon = $__c; }
    }
}
ob_start(function ($__buf) use ($__urlCanon) {
    if ($__urlCanon !== '') { $__buf = str_replace(SITE_URL, $__urlCanon, $__buf); }
    return preg_replace_callback('#[ \t]*<url>.*?</url>\r?\n?#s', function ($__m) {
        return strpos($__m[0], '<loc>') === false ? '' : $__m[0];
    }, $__buf);
});
include(INC_PATH."/mdl/lib.lien.inc.php");
include(INC_PATH."/".STR_SITE_CODE."/arborescence.inc.php");

/**********************************************************/
/*
* Fonction		generer_sitemap
* Description 	retourne le contenu du sitemap
				liste des pages + recherches prédéfinies
*/
/**********************************************************/
function generer_sitemap() {	
	global $bdd;
	 /* Liste des tables de la base*/
    $tab_db_tables = array();
    $tab_db_tables = return_mysql_tab_table_lists($GLOBALS['bdd']);
    
	$sql = "SELECT * FROM dd_page
		WHERE flt_sitemap_poids > 0 AND
		int_authentification=0 AND
		str_sit_code = '".STR_SITE_CODE."' 
		ORDER BY flt_sitemap_poids desc, id_page";
	
    $rs = mysql_query($sql,$bdd) or die(erreur_mysql($sql));
	$int_nb_lignes = mysql_num_rows($rs);
	if ($int_nb_lignes==0)
		return;

	/* Requête sur les pages */	
	while ($row = mysql_fetch_assoc($rs)) {
		//$url = SITE_URL.get_page_file_name($row['id_page'], true);	
    $url = mkHref($row);	
		
		if ($row['str_sitemap_frequence'] == "daily")
      $date_modification = date("Y-m-d");
    else
      $date_modification = ($row['date_sitemap_modification']!="")?$row['date_sitemap_modification']:date("Y-m-d",$row['tmp_modification']);  
    
    $flt_sitemap_poids = ($row['flt_sitemap_poids']=="1")?"1.0":$row['flt_sitemap_poids'];
		print "  <url>\n";			
		print "    <loc>$url</loc>\n";
		print "    <lastmod>$date_modification</lastmod>\n";
		print "    <changefreq>".$row['str_sitemap_frequence']."</changefreq>\n";
		print "    <priority>".$flt_sitemap_poids."</priority>\n";
		print "  </url>\n";		
	}
	
	/* Requête sur les recherches prédéfinies */
	$sql = "SELECT * FROM dd_recherche_referencement WHERE arr_sit_code like '%".STR_SITE_CODE."%' ORDER BY flt_sitemap_poids desc, id_recherche_referencement";
	
	$rs = mysql_query($sql,$bdd) or die(erreur_mysql($sql));
	$int_nb_lignes = mysql_num_rows($rs);

	if ($tab_une_page = get_page_mdl("MDL_RECHERCHE")) {			
		$preciser_mdl_recherche = false;
	} else {
		$tab_une_page = get_page_from_id(ID_PAGE_ACCUEIL);
		$preciser_mdl_recherche = true;
	}

	while ($row = mysql_fetch_assoc($rs)) {
  	/* Requête sur les pages */
		if ($preciser_mdl_recherche) {
			$url =mkHref($tab_une_page,"",
				array("mdl_code"=>"MDL_RECHERCHE", "search_string"=>$row['str_recherche_referencement_page_titre']));		
		} else {
			$url = mkHref($tab_une_page,$row['id_recherche_referencement'],
				array("mdl_code"=>"MDL_REC_REF_FICHE","t"=>$row['str_recherche_referencement_page_titre']));
		}
		$date_modification = $row['date_sitemap_modification'];
		
		print "  <url>\n";			
		print "    <loc>$url</loc>\n";
		print "    <lastmod>$date_modification</lastmod>\n";
		print "    <changefreq>".$row['str_sitemap_frequence']."</changefreq>\n";
		print "    <priority>".$row['flt_sitemap_poids']."</priority>\n";
		print "  </url>\n";
				
	}	

	/***************/
  /*   Albums    */
  /***************/
  if (in_array("de_album",$tab_db_tables) && false) {
    $sql = "SELECT a.*, de_album_traduction.str_album_titre, 
    		de_album_categorie_traduction.str_album_categorie_titre 
    		FROM de_album as a
        INNER JOIN de_album_traduction on (a.id_album = de_album_traduction.id_album and de_album_traduction.str_id_langue = '".STR_SIT_LANGUE."')
    		inner join de_album_categorie as c using (id_album_categorie)  
        INNER JOIN de_album_categorie_traduction on (c.id_album_categorie = de_album_categorie_traduction.id_album_categorie and de_album_categorie_traduction.str_id_langue = '".STR_SIT_LANGUE."')
        WHERE arr_sit_code like '%".STR_SITE_CODE."%' 
    	ORDER BY date_modification desc";
    $rs = mysql_query($sql,$GLOBALS["bdd"]) or die(erreur_mysql($sql));
    
    while($row = mysql_fetch_array($rs)){ 
      require_once(INC_PATH."/mdl/lib.album.inc.php");
    	$id_album = return_html_format($row['id_album'], "id");
    	$id_album_categorie = return_html_format($row['id_album_categorie'], "id");
    	$str_album_titre  = return_html_format($row['str_album_titre'], "str");
    	$str_album_titre = return_html_decoded($str_album_titre);
      $str_album_titre = str_replace("’","'",$str_album_titre);
    
    	$str_album_categorie_titre  = return_html_format($row['str_album_categorie_titre'], "str");
    	$str_album_categorie_titre = return_html_decoded($str_album_categorie_titre);
      $str_album_categorie_titre = str_replace("’","'",$str_album_categorie_titre);
    	
    	$url_afficher = calculer_url_album($_rowPageTpl['id_page'], "FICHE", $id_album_categorie, $id_album, $str_album_titre);
      
      if (!empty($url_afficher)) {
      		print "  <url>\n";			
      		print "    <loc>$url_afficher</loc>\n";
      		print "    <lastmod>".$row['date_modification']."</lastmod>\n";
      		print "    <changefreq>monthly</changefreq>\n";
      		print "    <priority>0.6</priority>\n";
      		print "  </url>\n";
  		}  				
  	}	
  }

    /*************************/
    /*   Ville croisement    */
    /*************************/
    if (in_array("de_ville_croisement",$tab_db_tables)) {
        $tmp_sql_query="SELECT id_ville_croisement,id_page, str_ville_croisement_titre, str_variable, flt_latitude, flt_longitude, arr_departement, int_ville_croisement_rayon, arr_departement, int_ville_croisement_taille, id_ville
                      FROM de_ville_croisement
                      INNER JOIN de_ville using (id_ville) where de_ville_croisement.arr_sit_code like '%".STR_SITE_CODE."%'";
        
        $tmp_sql_result=mysql_query($tmp_sql_query,$bdd);
        
        while ($row = mysql_fetch_array($tmp_sql_result)) {
            $str_ville_croisement_titre = return_html_format($row['str_ville_croisement_titre'], "str");
            $str_ville_croisement_titre_origine = $str_ville_croisement_titre;
            $str_variable = return_html_format($row['str_variable'], "str");
            $LAT = return_html_format($row['flt_latitude'], "flt");
            $LONG = return_html_format($row['flt_longitude'], "flt");
            
            if (!empty($row['arr_departement']))
                $aDep = explode('@', $row['arr_departement']);
                
                $id_ville = $row['id_ville'];
                $id_ville_croisement = $row['id_ville_croisement'];
                $int_ville_croisement_taille = return_html_format($row['int_ville_croisement_taille'], "int");
                $int_ville_croisement_rayon = return_html_format($row['int_ville_croisement_rayon'], "int");
                
                $limit = '';
                $sqlCplt = " OR id_ville= ' $id_ville '" ;
                
                if (is_array($aDep) && sizeof($aDep) > 0)
                    $cplt_dep = "id_departement in(".implode(",",$aDep).") and";
                    else
                        $cplt_dep = '';
                        
                        $sql="SELECT SQL_CACHE id_ville,str_ville_titre,
            (6366*acos(cos(radians($LAT))*cos(radians(flt_latitude))*cos(radians(flt_longitude)-radians($LONG))+sin(radians($LAT))*sin(radians(flt_latitude)))) as Proximite
            from de_ville
            where ( $cplt_dep (6366*acos(cos(radians($LAT))*cos(radians(flt_latitude))*cos(radians(flt_longitude)-radians($LONG))+sin(radians($LAT))*sin(radians(flt_latitude)))) <= $int_ville_croisement_rayon
            and int_nb_habitant >= $int_ville_croisement_taille) $sqlCplt";
                        //$order_clause .= "limit $int_start, $int_count ";
                        
                        $rs = mysql_query($sql,$GLOBALS['bdd']) or die(erreur_mysql($sql));
                        $int_nb_lignes = mysql_num_rows($rs);
                        $int_nb_lignes_total = return_mysql_FOUND_ROWS();
                        $int_nb_colonnes = mysql_num_fields($rs);
                        
                        if ($tab_une_page = get_page_mdl("MDL_VILLECROIS_LISTE",$id_ville_croisement )) {
                        } elseif (!empty($row['id_page']) && ($tab_une_page = get_page_from_id($row['id_page']))) {
                            /* claude 2026-07-25 : le croisement porte SA page dans de_ville_croisement.id_page
                               (=78 pour les 2 croisements de ce site). Sans cette branche, un croisement sans page
                               portant MDL_VILLECROIS_LISTE tombait sur get_page_courante(), inutilisable en contexte
                               sitemap : mkHref rendait la RACINE, repetee 188 fois, et les 188 vraies pages ville
                               etaient ABSENTES du sitemap (verifie : elles repondent 200, ex robot-aspirateur/32-voiron). */
                        } else {
                            $tab_une_page = get_page_courante();
                        }
                        
                        for ($i=0;$i<$int_nb_lignes_total;$i++) {
                            //for ($i=0;$i<($int_ulimit-$GLOBALS['int_start']);$i++) {
                            for ($j=0;$j<$int_nb_colonnes;$j++) {
                                $field_name = mysql_field_name($rs,$j);
                                $field_value = mysql_result($rs, $i, $field_name);
                                $pos = strpos($field_name,"_");
                                $field_type = substr($field_name,0,$pos);
                                ${$field_name} = return_html_format($field_value, $field_type);
                            }
                            
                            $str_ville_croisement_titre = $str_ville_croisement_titre_origine;
                            $str_ville_croisement_titre = str_replace('{VILLE}', $str_ville_titre, $str_ville_croisement_titre);
                            $str_ville_croisement_titre = str_replace('{DEPARTEMENT}', $str_departement_titre, $str_ville_croisement_titre);
                            $str_ville_croisement_titre = str_replace('{REGION}', $str_region_titre, $str_ville_croisement_titre);
                            $str_ville_croisement_titre = str_replace('{CODE_POSTALE}', $str_code_postal, $str_ville_croisement_titre);
                            
                            $url_afficher = mkHref($tab_une_page,$id_ville_croisement, array("mdl_code"=>"MDL_VILLECROIS_FICHE",$str_variable=>$id_ville.'-'.strtolower(str_to_filename_format($str_ville_titre)),"t"=>$str_ville_croisement_titre));
                            
                            if (!empty($url_afficher)) {
                                print "  <url>\n";
                                print "    <loc>$url_afficher</loc>\n";
                                print "    <lastmod>".date("Y-m-d")."</lastmod>\n";
                                print "    <changefreq>monthly</changefreq>\n";
                                print "    <priority>0.7</priority>\n";
                                print "  </url>\n";
                            }
                        }
        }
    }
	
	/***********/
  /* Billets */
  /***********/
  if (in_array("de_billet",$tab_db_tables)) {
     $sql = "SELECT de_billet.id_billet, de_billet.id_billet_categorie, str_billet_titre, tmp_creation, tmp_modification 
        from de_billet 
        WHERE arr_sit_code like '%".STR_SITE_CODE."%' and id_billet_categorie not in (9,5)
            ORDER BY tmp_creation desc ";
        $rs = mysql_query($sql,$GLOBALS["bdd"]) or die(erreur_mysql($sql));
        if (mysql_num_rows($rs)) {
            require_once(INC_PATH."/mdl/lib.billet.inc.php");                		                            
            while ($row = mysql_fetch_assoc($rs)) {
                $id_billet = $row['id_billet'];
                $id_billet_categorie = $row['id_billet_categorie'];                  	
            	$str_billet_titre  = return_html_format($row['str_billet_titre'], "str");                            	
                $sitemap_date =   date("Y-m-d",$row['tmp_modification']);                       		            	    		            
                $url_afficher  = calculer_url_billet($id_page_afficher, "FICHE", $id_billet_categorie, $id_billet, $str_billet_titre);    
           
                if ($url_afficher != SITE_HTTP.$_SERVER['HTTP_HOST'].SITE_DIR ) {
                    print "  <url>\n";			
                	print "    <loc>$url_afficher</loc>\n";
                	print "    <lastmod>".$sitemap_date."</lastmod>\n";
                	print "    <changefreq>weekly</changefreq>\n";
                	print "    <priority>0.7</priority>\n";
                	print "  </url>\n";
                }
    		}
      }
  }

	/***************/
  /*  Glossaire  */
  /***************/
	if (in_array("de_glossaire",$tab_db_tables)) {
        if ($tab_une_page_fiche = get_page_mdl("MDL_GLOSSAIRE_FICHE")) {
        } else {
            $tab_une_page_liste = get_page_mdl("MDL_GLOSSAIRE_LISTE");		
        } 

	   $sql = "SELECT de_glossaire.id_glossaire, str_glossaire_titre, tmp_creation   
        from de_glossaire 
        WHERE arr_sit_code like '%".STR_SITE_CODE."%' 
            ORDER BY tmp_creation desc ";
        $rs = mysql_query($sql,$GLOBALS["bdd"]) or die(erreur_mysql($sql));
        if (mysql_num_rows($rs)) {                           		                            
            while ($row = mysql_fetch_assoc($rs)) {
                $id_glossaire = $row['id_glossaire'];
                $id_glossaire_categorie = $row['id_glossaire_categorie'];                  	
            	  $str_glossaire_titre  = return_html_format($row['str_glossaire_titre'], "str");                            	
                $sitemap_date =   date("Y-m-d",$row['tmp_creation']);                       		            	    		                            
                
                if ($tab_une_page_fiche) {
                    $url_afficher = mkHref($tab_une_page_fiche, $id_glossaire,array("t"=>$str_glossaire_titre));
                } else {
                    $url_afficher = mkHref($tab_une_page_liste, $id_glossaire,array("t"=>$str_glossaire_titre,"mdl_code"=>"MDL_GLOSSAIRE_FICHE"));
                }                
                
                if ($url_afficher != "http://".$_SERVER['HTTP_HOST'].SITE_DIR ) {
                  print "  <url>\n";			
                	print "    <loc>$url_afficher</loc>\n";
                	print "    <lastmod>".$sitemap_date."</lastmod>\n";
                	print "    <changefreq>weekly</changefreq>\n";
                	print "    <priority>0.5</priority>\n";
                	print "  </url>\n";
                }
    		}
        }   
	}
  	
	/* Requête sur les liens */
	$sql = "SELECT * FROM de_lien 
          inner join de_lien_categorie using (id_lien_categorie)
          WHERE arr_sit_code like '%".STR_SITE_CODE."%' ORDER BY id_lien";
	$rs = mysql_query($sql,$bdd) or die(erreur_mysql($sql));
    $tab_page_speciale_annuaire =get_page_speciale("PGS_LIEN");
    
	while ($row = mysql_fetch_assoc($rs)) {
      	$my_tab_categorie = array();
      	$my_tab_categorie [] = $row['id_lien_categorie'];
      	_get_lien_categorie_tab_parent($my_tab_categorie, $row['id_lien_categorie']);      
        $url_afficher = "";
        
        /* Requête sur les pages */
		foreach($my_tab_categorie as $key=>$id_parent_categorie) {
		  if ($id_parent_categorie == 0)
		      break;
           
            if ($tab_une_page = get_page_mdl("MDL_LIEN_CAT_LISTE",$id_parent_categorie)) {
                $id_page = $tab_une_page['id_page'];                                
                if ($tab_une_page_fiche = get_page_mdl("MDL_LIEN_FICHE",'',$id_page)) {                            
                    $url_afficher = mkHref($tab_une_page_fiche, $row['id_lien'], array("mdl_code"=>"MDL_LIEN_FICHE","t"=>$row['str_lien_titre']));
                    break;
                } else {
                    $url_afficher = mkHref($tab_une_page, $row['id_lien'], array("mdl_code"=>"MDL_LIEN_FICHE","t"=>$row['str_lien_titre']));        
                    break;
                }
            }
        }	
		    if (empty($url_afficher) && $tab_page_speciale_annuaire) {
          if ($tab_une_page_fiche = get_page_mdl("MDL_LIEN_FICHE",'',$tab_page_speciale_annuaire['id_page'])) {                            
              $url_afficher = mkHref($tab_une_page_fiche, $row['id_lien'], array("mdl_code"=>"MDL_LIEN_FICHE","t"=>$row['str_lien_titre']));
          } else {
      		    //on n'a pas trouvé de page d'affichage => renvoyer vers la page spéciale PGS_ANNUAIRE si elle existe
              $url_afficher = mkHref($tab_page_speciale_annuaire, $row['id_lien'], array("mdl_code"=>"MDL_LIEN_FICHE","t"=>$row['str_lien_titre']));                       
          }
        }
        if (!empty($url_afficher)) {
    		print "  <url>\n";			
    		print "    <loc>$url_afficher</loc>\n";
    		print "    <lastmod>".$row['date_modification']."</lastmod>\n";
    		print "    <changefreq>monthly</changefreq>\n";
    		print "    <priority>0.6</priority>\n";
    		print "  </url>\n";
		}				
	}	

	/* Requête sur les villes pour fasilannuaire */
	if (STR_SITE_CODE == "SIT_FASILANNUAIRE") {
    	$sql = "SELECT de_ville.*, max(de_lien.date_modification) as date
    		FROM de_ville
    		inner join de_lien using (id_ville)
    		WHERE de_lien.arr_sit_code LIKE '%".STR_SITE_CODE."%'					
    		GROUP BY id_ville
            ORDER BY str_ville_titre";
    	$rs = mysql_query($sql,$bdd) or die(erreur_mysql($sql));
        $tab_page_speciale_annuaire =get_page_speciale("PGS_LIEN");
        
    	while ($row = mysql_fetch_assoc($rs)) {     
            $url_afficher = "";
            
            /* Requête sur les pages */
    		$titre_page=str_replace(" ","-",$row['str_ville_titre']);
    
    	 	if ($tab_une_page = get_page_mdl("MDL_LIEN_VILLE_FICHE",$row['id_ville'])) {
    			$url_afficher = mkHref($tab_une_page,"",array("t"=>$titre_page));	
            } elseif ($tab_une_page = get_page_mdl("MDL_LIEN_VILLE_FICHE")) {
    			$url_afficher = mkHref($tab_une_page,$row['id_ville'],array("mdl_code"=>"MDL_LIEN_VILLE_FICHE","t"=>"sites internet ".$titre_page." (".$row['str_code_postal'].")"));		
    		} else {
    			$tab_une_page = get_page_from_id(ID_PAGE_ACCUEIL);
    			$url_afficher = mkHref($tab_une_page, $row['id_ville'], 
    				array("mdl_code"=>"MDL_LIEN_VILLE_FICHE","t"=>"sites internet ".$titre_page." (".$row['str_code_postal'].")"));
    		}
    		
    		if (empty($url_afficher) && $tab_page_speciale_annuaire) {
    		    //on n'a pas trouvé de page d'affichage => renvoyer vers la page spéciale PGS_ANNUAIRE si elle existe
                $url_afficher = mkHref($tab_page_speciale_annuaire, $row['id_lien'], array("mdl_code"=>"MDL_LIEN_FICHE","t"=>$row['str_lien_titre']));                
            }
            if (!empty($url_afficher)) {
        		print "  <url>\n";			
        		print "    <loc>$url_afficher</loc>\n";
        		print "    <lastmod>".$row['date']."</lastmod>\n";
        		print "    <changefreq>weekly</changefreq>\n";
        		print "    <priority>0.7</priority>\n";
        		print "  </url>\n";
    		}
    				
    	}
	}
    /*****************/
    /* Annonces Immo */
    /*****************/
    if (in_array("de_immo_annonce",$tab_db_tables)) {
    //if (true) {
        $sql = "SELECT id_immo_annonce, 
            str_immo_annonce_titre,  
            de_immo_annonce.id_type_bien, 
            de_immo_annonce.id_type_annonce,         
            de_immo_annonce.tmp_modification,
            de_immo_type_annonce.str_id_type_annonce,
            str_ville_titre     
    		FROM de_immo_annonce	
    		inner join de_immo_type_annonce using(id_type_annonce)
            inner join de_ville on(de_ville.id_ville = de_immo_annonce.id_ville)		
            WHERE bln_vendu = 0
            and date_debut <= '".date("Y-m-d")."' 
            and (ISNULL(date_fin) or date_fin >= '".date("Y-m-d")."') 
            and de_immo_annonce.arr_sit_code like '%".STR_SITE_CODE."%'
            ORDER BY de_immo_annonce.tmp_modification desc";
  
        $rs = mysql_query($sql,$GLOBALS["bdd"]) or die(erreur_mysql($sql));
        if (mysql_num_rows($rs)) {
            require_once(INC_PATH."/mdl/lib.immo_annonce.inc.php");    		                            
            while ($row = mysql_fetch_assoc($rs)) {
                $id_immo_annonce = $row['id_immo_annonce'];
                $id_type_bien = $row['id_type_bien'];
                $str_id_type_annonce= $row['str_id_type_annonce'];        	
              	$str_immo_annonce_titre  = return_html_format($row['str_immo_annonce_titre'], "str");
              	$str_ville_titre = return_html_format($row['str_ville_titre'], "str");
                $sitemap_date =   date("Y-m-d",$row['tmp_modification']);                       		   		            
            	  $url_afficher = calculer_url_immo_annonce("IMMO_FICHE", $str_id_type_annonce, $id_type_bien, $id_immo_annonce, $str_immo_annonce_titre." ".$str_ville_titre);                
                if ($url_afficher != "http://".$_SERVER['HTTP_HOST'].SITE_DIR ) {
                    print "  <url>\n";			
                  	print "    <loc>$url_afficher</loc>\n";
                		print "    <lastmod>".$sitemap_date."</lastmod>\n";
                		print "    <changefreq>weekly</changefreq>\n";
                		print "    <priority>0.6</priority>\n";
                		print "  </url>\n";
        		    }           		        	
            }
        }
    } //fin annonces immo

    /**************************/
    /* Annonces Immo par ville*/
    /**************************/
    if (in_array("de_immo_annonce",$tab_db_tables)) {
    //if (true) {
        $sql = "SELECT de_ville.id_ville, str_ville_titre, str_type_bien_titre, str_id_type_annonce, str_type_annonce_titre, max(de_immo_annonce.tmp_modification) as date
                FROM `de_immo_annonce` 
                INNER JOIN de_ville ON ( de_ville.id_ville = de_immo_annonce.id_ville ) 
                INNER JOIN de_immo_type_annonce ON ( de_immo_type_annonce.id_type_annonce = de_immo_annonce.id_type_annonce ) 
                INNER JOIN de_immo_type_bien ON ( de_immo_type_bien.id_type_bien = de_immo_annonce.id_type_bien ) 
                WHERE bln_vendu = 0
                  and date_debut <= '".date("Y-m-d")."' 
                  and (ISNULL(date_fin) or date_fin >= '".date("Y-m-d")."') 
                  and de_immo_annonce.arr_sit_code like '%".STR_SITE_CODE."%' 
                GROUP BY str_ville_titre, str_type_bien_titre, str_type_annonce_titre
                ";
  
        $rs = mysql_query($sql,$GLOBALS["bdd"]) or die(erreur_mysql($sql));
        if (mysql_num_rows($rs)) {
            require_once(INC_PATH."/mdl/lib.immo_annonce.inc.php");    		                            
            while ($row = mysql_fetch_assoc($rs)) {
            	$id_ville = $row['id_ville'];
              $str_ville_titre = return_html_format($row['str_ville_titre'], "str");
              $type_bien_titre = strtolower(str_to_filename_format($row['str_type_bien_titre']));
              $type_annonce_titre = strtolower(str_to_filename_format($row['str_type_annonce_titre']));
              $sitemap_date =   date("Y-m-d",$row['date']);                       		
              
              if ($tab_une_page = get_page_speciale("PGS_IMMO_".$row['str_id_type_annonce'])) {
                  $url_afficher = mkHref($tab_une_page,$row['id_ville'], array("mdl_code"=>"MDL_IMMO_LISTE_VILLE",$type_annonce_titre=>$type_bien_titre,"t"=>"immobilier ".$str_ville_titre));
              } elseif ($tab_une_page = get_page_mdl("MDL_IMMO_LISTE")) {
                  $url_afficher = mkHref($tab_une_page,$id_ville, array("mdl_code"=>"MDL_IMMO_LISTE_VILLE",$type_annonce_titre=>$type_bien_titre,"t"=>"immobilier ".$str_ville_titre));
              } else {
                  $url_afficher = "";
              }
              
              if (!empty($url_afficher)) {
                print "  <url>\n";			
                print "    <loc>$url_afficher</loc>\n";
                print "    <lastmod>".$sitemap_date."</lastmod>\n";
                print "    <changefreq>weekly</changefreq>\n";
                print "    <priority>0.5</priority>\n";
                print "  </url>\n";
              }		        	
            }
        }
    } //fin annonces immo
    
    /********************/
    /* Petites annonces */
    /********************/
    if (in_array("de_annonce",$tab_db_tables)) {    
        $sql = "SELECT de_annonce.id_annonce, 
            de_annonce.id_annonce_categorie, 
            de_annonce.str_annonce_titre, 
            de_annonce.date_modification,
            str_ville_titre             
            FROM de_annonce 		 
    		inner join de_ville on(de_ville.id_ville = de_annonce.id_ville)
            
            WHERE date_validite >= '".date("Y-m-d")."'
    		and bln_valide = 1 
            and de_annonce.arr_sit_code LIKE '%".STR_SITE_CODE."%'
            order by de_annonce.date_modification desc";
          
        $rs = mysql_query($sql,$GLOBALS["bdd"]) or die(erreur_mysql($sql));
        if (mysql_num_rows($rs)) {
        	require_once(INC_PATH."/mdl/lib.annonce.inc.php");    		                            
            while ($row = mysql_fetch_assoc($rs)) {
                $id_annonce = $row['id_annonce'];
                $id_annonce_categorie= $row['id_annonce_categorie'];            	
            	$str_annonce_titre  = return_html_format($row['str_annonce_titre'], "str");            	            	
                $str_ville_titre = return_html_format($row['str_ville_titre'], "str");	
                list($annee, $mois, $jour) = explode("-", $row['date_modification']);
                $sitemap_date = "$annee-$mois-$jour";
                 		
            	$url_afficher  = calculer_url_annonce("FICHE", $id_annonce_categorie, $id_annonce, $str_annonce_titre,$str_ville_titre);    		            
                print "  <url>\n";			
            	print "    <loc>$url_afficher</loc>\n";
        		print "    <lastmod>".$sitemap_date."</lastmod>\n";
        		print "    <changefreq>weekly</changefreq>\n";
        		print "    <priority>0.6</priority>\n";
        		print "  </url>\n";
            		        	
            }
        }
    } //fin petites annonces

	/* Requête sur les villes pour fasilannonce */
	if (STR_SITE_CODE == "SIT_FASILAIMMO") {
    	$sql = "SELECT de_ville.*, max(de_immo_annonce.tmp_modification) as date_immo, max(de_annonce.date_modification) as date_annonce 
    		FROM de_ville
    		left join de_annonce using (id_ville)
    		left join de_immo_annonce using (id_ville)					
    		GROUP BY id_ville
            ORDER BY str_ville_titre";
    	$rs = mysql_query($sql,$bdd) or die(erreur_mysql($sql));
        
    	while ($row = mysql_fetch_assoc($rs)) {     
            $url_afficher = "";
            
            /* Requête sur les pages */
    		$titre_page=str_replace(" ","-",$row['str_ville_titre']);
    
    	 	if ($tab_une_page = get_page_mdl("MDL_VILLE_LISTE")) {
    			$url_afficher = mkHref($tab_une_page,$row['id_ville'],array("mdl_code"=>"MDL_VILLE_FICHE","t"=>"annonces gratuites pour la ville de ".$row['str_ville_titre']));		
    		} else {
                $url_afficher = "";
      		}
    		
    		if (isset($row['date_immo']) || isset($row['date_annonce'])) {
    		  list($annee, $mois, $jour) = explode("-", $row['date_annonce']);
              $date_annonce = mktime(0, 0, 0, $mois, $jour, $annee); 
              $date = ($row['date_immo'] > $date_annonce)?$row['date_immo']:$date_annonce;
    		} else
    		  $date = $row['tmp_modification'];
    		  
    		
		  if ($url_afficher != "https://".$_SERVER['HTTP_HOST'].SITE_DIR ) {
        		print "  <url>\n";			
        		print "    <loc>$url_afficher</loc>\n";
        		print "    <lastmod>".date("Y-m-d",$date)."</lastmod>\n";
        		print "    <changefreq>weekly</changefreq>\n";
        		print "    <priority>0.4</priority>\n";
        		print "  </url>\n";
    		}
    				
    	}
	}
	$sql = "SELECT * FROM de_produit
          inner join de_categorie using (id_categorie)
          WHERE arr_sit_code like '%".STR_SITE_CODE."%' AND bln_enligne = 1 AND de_produit.bln_envente = 1 ORDER BY id_produit";
	$rs = mysql_query($sql,$bdd) or die(erreur_mysql($sql));
	require_once(INC_PATH."/mdl/lib.produit.inc.php");
	while ($row = mysql_fetch_assoc($rs)) {
	    $id_categorie = ($row['id_categorie_parent']==0)?$row['id_categorie']:$row['id_categorie_parent'];
	    $url_afficher = calculer_url_produit($id_page_afficher,"FICHE", $id_categorie,$row['id_produit'], $row['str_produit_titre']);
	    $date_modification = date("Y-m-d",$row['tmp_modification']);
	    if ($url_afficher != "https://".$_SERVER['HTTP_HOST'].SITE_DIR ) {
	    print "  <url>\n";
	    print "    <loc>$url_afficher</loc>\n";
	    print "    <lastmod>".$date_modification."</lastmod>\n";
	    print "    <changefreq>monthly</changefreq>\n";
	    print "    <priority>0.6</priority>\n";
	    print "  </url>\n";
	    }
	    
	} 
	$sql = "SELECT distinct(id_marque),de_marque.* FROM de_marque
          inner join de_produit using (id_marque)
          WHERE de_produit.arr_sit_code like '%".STR_SITE_CODE."%' AND de_produit.bln_enligne = 1 AND de_produit.bln_envente = 1 group by id_marque";
	$rs = mysql_query($sql,$bdd) or die(erreur_mysql($sql));
	require_once(INC_PATH."/mdl/lib.produit.inc.php");
	while ($row = mysql_fetch_assoc($rs)) {
	    
	    if ($tab_une_page = get_page_mdl("MDL_MARQUE_LISTE")){
	        $url_afficher = mkHref($tab_une_page,$row['id_marque'],array("t"=> $row['str_marque_titre'],"mdl_code"=>"MDL_MARQUE_FICHE"));
	    }
	    
	    
	    
	    $date_modification = date("Y-m-d",$row['tmp_modification']);
	    if (!empty($url_afficher)) {
    	    print "  <url>\n";
    	    print "    <loc>$url_afficher</loc>\n";
    	    print "    <lastmod>".$date_modification."</lastmod>\n";
    	    print "    <changefreq>monthly</changefreq>\n";
    	    print "    <priority>0.6</priority>\n";
    	    print "  </url>\n";
	    }
	    
	} 
	if(false){
	require_once(INC_PATH."/".STR_SITE_CODE."/produit_categorie_arborescence_fo.inc.php");
	$my_tab = $GLOBALS['glbProduitCategorieTab'];
	 
	foreach($my_tab as $id_categorie => $tab_cat){
	    if($tab_cat['id_categorie_parent'] != 1){
	    $select = "select tmp_modification from de_produit where id_categorie = $id_categorie order by tmp_modification desc limit 0,1";
	    $rs = mysql_query($select,$bdd) or die(erreur_mysql($select));
	    if($row=mysql_fetch_assoc($rs)) {
	        $date_modification = date("Y-m-d",$row['tmp_modification']);
	    }
	    $url_categorie_fiche = calculer_url_produit($id_page_categorie, "CATEGORIE", $id_categorie, 0, $tab_cat['str_categorie_titre']);
	    print "  <url>\n";
	    print "    <loc>$url_categorie_fiche</loc>\n";
	    print "    <lastmod>".$date_modification."</lastmod>\n";
	    print "    <changefreq>monthly</changefreq>\n";
	    
	    print "    <priority>0.7</priority>\n";
	    print "  </url>\n";
	    }
	}
	}
	$sql = "select de_produit_attribut.id_produit_attribut_groupe,str_produit_attribut_titre,str_produit_attribut_groupe_titre,de_produit_attribut.id_produit_attribut,de_produit.tmp_modification
			from de_produit
	    
			inner join de_produit_combinaison on (de_produit.id_produit= de_produit_combinaison.id_produit)
			inner join de_produit_attribut on (de_produit_combinaison.id_produit_attribut=de_produit_attribut.id_produit_attribut)
			inner join de_produit_attribut_traduction on (de_produit_attribut.id_produit_attribut=de_produit_attribut_traduction.id_produit_attribut)
			inner join de_produit_attribut_groupe on (de_produit_attribut.id_produit_attribut_groupe=de_produit_attribut_groupe.id_produit_attribut_groupe)
			inner join de_produit_attribut_groupe_traduction on (de_produit_attribut_groupe.id_produit_attribut_groupe=de_produit_attribut_groupe_traduction.id_produit_attribut_groupe)
            where 1 and de_produit_attribut_groupe.id_produit_attribut_groupe = 74  ";
	
	
	$sql .=  " group by de_produit_attribut.id_produit_attribut order by de_produit_attribut_traduction.str_produit_attribut_titre asc  ";
	
	$rsConfig  = mysql_query($sql,$GLOBALS['bdd']) or die(erreur_mysql($sql));

	while ($rowConfig = mysql_fetch_array($rsConfig)) {
	    $page = get_page_speciale('PGS_PRODUIT');
	    $date_modification = date("Y-m-d",$row['tmp_modification']);
	    $url = mkHref($page,1,array('frm_application'=>$rowConfig['id_produit_attribut'],'mdl_code'=>'MDL_PRODUIT_CATEG_LISTE'));
	    print "  <url>\n";
	    print "    <loc>$url</loc>\n";
	    print "    <lastmod>".$date_modification."</lastmod>\n";
	    print "    <changefreq>monthly</changefreq>\n";
	    
	    print "    <priority>0.5</priority>\n";
	    print "  </url>\n";
	   // $retour .= "<li><a href=\"".$url."\">".$rowConfig['str_produit_attribut_titre']."</a></li>";
	}
	return "";
}

if (preg_match('/cgi/',php_sapi_name())) {
	header("Content-Type: text/xml;charset=UTF-8");
} elseif (version_compare(phpversion(),'4.3.0','>=')) {
	header('Content-Type:text/xml;charset=UTF-8', TRUE);
} else {
	header('Content-Type: text/xml;charset=UTF-8');
}

print '<?xml version="1.0" encoding="UTF-8"?>';?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<? generer_sitemap();?>
</urlset>
