	<?php
		date_default_timezone_set("Pacific/Auckland");

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  
  	include("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;
}
}

	 include 'configi.php';	
	

	$uid_supp		=  $_REQUEST['uid_supp'];
	$title			=  $_REQUEST['title'];
	
	$title			= GetSQLValueString($title, "text");
	
//	$name_array = explode(' ',trim($_REQUEST['tagsprodtitle']));
//	$first_name = $name_array[0]; // will print Test
 
	$curdate = date("Y-m-d H:i:s");
	
	
		$queryclient="select * from " . $_COOKIE['phxcrmclient_id'] . "_client WHERE uid_client=" . $uid_supp;
	//	echo $queryprod;
		$resultclient=mysqli_query($conn, $queryclient);

		while($row=mysqli_fetch_array($resultclient)) { 
		
			$comp_name			= $row['comp_name'];
			$comp_name 			= GetSQLValueString($comp_name, "text");
	
		}
	

		$insclient="insert into ".$_COOKIE['phxcrmclient_id']."_prod_search(title, prod_suppid, prod_suppname, prod_condition, prod_date_received) values (".$title.",".$uid_supp.",".$comp_name.", '2nd hand', '".$curdate."')";
	
		//			echo $insclient;
		$resultinsclient=mysqli_query($conn, $insclient);	

		$new_id =  mysqli_insert_id($conn);

		$updst="update ".$_COOKIE['phxcrmclient_id']."_prod_search set sel_uid = ".$new_id.", main_uid = ".$new_id.", v_uid = 0 where uid = " . $new_id;
	
			//	echo $addst;
		$resultst=mysqli_query($conn, $updst);
		
		$phx_result = "successful";
	
	
		$outputarray = array('phx_result' => $phx_result,'new_id' => $new_id);
		$output2 = json_encode($outputarray);
		echo $output2;

		exit;
	

			
			?>