<? session_start();?>
<?php include("anti_sql2.php") ?>
<?php include("conn.php") ?>
<? 

$read_stuid=$_GET["stuid"];
$read_juan_id=$_GET["juan_id"];
$read_shiti_id=$_GET["id"];
$read_shititype=$_GET["shititype"];

?>



<? 

//------------------------------将EXAMINFO.----------
$getlist=array();
$new_id_str='';

$sql="select  *  from  cang ";
$sql=$sql."   where  stuid='".$read_stuid."'";
$sql=$sql."   and   juan_id=".$read_juan_id;

$rs=$conn->execute($sql);
$exist_cang_flag=0;
if (!$rs->EOF)
{
	$exist_cang_flag=1;
	$read_s_old_str=$rs->fields["test_lunshu"];
}
$rs->close;



if ($exist_cang_flag==1)
{
	//更新-------------
	
	
	$getlist=explode("#",$read_s_old_str);
	$s_count=count($getlist);
	$s_id_exist=0;
	for($x=0;$x<$s_count;$x++)
	{
		if ($getlist[$x]==$read_shiti_id)
		{
			$s_id_exist=1;
			//break;
			$getlist[$x]=0;
		}
		
		
	}
	
	for($x=0;$x<$s_count;$x++)
	{
		if ($getlist[$x]!=0)
		{
			$new_id_str=$new_id_str.$getlist[$x]."#"; 
		}
	}
	
	
	if ($s_id_exist==0)  //shiti_id 不存在
	{
		$new_s_str=$read_s_old_str.$read_shiti_id."#";
		$sql="update  cang  set  test_lunshu='".$new_s_str."'";
		$sql=$sql."   where  stuid='".$read_stuid."'";
		$sql=$sql."   and   juan_id=".$read_juan_id;
		$rs=$conn->execute($sql);
		
		$rs->close;
	}
	
	if ($s_id_exist==1)  //shiti_id 存在
	{
	    
		$sql="update  cang  set  test_lunshu='".$new_id_str."'";
		$sql=$sql."   where  stuid='".$read_stuid."'";
		$sql=$sql."   and   juan_id=".$read_juan_id;
		$rs=$conn->execute($sql);
		
		$rs->close;
	}
	
	
	
	
	
}

if ($exist_cang_flag==0)
{
	
	$s_str=$read_shiti_id."#";
	//新建记录-------------
	$sql="insert into cang (juan_id,stuid,test_lunshu) values (";
	$sql=$sql.$read_juan_id.",";
	$sql=$sql."'".$read_stuid."'".",";
	$sql=$sql."'".$s_str."'";
	$sql=$sql." )";
		
	$rs=$conn->execute($sql);
	$rs->close;
	
}
if ($s_id_exist==1)
{
	echo "1";
}
if ($s_id_exist==0)
{
	echo "0";
}



