##########################################################
#                #                                       #
#	 ManyPage    #    See habille.pl / Voir habille.pl   #
#                #                                       #
##########################################################
#
# Cette fonction gere les path pour la creation d'un fichier <LIEN>
# Ancienne version MDP
#
###################
#
#  Copyright (C) 2000 Pierre Cordani - Pascal Vuylsteker
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier conformŽment
# aux dispositions de la Licence Publique GŽnŽrale GNU, telle que publiŽe par la Free Software
# Foundation ; version 2 de la licence, ou encore (ˆ votre choix) toute version ultŽrieure.
#
###################

sub change_path
{
 local ($contenu,$le_path,$new) = @_;
# print "$contenu\n";
# print "($le_path,$new)\n";
 local $nb_my_path = local (@my_path) = split (/\//,$le_path);
 local ($desc,$path) = ('','');
  
 if($le_path =~ /.*$Dest\/(.*)/is)
  {
   $path = $1;
  }

 if($new =~ /((\.\.\/)+)(.*)/is)
  {
#   print "$nb_my_path $my_path[$nb_my_path-1]\n";
   local $nb_slash = split(/\//,$1);
   local $nb_slash2 = split(/\//,$3);
   for(local($i_slash) = 1; $i_slash <= $nb_slash; $i_slash++)
    {
	 $desc = "$my_path[$nb_my_path-$i_slash]/$desc";
	}
   for(local($i_slash) = 1; $i_slash < $nb_slash2; $i_slash++)
    {
	 $desc = "../$desc";
	}
#   print "$desc\n";
  }
 elsif($new =~ /^\/.*/is)
  {
	$desc = '/';
#   print "-->$new\n";
  }
 else
  {
   local $nb_slash = split(/\//,$new);
   for(local($i_slash) = 1; $i_slash < $nb_slash; $i_slash++)
    {
	 $desc .= '../';
	}
   $path = '';
  }

#print "==>$desc\n";

 local($contenu_buffer) = $contenu;
 local($nb_tags) = 0;
 while($TAGS[$nb_tags])
  {
#   print "Tags : $TAGS[$nb_tags]\n";
   while($contenu_buffer =~ /($TAGS[$nb_tags]\s*=\s*"([^\/](.*?))")/is)
    {local ($buf_c,$buf_l) = ($1,$2);
#     print "==>($buf_c,$buf_l)\n";
	 if(!($2 =~ /^#.*/is) && !($2 =~ /^mailto:.*/is) && !($2 =~ /^http:.*/is) && !($2 =~ /^news:.*/is))
      {
	   local ($res) = elimine_points("$desc$buf_l");
	   $contenu =~ s/\Q$buf_c\E/$TAGS[$nb_tags]="$res"/gis;
#     print "Je remplace $buf_c par $res\n";
	  }
     $contenu_buffer =~ s/\Q$buf_c\E//gis;
    }
   $nb_tags++;
  }
 return $contenu;
}

###################
#
# Cette fonction gere la partie link des fichiers
#
###################
sub gestion_mdp
{
 local ($mdp_info,$name,$file_solo) = @_;

# print "Je recois $mdp_info,$name,$file_solo\n";


 local($name_dest) = $name;
 $name_dest =~ s/(.*)\/([^\/]*)$/$1/is;
 local($file_dest) = $file_solo;
 $name_dest =~ s/$Source/$Dest/is;
 $sauve = $/;
 undef $/;

# print "J'ai $name_dest et $Parallele\n";
 local $ok_par = 0;
 if($Parallele ne "" && $parallele_ok)
  {
   $ok_par = 1;
   $file_dest .= ".$Parallele";
  }

 while($mdp_info =~ /(.*)<LIEN>(.*?)<\/LIEN>(.*)/gis)
  {
   local ($file) =  $2;
   if($ok_par eq "1")
    {$file = remplace_nom_parallele($file,$Parallele)}

   $mdp_info = $1;
   $file =~ s/\s*//gis;
   affiche( "Link => $file\n") if ($file ne '');

   if($name_dest =~ /.*$Dest\/(.*)/is)
    {&creation_repertoires("$1/$file")}
#   print "=-=>$file_dest\n";

   if($file =~ /(.*)\.\+\s*$/is)
    {
     local ($i_lien) = 0;
#	 print "$name_dest/$file_dest.$Les_Langues_Suf[0].html\n";
	 
	 if(!(-e "$name_dest/$file_dest.$Les_Langues_Suf[0].html"))
	  {
	   open (IN,"$name_dest/$file_dest.html");
	   if(-e "$name_dest/$1.html")
	    {unlink ("$name_dest/$1.html");}
	   open (OUT,">$name_dest/$1.html");
	   print OUT &change_path(<IN>,$name_dest,$1);
	   close (IN);
	   close (OUT);
	  }
	 else
	  {
	   while($Les_Langues_Suf[$i_lien])
	    {
		 open (IN,"$name_dest/$file_dest.$Les_Langues_Suf[$i_lien].html");
	     if(-e "$name_dest/$1.$Les_Langues_Suf[$i_lien].html")
	      {unlink ("$name_dest/$1.$Les_Langues_Suf[$i_lien].html");}
	     open (OUT,">$name_dest/$1.$Les_Langues_Suf[$i_lien].html");
	     print OUT &change_path(<IN>,$name_dest,$1);
		 close (IN);
	     close (OUT);
	     $i_lien++;
	    }
	  }
	}
   elsif($file =~ /(.*)\.(html?)\s*$/is)
    {
#	   print "$name_dest/$file_dest.html et $name_dest/$1.html\n";
	 if(!open (IN,"$name_dest/$file_dest.fr.html"))
	  {close (IN);
	   open (IN,"$name_dest/$file_dest.html")
	  }
	 if(-e "$name_dest/$1.$2")
	  {unlink ("$name_dest/$1.$2");}
	 open (OUT,">$name_dest/$1.$2");
	 print OUT &change_path(<IN>,$name_dest,$1);
		 close (IN);
	 close (OUT);
	}
  }
 $/ = $sauve; 

}

return 1;
