<?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 agences  */
/* et fichiers rattachés                          */
/**************************************************/

/** Catégories **/

// Vérification du nombre de catégories d'agences
function nb_acat()
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBACAT;
	$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 catégorie agence
function lit_enr_acat($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT * FROM " .TBACAT. " WHERE acat_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;
}

/** Agences **/

// Vérification du nombre d'interventions sur une agence
function nb_int($agence)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	if ($agence <> "")
		$rexist = "SELECT * FROM `" .TBINT. "` WHERE `int_codeage` = '".$agence."'";
	else
		$rexist = "SELECT * FROM `" .TBINT. "`";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $nbexist;
}

// Vérification du type de facturation sur une agence (par le CDG ou par l'agence)
function mod_fact_age($code)
{
	$age_fact = 0;
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT age_fact FROM " .TBAGE. " WHERE age_code = '$code'";
	$rs2 = mysql_query($rech2) or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
		extract($row2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $age_fact;
}

// Vérification si une agence peut louer
function age_loc_ok($code,$open)
{
	$age_loc = 0;
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech2 = "SELECT age_loc FROM " .TBAGE. " WHERE age_code = '$code'";
	$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 $age_loc;
}

// Vérification du nombre d'agences actives
function nb_age_actives()
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBAGE. "`  WHERE `age_ouvert` = '1'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $nbexist;
}

// Vérifie si un client (ou un  de ses sites secondaires) est bien géré par une agence (dans le département couvert
// et pas déjà géré par une autre agence)
// $ouvrir : TRUE -> On ouvre et on referme le fichier
function client_age_ok($client,$agence,$ouvrir)
{
	$result = FALSE;
	
	if ($ouvrir==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	// On lit le client
	$rech = "SELECT * FROM `" .TBCLI. "` WHERE `cli_code` = '".$client."'";
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) >0)
	{
		if ($res = mysql_fetch_array($rs)) 
		{
			extract($res);
			if ($cli_prop<>NULL) // Ce client est affecté à une agence
			{
				// Ce client n'est pas affecté à cette agence, on vérifie si elle gère un site secondaire de ce client
				if ($cli_prop<>$agence)
				{
					// Il y a des sites secondaires ?
					$rech1 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_codecli` = '".$client."'";
					$rs1 = mysql_query($rech1) or die(mysql_error());
					if (mysql_num_rows($rs1) >0) // Oui...on vérifie
					{
						$rech2 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_codecli` = '".$client."' AND `scli_prop` = '".$agence."'";
						$rs2 = mysql_query($rech2) or die(mysql_error());
						if (mysql_num_rows($rs2) >0)
							return TRUE;
						else // Elle n'en gère pas, on vérifie qu'elle ne couvre pas un site noté comme "agences couvrant ce département"
						{
							$rech3 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_codecli` = '".$client."' AND `scli_prop` = '-1'";
							$rs3 = mysql_query($rech3) or die(mysql_error());
							if (mysql_num_rows($rs3) >0)
							{
								while ($row3 = mysql_fetch_array($rs3)) 
								{
									extract($row3);
									$rech4 = "SELECT * FROM `" .TBZCC. "` WHERE `zcc_code` = '".$agence."' AND `zcc_codepays` = '".$scli_codepays."' AND `zcc_codedep` = '".$scli_dep."'";
									$rs4 = mysql_query($rech4) or die(mysql_error());
									if (mysql_num_rows($rs4) > 0)
										return TRUE;
									mysql_free_result($rs4);
								}
							}
							mysql_free_result($rs3);
						}
						mysql_free_result($rs2);
					}
					mysql_free_result($rs1);
				}
				else
					return TRUE;
			}
			// On lit l'agence pour vérifier si les départements sont ok
			else
			{
				$rech3 = "SELECT * FROM `" .TBZCC. "` WHERE `zcc_code` = '".$agence."' AND `zcc_codepays` = '".$cli_codepays."' AND `zcc_codedep` = '".$cli_dep."'";
				$rs3 = mysql_query($rech3) or die(mysql_error());
				if (mysql_num_rows($rs3) > 0)
					return TRUE;
				mysql_free_result($rs3);
			}
		}
	}
	mysql_free_result($rs);
	if ($ouvrir==TRUE)
		mysql_close($conn2);
	return $result;
}

// Donne le niveau de gestion du client
// -1 : Rien autorisé
// 0 : lecture seule (site principal)
// 9 : tout autorisé
function nivges_cli($client,$agence,$ouvrir)
{
	global
		$_SESSION;
	$nivges = -1;
	
	switch ($_SESSION["niv_log"])
	{
		case 3 :
		case 4 :
			if ($ouvrir==TRUE)
			{
				$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
			}
			// On lit le client
			$rech = "SELECT * FROM `" .TBCLI. "` WHERE `cli_code` = '".$client."' AND (`cli_prop` = '".$agence."' OR `cli_prop` IS NULL)";
			$rs = mysql_query($rech) or die(mysql_error());
			if (mysql_num_rows($rs) >0)
			{
				if ($res = mysql_fetch_array($rs)) 
				{
					extract($res);
					// Ce client n'est pas affecté à cette agence, on vérifie si elle gère un site secondaire
					if ($cli_prop<>$agence)
					{
						$rech2 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_codecli` = '".$client."' AND `scli_prop` = '".$agence."'";
						$rs2 = mysql_query($rech2) or die(mysql_error());
						if (mysql_num_rows($rs2) >0)
							$nivges=0;
						// Ce client ou un de ses sites secondaires ne sont pas affectés à cette agence,
						// on lit l'agence pour vérifier si les départements sont ok
						else
						{
							$rech3 = "SELECT * FROM `" .TBZCC. "` WHERE `zcc_code` = '".$agence."' AND `zcc_codepays` = '".$cli_codepays."' AND `zcc_codedep` = '".$cli_dep."'";
							$rs3 = mysql_query($rech3) or die(mysql_error());
							if (mysql_num_rows($rs3) > 0)
								$nivges=9;
							mysql_free_result($rs3);
						}
						mysql_free_result($rs2);
					}
					else
						$nivges=9;
				}
			}	
			mysql_free_result($rs);
			if ($ouvrir==TRUE)
				mysql_close($conn2);
			break;
		case 5 :
		case 9 :
			$nivges=9;
			break;
	}
	
	return $nivges;
}

