<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
		<title>部门管理</title>
		<link rel="stylesheet" type="text/css" href="<?php echo style2015;?>content/css/style.css">
        <link rel="stylesheet" type="text/css" href="<?php echo style2015;?>content/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="<?php echo style2015;?>content/css/bootstrap-modal.css" />
		        <link rel="stylesheet" type="text/css" href="<?php echo style2015;?>content/css/bootstrap.css"> 
				<link rel="stylesheet" type="text/css" href="<?php echo style2015;?>bootstrap/css/bootstrap-datetimepicker.css"> 
		<script type="text/javascript" src="<?php echo style2015;?>content/js/jquery.min.js"></script>
		<script type="text/javascript" src="<?php echo style2015;?>content/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="<?php echo style2015;?>content/js/bootstrap-modal.js"></script>
		<script type="text/javascript" src="<?php echo style2015;?>content/js/bootstrap-modalmanager.js"></script>

   </head>
	<body >
	<div  id="add" style="height:445px;min-width:600px !important;" class="modal hide fade">
				<div class="modal-header">
					<a class="close" data-dismiss="modal" onClick="js:$('#FileFolderPublic-form .files').empty();">×</a>
					<h4>添加新部门</h4>
				</div>
				<div class="modal-body" style="overflow: visible !important;position: relative !important; height:295px;">
					<form class="form-horizontal" name="addform" action="admin.php?ac=department&fileurl=mana&do=add" method="post">
	<input type="hidden" name="view" value="edit" />
	<div class="alert alert-success" id="message-add"></div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门名称 <span class="required">*</span></label>
		<div class="controls">
			<input name="name" size="16" type="text" value="" class="span5">	
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">上级部门 <span class="required">*</span></label>
		<div class="controls">
			<div id="fathercss"><?php get_depabox(1,'father','','选择部门',$width=100,$height=20);
	  ?></div><label class="checkbox inline"><input name="fathers" id="fathers" value="1" type="checkbox"  />顶级部门</label>
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门主管 </label>
		<div class="controls">
			<?php echo get_pubuser(1,"addpersno",'',"+选择人员",120,20);?>
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门助理 </label>
		<div class="controls">
			<?php echo get_pubuser(1,"addpersno1",'',"+选择人员",120,20);?>
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门分管领导 </label>
		<div class="controls">
			<?php echo get_pubuser(1,"addpersno2",'',"+选择人员",120,20);?>
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门主管领导 </label>
		<div class="controls">
			<?php echo get_pubuser(1,"addpersno3",'',"+选择人员",120,20);?>
		</div>
	</div>
	
	</form> 
					
				</div>
				<div class="modal-footer" style="text-align:right">
    <button onClick="addsave();" class="btn btn-danger" type="button">保存数据</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button data-dismiss="modal" class="btn" id="yw12" name="yt10" type="button">取消</button></div>
			</div>
	<div class="search_area">
        <div class="form-search form-search-top" style="text-align:left;padding-left:10px;">
	        <div class="adv-select-label big3">部门管理</div>
		   <a class="btn btn-danger" onClick="Delete();" style=" float:right;margin-right:25px;">删除</a>
		   <a class="btn btn-info" onClick="edit();" style=" float:right;margin-right:15px;">保存</a>
		   <a class="btn btn-success" onClick="add();" style=" float:right;margin-right:15px;">新增部门</a>   
        </div>

