<?
include "../conf.php";
connection();

$tp=$rep;

function verif1($content)
{
if (eregi("<a href=\"(.*)&hist=1\">", $content, $regs[]))
                {echo "1";
                for ($i=0;$i<sizeof($regs);$i++) {
                //echo htmlspecialchars($regs[$i][1])." (1)<br><br>";
                $tab1=explode("fiche=",$regs[$i][1]);
                $tab2=explode("&hist=",$tab1[1]);
                if ($tab2[0]!="") {
                $sql="select fkey_n from fiches where pkey_fiche=$tab2[0]";
		$result=mysql_query($sql);
		$f_dest=mysql_result($result,0,0);
		$strings="visu.php?fiche=".$tab2[0]."&hist=1";
		//echo htmlspecialchars($strings)."<br>";
                $replace="visu".$f_dest.".html?hist=1";
                $content=str_replace($strings,$replace,$content);}
                }
                }
                return($content);
}

function verif2($content)
{
if (eregi("<a href='(.*)&hist=1'>", $content, $regs[]))
                {echo "2";
                for ($i=0;$i<sizeof($regs);$i++) {
                //echo htmlspecialchars($regs[$i][1])." (1)<br><br>";
                $tab1=explode("fiche=",$regs[$i][1]);
                $tab2=explode("&hist=",$tab1[1]);
                if ($tab2[0]!="") {
                $sql="select fkey_n from fiches where pkey_fiche=$tab2[0]";
		$result=mysql_query($sql);
		$f_dest=mysql_result($result,0,0);
		$strings="visu.php?fiche=".$tab2[0]."&hist=1";
		//echo htmlspecialchars($strings)."<br>";
                $replace="visu".$f_dest.".html?hist=1";
                $content=str_replace($strings,$replace,$content);}
                }
                }
                return($content);
}

function verif3($content)
{
if (eregi("<a href=\"(.*)&hist=1\" onMouseOver", $content, $regs3[]))
                {
		for ($i=0;$i<sizeof($regs3);$i++) {
                //echo htmlspecialchars($regs3[$i][1])." (2)<br><br>";
		$tab1=explode("fiche=",$regs3[$i][1]);
		$tab2=explode("&hist=",$tab1[1]);
		if ($tab2[0]!="") {
		$sql="select fkey_n from fiches where pkey_fiche=$tab2[0]";
		$result=mysql_query($sql);
		$f_dest=mysql_result($result,0,0);
		$strings="visu.php?fiche=".$tab2[0]."&hist=1";
		//echo htmlspecialchars($strings)."<br>";
                $replace="visu".$f_dest.".html?hist=1";
                $content=str_replace($strings,$replace,$content);}
                }
                }
                return($content);
}


