<?php session_start();


$result_message 			=	"";
$uid_string 				=  $_POST['uid_string'];
$sprod_status_new 			=  $_POST['sprod_status_new'];
$sprod_date_new 			=  $_POST['sprod_date_new'];

$sprod_date_new = date('Y-m-d H:i:s', strtotime($_POST['sprod_date_new']));


//echo "POST['client_id']= " . $_POST['client_id'];


$myVar = explode("^", $uid_string);

$myVarcount = count($myVar);

//$myVarcount = $myVarcount - 1;

$inclause = "in (";

$int = 1;

foreach ($myVar as $value)
   {
  // echo "vc" . $myVarcount . "int" . $int;
   
		if (strlen($value) > 0){

			if ($int == $myVarcount){

				$inclause = $inclause . $value;

			}else{

				$inclause = $inclause . $value . ",";

			}


		}else{

				}

		$int = $int + 1;
   }
   
   $inclause = $inclause . ")";

  // echo $inclause . $sprod_status_new . $sprod_date_new;


	include("configi.php");

if ($sprod_status_new == "Sold") {

	$sql = "update " . $_COOKIE['phxcrmclient_id'] . "_prod_search set prod_status = '" . $sprod_status_new . "', prod_date_sold = '" . $sprod_date_new . "' where sel_uid " . $inclause . ";";

}elseif ($sprod_status_new == "Returned") {

	$sql = "update " . $_COOKIE['phxcrmclient_id'] . "_prod_search set prod_status = '" . $sprod_status_new . "', prod_date_returned = '" . $sprod_date_new . "' where sel_uid " . $inclause . ";";

}elseif ($sprod_status_new == "Donated") {

	$sql = "update " . $_COOKIE['phxcrmclient_id'] . "_prod_search set prod_status = '" . $sprod_status_new . "', prod_date_donated = '" . $sprod_date_new . "' where sel_uid " . $inclause . ";";

}elseif ($sprod_status_new == "Paid") {

	$sql = "update " . $_COOKIE['phxcrmclient_id'] . "_prod_search set prod_status = '" . $sprod_status_new . "', prod_date_paid = '" . $sprod_date_new . "' where sel_uid " . $inclause . ";";

}else{

	$sql = "update " . $_COOKIE['phxcrmclient_id'] . "_prod_search set prod_status = '" . $sprod_status_new . "' where sel_uid " . $inclause . ";";

}

//echo $sql;


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

//echo $sql;

if($result){ 
    $result_message = $result_message . "Update Successful"; 
} else { 
    $result_message = $result_message . "insert failed" . $result;
}

$resultc = mysqli_query($conn, "COMMIT;"); 

mysqli_close($conn);

echo $result_message;

?>