</div>
<link rel="stylesheet" href="template/style2015/zTree/css/demo.css" type="text/css">
	<link rel="stylesheet" href="template/style2015/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="template/style2015/zTree/js/jquery.ztree.core-3.5.js"></script>
	<SCRIPT type="text/javascript">
		<!--
		var curMenu = null, zTree_Menu = null;
		var setting = {
			view: {
				showLine: false,
				showIcon: false,
				selectedMulti: false,
				dblClickExpand: false,
				addDiyDom: addDiyDom
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeClick: beforeClick
			}
		};

		var zNodes =[
			{ id:9999, pId:0, name:"<?php echo $_CONFIG->config_data('name');?>"}<?php
			global $db;
			$query = $db->query("SELECT name,id FROM ".DB_TABLEPRE."department where father='0' and jituanid='".$_USER->jituanid."' ORDER BY id Asc");
				while ($row = $db->fetch_array($query)) {
			?>,<?php echo chr(13).chr(10);?>{ id:<?php echo trim($row['id']);?>, pId:9999, name:"<?php echo trim($row['name']);?>"}
			<?php 
			$rsfno = $db->fetch_one_array("SELECT id FROM ".DB_TABLEPRE."department where father='".$row['id']."' and jituanid='".$_USER->jituanid."' ORDER BY id asc limit 0,1");
			if($rsfno['id']!=''){
				_dep_user(trim($row['id']));
			}
			}?>
		];

		function addDiyDom(treeId, treeNode) {
			var spaceWidth = 12;
			var switchObj = $("#" + treeNode.tId + "_switch"),
			icoObj = $("#" + treeNode.tId + "_ico");
			switchObj.remove();
			icoObj.before(switchObj);
			if (treeNode.level > 1) {
				var spaceStr = "<span style='display: inline-block;width:" + (spaceWidth * treeNode.level)+ "px'></span>";
				switchObj.before(spaceStr);
			}
		}

		function beforeClick(treeId, treeNode) {
			//if (treeNode.level == 0 ) {
				var zTree = $.fn.zTree.getZTreeObj("treeDemo");
				zTree.expandNode(treeNode);
				$("#folder-grid_c1").html(treeNode.name);
				ajaxuser(treeNode.id);
				//alert(treeNode.id + ", " + treeNode.name);
				return false;
			//}
			//return true;
		}
		function ajaxuser(depid){
			jQuery.ajax({
					type: 'GET',
					url:  'admin.php?ac=department&fileurl=mana&do=ajax&depid='+depid+'&date='+new Date(),
					success: function(data){
						if(data!=''){
							var value=data.split(',');
							$('input[name="name"]').val(value[0]);
							$('input[name="persnoid"]').val(value[1]);
							$('input[name="persno1id"]').val(value[2]);
							$('input[name="persno2id"]').val(value[3]);
							$('input[name="persno3id"]').val(value[4]);
							$('input[name="persno"]').val(value[5]);
							$('input[name="persno1"]').val(value[6]);
							$('input[name="persno2"]').val(value[7]);
							$('input[name="persno3"]').val(value[8]);
							$('input[name="id"]').val(depid);
						}else{
							$("#name").html('');
							$("#persno").html('');
							$("#persno1").html('');
							$("#persno2").html('');
							$("#persno3").html('');
							$('input[name="id"]').val('');
						}
			        }
			   });
		}
		$(document).ready(function(){
			$("#message-info").hide();
			$("#message-add").hide();
			var treeObj = $("#treeDemo");
			$.fn.zTree.init(treeObj, setting, zNodes);
			zTree_Menu = $.fn.zTree.getZTreeObj("treeDemo");
			curMenu = zTree_Menu.getNodes()[0].children[0].children[0];
			zTree_Menu.selectNode(curMenu);
			treeObj.hover(function () {
				if (!treeObj.hasClass("showIcon")) {
					treeObj.addClass("showIcon");
				}
			}, function() {
				treeObj.removeClass("showIcon");
			});
			$("#fathers").live('click',function(event) {
						var chk_value =[]; 
						$('input[name="fathers"]:checked').each(function(){ 
							chk_value.push($(this).val()); 
						}); 
						if(chk_value==1){
							$('#fathercss').hide();
						}else{
							$('#fathercss').fadeIn("slow");
						}
					}
					);
		});
		function add(){
			$("#add").modal({
				"backdrop": "static",
				"show": true
			});
			$('input[name="father"]').val($('input[name="name"]').val());
			$('input[name="fatherid"]').val($('input[name="id"]').val());
		}
		function addsave() {
			var chk_value =[]; 
			$('input[name="fathers"]:checked').each(function(){ 
					chk_value.push($(this).val()); 
			}); 
			if($('#add input[name="name"]').val()==''){
				_MSG("message-add","部门名称不能为空，请输入！");
				return (false);
			}
			if(chk_value!=1){
				if($('#add input[name="father"]').val()==''){
					_MSG("message-add","上级部门不能为空，请输入！");
					return (false);
				}
			}
			document.addform.submit();
		}
		function edit() {
			if($('input[name="id"]').val()!=""){
				document.editform.submit();
			}else{
				$("#MsgShow").modal({
				"backdrop": "static",
				"show": true
				});
				$("#MsgShowContent").text('请选择您要编辑的部门！');
			}
		}
		function Delete() {
			if(window.confirm('确定要删除部门吗？删除后将不可还原！')){
				jQuery.ajax({
					type: 'GET',
					url:  'admin.php?ac=department&fileurl=mana&do=update&depid='+$('input[name="id"]').val()+'&date='+new Date(),
					success: function(data){
						if(data=='true'){
							location.reload(true);
						}else if(data=='false'){
							$("#MsgShow").modal({
								"backdrop": "static",
								"show": true
							});
							$("#MsgShowContent").text('删除失败，该部门下有子部门，不可删除！');
							//location.reload(true);
						}else{
							$("#MsgShow").modal({
								"backdrop": "static",
								"show": true
							});
							$("#MsgShowContent").text('删除失败，部门ID不能为空，请选择部门！');
						}
						
					}
				});
			}
		}
		
		//-->
	</SCRIPT>
	<style type="text/css">
