<?php
	require_once('../Connections/conn_ama.php');
	include("../../../../../../functions/functions.php");

	$curr_time = date("Y-m-d H:i:s");

	if (!isset($_SESSION)) {
	  session_start();
	}

	if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "save-new-project")) {

		$insertSQL = sprintf("INSERT INTO projects (ah, projtitle, projcategory,`projectdesc`,communities, gps, startdate, enddate, projectstatus, `percentage`, dateadded) VALUES (SHA1(MD5(RAND())), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )",
												//	GetSQLValueString(trim($_POST['ah']), "text"),
                          GetSQLValueString($_POST['projtitle'], "text"),
                          GetSQLValueString($_POST['projcategory'], "text"),
                          GetSQLValueString($_POST['projectdesc'], "text"),
                          GetSQLValueString($_POST['communities'], "text"),
                          GetSQLValueString($_POST['gps'], "text"),
                          GetSQLValueString($_POST['startdate'], "text"),
                          GetSQLValueString($_POST['enddate'], "text"),
                          GetSQLValueString($_POST['projectstatus'], "text"),
                          GetSQLValueString($_POST['percentage'], "text"),
													GetSQLValueString($curr_time, "text"));

	  	$Result1 = mysqli_query($conn_ama, $insertSQL) or die(mysqli_error($conn_ama));
	  		$projectID = mysqli_insert_id($conn_ama);
		  if($Result1){

		  	//List the uploaded news-article via the newsID
		    $query_rsArticle = "SELECT projectID, ah FROM projects WHERE projectID = ".$projectID;
				$rsArticle  = mysqli_query($conn_ama, $query_rsArticle) or die(mysqli_error($conn_ama));
				$row_rsArticle  = mysqli_fetch_assoc($rsArticle);
				$totalRows_rsArticle  = mysqli_num_rows($rsArticle);

			$reference = $row_rsArticle['ah'];//$projectID;
				if(isset($reference)){
				  echo "datasent:".$reference;
				}
			 }
			else{
				echo "notset";
			}
	}

 ?>
