<?php header('Content-Type: text/html; charset=utf-8');?>
<?php 


include("cnf.php");?>
<?php include("selects.php");$queries = new DatabaseFunctions($db5);?>
<?php


if(isset($_POST['factor']) && 
   isset($_POST['p1']) && 
   isset($_POST['p2']) && 
   isset($_POST['p3']) 
  ){

$factortemp = $_POST['factor'];
$p1 = $_POST['p1'];
$p2 = $_POST['p2'];
$p3 = $_POST['p3'];
  
$factortemp= json_decode($factortemp,true);		
if(sizeof($factortemp) > 0){

$randfactorid = rand();	
for($i=0;$i<sizeof($factortemp);$i++){
	
$factor = $factortemp[$i];


$partnumber  =  iconv( "UTF-8", "Windows-1256",$factor['partnumber'] );
$tasvieh  =  iconv( "UTF-8", "Windows-1256",$factor['tasvieh'] );
$day_numb  =  iconv( "UTF-8", "Windows-1256",$factor['day_numb'] );
$cod_cast  =  iconv( "UTF-8", "Windows-1256",$factor['cod_cast'] );
$cod_kala  =  iconv( "UTF-8", "Windows-1256",$factor['cod_kala'] );
$numb  =  iconv( "UTF-8", "Windows-1256",$factor['numb'] );
$price  =  iconv( "UTF-8", "Windows-1256",$factor['price'] );
$username  =  iconv( "UTF-8", "Windows-1256",$factor['username'] );
$factorid  =  iconv( "UTF-8", "Windows-1256",$factor['factorid'] );
$yad  =  iconv( "UTF-8", "Windows-1256",$factor['yad'] );
	
$valdataCheck = $queries -> addfactors($partnumber, $cod_cast, $tasvieh, $day_numb, $numb, $username, $price, $randfactorid, $cod_kala, $yad ,$p1,$p2,$p3);	
	
	
}	
	
$queries -> updateFactor("EXEC dbo.updatefactorflag @ucid = ".$p3.", @factorid = ".$randfactorid.", @sync_flag = 1");
$rs2= "1200";	    

}else{
$rs2= '2400';	
}

echo $rs2;	
	
}else{

exit("Direct access not permitted.");  

}
 

?>