.ztree * {font-size: 10pt;font-family:"Microsoft Yahei",Verdana,Simsun,"Segoe UI Web Light","Segoe UI Light","Segoe UI Web Regular","Segoe UI","Segoe UI Symbol","Helvetica Neue",Arial}
.ztree li ul{ margin:0; padding:0}
.ztree li {line-height:30px;}
.ztree li a {width:300px;height:30px;padding-top: 0px;}
.ztree li a:hover {text-decoration:none; background-color: #E7E7E7;}
.ztree li a span.button.switch {visibility:hidden}
.ztree.showIcon li a span.button.switch {visibility:visible}
.ztree li a.curSelectedNode {background-color:#D4D4D4;border:0;height:30px;}
.ztree li span {line-height:30px;}
.ztree li span.button {margin-top: -7px;}
.ztree li span.button.switch {width: 16px;height: 16px;}
.ztree li a.level0 span {font-size: 150%;font-weight: bold;}
.ztree li span.button {background-image:url("template/style2015/zTree/css/zTreeStyle/img/left_menuForOutLook.png"); *background-image:url("template/style2015/zTree/css/zTreeStyle/img/left_menuForOutLook.gif")}
.ztree li span.button.switch.level0 {width: 20px; height:20px}
.ztree li span.button.switch.level1 {width: 20px; height:20px}
.ztree li span.button.noline_open {background-position: 0 0;}
.ztree li span.button.noline_close {background-position: -18px 0;}
.ztree li span.button.noline_open.level0 {background-position: 0 -18px;}
.ztree li span.button.noline_close.level0 {background-position: -18px -18px;}
	</style>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="300"><div class="zTreeDemoBackground">
		<ul id="treeDemo" class="ztree"></ul>
	</div></td>
    <td valign="top" width="90%" style="padding-top:30px; padding-left:50px;">
	
	<form class="form-horizontal" name="editform" action="admin.php?ac=department&fileurl=mana&do=add" method="post">
	<input type="hidden" name="id" value="" />
	<input type="hidden" name="view" value="edit" />
	<div class="alert alert-success" id="message-info"></div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门名称 <span class="required">*</span></label>
		<div class="controls">
			<input name="name" size="16" type="text" value="" class="span5">	
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门主管 </label>
		<div class="controls">
			<?php echo get_pubuser(1,"persno",'',"+选择人员",120,20);?>
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门助理 </label>
		<div class="controls">
			<?php echo get_pubuser(1,"persno1",'',"+选择人员",120,20);?>
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门分管领导 </label>
		<div class="controls">
			<?php echo get_pubuser(1,"persno2",'',"+选择人员",120,20);?>
		</div>
	</div>
	<div class="control-group ">
		<label class="control-label required" for="AttachmentItem_file_name">部门主管领导 </label>
		<div class="controls">
			<?php echo get_pubuser(1,"persno3",'',"+选择人员",120,20);?>
		</div>
	</div>
	
	</form> 
<div  id="MsgShow" style="height:200px;min-width:500px !important;" class="modal hide fade">
		<div class="modal-header">
			<a class="close" data-dismiss="modal" onClick="js:$('#FileFolderPublic-form .files').empty();">×</a>
			<h4>消息提示</h4>
		</div>
		<div class="modal-body" id="MsgShowContent" style="font-size:22px; text-align:center; line-height:60px;color:#009933;"></div>
	</div>
	<script type="text/javascript" src="<?php echo style2015;?>content/js/workflow.js"></script>
	</body>
</html>