<?php
require("../../include/conn.php");
require("../../include/db_conn.php");
require("../../tree/TreeMenu.php");
$dbconn = new db_conn();
$tree_menu = new TreeMenu($conn);
//托拽类型
$drag_type = $_POST['drag_type'];
//被拖动的节点ID
$drag_id = $_POST['drag_id'];
//目标ID
$target_id = $_POST['target_id'];
//如果节点为根
if($target_id=='tree-menu-root'){
$target_id = 1;
}
//目标节点类型
$str_type = $_POST['str_type'];
$flag=1;
$sql = "update tb_struct set ";
//如果拖动类型为append,
if($drag_type=='append'){
if($str_type=='person'){//目标节点类型为person,则不成功,否则更新部门
$flag=0;
}else{
$sql.=" parent_id = '".$target_id."'";
}
//sql: update tb_struct set parent_id = '".$target_id."'";
}else{
//如果不是附加到上面.则查询目标ID所属部门的ID.即parent_id;
$dept_sql = "select * from tb_struct where str_id='".$target_id."'";
$dept_result = mysql_query($dept_sql,$conn);
if($deptrow = mysql_fetch_assoc($dept_result)){
$target_id = $deptrow['parent_id'];
$sql.= " parent_id = '".$target_id."'";
}
}
$sql.= " where str_id='".$drag_id."'";
//以上形成的sql语句为更新所属部门.
//е˵sql update tb_struct set parent_id = '".$target_id."' where str_id='".$drag_id."'";
//echo $sql;
if($flag==1){
//try catch中是策略更新的操作,
try{
//更新所属部门
$result = mysql_query($sql,$conn);
/*获取部门自身的策略,供被拖动的节点继承.*/
$dept_policy_sql = "select self_policy from tb_policy_apply where str_id=".$target_id;
$dept_policy = $dbconn -> get_first_cell($dept_policy_sql);
//如果没有对部门下发策略,则为0
if(empty($dept_policy)){$dept_policy=0;}
/*获取部门自身的策略,供被拖动的节点继承.*/
//更新策略目标ID的策略.
$dbconn -> get_result("update tb_policy_apply set policy = self_policy where str_id='".$drag_id."'");
//查找被拖动节点是否为部门,如果为部门则获取所有的子部门或成员.
$drag_type = $dbconn -> get_first_cell("select str_type from tb_struct where str_id='".$drag_id."'");
if($drag_type=='dept'){
//获取所有子部门成员
$drag_id .= ",".$tree_menu -> get_users($drag_id);
}
//获取当前时间
$apply_time= date("h-i-s");
//应用策略.
$has_policy_sql ="update tb_policy_apply set policy= concat(self_policy,',".$dept_policy."'),apply_time='".$apply_time."',apply_status='1' where str_id in(".$drag_id.")";
$update_result = $dbconn -> get_result($has_policy_sql);
//echo $has_policy_sql."<br>";
//}
echo 'ok';
}catch(Exception $e){
echo 'nopass';
}
}else{
//如果目标节点为person,则不成功.
echo 'nopass';
}
mysql_close();
?>