<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.7

Copyright (C) 2006-2007  Sylvain FATOME
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.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/


// Vérification des tentatives de hack
$pos=strpos($_SERVER['PHP_SELF'],"inc.php");
if ($pos===FALSE)
	$ok_inc=TRUE;
else
	$ok_inc=FALSE;
if ($ok_inc==FALSE) header("Location: ../index.php");

/************************************/
/* Gestion des fichiers/répertoires */
/************************************/

// Donne le chemin parent d'un fichier ou répertoire
function donne_chemin_parent($nom_ficdir)
{
	$chemin_parent="";
	$tab_chemin=explode("/",$nom_ficdir);
	for ($i=0; $i<count($tab_chemin)-1; $i++)
	{
		$chemin_parent.="/".$tab_chemin[$i];
	}

	return $chemin_parent;	
}


// Donne le nom du chemin parent d'un fichier ou répertoire
function donne_nom_chemin_parent($nom_ficdir)
{
	global
		$url_gfc;
		
	$nom_chemin_parent="";
	$chemin_parent=donne_chemin_parent($nom_ficdir);
	if ($chemin_parent<>"")
	{
		$row= lit_enr_fic($url_gfc.$chemin_parent);
		if (is_array($row))
		{
			extract($row);
			$nom_chemin_parent=$fic_desc;
		}
		else
			$nom_chemin_parent="Non référencé";
	}
	else
		$nom_chemin_parent="Répertoire principal";
		
	return $nom_chemin_parent;
}


// Donne la liste des dossiers d'un répertoire
function Recup_dossiers($dir)
{
	if(is_dir($dir))
	{
		$d = dir($dir);
		while (false !== ($entry = $d->read()))
		{
			if(($entry!='.') AND ($entry!='..') AND (is_dir($dir.'/'.$entry)))
			{
				$ssrep = $dir.'/'.$entry;
				if (is_dir($ssrep))
				{
					$subdirs = Recup_dossiers($ssrep);
					if ($subdirs)
					{
						$tab_dir[] = $ssrep;
						$tab_dir = array_merge($tab_dir, $subdirs);
					}
					else
						$tab_dir[] = $ssrep;
				}
			}
		}
		$d->close();
	}
	return $tab_dir;
}

// Renvoie vrai si le répertoire est vide
// Faux s'il contient des répertoires ou des fichiers
function is_empty_folder($dir) 
{
	if ($dl = opendir($dir))
	{
		while (false !== ($file = readdir($dl)))
		{
			if (($file <> ".") AND ($file <> "..") AND ($file<>".htaccess"))
			{
				if (is_dir("$dir/$file") OR is_file("$dir/$file"))
				{
					return false;
					break;
				}
			}
		}
	closedir($dl);
	}
	return true;
}


?>