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

Version 0.9.9

Copyright (C) 2006-2009  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");

/************************************************************/
/* Fonctions pour les accès aux fichiers dépôts de location */
/************************************************************/

// Vérification du nombre de dépôts actifs
function nb_dloc_actifs()
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBDLOC. "`  WHERE `dloc_ouvert` = '1'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $nbexist;
}

// Donne le nombre de dépôts
function nb_dloc()
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBDLOC. "`";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $nbexist;
}

// Lecture d'un enregistrement dépôt
function lit_enr_dloc($nom)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT * FROM " .TBDLOC. " WHERE dloc_nom = '$nom'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $row2;
}

// Lecture d'un enregistrement dépôt par son id
function lit_enr_dloc_id($id,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech2 = "SELECT * FROM " .TBDLOC. " WHERE dloc_id = '$id'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);
	
	return $row2;
}

// Donne le numéro d'ID du dépôt principal d'une agence
function id_dloc_page($age,$open)
{
	$dloc_id=-1;
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech2 = "SELECT dloc_id FROM " .TBDLOC. " WHERE dloc_codeage = '$age'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
		extract($row2);
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);
	
	return $dloc_id;
}

// Vérification de la présence d'un dépôt dans un produit à louer
function exist_dloc_in_pdtloc($nom,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rexist = "SELECT * FROM " .TBDLOC. ", ".TBPDTLOC;
	$rexist.= " WHERE dloc_nom = '$nom'";
	$rexist.= " AND ".TBDLOC.".dloc_id = ".TBPDTLOC.".pdtloc_iddloc";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if (mysql_num_rows($rs2) <> 0)
		$exist=TRUE;
	else
		$exist=FALSE;
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);
	
	return $exist;
}

// Vérification de la présence d'un dépôt dans un produit louable
function exist_dloc_in_pdtloc_louable($nom,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rexist = "SELECT * FROM " .TBDLOC. ", ".TBPDTLOC;
	$rexist.= " WHERE ".TBDLOC.".dloc_nom = '$nom'";
	$rexist.= " AND ".TBDLOC.".dloc_id = ".TBPDTLOC.".pdtloc_iddloc";
 	$rexist.= " AND ".TBPDTLOC.".pdtloc_louable = '1'";
 	$rs2 = mysql_query($rexist) or die(mysql_error());
	if (mysql_num_rows($rs2) <> 0)
		$exist=TRUE;
	else
		$exist=FALSE;
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);
	
	return $exist;
}


?>