<?php

include("../include/vars_adm.php");
include("../include/util.inc.php");
include("../include/utiljs.php");


function purger($txt) {
return preg_replace("/\\\\+\\'/","'",$txt);

}

opensession('Sadmin',false);
connecte($host,$user,$mdp,$db);

print "<h1>Purge des \ dans les libellés</h1><hr><br />";
print "<b>Légende :</b><br />";
print "<span style=\"color:red\">Item <u>institutionnel</u> AVANT le passage de la moulinette.</span><br />";
print "<span style=\"color:red\">Item <u>de base (GiSCCo)</u> AVANT le passage de la moulinette.</span><br />";
print "<span style=\"color:blue\">Item <u>institutionnel</u> APRES le passage de la moulinette.</span><br />";
print "<span style=\"color:blue\">Item <u>de base (GiSCCo)</u> APRES le passage de la moulinette.</span><br />";

print "<h2>Libellés standard</h2>";
$reslib=query("SELECT * FROM libelles");
while (list($item_id, $inst, $base)=mysql_fetch_array($reslib)) {
	$inst=stripslashes($inst);
	$base=stripslashes($base);
	
	print "<p><b>Item : $item_id</b></p>";
	print "<span style=\"color:red\">$inst</span>\n";
	print"<br />";
	print "<span style=\"color:red\">$base</span><br />\n";

	$newinst=purger($inst);
	$newbase=purger($base);
		
	print "<span style=\"color:blue\">$newinst</span>\n";
	print"<br />";
	print "<span style=\"color:blue\">$newbase</span>\n";
	
	$newinst=mysql_escape_string($newinst);
	$newbase=mysql_escape_string($newbase);
	
	query("UPDATE libelles SET inst='$newinst',base='$newbase' WHERE item_id=$item_id");
	}

print "<br /><h2>Libellés particuliers aux établissements</h2>";
$reslib=query("SELECT * FROM libelles_perso ORDER BY etab_id");
while (list($item_id, $libelle, $etab_id)=mysql_fetch_array($reslib)) {
	$libelle=stripslashes($libelle);
	print "<p><b>Etab : $etab_id, item : $item_id</b></p>";
	print "<span style=\"color:red\">$libelle</span>\n";

	$newlibelle=purger($libelle);
		
	print "<br /><span style=\"color:blue\">$newlibelle</span>\n";
	
	$newlibelle=mysql_escape_string($newlibelle);
	
	query("UPDATE libelles_perso SET libelle='$newlibelle' WHERE item_id=$item_id AND etab_id=$etab_id");
	}

?>