<?php 

	include('config/config_DB.php');
	
	$action = $_GET['action'];
	
	if($action == 'project')
	{
		$categorie = $_POST['categorie'];
		$projet_name = $_POST['pname'];
		$location = $_POST['location'];
		//$description = mysqli_real_escape_string($_POST['description']);
		$description = $_POST['description'];
		$client = $_POST['client'];
		$project_manager =$_POST['project_manager'];
		$design_leader =$_POST['design_leader'];
		$start_date =$_POST['start_date'];
		$end_date =$_POST['end_date'];
		
		$query = "INSERT INTO appli_projects (categorie, project,location,
		description, client, project_manager, design_leader ,start_date,end_date,date_added)
		VALUES('$categorie', '$projet_name','$location','$description','$client',
		'$project_manager','$design_leader','$start_date','$end_date',now() )";
		
		mysqli_query($connexion, $query);
		
		/*$query = mysqli_query($conn,"INSERT INTO projects (project,location,overall_cost,start_date,deadline,site_pic,tid,date_added,io,proposed_project)
		VALUES('$pname','$location','$cost','$sdate','$deadline','$file','$tid',now(),'1','$p_type')");
		*/
		
		/*$last_id = mysqli_insert_id($conn);
		
		if(isset($_POST['divs']))
		{

			$divs= $_POST['divs'];
			$cd = count($divs);
			for($i=0; $i < $cd; $i++)
			{
				$query2 = mysqli_query($conn,"INSERT INTO project_partition (project_id,pd_id)
				VALUES('$last_id','$divs[$i]')");
			}
		}
	
		if($query && $query2)
		{
			echo '<script>$("#suc_msg2").show("slidedown");
			var delay = 1500;
                    setTimeout(function(){  window.location = "index.php?page=project_detail&id='. $last_id.'&dattyp=new";   }, delay);
			</script>';
		}
		else
		{
			echo $query;
		}	*/
		
		$myfile = fopen("check_newfile.txt", "w") or die("Unable to open file!");

		$txt = $categorie ."\n";
		fwrite($myfile, $txt);

		$txt = $projet_name ."\n";
		fwrite($myfile, $txt);

		$txt = $location ."\n";	
		fwrite($myfile, $txt);
		
		$txt = $description ."\n";	
		fwrite($myfile, $txt);
		
		$txt = $client ."\n";	
		fwrite($myfile, $txt);
		
		$txt = $project_manager ."\n";	
		fwrite($myfile, $txt);
		
		$txt = $design_leader ."\n";	
		fwrite($myfile, $txt);

		$txt = $start_date ."\n";	
		fwrite($myfile, $txt);

		$txt = $end_date ."\n";	
		fwrite($myfile, $txt);

		fclose($myfile);

		/*
		echo '<script>$("#suc_msg2").show("slidedown");
			var delay = 1500;
                    setTimeout(function(){  window.location = "index.php?page=project_detail&id='. $last_id.'&dattyp=new";   }, delay);
			</script>';
			*/
		echo "Zoulou";	
	}
	

?>