<?php

class menu
{

# --------------------------
# ZONE GEOGRAPHIQUE
# --------------------------

	function select_zone_geo($selected)
	{
		$data = "<select name=\"id_zone\" id=\"id_zone\" size=\"1\">\n";
		$data .= "<option value=\"\">-- Choisir --</option>\n";

		$q = "SELECT * FROM zone_geo ORDER BY zone_nom ASC";
		$r = mysql_query($q);

		if ($r)
		{
			if ($t = mysql_num_rows($r))
			{
				while ($n = mysql_fetch_assoc($r))
					$data .= "<option value=\"" . $n["id_zone"] . "\"" . ($n["id_zone"] == $selected ? " selected" : "") . ">" . $n["zone_nom"] . "</option>\n";
			}
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		$data .= "</select>";

		return $data;
	}

	function list_zone_geo()
	{
		$data = array();

		$q = "SELECT * FROM zone_geo ORDER BY zone_nom ASC";
		$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_zone_geo($id_zone)
	{
		$q = "SELECT * FROM zone_geo WHERE id_zone = '" . $id_zone . "'";
		$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_zone_geo($id_zone, $zone_nom)
	{
		if ($id_zone)
			$q = "UPDATE zone_geo SET zone_nom = '" . sqldata($zone_nom) . "' WHERE id_zone = '" . $id_zone . "'";
		else
			$q = "INSERT INTO zone_geo (zone_nom) VALUES ('" . sqldata($zone_nom) . "')";
		$r = mysql_query($q);

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

		return false;
	}

	function del_zone_geo($id_zone)
	{
		$q = "DELETE FROM zone_geo WHERE id_zone = '" . $id_zone . "'";
		$r = mysql_query($q);

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

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

		return false;
	}

	function check_zone_geo($id_zone)
	{
		$q = "SELECT id_zone FROM patient WHERE id_zone = '" . $id_zone . "'";
		$r = mysql_query($q);

		if ($r)
		{
			if ($t = mysql_num_rows($r))
				return true;
				
			$q = "SELECT id_zone FROM utilisateur WHERE id_zone = '" . $id_zone . "'";
			$r = mysql_query($q);

			if ($r)
			{
				if ($t = mysql_num_rows($r))
					return true;
			}
			else
				die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());
			
		return false;
	}
	
# ---------------------------
# COUVERTURE SOCIALE
# ---------------------------

	function select_couv_soc($selected)
	{
		$data = "<select name=\"id_couv\" id=\"id_couv\" size=\"1\">\n";
		$data .= "<option value=\"\">-- Choisir --</option>\n";

		$q = "SELECT * FROM couv_soc ORDER BY couv_nom ASC";
		$r = mysql_query($q);

		if ($r)
		{
			if ($t = mysql_num_rows($r))
			{
				while ($n = mysql_fetch_assoc($r))
					$data .= "<option value=\"" . $n["id_couv"] . "\"" . ($n["id_couv"] == $selected ? " selected" : "") . ">" . $n["couv_nom"] . "</option>\n";
			}
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		$data .= "</select>";

		return $data;
	}

	function list_couv_soc()
	{
		$data = array();

		$q = "SELECT * FROM couv_soc ORDER BY couv_nom ASC";
		$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_couv_soc($id_couv)
	{
		$q = "SELECT * FROM couv_soc WHERE id_couv = '" . $id_couv . "'";
		$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_couv_soc($id_couv, $couv_nom)
	{
		if ($id_couv)
			$q = "UPDATE couv_soc SET couv_nom = '" . sqldata($couv_nom) . "' WHERE id_couv = '" . $id_couv . "'";
		else
			$q = "INSERT INTO couv_soc (couv_nom) VALUES ('" . sqldata($couv_nom) . "')";
		$r = mysql_query($q);

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

		return false;
	}

	function del_couv_soc($id_couv)
	{
		$q = "DELETE FROM couv_soc WHERE id_couv = '" . $id_couv . "'";
		$r = mysql_query($q);

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

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

		return false;
	}
	
	function check_couv_soc($id_couv)
	{
		$q = "SELECT id_couv FROM situpat WHERE id_couv = '" . $id_couv . "'";
		$r = mysql_query($q);
				
		if ($r)
		{
			if ($t = mysql_num_rows($r))
				return true;
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());
			
		return false;	
	}

# --------------
# SPECIALITE
# --------------

	function select_specialite($selected)
	{
		$data = "<select name=\"id_spe\" id=\"id_spe\" size=\"1\">\n";
		$data .= "<option value=\"\">-- Choisir --</option>\n";

		$q = "SELECT * FROM specialite ORDER BY spe_nom ASC";
		$r = mysql_query($q);

		if ($r)
		{
			if ($t = mysql_num_rows($r))
			{
				while ($n = mysql_fetch_assoc($r))
					$data .= "<option value=\"" . $n["id_spe"] . "\"" . ($n["id_spe"] == $selected ? " selected" : "") . ">" . $n["spe_nom"] . "</option>\n";
			}
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		$data .= "</select>";

		return $data;
	}

	function list_specialite()
	{
		$data = array();

		$q = "SELECT * FROM specialite ORDER BY spe_nom ASC";
		$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_specialite($id_spe)
	{
		$q = "SELECT * FROM specialite WHERE 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_specialite($id_spe, $spe_nom)
	{
		if ($id_spe)
			$q = "UPDATE specialite SET spe_nom = '" . sqldata($spe_nom) . "' WHERE id_spe = '" . $id_spe . "'";
		else
			$q = "INSERT INTO specialite (spe_nom) VALUES ('" . sqldata($spe_nom) . "')";
		$r = mysql_query($q);

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

		return false;
	}

	function del_specialite($id_spe)
	{
		$q = "DELETE FROM specialite WHERE id_spe = '" . $id_spe . "'";
		$r = mysql_query($q);

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

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

		return false;
	}

	function check_specialite($id_spe)
	{
		$q = "SELECT id_spe FROM correspondants WHERE id_spe = '" . $id_spe . "'";
		$r = mysql_query($q);
				
		if ($r)
		{
			if ($t = mysql_num_rows($r))
				return true;
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());
			
		return false;	
	}	
	
# ----------
# MODULE
# ----------

	function select_module($selected)
	{
		$data = "<select name=\"id_mod\" id=\"id_mod\" size=\"1\">\n";
		$data .= "<option value=\"\">-- Aucun --</option>\n";

		$q = "SELECT * FROM module ORDER BY mod_nom ASC";
		$r = mysql_query($q);

		if ($r)
		{
			if ($t = mysql_num_rows($r))
			{
				while ($n = mysql_fetch_assoc($r))
					$data .= "<option value=\"" . $n["id_mod"] . "\"" . ($n["id_mod"] == $selected ? " selected" : "") . ">" . $n["mod_nom"] . "</option>\n";
			}
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());

		$data .= "</select>";

		return $data;
	}

	function list_module()
	{
		$data = array();

		$q = "SELECT * FROM module ORDER BY mod_nom ASC";
		$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_module($id_mod)
	{
		$q = "SELECT * FROM module WHERE id_mod = '" . $id_mod . "'";
		$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_module($id_mod, $mod_nom)
	{
		if ($id_mod)
			$q = "UPDATE module SET mod_nom = '" . sqldata($mod_nom) . "' WHERE id_mod = '" . $id_mod . "'";
		else
			$q = "INSERT INTO module (mod_nom) VALUES ('" . sqldata($mod_nom) . "')";
		$r = mysql_query($q);

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

		return false;
	}

	function del_module($id_mod)
	{
		$q = "DELETE FROM module WHERE id_mod = '" . $id_mod . "'";
		$r = mysql_query($q);

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

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

		return false;
	}

	function check_module($id_mod)
	{
		$q = "SELECT id_mod FROM proposition WHERE id_mod = '" . $id_mod . "'";
		$r = mysql_query($q);
				
		if ($r)
		{
			if ($t = mysql_num_rows($r))
				return true;
		}
		else
			die("Erreur mécanique " . mysql_errno() . " : " . mysql_error());
			
		return false;	
	}
}

?>