<?php session_start();

	
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  
  	include("../php/configi.php");


  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($conn, $theValue) : mysqli_escape_string($conn, $theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$gettotals	=	"0";

//echo "dave22";

	include("../php/configi.php");

//	echo "job fields" . stripslashes($_POST['jobfields']);
	
	// Test if our data came through
if (isset($_POST["jobfields"])) {

//echo "data came through";
    // Decode our JSON into PHP objects we can use

//    $jobfields = json_decode($_POST['jobfields']);
	   $jobfields = json_decode(stripslashes($_POST['jobfields']));
	   
//	   echo "jobfields is" . json_decode(stripslashes($_POST['jobfields']));
	   
	   
    // Access our object's data and array values.
    //echo "sales_id is: " . $jobfields->sales_id . "<br>";
   // echo "field_name is: " . $jobfields->field_name . "<br>";
   // echo "field_type is: " . $jobfields->field_type . "<br>";
   // echo "field_name1_db is: " . $jobfields->field_name1_db . "<br>";
   // echo "field_name2_db is: " . $jobfields->field_name2_db . "<br>";
   // echo "field_value1 is: " . $jobfields->field_value1 . "<br>";
   // echo "field_value2 is: " . $jobfields->field_value2 . "<br>";
		
}else{
	echo "data did not come through";
}


//echo $jobfields;

$outlet_id = 1;

$st_id				=	$jobfields->st_id;
$new_uid_client		=	$jobfields->new_uid_client;
$new_cont_name		=	GetSQLValueString($jobfields->new_cont_name, "text");
$new_cont_mobile	=	GetSQLValueString($jobfields->new_cont_mobile, "text");
$new_cont_email		=	GetSQLValueString($jobfields->new_cont_email, "text");	
$new_cont_jobtitle	=	GetSQLValueString($jobfields->new_cont_jobtitle, "text");
$new_cont_attn		=	GetSQLValueString($jobfields->new_cont_attn, "text");


$new_total		=	0;

$result_message = "";

	
		$queryinsert = "insert into  ".$_COOKIE['phxcrmclient_id']."_client_contacts (uid_client, contact_mobile,  contact_name, contact_job_title, contact_email_acct, contact_email, contact_attn) values (".$new_uid_client.",".$new_cont_mobile.",".$new_cont_name.",".$new_cont_jobtitle.",".$new_cont_email.",".$new_cont_email.",".$new_cont_attn.")";
		
	//	echo $queryinsert;
		
		
	//	echo $queryupdate;

		$result=mysqli_query($conn, $queryinsert);

		if($result){ 
			$result_message = ""; 
		} else { 
			 $result_message = "update failed" . $result . mysqli_error();
		}
	
		
		$new_id = mysqli_insert_id($conn);


		
	$outputarray = array('phx_result' => $result_message);

//		echo $outputarray;
		

	$output2 = json_encode($outputarray);
	
	echo $output2;
	

?>