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

//echo "<pre>";print_r($_POST);echo "</pre>";

// DATAS									
	
	// Type de contrat
	if( $_POST['type_contrat'] == 'Autre')	$autre_type = $_POST['autre_type'];
	else									$autre_type = '';

	// debut contrat
	$_DATE			= explode(' / ',$_POST['debut_contrat']);
	$debut_contrat	= $_DATE[2].'/'.$_DATE[1].'/'.$_DATE[0];


// NOUVELLE ENTREE

		dbquery("INSERT INTO site_offres(id_entreprise) VALUES('".$_SESSION['entreprise']['id']."')");

		$sql = dbquery("SELECT * FROM site_offres WHERE id_entreprise ='".$_SESSION['entreprise']['id']."' ORDER BY id_offre DESC LIMIT 1");

		$id_offre = dbresult($sql,0,"id_offre");


// UPDATE
		
		$date = date("Y-m-d");

		$q= "	UPDATE	site_offres

				SET		intitule				= '".addslashes($_POST['intitule'])."',
						duree_contrat			= '".addslashes($_POST['duree_contrat'])."',
						remuneration_mensuelle	= '".addslashes($_POST['remuneration_mensuelle'])."',
						diplomes_exiges			= '".addslashes($_POST['diplomes_exiges'])."',
						competences_exigees		= '".addslashes($_POST['competences_exigees'])."',
						type_contrat			= '".addslashes($_POST['type_contrat'])."',
						autre_type				= '".addslashes($autre_type)."',
						debut_contrat			= '".addslashes($debut_contrat)."',
						commune					= '".addslashes($_POST['commune'])."',
						objectifs				= '".addslashes($_POST['objectifs'])."',
						descriptif				= '".addslashes($_POST['descriptif'])."',
						missions				= '".addslashes($_POST['missions'])."',
						niveau_formation		= '".addslashes($_POST['niveau_formation'])."',
						contact_civilite		= '".addslashes($_POST['contact_civilite'])."',
						contact_nom				= '".addslashes($_POST['contact_nom'])."',
						contact_prenom			= '".addslashes($_POST['contact_prenom'])."',
						contact_fonction		= '".addslashes($_POST['contact_fonction'])."',
						contact_service			= '".addslashes($_POST['contact_service'])."',
						contact_tel				= '".addslashes($_POST['contact_tel'])."',
						contact_mail			= '".addslashes($_POST['contact_mail'])."',
						modalites				= '".addslashes($_POST['modalites'])."',
						date_enregistrement		= '".$date."'

				WHERE	id_offre = '".$id_offre."'
			";

		//echo $q;

		dbquery($q);
		
		// MAIL

		$contenu_mail = "
		Une offre a été déposée via l'Espace Entreprises.<br><br>

		<a href='http://www.cnam.re/base_adm/site/etat/entreprises/index.php?id_entreprise=".$id_offre."#2'>Cliquer ici pour accéder directement à l'offre.</a>
		<br><br>
		";
		
		$headers	='From: Espace Entreprises - cnam.re'."\n";
		$headers	.='Content-Type:text/html; charset="iso-8859-1"'."\n"; 
		$headers	.='Content-Transfer-Encoding: 8bit';
		$objet		="Dépôt d'une offre";
		
		mail("al.lafont@gmail.com",$objet,utf8_decode($contenu_mail),$headers);
		//mail("al.lafont@gmail.com",$objet,utf8_decode($contenu_mail),$headers);
		//mail("cdandrea@cnam.re",$objet,utf8_decode($contenu_mail),$headers);

		//Header("Location: offre_confirm.php");

?>