<?php
include_once("htui_header.php");

$scuser_id=$_SESSION["a_uid"];
if (!empty($_POST["tocateid"]) && !empty($_POST["movecateid"])){

	if (check_permission($scuser_id,'movecate.php',2) && $_SESSION["a_type"]==1){

		$movecateidarr=$_POST["movecateid"];
		for($i=0; $i<count($movecateidarr); $i++){
		   $cateidstr.=$movecateidarr[$i].",";
		}

		$cate_id=substr($cateidstr,0,strlen($cateidstr)-1);//要转移的ID串
		$tocateid=intval($_POST["tocateid"]);

		$sql="update {$tablepre}categorymng set category_id='".$tocateid."' where category_id in (".$cate_id.")";
		$db->update($sql);

		$response_arr = array("status" => 1,"message"  => '数据转换成功!');
        echo json_encode($response_arr);
        exit;

	}else{
        $response_arr = array("status" => -1,"message"  => '对不起,您无权限操作!');
        echo json_encode($response_arr);
        exit;
	}
}

$sql = "select * from {$tablepre}category order by category_order asc, category_id Desc";
$ListArray = $db->get_all($sql);

if(!empty($ListArray) && is_array($ListArray)){
   $cate_arr=array();
   foreach($ListArray as $k => $row){
	  $createtime = dateFormat($row['category_createtime'],'Y-m-d H:i:s');
	  $cate_arr[] = array($row['category_id'],$row['category_name'],$row['category_parentid'],$row['category_order'],$row['category_status'],$row['category_url'],$createtime,$row['category_icon']);
   }
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta id="scale" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>数据转移 - 飞天素材网</title>
<meta name="author" content="ftsucai.com">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/htstyle.css" rel="stylesheet">
<link href="../css/jquery-confirm.min.css" rel="stylesheet">
</head>
  
<body>
    <!--页面主要内容-->
    <main class="ftdms-layout-content">
      
      <div class="container-fluid" style="margin-bottom:90px;">
        
        <div class="row" style="margin-top:15px;">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-header"><h4>数据转移</h4></div>

              <div class="card-body">
                <div class="table-responsive">
				   <form name="form1" class="form-horizontal" method="post" action="" id="form">
					  <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="table table-bordered">
					   <tr>
						 <td width="30%">
						   <table width="90%" border="0" bgcolor="#f2f2f2" cellspacing="1" cellpadding="1" align="center" class="table table-bordered">
							<?php form_tree(0,0,1);?>
						   </table>
						 </td>
						 <td width="10%" align="center">转移到</td>
						 <td width="30%">
						   <table width="90%" border="0" bgcolor="#f2f2f2" cellspacing="1" cellpadding="1" align="center" class="table table-bordered">
							<?php form_tree(0,0,2);?>
						   </table>
						 </td>
					   </tr>
					   <tr>
						 <td height="30" colspan="4" align="center">
						   <button class="btn btn-primary" type="button" id="submit">开始转移</button>
						 </td>
					   </tr>
					 </table>
                  </form>
                </div>	
       
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>
<script type="text/javascript" src="../js/jquery-confirm.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/tips.js"></script>
<script>
$("#submit").click(function(){
    var id='';
    $('input[name="movecateid[]"]:checked').each(function(){ 
    	id += ','+this.value;
    });

    //var toid = $("input[name='tocateid']:checked").val();
	var toid = $("input[type='radio']:checked").val();

	var listid=id.substr(1);
    if (listid==''){
        tips.notify('请选择要转换的分类！', 'danger', 1000);
		return false;
	}

	if (toid==undefined){
        tips.notify('请选择要转换到的分类！', 'danger', 1000);
		return false;
	}

    $.post("movecate.php", $("#form").serialize(), function(data) {
		var rs  = eval('('+data+')');
        if(rs.status==1){
           tips.notify(rs.message, 'success', 1000, 'ftsucai-name', 'top', 'center');
		}else{
		   tips.notify(rs.message, 'danger', 200);
		}
    });
	
});
</script>
</body>
</html>