<?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($_GET['user']!=''){
	$user=$_GET['user'];
}else{
	$user=$_POST['user'];
}
if ($do == 'list') {
	//列表信息 
	$wheresql = '';
	$url = getGP('weburl','P');
	$keyword=$_GET[keyword];
	if($user!=''){
		$users="'".str_replace(",","','",$user)."'";
	}
	if ($user !='') {
		$wheresql .= " AND a.name in(".$users.")";
	}
	if ($keyword !='') {
		$wheresql .= " AND a.name LIKE '%$keyword%'";
	}
	if($user=='' && $keyword==''){
		$wheresql .= " AND b.online=1";
	}
    $sql = "SELECT * FROM ".DB_TABLEPRE."user_view a,".DB_TABLEPRE."user b WHERE a.uid=b.id $wheresql  ORDER BY b.numbers asc";
	$result = $db->fetch_all($sql);
	include_once('template/jtuser_radio.php');

}elseif($do=='add'){
	if(getGP('inputname','P')!=''){
		$participation=getGP('inputname','P');
	}else{
		$participation='participation';
	}
	$puboaid="0";
	$puboaname="0";
	$puboaphone="0";
	$department = $_POST['vid'];   
	for($i=0;$i<count($department);$i++){
		$puboaid=$puboaid.",".$_POST['oaid'.$department[$i].''];
		$puboaname=$puboaname.",".$_POST['oaname'.$department[$i].''];
		$puboaphone=$puboaphone.",".$_POST['oaphone'.$department[$i].''];
	}
	
	echo "<script>window.opener.document.getElementById('".$participation."').value = '".str_replace("0,"," ",$puboaname)."';</script>";
	echo "<script>window.opener.document.getElementById('".$participation."id').value = '".str_replace("0,"," ",$puboaid)."';</script>";
	echo "<script>window.opener.document.getElementById('".$participation."phone').value = '".str_replace("0,"," ",$puboaphone)."';</script>";
	echo '<script language="JavaScript">window.close()</script>';
}elseif($do=='ajax'){
	$html='';
	$sql = "SELECT * FROM ".DB_TABLEPRE."user_view a,".DB_TABLEPRE."user b WHERE a.uid=b.id and b.departmentid LIKE '%,".$_GET['depid'].",%' ORDER BY b.numbers asc";
	$result = $db->fetch_all($sql);
	foreach ($result as $row) {
		if(unescape($user)!=''){
			if(sizeof(explode(','.$row['name'].',',','.unescape($user).','))>1){
				$html.='<tr class="odd">';
				$html.='<td class="notopen" style="width:10px">';
				$html.='<input type="hidden" name="oaid'.$row['vid'].'" value="'.$row['uid'].'" />';
				$html.='<input type="hidden" name="oaname'.$row['vid'].'" value="'.$row['name'].'" />';
				$html.='<input type="hidden" name="oaphone'.$row['vid'].'" value="'.$row['phone'].'" />';
				$html.='<input type="radio" name="vid[]" value="'.$row['vid'].'" ';
				$html.=' style="border:0px;margin-bottom:8px;" /></td>';
				$html.='<td class="ellipsis" style="width:100%;">';
				if($row['online']==1){
					$html.='<img src="template/default/images/2EDkuGH6eXMM.gif" ';
					$html.=' style="margin-right:4px;margin-bottom:8px; height:16px; width:16px;">';
				}
				$html.=$row['name'].'</td></tr>';
			}
		}else{
			$html.='<tr class="odd">';
			$html.='<td class="notopen" style="width:10px">';
			$html.='<input type="hidden" name="oaid'.$row['vid'].'" value="'.$row['uid'].'" />';
			$html.='<input type="hidden" name="oaname'.$row['vid'].'" value="'.$row['name'].'" />';
			$html.='<input type="hidden" name="oaphone'.$row['vid'].'" value="'.$row['phone'].'" />';
			$html.='<input type="radio" name="vid[]" value="'.$row['vid'].'" ';
			$html.=' style="border:0px;margin-bottom:8px;" /></td>';
			$html.='<td class="ellipsis" style="width:100%;">';
			if($row['online']==1){
				$html.='<img src="template/default/images/2EDkuGH6eXMM.gif" ';
				$html.=' style="margin-right:4px;margin-bottom:8px; height:16px; width:16px;">';
			}
			$html.=$row['name'].'</td></tr>';
		}
	}
	echo $html;
	exit;
}
function _dep_user($father,$jituanid,$pid){
	global $db;
	global $_USER;
	if($father.int!=''){
		$sql="SELECT name,id FROM ".DB_TABLEPRE."department where 
			  father='".$father."' and jituanid='".$jituanid."' ORDER BY id Asc";
		$query = $db->query($sql);
		//echo $sql;
		while ($row = $db->fetch_array($query)) {
			echo ','.chr(13).chr(10).'{ id:'.trim($row['id']).', pId:'.$pid.', name:"'.trim($row['name']).'"}';
			$rsfno = $db->fetch_one_array("SELECT id FROM ".DB_TABLEPRE."department where father='".$row['id']."' and jituanid='".$jituanid."' ORDER BY id asc limit 0,1");
			if($rsfno['id']!=''){
				_dep_user(trim($row['id']),$jituanid,trim($row['id']));
			}
		}
	}
}
?>
