<?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");

/*********************************************************/
/* Fonctions pour les accès aux fichiers sous-traitants  */
/* et fichiers rattachés                                 */
/*********************************************************/

// Vérification du type de facturation sur un donneur d'ordre (par le CDG ou par le sous-traitant)
function mod_fact_st($code)
{
	$fact_st = 0;
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT * FROM " .TBST. " WHERE st_code = '$code'";
	$rs2 = mysql_query($rech2) or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
		$fact_age = $row2["st_fact"];
	}
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $fact_st;
}

// Vérification du nombre de sous-traitants actifs
function nb_st_actifs()
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBST. "`  WHERE `st_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 sous-traitants
function nb_st()
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBST. "`";
	$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 sous-traitant
function lit_enr_st($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT * FROM " .TBST. " WHERE st_code = '$code'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $row2;
}

// Vérification du nombre d'ordres sur un sous-traitant
function nb_ot_st($st)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	if ($st <> "")
		$rexist = "SELECT * FROM `" .TBOT. "` WHERE `ot_codest` = '".$st."'";
	else
		$rexist = "SELECT * FROM `" .TBOT. "`";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $nbexist;
}

// Vérification de la présence d'un donneur d'ordres dans un bon de travail
function exist_st_in_ot($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBOT. "` WHERE `ot_codest` = '$code'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if (mysql_num_rows($rs2) <> 0)
		$exist=TRUE;
	else
		$exist=FALSE;
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $exist;
}

// Vérification de la présence d'un donneur d'ordres dans un bon de travail non clôt
function exist_st_in_ot_ouv($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBOT. "` WHERE `ot_codest` = '$code' AND `ot_datefin` = '0000-00-00'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if (mysql_num_rows($rs2) <> 0)
		$exist=TRUE;
	else
		$exist=FALSE;
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $exist;
}

// Vérification de la présence d'un donneur d'ordres dans une fiche technicien non licencié
function exist_st_in_tec_present($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist= "SELECT * FROM `" .TBTEC. "` WHERE `tec_codest` = '$code' AND `tec_out` = '0'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if (mysql_num_rows($rs2) <> 0)
		$exist = TRUE;
	else
		$exist = FALSE;
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $exist;
}

// Vérification de la présence d'un donneur d'ordres dans une fiche technicien
function exist_st_in_tec($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist= "SELECT * FROM `" .TBTEC. "` WHERE `tec_codest` = '$code'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if (mysql_num_rows($rs2) <> 0)
		$exist = TRUE;
	else
		$exist = FALSE;
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $exist;
}

?>