<?php

class correspondants
{

	function list_correspondants($id_consult)
	{
		$data = array();

		$q = "SELECT * FROM correspondants WHERE id_consult = '" . $id_consult . "'";
		$r = mysql_query($q);

		if ($r)
		{
			if ($t = mysql_num_rows($r))
			{
				while ($n = mysql_fetch_assoc($r))
					$data[] = $n;
			}
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		return $data;
	}

	function get_correspondants($id_consult, $id_spe)
	{
		$q = "SELECT * FROM correspondants WHERE id_consult = '" . $id_consult . "' && id_spe = '" . $id_spe . "'";
		$r = mysql_query($q);

		if ($r)
		{
			$n = mysql_fetch_assoc($r);
			return $n;
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		return false;
	}

	function edit_correspondants($id_consult, $id_spe, $corres_coords, $corres_reseau)
	{
		$q = "INSERT INTO correspondants (id_consult, id_spe, corres_coords, corres_reseau) VALUES ('" . $id_consult . "', '" . $id_spe . "' , '" . sqldata($corres_coords) . "' , '" . $corres_reseau . "')";
		$r = mysql_query($q);

		if ($r) 
			return true;
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		return false;
	}

	function purge_correspondants($id_consult)
	{
		$q = "DELETE FROM correspondants WHERE id_consult = '" . $id_consult . "'";
		$r = mysql_query($q);

		if ($r) 
			return true;
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		return false;
	}

	function del_correspondants($id_consult, $id_spe)
	{
		$q = "DELETE FROM correspondants WHERE id_consult = '" . $id_consult . "' && id_spe = '" . $id_spe . "'";
		$r = mysql_query($q);

		if ($r)
		{
			$q = "OPTIMIZE TABLE correspondants";
			$r = mysql_query($q);

			return true;
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		return false;
	}

}

?>