<?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
****************************************************************************************/

/***************************************************************************/
/* Récupération contacts donneur d'ordre en fonction code donneur d'ordres */
/***************************************************************************/

session_start(); 
sleep(1);
if (array_key_exists("do", $_REQUEST))
{
	$tomorrow = 0;//60*60*24; // en nb de secondes
	header("Cache-Control: max-age=$tomorrow");
	print_plain();
}
else
{
	print "Usage : $_SERVER[PHP_SELF]?do=un-code-donneur-ordre";
}

function print_plain()
{
	include_once("../inc/fic_hum.inc.php");
	header("Content-type: text/html; charset=windows-1252");
	$cdo = get_cdo($_REQUEST["do"]);
	$result = array();
	foreach ($cdo as $row)
	{
		$txt = $row["cdo_nom"]." ".$row["cdo_prenom"];
		$row2=lit_enr_fonc($row["cdo_codefonc"],TRUE);
		if (is_array($row2))
		{
			extract($row2);
			$txt_fonc=$fonc_desc;
		}
		else
			$txt_fonc=$row["cdo_codefonc"];
		$txt.=" (".$txt_fonc.")";
		$result[] = $row["cdo_id"]."=".$txt;
	}
	print implode(";", $result);
}

function get_cdo($do)
{
	if (!isset($_SESSION["lng"])) $_SESSION["lng"]="fr";
	include_once("../lng/".$_SESSION["lng"].".inc.php"); // Paramètres de language
	include_once("../inc/config.inc.php");
	// On se connecte a la base
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$result = array();
	// On recupere les contacts sur le donneur d'ordres
	$rech = "SELECT * FROM ".TBCDO." WHERE cdo_codedo='".$do."' ORDER BY cdo_nom";
	$rs = mysql_query($rech) or die(mysql_error());
	while ($row = mysql_fetch_array($rs))
	{
		$result[] = $row;
	}
		
	mysql_close();
	return $result;
}

?>