<?php
/*
	[Office 515158] (C) 2009-2012 天生创想 Inc.
	$Id: oa 1209087 2012-01-08 08:58:28Z baiwei.jiang $
*/

(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');

//if ( !is_superadmin() && !check_purview('manage_link') ) prompt('对不起，你没有权限执行本操作！');

empty($do) && $do = 'list';
if ($do == 'list') {
	$keyword=$_GET[keyword];
	if ($keyword !='') {
		$sql = "SELECT name,id FROM ".DB_TABLEPRE."department WHERE name LIKE '%$keyword%' and jituanid='".$_USER->jituanid."'  ORDER BY id asc";
		$result = $db->fetch_all($sql);
	}
	include_once('template/dep_checkbox.php');

}elseif($do=='add'){
	$idarr = getGP('id','P','array');
	if(getGP('inputname','P')!=''){
		$participation=getGP('inputname','P');
	}else{
		$participation='department';
	}
	foreach ($idarr as $id) {
		if($id!=''){
			$ids.=$id.',';
		}
	}
	echo "<script>window.opener.document.save.".$participation.".value='".get_realdepaname($ids)."';</script>";
	echo "<script>window.opener.document.save.".$participation."id.value='".substr($ids, 0, -1)."';</script>";
	echo '<script language="JavaScript">window.close()</script>';
}
function _dep_user($father){
	global $db;
	global $_USER;
	if($father!=''){
		$query = $db->query("SELECT name,id FROM ".DB_TABLEPRE."department where father='".$father."' and jituanid='".$_USER->jituanid."' ORDER BY id Asc");
		while ($row = $db->fetch_array($query)) {
			echo ','.chr(13).chr(10).'{ id:'.trim($row['id']).', pId:'.$father.', name:"'.trim($row['name']).'"}';
			$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']));
			}
		}
	}
}

?>