function update(){
     global $cachefile, $scriptURL, $tp;
     $tab1[]=NULL;
     $tab2[]=NULL;
     $regs[]=NULL;
     $regs2[]=NULL;
     if($content = implode("",file("$scriptURL"))){
           
                
                if (eregi("<a href=\"(.*)&hist=1\">", $content, $regs[]))
                {
                for ($i=0;$i<sizeof($regs);$i++) {
                //echo htmlspecialchars($regs[$i][1])." (1)<br><br>";
                $tab1=explode("fiche=",$regs[$i][1]);
                $tab2=explode("&hist=",$tab1[1]);
                if ($tab2[0]!="") {
                $sql="select fkey_n from fiches where pkey_fiche=$tab2[0]";
		$result=mysql_query($sql);
		$f_dest=mysql_result($result,0,0);
		$strings="visu.php?fiche=".$tab2[0]."&hist=1";
		//echo htmlspecialchars($strings)."<br>";
                $replace="visu".$f_dest.".html?hist=1";
                $content=str_replace($strings,$replace,$content);}
                }
                }
                while (eregi("<a href=\"(.*)&hist=1\">", $content)) {$content=verif1($content);}
               
                if (eregi("<a href='(.*)&hist=1'>", $content, $regs2[]))
                {
		for ($i=0;$i<sizeof($regs2);$i++) {
                //echo htmlspecialchars($regs2[$i][1])." (2)<br><br>";
		$tab1=explode("fiche=",$regs2[$i][1]);
		$tab2=explode("&hist=",$tab1[1]);
		if ($tab2[0]!="") {
		$sql="select fkey_n from fiches where pkey_fiche=$tab2[0]";
		$result=mysql_query($sql);
		$f_dest=mysql_result($result,0,0);
		$strings="visu.php?fiche=".$tab2[0]."&hist=1";
		//echo htmlspecialchars($strings)."<br>";
                $replace="visu".$f_dest.".html?hist=1";
                $content=str_replace($strings,$replace,$content);}
                }
                }
                while (eregi("<a href='(.*)&hist=1'>", $content)) {$content=verif2($content);}
        
		if (eregi("<a href=\"(.*)&hist=1\" onMouseOver", $content, $regs3[]))
                {
		for ($i=0;$i<sizeof($regs3);$i++) {
                //echo htmlspecialchars($regs3[$i][1])." (2)<br><br>";
		$tab1=explode("fiche=",$regs3[$i][1]);
		$tab2=explode("&hist=",$tab1[1]);
		if ($tab2[0]!="") {
		$sql="select fkey_n from fiches where pkey_fiche=$tab2[0]";
		$result=mysql_query($sql);
		$f_dest=mysql_result($result,0,0);
		$strings="visu.php?fiche=".$tab2[0]."&hist=1";
		//echo htmlspecialchars($strings)."<br>";
                $replace="visu".$f_dest.".html?hist=1";
                $content=str_replace($strings,$replace,$content);}
                }
                }
                while (eregi("<a href=\"(.*)&hist=1\" onMouseOver", $content)) {$content=verif3($content);}

                $content=ereg_replace("../../$tp/fiches/editor/images/","../editor/",$content);
if ($cachefile!="demo.html" and $cachefile!="xtree.js" and $cachefile!="tree.js") {
              $content="<script type=\"text/javascript\" language=\"javascript\">

var paramOk = true;

function FaitTableau(n) {
  this.length = n;
  for (var i = 0; i <= n; i++) {
    this[i] = 0
  }
  return this
}

function ParamValeur(nValeur) {
if (paramOk==false) {return(false);}
  var nTemp = \"\";
  for (var i=0;i<(param.length+1);i++) {
    if (param[i].substring(0,param[i].indexOf(\"=\")) == nValeur)
      nTemp = param[i].substring(param[i].indexOf(\"=\")+1,param[i].length)
  }
  return Decode(nTemp)
}


if (!location.search) {
  paramOk = false; 
}
else {
  nReq = location.search.substring(1,location.search.length)
  // Extrait les différents paramètres avec leur valeur.
  nReq = nReq.split(\"&\");
  param = new FaitTableau(nReq.length-1)
  for (var i=0;i<(nReq.length);i++) {
    param[i] = nReq[i]
  }
}

function Decode(tChaine) {
  while (true) {
    var i = tChaine.indexOf('+');
    if (i < 0) break;
    tChaine = tChaine.substring(0,i) + '%20' + tChaine.substring(i + 1, tChaine.length);
  }
  return unescape(tChaine)
}
</script>
<script language=javascript>hist = ParamValeur(\"hist\");  if (hist==1) {document.write(\"&nbsp;<font face='verdana' size='2'><a href='javascript:history.go(-1)'><img src='retour.jpg' alt='Retour' border='0'></a></font>\");}
</script>".$content;  }
                //echo $chaine1;
                $content=ereg_replace("../medias/","medias/",$content);
                if($w = fopen("$cachefile","w")){
		                               fwrite($w,$content);
                           fclose($w);
                //echo $content;
           }else{echo "Unable to open the Cachefile for writing";}
     }else{echo  "Unable to run your content grabbing script";}
}




$sqla="select fkey_n from fiches";
$resulta=mysql_query($sqla);
while ($rowa=mysql_fetch_row($resulta))
{
$f=$rowa[0];
$cachefile="visu$f.html";
$scriptURL = "http://".$HTTP_HOST."/".$tp."/viewer/visu.php?f=".$f;
update();

}

$cachefile="xtree.js";
$scriptURL = "http://".$HTTP_HOST."/".$tp."/viewer/xtree.js";
update();

$cachefile="demo.html";
$scriptURL = "http://".$HTTP_HOST."/".$tp."/viewer/demo.php";
update();


$cachefile="tree.js";
$scriptURL = "http://".$HTTP_HOST."/".$tp."/viewer/tree.js";
$content = implode("",file("$scriptURL"));
$tab=explode("visu.php?f=",$content);
for ($i=0;$i<sizeof($tab);$i++)
{
$tab2=explode("');",$tab[$i]);
$stringr="visu.php?f=".$tab2[0]."')";

$replace="visu".$tab2[0].".html')";
$content=str_replace($stringr,$replace,$content);
}
if($w = fopen("$cachefile","w")){
	fwrite($w,$content);
	fclose($w);
           }
           else{echo "Unable to open the Cachefile for writing";}
           
                



//##########Main

?>
<div id="attente" style="position:absolute;width :100%;height :100%;left :0 px;top :0 px;visibility:hidden ;z-index:82;">
<table width="100%" height="100%" border="0" bgcolor="#FFFFFF"><tr><td bgcolor="#FFFFFF">&nbsp;</td><td align="center" valign="middle" bgcolor="#FFFFFF"><font size="1" face="Verdana"><img src="../../construction025.gif" alt="" height="84" width="80" align="left" border="0">Copie des fichiers en cours...<br>
				Veuillez patienter quelques instants,<br>
				jusqu'&agrave; l'affichage de la page de confirmation.</font></td><td width="50%" bgcolor="#FFFFFF">&nbsp;</td></tr></table>
</div>
<font face="verdana" size="2">L'export s'est terminé avec succès.<br>
Vous pouvez récupérer les fichiers en cliquant <a href="C:\Tpworks\www\<?echo $tp;?>" target="_blank">ici</a>.<br>
Les répertoires a copier sont : export, medias, presentation et fonds.</font>
<script language="javascript">attente.style.visibility="visible"; document.location="../envoi";</script>