// Donne le nombre d'agences
function nb_age()
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBAGE. "`";
	$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 agence
function lit_enr_age($code,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech2 = "SELECT * FROM " .TBAGE. " WHERE age_code = '$code'";
	$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;
}

// Vérification de la présence d'une agence dans un contrat non clôt
function exist_age_in_cocl_ouv($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBCOCL. "` WHERE `cocl_codeage` = '$code' AND `cocl_signe` IS NOT NULL AND `cocl_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'une agence dans une fiche intervention
function exist_age_in_int($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBINT. "` WHERE `int_codeage` = '$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'une agence dans une fiche intervention non close
function exist_age_in_int_ouv($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBINT. "` WHERE `int_codeage` = '$code' AND `int_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'une agence dans une fiche technicien non licencié
function exist_age_in_tec_present($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist= "SELECT * FROM `" .TBTEC. "` WHERE `tec_codeage` = '$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'une agence dans une fiche technicien
function exist_age_in_tec($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist= "SELECT * FROM `" .TBTEC. "` WHERE `tec_codeage` = '$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'une agence dans un dépôt de location
function exist_age_in_dloc($code,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rexist = "SELECT * FROM `" .TBDLOC. "` WHERE `dloc_codeage` = '$code'";
	$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'une agence dans un contrat de location
function exist_age_in_coloc($code,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rexist = "SELECT * FROM ".TBCOLOC;
	$rexist.= " WHERE coloc_codeage = '$code'";
	$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'une agence dans un contrat de location ouvert
function exist_age_in_coloc_ouv($code,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rexist = "SELECT * FROM " .TBCOLOC;
	$rexist.= " WHERE coloc_codeage = '$code'";
 	$rexist.= " AND coloc_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);
	if ($open==TRUE)
		mysql_close($conn2);
	
	return $exist;
}


/** Contacts Agences **/

// Vérification du nombre de contacts dans une fiche agence
function nb_cage_in_age($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBCAGE. "` WHERE `cage_codeage` = '$code'";
	$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 contact agence
function lit_enr_cage_id_in_age($id,$code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "SELECT * FROM `" .TBCAGE. "` WHERE `cage_id` = '$id' AND `cage_codeage` = '$code'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);

	return $row2;
}

// Suppression des contacts dans une fiche agence
function del_cage_in_age($code)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rexist = "DELETE FROM `" .TBCAGE. "` WHERE `cage_codeage` = '$code'";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	mysql_close($conn2);
}


/* Prix de revient */

// Vérification du nombre de prix de revient enregistrés pour une agence
function nb_agepr($age,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	if ($age <> "")
		$rexist = "SELECT * FROM `" .TBAGEPR. "` WHERE `agepr_codeage` = '".$age."'";
	else
		$rexist = "SELECT * FROM `" .TBAGEPR. "`";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);

	return $nbexist;
}

// Vérification s'il y a un problème de prix de revient pour les responsables des agences ouvertes
function pbm_agespr($open)
{
	$pbm=0;
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	$rech2 = "SELECT age_code FROM `" .TBAGE. "` WHERE age_ouvert='1'";
	$rs2 = mysql_query($rech2) or die(mysql_error());
	if (mysql_num_rows($rs2) > 0)
	{
		if ($row2 = mysql_fetch_array($rs2))
		{
			extract($row2);
			$rech3 = "SELECT * FROM `" .TBAGEPR. "` WHERE `agepr_codeage` = '".$age_code."'";
			$rs3 = mysql_query($rech3) or die(mysql_error());
			if (mysql_num_rows($rs3) == 0)
			{
				$pbm=1;
				return $pbm;
			}
			mysql_free_result($rs3);
		}
	}
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);

	return $pbm;
}

// Lecture d'un enregistrement prix de revient agence
function lit_enr_agepr($id)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT * FROM `" .TBAGEPR. "` WHERE `agepr_id` = '$id'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $row2;
}

// Retourne le dernier enregistrement d'un prix de revient agence
function last_id_agepr($code)
{
	$agepr_id=0;
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT agepr_id FROM `" .TBAGEPR. "` WHERE `agepr_codeage` = '$code' ORDER BY agepr_id DESC";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
		extract($row2);
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $agepr_id;
}

// Retourne la dernière date de modif d'un prix de revient agence
function last_date_agepr($id)
{
	global
		$datea;
	$agepr_date=$datea;
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT agepr_date FROM `" .TBAGEPR. "` WHERE `agepr_id` = '$id'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
		extract($row2);
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $agepr_date;
}

// Vérification du nombre de prix de revient enregistrés pour un contact agence
function nb_cagepr($idcage,$open)
{
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	if ($agence <> "")
		$rexist = "SELECT * FROM `" .TBCAGEPR. "` WHERE `cagepr_idcage` = '".$idcage."'";
	else
		$rexist = "SELECT * FROM `" .TBCAGEPR. "`";
	$rs2 = mysql_query($rexist) or die(mysql_error());
	$nbexist = mysql_num_rows($rs2);
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);

	return $nbexist;
}

// Vérification s'il y a un problème de prix de revient pour les contacts d'une agence
function pbm_cagespr($idcage,$open)
{
	$pbm=0;
	if ($open==TRUE)
	{
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
	}
	if ($agence <> "")
		$rech2 = "SELECT cage_id FROM `" .TBCAGE. "` WHERE `cage_codeage` = '".$agence."'";
	else
		$rech2 = "SELECT cage_id FROM `" .TBCAGE. "`";
	$rs2 = mysql_query($rech2) or die(mysql_error());
	if (mysql_num_rows($rs2) > 0)
	{
		if ($row2 = mysql_fetch_array($rs2))
		{
			extract($row2);
			$rech3 = "SELECT * FROM `" .TBCAGEPR. "` WHERE `cagepr_idcage` = '".$cage_id."'";
			$rs3 = mysql_query($rech3) or die(mysql_error());
			if (mysql_num_rows($rs3) == 0)
			{
				$pbm=1;
				return $pbm;
			}
			mysql_free_result($rs3);
		}
	}
	mysql_free_result($rs2);
	if ($open==TRUE)
		mysql_close($conn2);

	return $pbm;
}

// Lecture d'un enregistrement prix de revient pour un contact agence
function lit_enr_cagepr($id)
{
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT * FROM `" .TBCAGEPR. "` WHERE `cagepr_id` = '$id'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
	{
	}
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $row2;
}

// Retourne le dernier enregistrement d'un prix de revient contact agence
function last_id_cagepr($id)
{
	$cagepr_id=0;
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT cagepr_id FROM `" .TBCAGEPR. "` WHERE `cagepr_idcage` = '$id' ORDER BY cagepr_id DESC";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
		extract($row2);
	mysql_free_result($rs2);
	mysql_close($conn2);
	return $cagepr_id;
}

// Retourne la dernière date de modif d'un prix de revient contact agence
function last_date_cagepr($id)
{
	global
		$datea;
	$cagepr_date=$datea;
	$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech2 = "SELECT cagepr_date FROM `" .TBCAGEPR. "` WHERE `cagepr_id` = '$id'";
	$rs2 = mysql_query($rech2)or die(mysql_error());
	if ($row2 = mysql_fetch_array($rs2))
		extract($row2);
	mysql_free_result($rs2);
	mysql_close($conn2);
	
	return $cagepr_date;
}


?>
