<?php
session_start();
if(!isset($_SESSION['auth'])) {
	header("location:index.php");
}

require_once("../inc/confNetisse.php");
require_once("./functions.php");

$PID = 0;
if(!isset($_GET["did"])) {
	header("location:drList.php");
} else {
	$DID = intval($_GET["did"]);
}
$direction = getDrByID($DID);
if($direction == null) header("location:drList.php");
?>

<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><?php echo $PROJECT_TITLE;?> : Edition d'une direction</title>
	<link rel="stylesheet" href="css/font-awesome.min.css" />
	<link rel="stylesheet" type="text/css" href="css/cadif.css" />
	<link rel="stylesheet" type="text/css" href="css/dashboard.css" />
	<link rel="stylesheet" type="text/css" href="css/cans/jquery-ui-1.8.17.custom.css" />
	<!--<link rel="stylesheet" type="text/css" href="css/tableTools_jui.css" />-->
	<link rel="stylesheet" type="text/css" href="css/datatable_jui.css" />

	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="js/jquery-ui-1.8.22.custom.min.js"></script>
	<script type="text/javascript" src="js/jquery.dataTables.js"></script>
	<script type="text/javascript">
		function delDr() {
			if (confirm("Etes-vous sûr de vouloir supprimer cette direction ?")) {
				document.getElementById("supp").value = 1;
				document.formAgencyUpd.submit();
			} else {
				document.getElementById("supp").value = 0;
			}

		}

		function checkForm() {
			if (document.getElementById("nom").value == "") {
				var POP = $('<div></div>').html("<center>Vous devez renseigner le champ 'Nom'.</center>").dialog({autoOpen: false,title: 'Erreur'});
				POP.dialog({autoOpen:false, modal:true, draggable: false, width:360,close:function(ev, ui){document.getElementById("nom").focus();} });
				POP.dialog("open");
			} else {
				document.formAgencyUpd.submit();
			}
		}
		function addSecteur(){
			window.location.href = "secteurNew.php?pid=<?php echo $PID;?>";
		}
	</script>
</head>


<body>

	<div id="global">

		<div id="home">
			<div id="logo"><a href="dashboard.php"><img src="<?php echo $SERVER; ?>assets/img/logo.png" height="110" border="0"/></a></div>
			<div id="username">
				<b><?php echo isset($_SESSION["nom"]) ? $_SESSION["nom"] : $_SESSION["matricule"];?></b> &nbsp; | &nbsp; <a href="close.php" class="link" title="Fermer et clore votre session">D&#233;connexion</a>
				<br/>
			</div>
		</div>
		<div id="panels">
			<?php include "menu.php";?>
			<div class="main-content">
				<div id="title">
					Edition d'une direction
				</div>
				<div id="form">
		<form name="formAgencyUpd" id="formAgencyUpd" action="do.php" method="post">
			<input type="hidden" name="act" value="drUpd"/>
			<input type="hidden" name="did" value="<?php echo $DID; ?>"/>
			<input type="hidden" name="supp" id="supp" value="0"/>

			<table align="center" class="form">
			<tr>
			<td width="100">Nom de la direction</td>
			<td><input type="text" name="nom" id="nom" size="30" tabindex="1" value="<?php echo $direction->nom_dr; ?>"/></td>
			</tr>
			<tr>
			<td colspan="2">
				<br/><br/>
				<input type="button" class="formAct" name="supprimer" id="supprimer" value="Supprimer" onclick="delDr();" tabindex="9"/>
				&nbsp;&nbsp;<input type="button" class="formAct" name="valider" id="valider" value="Valider" onclick="checkForm();" tabindex="8"/>
				&nbsp;&nbsp;<input type="button" class="formAct2" name="ajouter" id="ajouter" value="Ajouter un secteur" onclick="addSecteur();" tabindex="9"/></td>
			</tr>
			</table>
		</form>
		</div>
	</div>

</div>

			<?php include 'footer.php';?>
<script>
document.getElementById('nom').focus();
</script>

</body>

</html>