<?php 

//pre($_POST);
//exit;

$postv = $_POST;


$doselect = $postv['doselect'];

if($doselect=='order'){

		foreach ($postv as $k=>$v){
			 if(substr($k,0,3)=='id-'){
			 	//echo '<Br>k:'.$k;
			 	$id = substr($k,3);
			 //	echo '<Br>id:'.$id;
			 	 $v= (int)$v;
			     $id= (int)$id;
			    $sql = "update ".TABLE_NODE." set  pos='$v' where id='$id' and lang='".LANG."'  limit 1";
			  //  echo '<br>'.$sql;
			    iquery($sql);
			 }			   
			}


}
else{ 
	// del tj  tjno  new  newno  show  hide  access  accessno
					$setv =  " sta_tj='y' ";
					if($doselect == 'tj') $setv =  " sta_tj='y' ";
	  	  			if($doselect == 'tjno') $setv =  " sta_tj='n' ";
	  	  			if($doselect == 'new') $setv =  " sta_new='y' ";
	  	  			if($doselect == 'newno') $setv =  " sta_new='n' ";
	  	  			if($doselect == 'show') $setv =  " sta_visible='y' ";
	  	  			if($doselect == 'hide') $setv =  " sta_visible='n' "; 
	  	  			if($doselect == 'access') $setv =  " sta_noaccess='n' "; 
	  	  			if($doselect == 'accessno') $setv =  " sta_noaccess='y' "; 

	   
	  if(array_key_exists('checkboxv',$postv)){
	  	  foreach($postv['checkboxv'] as $v){	  	  		
	  	  		$id = $v;
	  	  		//echo '<br>'.$id;
	  	  		$arract = ['tj','tjno','new','newno','show','hide','access','accessno'];
	  	  		
	  	  		if(in_array($doselect,$arract)) {
	  	  			
	  	  			$sql = "update ".TABLE_NODE." set $setv where id='$id' and lang='".LANG."'  limit 1";
	  	  		 // echo '<br>'.$sql;
	  	  			iquery($sql);

	  	  		}
	  	  		

	  	  		if($doselect=='del'){
	  	  		// echo '<br>'.$id;
					 	dodelnode($id);

	  	  		}



	  	  }


	  
	  } 
	  else {
	  	alert('请先勾选内容');
	  	jump($jumpv_catid);
	  }


}
  
  jump($jumpv_catid);

  //exit;

 

function dodelnode($id){
	global $jumpv_catid;
	global $andlangbh;
	$pidname = get_field(TABLE_NODE,'pidname',$id,'id');

	 //echo '<br>'.$pidname;


	   //del album
	  	$sql = "SELECT pidname from  ".TABLE_ALBUM."  where  pid= '$pidname' $andlangbh order by id";
  			if(getnum($sql)>0){
  				$res = getall($sql);
  				//pre($res);
  				foreach($res as $v){
  					//echo '<br>'.$v['pidname'];
  					//del img
  					$albumid = $v['pidname'];
  					$sqlimg = "SELECT * from  ".TABLE_ALBUM."  where  pid= '$albumid' $andlangbh order by id";
		  			if(getnum($sqlimg)>0){
		  				$res_abm = getall($sqlimg);
		  				//pre($res_abm);
		  				foreach($res_abm as $vimg){
		  					 $img = $vimg['kvsm'];
		  					 $imgid = $vimg['id'];
			  				$imgv = UPLOADROOTIMAGE.$img;
								$imgvsm = UPLOADROOTIMAGE.gl_img_s($img).'_s.'.gl_imgtype($img);
							// echo '<br>'.$imgvsm.'<br>';
									
								unlinkdm($imgv);
								unlinkdm($imgvsm);					 

					  $ss = "delete from ".TABLE_ALBUM." where id='$imgid'  ". ANDLANGBH." limit 1";
								// echo $ss.'<br>';
							    iquery($ss);

		  				}
		  			}
		  			//-------------
		  			 $ss = "delete from ".TABLE_ALBUM." where pid= '$pidname' ". ANDLANGBH ." limit 1";
					 // echo $ss.'<br>';
					  iquery($ss);

		  			//---------------

  				}


  			}
  			//--del music----------
  			$sql = "SELECT pidname from  ".TABLE_MUSIC."  where  pid= '$pidname' $andlangbh order by id";
  			if(getnum($sql)>0){
  				 $res = getall($sql);
  				pre($res);
  				foreach($res as $v){
  					$albumid = $v['pidname'];
  					$sqlimg = "SELECT * from  ".TABLE_MUSIC."  where  pid= '$albumid' $andlangbh order by id";
		  			if(getnum($sqlimg)>0){
		  				$res_abm = getall($sqlimg);
		  				//pre($res_abm);
		  				foreach($res_abm as $vimg){ 
		  					 $imgid = $vimg['id']; 
						 $ss = "delete from ".TABLE_MUSIC." where id='$imgid'  ". ANDLANGBH ." limit 1";
								// echo $ss.'<br>';
							  iquery($ss);

		  				}
		  			}
		  			//-------------
		  			 $ss = "delete from ".TABLE_MUSIC." where pid= '$pidname' ". ANDLANGBH ." limit 1";
					 // echo $ss.'<br>';
					  iquery($ss);

		  			//---------------
  				}
  			}




		 
		  ifsuredel_fieldmore(TABLE_NODETEXT,'pid',$pidname,'equal','noback');
		  ifsuredel_fieldmore(TABLE_VIDEO,'pid',$pidname,'equal','noback');

		  $kvarr = get_fieldarr(TABLE_NODE,$pidname,'pidname');
		    //pre($kvarr);
		  $kv = $kvarr['kv'];$kvsm = $kvarr['kvsm'];$kvsm2 = $kvarr['kvsm2'];

		  if($kv<>'')  p2030_delimg($kv,'y','n');//p2030_delimg($addr,$delbig,$delsmall) //delsmall only ablum small img.
		  if($kvsm<>'')  p2030_delimg($kvsm,'y','n');
		  if($kvsm2<>'')  p2030_delimg($kvsm2,'y','n');
		 //ifsuredel_fieldmore(TABLE_FIELDVALUE,'pidnode',$pidname,'equal','noback');
		 delpriimgfg($pidname);
		 ifsuredel_fieldmore(TABLE_TAGNODE,'node',$pidname,'equal','noback');
		 ifsuredel_field(TABLE_NODE,'pidname',$pidname,'equal','noback');

}