<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/espace_personnel/inc/head-lib.php');

$sql = dbquery("SELECT * FROM cv_diplomes WHERE id_cv = '".$_SESSION['user']['id_cv']."' AND id_diplome_cv= '".$_GET['id_diplome']."' ");

if(dbnumrows($sql)>0){
	$type				= dbresult($sql,0,'type');
	$code_diplome		= dbresult($sql,0,'code_diplome');
	$specialite			= dbresult($sql,0,'specialite');
	$etablissement		= dbresult($sql,0,'etablissement');
	$intitule			= dbresult($sql,0,'intitule');
	$lieu_delivrance	= dbresult($sql,0,'lieu_delivrance');
	$annee_obtention	= dbresult($sql,0,'annee_obtention');
}

else{
	$type				= '';
	$code_diplome		= '';
	$specialite			= '';
	$etablissement		= '';
	$intitule			= '';
	$lieu_delivrance	= '';
	$annee_obtention	= '';
}

if(isset($_GET['id_diplome'])){
	$id_diplome = $_GET['id_diplome'];
	$display	= '';
}
else{
	$id_diplome = "new";
	$display	= 'display:none;';
}

?>

<style>
label {width:40%;}
 </style>

<form action="update_diplome.php?tab=2" method="POST" class="valid_form">
	
	<input type="hidden" name="id_diplome" value="<?php echo $id_diplome;?>"/>

	<label>Type de diplôme : </label>
	<select name="diplome_type" id="diplome_type" style="width:220px;">
		<option value="null">Choisir...</option>
		<option value="0" <?php if($type==0) echo 'selected';?>>Diplôme de l'enseignement secondaire français <u>obtenu</u></option>
		<option value="1" <?php if($type==1) echo 'selected';?>>Diplôme de l'enseignement supérieur français <u>obtenu</u></option>
		<option value="2" <?php if($type==2) echo 'selected';?>>Diplôme etranger <u>obtenu</u></option>
		<option value="3" <?php if($type==3) echo 'selected';?>>Diplôme préparé <u>en cours de validation</u></option>
		<option value="4" <?php if($type==4) echo 'selected';?>>Autre formation suivie <u>sanctionnées par un certificat ou diplôme d'établissement ou attestation de suivi</u></option>
	</select>
	<br><br>
	<label id="diplome_label" style="<?php echo $display;?>">Diplôme : </label>

	<?php
		for($i=0;$i<5;$i++){
			if($type <> $i)	$display_2 = 'display:none;';
			else			$display_2 = '';
			$select = str_replace('<select','<select class="diplome_select" id="diplome_select_'.$i.'" style="width:220px;'.$display.$display_2.'"',$_SELECT['select']['diplome_intitule'][$i]);
			$select = str_replace('value="'.$code_diplome.'"','value="'.$coe_diplome.'" selected ',$select);
			echo $select;
		}
		
		$select_specialite = str_replace('<select','<select style="width:220px;"',$_SELECT['select']['diplome_specialites']);
		$select_specialite = str_replace('value="'.$specialite.'"','value="'.$specialite.'" selected ',$select_specialite);

		echo '
			<div id="diplome_form" style="'.$display.'"><br>
				<label id="specialite_label">Spécialité : </label>
				'.$select_specialite.'<br><br>
				<label>Intitulé exact :</label>
					<input type="text" style="width:220px;" name="intitule" required="required" value="'.$intitule.'"/><br><br>
				<label>Établissement / Institution :</label>
					<input type="text" style="width:220px;" name="etablissement" required="required" value="'.$etablissement.'"/><br><br>
				<label>Lieu de délivrance :</label>
					<input type="text" style="width:220px;" name="lieu_delivrance" required="required" value="'.$lieu_delivrance.'"/><br><br>
				<label>Année d\'obtention :</label>
					<input type="text" style="width:100px;" name="annee_obtention" required="required" value="'.$annee_obtention.'" maxlength="4"/>
				<br><br>
				<label></label><input class="bg-red" type="submit" value="Valider" />
			</div>
		';
	?>
</form>

<script>
	function diplome(){
		$('#diplome_type').change(function(){
			var select_value = $(this).val();	
			$('.diplome_select').hide();
			$('#diplome_label').fadeIn('fast');
			$('#diplome_select_'+select_value).fadeIn('fast');
			$('#diplome_form').fadeIn('fast');
		});
	}

	$(window).load(diplome());
</script>
