<?php
/*
	[Office 515158] (C) 2009-2015 天生创想 Inc.
	$Id: function_apps.php 1209087 2015-01-08
*/
!defined('IN_TOA') && exit('Access Denied!');
//单选
function apps_radio($name='',$radiovalue='',$value=''){
		$inputvaluenum=explode('|',$radiovalue); 
		$html.='<!--{radio'.$name.'start}-->';
		for($i=0;$i<sizeof($inputvaluenum);$i++){
			$html.= '<input name="'.$name.'" type="radio" value="'.$inputvaluenum[$i].'" ';
			if($value==''){
				if($i==0){
					$html.= 'checked="checked"';
				}
			}else{
				if(trim($value)==trim($inputvaluenum[$i])){
					$html.= 'checked="checked"';
				}
			}
			$html.= '/>'.$inputvaluenum[$i].' ';
		}
		$html.='<!--{radio'.$name.'end}-->';
	return $html;
}
//多选
function apps_checkbox($name='',$radiovalue='',$value=''){
		$inputvaluenum=explode('|',$radiovalue); 
		$html.='<!--{checkbox'.$name.'start}-->';
		for($i=0;$i<sizeof($inputvaluenum);$i++){
			$html.= '<input name="'.$name.'[]" type="checkbox" value="'.$inputvaluenum[$i].'" ';
			if($value==''){
				if($i=='0'){
					$html.= 'checked="checked"';
				}
			}else{
				if(sizeof(explode($inputvaluenum[$i],$value))>1){
					$html.= 'checked="checked"';
				}
			}
			$html.= '/>'.$inputvaluenum[$i].' ';
		}
		$html.='<!--{checkbox'.$name.'end}-->';
	return $html;
}
//日期
function apps_date($name='',$w,$h,$value){
	if($w=='' || $w=='0') $w='180';
	if($h=='' || $h=='0') $h='20';
	return '<input class="BigInput" style="width:'.$w.'px;height:'.$h.'px;line-height:'.$h.'px;font-size:14px;margin-top:6px;" type="text" value="'.$value.'" name="'.$name.'" onClick="WdatePicker();" />';
}

//文本域
function apps_input($name='',$w,$h,$value=''){
	if($w=='' || $w=='0') $w='260';
	if($h=='' || $h=='0') $h='20';
	return '<input type="text" class="span3" name="'.$name.'" style="width:'.$w.'px;height:'.$h.'px;line-height:'.$h.'px;font-size:14px;margin-top:6px;" value="'.$value.'" />';
}
//下拉框
function apps_select($name='',$radiovalue='',$value='',$w,$h){
	if($w=='' || $w=='0') $w='260';
	if($h=='' || $h=='0') $h='30';
	$inputvaluenum=explode('|',$radiovalue); 
	$html.='<!--{option'.$name.'start}-->';
	$html.='<select class="span3" name="'.$name.'" id="'.$name.'" style="width:'.$w.'px;height:'.$h.'px;line-height:'.$h.'px;font-size:14px;margin-top:6px;">';
	$html.='<option value="" selected="selected">选择内容</option>';
	for($i=0;$i<sizeof($inputvaluenum);$i++){
		if($inputvaluenum[$i]==$value){
			$selected='  selected="selected"';
		}else{
			$selected='';
		}
		$html.='<option value="'.$inputvaluenum[$i].'" '.$selected.'>'.$inputvaluenum[$i].'</option>';	
	}
	$html.='</select> ';
	$html.='<!--{option'.$name.'end}-->';
	return $html;
}
//文本框
function apps_textarea($name='',$w,$h,$value=''){
	if($w=='' || $w=='0') $w='600';
	if($h=='' || $h=='0') $h='200';
	$_CONFIG=new config();
	if($_CONFIG->config_data('configwork')=='1'){
		$html.= '<textarea name="'.$name.'" id="'.$name.'" style="width:'.$w.'px;height:'.$h.'px;margin-top:6px;margin-bottom:6px;" class="ckeditor">'.$value.'</textarea>';
	}else{
		$html.= '<textarea name="'.$name.'" style="width:'.$w.'px;height:'.$h.'px;margin-top:6px;margin-bottom:6px;" class="span3">'.$value.'</textarea>';
	}
	return $html;
}

function app_db($id=0,$name=''){
	global $db;
	$tpl = $db->fetch_one_array("SELECT tplid FROM ".DB_TABLEPRE.DB_JT."apps where id='".$id."'");
	$row = $db->fetch_one_array("SELECT ".$name." FROM ".DB_TABLEPRE.DB_JT."apps_".$tpl['tplid']." where appid='".$id."'  ORDER BY did Asc");
	return $row[$name];	
}
//模板植入单框数据读取
function apps_db($tplid=0,$inputname='',$w=0,$h=0,$value=''){
	global $db;
	$tpl = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE.DB_JT."app_from where  tplid='".$tplid."' and inputname='".$inputname."'  ORDER BY fromid Asc");
	if($tpl['inputtype']=='0'){
		if($tpl["inputtype1"]=='1'){
			return apps_input($tpl["inputname"],$w,$h,$value);
		}elseif($tpl["inputtype1"]=='2'){
			return apps_textarea($tpl["inputname"],$w,$h,$value);
		}elseif($tpl["inputtype1"]=='3'){
			return apps_radio($tpl["inputname"],$tpl["inputvaluenum"],$value);
		}elseif($tpl["inputtype1"]=='4'){
			return apps_checkbox($tpl["inputname"],$tpl["inputvaluenum"],$value);		
		}elseif($tpl["inputtype1"]=='5'){
			return apps_select($tpl["inputname"],$tpl["inputvaluenum"],$value);	
		}
	}elseif($tpl["inputtype"]=='3'){
		return apps_date($tpl["inputname"],$w,$h,$value);
	}elseif($tpl["inputtype"]=='4'){
		$dep= "<input type='text' name='".$tpl["inputname"]."' style='width:".$w."px;height:".$h."px;background-color:#F5F5F5;color:#006600;margin-top:6px;' value='".$value."' readonly />";
        $dep.= '<a href="#" onClick="window.open ';
		$dep.="('admin.php?ac=dep_radio&fileurl=public&inputname=".$tpl["inputname"]."', '".$tpl["inputname"]."', 'height=500, width=500, top=50, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no')";
		$dep.='">+选择部门</a>';
		return $dep;
	}elseif($tpl["inputtype"]=='5'){
	   $user= "<input type='text' name='".$tpl["inputname"]."' style='width:".$w."px;height:".$h."px;background-color:#F5F5F5;color:#006600;margin-top:6px;' value='".$value."' readonly />";
       $user.='<a href="javascript:;" onClick="window.open (';
	   $user.="'admin.php?ac=user_radio&fileurl=public&inputname=".$tpl["inputname"]."', '".$tpl["inputname"]."', 'height=500, width=500, top=50, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no'";
	   $user.=')">+选择人员</a>';
	   return $user;
	}elseif($tpl["inputtype"]=='7'){
		if($tpl["magnificent"]=='read'){
			return '<!--{阅者签名'.$tpl["inputname"].'}-->';
		}else{	
			return '<!--{流程控件'.$tpl["magnificent"].$tpl["inputname"].'}-->';
		}
	}
}
//获取并过滤表单数据
function apps_adddb($tplid,$tpltype,$appid,$tpladdr,$flowid){
	global $db;
	global $_USER;
	$query = $db->query("SELECT fromid,inputname,inputtype,inputtype1,inputvaluenum,magnificent FROM ".DB_TABLEPRE.DB_JT."app_from where tplid='".$tplid."' ORDER BY fromid Asc");
	while ($row = $db->fetch_array($query)) {
		$values=public_value($row['inputname'],DB_JT.'apps_'.$tplid,'appid='.$appid);
		if($flowid!=''){
			$formkey=public_value('formkey',DB_JT.'app_flow','fid='.$flowid);
		}
		if($values!=''){
			if($row['inputtype1']==3){
			    $values=apps_radio($row["inputname"],$row["inputvaluenum"],$values);
				$addr=get_subcontent($tpladdr,'<!--{radio'.$row['inputname'].'start}-->','<!--{radio'.$row['inputname'].'end}-->');
				$tpladdr=str_replace($addr,$values,$tpladdr);
			}elseif($row['inputtype1']==4){
				$values=apps_checkbox($row["inputname"],$row["inputvaluenum"],$values);
				$addr=get_subcontent($tpladdr,'<!--{checkbox'.$row['inputname'].'start}-->','<!--{checkbox'.$row['inputname'].'end}-->');
				$tpladdr=str_replace($addr,$values,$tpladdr);
			}elseif($row['inputtype1']==5){
				$values=apps_select($row["inputname"],$row["inputvaluenum"],$values);
				$addr=get_subcontent($tpladdr,'<!--{option'.$row['inputname'].'start}-->','<!--{option'.$row['inputname'].'end}-->');
				$tpladdr=str_replace($addr,$values,$tpladdr);
			}else{
				$tpladdr=str_replace("{".$row['inputname']."}",$values,$tpladdr);
			}
		}else{
			if($row['inputtype']==3){
				$tpladdr=str_replace("{".trim($row['inputname'])."}",get_date('Y-m-d',PHP_TIME),$tpladdr);
			}elseif($row['inputtype']==4){
				$tpladdr=str_replace("{".$row['inputname']."}",get_realdepaname(public_value('departmentid','user','id='.$_USER->id)),$tpladdr);
			}elseif($row['inputtype']==5){
				$tpladdr=str_replace("{".$row['inputname']."}",get_realname($_USER->id),$tpladdr);
			}else{
				$tpladdr=str_replace("{".$row['inputname']."}",'',$tpladdr);
			}
		}
		if(trim($row['inputtype'])=='7'){
			if(trim($row['magnificent'])=='read'){
					//$tpladdr=str_replace("&nbsp;",'',$tpladdr);
					//$tpladdr=str_replace("<!--".$row['inputname']."s--><!--{".$row['magnificent']."}--><!--".$row['inputname']."e-->",apps_read($appid),$tpladdr);
					$tpladdr=str_replace("<!--{".$row['inputname']."}-->",apps_read($appid),$tpladdr);
				}else{
					$tpladdr=str_replace("<!--{流程控件".$row['magnificent'].$row['inputname']."}-->",apps_flows($row['magnificent'],$appid),$tpladdr);
				}
		}
		if(sizeof(explode('"'.$row['inputname'].'"',$formkey))>1){
			
		}else{
			$tpladdr=str_replace('name="'.$row['inputname'],'disabled="disabled" name="'.$row['inputname'],$tpladdr);
		}
	}
	return $tpladdr;
}
//更新主表信息
function apps_update(){
	global $db;
	global $_USER;
	$apps = array();
	$apps['number']=check_str(getGP('number','P'));
	$apps['title']=check_str(getGP('title','P'));
	update_db(DB_JT.'apps',$apps, array('id' =>getGP('appid','P','int'),'uid'=>$_USER->id));
}
//更新表单信息
function appsform_update(){
	global $db;
	global $_USER;
	$apps = array();
	$appid=getGP('appid','P','int');
	$tplid=getGP('tplid','G','int');
	$tpltype=getGP('tpltype','G','int');
	$flowid=getGP('flowid','P','int');
	$formkey=public_value('formkey',DB_JT.'app_flow','fid='.$flowid);
	if(sizeof(explode('toa',$formkey))>1){
	$query = $db->query("SELECT * FROM ".DB_TABLEPRE.DB_JT."app_from where tplid='".$tplid."' and  inputtype!=7 ORDER BY fromid Asc");
	while ($row = $db->fetch_array($query)) {
		if(sizeof(explode('"'.$row['inputname'].'"',$formkey))>1){
			if($row['inputtype1']=='4'){
				$inputvalues='';
				$inputvalue=getGP(''.$row["inputname"].'','P','array');
				foreach ($inputvalue as $arrsave) {
					$inputvalues.=$arrsave.'|';
				}
				$apps[$row["inputname"]]=substr($inputvalues, 0, -1);
			}else{
				$apps[$row["inputname"]]=trim(getGP(''.$row["inputname"].'','P'));
			}
		}
	}
	update_db(DB_JT.'apps_'.$tplid,$apps, array('appid' =>$appid,'tplid'=>$tplid));
	}
	
}
//获取数据
function apps_viewdb($tplid,$tpltype,$appid,$tpladdr){
	global $db;
	global $_USER;
	$query = $db->query("SELECT inputname,inputtype,inputtype1,inputvaluenum,magnificent FROM ".DB_TABLEPRE.DB_JT."app_from where tplid='".$tplid."' ORDER BY fromid Asc");
	while ($row = $db->fetch_array($query)) {
		$values=public_value($row['inputname'],DB_JT.'apps_'.$tplid,'appid='.$appid);
		if($values!=''){
			if($row['inputtype1']==4){
				$values=str_replace("|",',',$values);
				$tpladdr=str_replace("<!--{".$row['inputname']."}-->",$values,$tpladdr);
			}else{
				$tpladdr=str_replace("<!--{".$row['inputname']."}-->",$values,$tpladdr);
			}
		}else{
			if($row['inputtype']=='7'){
				$addr=get_subcontent($tpladdr,"<!--".$row['inputname']."s-->","<!--".$row['inputname']."e-->");
				$addr=str_replace("<!--{",'',str_replace("}-->",'',$addr));
				if(trim($row['magnificent'])=='read'){
					//$tpladdr=str_replace("&nbsp;",'',$tpladdr);
					//$tpladdr=str_replace("<!--".$row['inputname']."s--><!--{".$row['magnificent']."}--><!--".$row['inputname']."e-->",apps_read($appid),$tpladdr);
					$tpladdr=str_replace("<!--{".$row['inputname']."}-->",apps_read($appid),$tpladdr);
				}else{
					//$tpladdr=str_replace("&nbsp;",'',$tpladdr);
					//$tpladdr=str_replace("<!--".$row['inputname']."s--><!--{".$row['magnificent']."}--><!--".$row['inputname']."e-->",apps_flows($addr,$appid),$tpladdr);
					$tpladdr=str_replace("<!--{".$row['inputname']."}-->",apps_flows($row['magnificent'],$appid),$tpladdr);
				}
			}
		}
	}
	return $tpladdr;
}
//显示流程
function apps_read($appid){
	global $db;
	global $_USER;
	$html='';
	$sqls = "SELECT readuid FROM ".DB_TABLEPRE.DB_JT."app_read where appid='".$appid."' and readdate!='' order by rid asc";
	$result = $db->fetch_all($sqls);
	foreach ($result as $rows) {
			$html.=get_realname($rows['readuid']).' , ';
	}
	return substr($html, 0, -3);		
}
function apps_flows($flowid,$appid){
	global $db;
	global $_USER;
	$html='';
	$sql = "SELECT flowkey2 FROM ".DB_TABLEPRE.DB_JT."app_flow  WHERE fid = '".$flowid."'";
	$flow = $db->fetch_one_array($sql);
	if($flow['flowkey2']==2){
		$sqls = "SELECT * FROM ".DB_TABLEPRE.DB_JT."app_personnel where appid='".$appid."' and flowid='".$flowid."' and pertype!=0  order by perid asc";
		$result = $db->fetch_all($sqls);
		foreach ($result as $pers) {
			$html.='<table width="96%" border="0" cellspacing="0" cellpadding="0">';
			$html.='<tr>';
			$html.='<td height="30" colspan="2" align="left" valign="top" style="font-size:14px;">';
			$html.=$pers['lnstructions'].'</td>';
			$html.='</tr><tr>';
			$html.='<td width="29%" height="40" align="left" valign="middle" style="font-size:14px;">办理人：'.participationwork($pers['name'],$pers['uid']).'</td><td width="71%" align="left" valign="middle" style="font-size:14px;">办理日期：'.$pers['approvaldate'].'</td>';
			$html.='</tr></table>';
	    }
	}else{
		$sqls = "SELECT * FROM ".DB_TABLEPRE.DB_JT."app_personnel  WHERE appid='".$appid."' and flowid='".$flowid."' and pertype!=0";
		$perid = $db->fetch_one_array($sqls);
		$sqls = "SELECT * FROM ".DB_TABLEPRE.DB_JT."app_personnel_log where appid='".$appid."' and perid='".$perid['perid']."' and pertype!=0  order by perid asc";
		$result = $db->fetch_all($sqls);
		foreach ($result as $pers) {
			$html.='<table width="96%" border="0" cellspacing="0" cellpadding="0">';
			$html.='<tr>';
			$html.='<td height="30" colspan="2" align="left" valign="top" style="font-size:14px;">';
			$html.=$pers['lnstructions'].'</td>';
			$html.='</tr><tr>';
			$html.='<td width="29%" height="40" align="left" valign="middle" style="font-size:14px;">办理人：'.participationwork($pers['name'],$pers['uid']).'</td><td width="71%" align="left" valign="middle" style="font-size:14px;">办理日期：'.$pers['approvaldate'].'</td>';
			$html.='</tr></table>';
	    }
	}
	return $html;			
}
function apps_pertype($type){
	switch ($type)
	{
		case 0:
		  echo "未审批";
		  break;
		case 1:
		  echo "通过";
		  break;
		case 2:
		  echo "拒绝";
		  break;
		case 3:
		  echo "退回";
		  break;
		case 4:
		  echo "等待审批";
		  break;
		case 5:
		  echo "结束";
		  break;
		default:
		  echo "错误类型";
	}
	return ;
}
function apps_pertype_log($type){
	switch ($type)
	{
		case 0:
		  echo "未审批";
		  break;
		case 1:
		  echo "通过";
		  break;
		case 2:
		  echo "拒绝";
		  break;
		case 3:
		  echo "退回";
		  break;
		default:
		  echo "错误类型";
	}
	return ;
}
//读取流程标志
function flowpic($value){
	if($value!=''){
		global $db;
		$staff=explode(',',$value);
		for($i=0;$i<sizeof($staff);$i++){
			if(trim($staff[$i])!=''){
				$sql = "SELECT flownum FROM ".DB_TABLEPRE.DB_JT."app_flow 
				where fid='".trim($staff[$i])."' limit 0,1";
				$row = $db->fetch_one_array($sql);
				if($row['flownum']!=''){
					$html.=$row['flownum'].'-->';
				}
			}
		}
	}
	return substr($html, 0, -3);
}
//获取并解析条件流
function apps_whereflow($flowkey5,$appid){
	$_flowkey5=explode('|',$flowkey5);
	if($_flowkey5[0]!=''){
		$flowinput=app_db($appid,$_flowkey5[0]);
		//单个解析条件（为什么不能批量解析？）
		if($_flowkey5[1]=='>='){
			if($flowinput>=(int)$_flowkey5[2]){
				return $_flowkey5[3];
				exit;
			}
		}elseif($_flowkey5[1]=='<='){
			if($flowinput<=(int)$_flowkey5[2]){
				return $_flowkey5[3];
				exit;
			}
		}elseif($_flowkey5[1]=='=='){
			if($flowinput==$_flowkey5[2]){
				return $_flowkey5[3];
				exit;
			}
		}elseif($_flowkey5[1]=='!='){
			if($flowinput!=$_flowkey5[2]){
				return $_flowkey5[3];
				exit;
			}
		}elseif($_flowkey5[1]=='>'){
			if($flowinput>(int)$_flowkey5[2]){
				return $_flowkey5[3];
				exit;
			}
		}elseif($_flowkey5[1]=='<'){
			if($flowinput<(int)$_flowkey5[2]){
				return $_flowkey5[3];
				exit;
			}
		}
	}
	return 0;
}
//获取有效的下一步流程
function apps_nextflow($tplid,$typeid,$appid,$flownum){
	global $db;
	$sql = "SELECT fid,flownum,flowkey5 FROM ".DB_TABLEPRE.DB_JT."app_flow  WHERE flownum >'".$flownum."' and tplid='".$tplid."' order by flownum asc";
	$per = $db->fetch_one_array($sql);
	if($per['fid']!=''){
		$flowkey5=apps_whereflow($per['flowkey5'],$appid);
		if($flowkey5==1){
			return apps_nextflow($tplid,$typeid,$appid,$per['flownum']);
		}else{
			//return $per['fid'];
			$sql2 = "SELECT fid,flownum,flowkey5,flowkey6 FROM ".DB_TABLEPRE.DB_JT."app_flow  WHERE flownum ='".($per['flownum']-1)."' and tplid='".$tplid."' order by flownum asc";
			$per2 = $db->fetch_one_array($sql2);
			$html='';
			if($per2['flowkey6']!=''){
				//过滤条件流
				$sql1 = "SELECT fid,flowkey5 FROM ".DB_TABLEPRE.DB_JT."app_flow   
						WHERE fid in(".substr($per2['flowkey6'], 0, -1).") order by flownum asc";
				$result1 = $db->query($sql1);
				while ($per1 = $db->fetch_array($result1)) {
					$flowkey51=apps_whereflow($per1['flowkey5'],$appid);
					if($flowkey51!=1){
						//$nextflow[]=$per1['fid'];
						$html.=$per1['fid'].',';
					}
				}
			}
			return substr($html, 0, -1);
		}
	}
}
//新成员审批条件
function apps_newuser($_flowusertype,$_flowuser){
	global $db;
	global $_USER;
	if($_flowusertype=='2'){
		$html='';
		$flowuser=explode(',',$_flowuser);
		for($i=0;$i<sizeof($flowuser);$i++){
			if(trim($flowuser[$i])!=''){
				$sqluser = "SELECT b.name FROM ".DB_TABLEPRE."user a,".DB_TABLEPRE."user_view b where a.id=b.uid and  a.positionid like '%,".trim($flowuser[$i]).",%'  ORDER BY b.uid desc";
				$rowuserresult = $db->fetch_all($sqluser);
				foreach ($rowuserresult as $rowuser1) {
					if($rowuser1['name']!=''){
						$html.=$rowuser1['name'].',';
					}
				}
			}
		}
		$flowuser1=substr($html, 0, -1);
	}elseif($_flowusertype=='3'){
		$html='';
		$flowuser=explode(',',$_flowuser);
		for($i=0;$i<sizeof($flowuser);$i++){
			if(trim($flowuser[$i])!=''){
				$sqluser = "SELECT b.name FROM ".DB_TABLEPRE."user a,".DB_TABLEPRE."user_view b where a.id=b.uid and  a.departmentid like '%,".trim($flowuser[$i]).",%'  ORDER BY b.uid desc";
				$rowuserresult = $db->fetch_all($sqluser);
				foreach ($rowuserresult as $rowuser1) {
					if($rowuser1['name']!=''){
						$html.=$rowuser1['name'].',';
					}
				}
			}
		}
		$flowuser1=substr($html, 0, -1);
	}elseif($_flowusertype=='4'){
		$html='';
		$r = $db->fetch_one_array("SELECT departmentid FROM ".DB_TABLEPRE."user WHERE id = '".$_USER->id."'  ");
		$flowuser=explode(',',$r['departmentid']);
		for($i=0;$i<sizeof($flowuser);$i++){
			if(trim($flowuser[$i])!=''){
				$sqluser = "SELECT b.name FROM ".DB_TABLEPRE."user a,".DB_TABLEPRE."user_view b where a.id=b.uid and  a.departmentid like '%,".trim($flowuser[$i]).",%'  ORDER BY b.uid desc";
				$rowuserresult = $db->fetch_all($sqluser);
				foreach ($rowuserresult as $rowuser1) {
					if($rowuser1['name']!=''){
						$html.=$rowuser1['name'].',';
					}
				}
			}
		}
		$flowuser1=substr($html, 0, -1);
	}else{
		$flowuser1=$_flowuser;
	}
	return $flowuser1;
}
function apps_automaticuser($_flowusertype,$_flowuser,$_f7,$uid){
	global $db;
	global $_USER;
	if($_f7=='1' || $_f7=='2' || $_f7=='3' || $_f7=='4' || $_f7=='5'){
		$sql = "SELECT departmentid FROM ".DB_TABLEPRE."user  WHERE id = '".$uid."'";
		$row = $db->fetch_one_array($sql);
		if($_f7=='1'){
			$flowuser1=get_realname($uid);
		}elseif($_f7=='2'){
			$flowuser1=get_realname(apps_dep($row['departmentid'],'persno'));
		}elseif($_f7=='3'){
			$flowuser1=get_realname(apps_dep($row['departmentid'],'persno1'));
		}elseif($_f7=='4'){
			$flowuser1=get_realname(apps_dep($row['departmentid'],'persno2'));
		}elseif($_f7=='5'){
			$flowuser1=get_realname(apps_dep($row['departmentid'],'persno3'));
		}
	}elseif($_f7=='6' || $_f7=='7' || $_f7=='8' || $_f7=='9' || $_f7=='10'){
		$sql = "SELECT departmentid FROM ".DB_TABLEPRE."user  WHERE id = '".$_USER->id."'";
		$row = $db->fetch_one_array($sql);
		if($_f7=='6'){
			$flowuser1=get_realname($_USER->id);
		}elseif($_f7=='7'){
			$flowuser1=get_realname(apps_dep($row['departmentid'],'persno'));
		}elseif($_f7=='8'){
			$flowuser1=get_realname(apps_dep($row['departmentid'],'persno1'));
		}elseif($_f7=='9'){
			$flowuser1=get_realname(apps_dep($row['departmentid'],'persno2'));
		}elseif($_f7=='10'){
			$flowuser1=get_realname(apps_dep($row['departmentid'],'persno3'));
		}
	}elseif($_f7=='11' || $_f7=='12' || $_f7=='13' || $_f7=='14'){
		if($_flowusertype=='3'){
			if($_f7=='11'){
				$flowuser1=get_realname(apps_dep($_flowuser,'persno'));
			}elseif($_f7=='12'){
				$flowuser1=get_realname(apps_dep($_flowuser,'persno1'));
			}elseif($_f7=='13'){
				$flowuser1=get_realname(apps_dep($_flowuser,'persno2'));
			}elseif($_f7=='14'){
				$flowuser1=get_realname(apps_dep($_flowuser,'persno3'));
			}
		}
	}elseif($_f7=='15' || $_f7=='16' || $_f7=='17' || $_f7=='18'){
		$sql = "SELECT departmentid FROM ".DB_TABLEPRE."user  WHERE id = '".$_USER->id."'";
		$row = $db->fetch_one_array($sql);
		$html='';
		$depid=explode(',',$row['departmentid']);
		for($i=0;$i<sizeof($depid);$i++){
			if($depid[$i]!=''){
				$sqld = "SELECT father FROM ".DB_TABLEPRE."department  
						 WHERE id = '".$depid[$i]."'";
				$rows = $db->fetch_one_array($sqld);
				$html.=$rows['father'].',';
			}
		} 
		if($_f7=='15'){
			$flowuser1=get_realname(apps_dep(substr($html, 0, -1),'persno'));
		}elseif($_f7=='16'){
			$flowuser1=get_realname(apps_dep(substr($html, 0, -1),'persno1'));
		}elseif($_f7=='17'){
			$flowuser1=get_realname(apps_dep(substr($html, 0, -1),'persno2'));
		}elseif($_f7=='18'){
			$flowuser1=get_realname(apps_dep(substr($html, 0, -1),'persno3'));
		}
	}elseif($_f7=='19'){
		$sql = "SELECT departmentid FROM ".DB_TABLEPRE."user  WHERE id = '".$uid."'";
		$row = $db->fetch_one_array($sql);
		$flowuser1=get_realname(apps_dep($row['departmentid']));
	}elseif($_f7=='20'){
		$sql = "SELECT departmentid FROM ".DB_TABLEPRE."user  WHERE id = '".$_USER->id."'";
		$row = $db->fetch_one_array($sql);
		$flowuser1=get_realname(apps_dep($row['departmentid']));
	}elseif($_f7=='21'){
		if($_flowusertype=='3'){
			$flowuser1=get_realname(apps_dep($_flowuser));
		}
	}elseif($_f7=='22'){
		$sql = "SELECT departmentid FROM ".DB_TABLEPRE."user  WHERE id = '".$_USER->id."'";
		$row = $db->fetch_one_array($sql);
		$html='';
		$depid=explode(',',$row['departmentid']);
		for($i=0;$i<sizeof($depid);$i++){
			if($depid[$i]!=''){
				$sqld = "SELECT father FROM ".DB_TABLEPRE."department  
						 WHERE id = '".$depid[$i]."'";
				$rows = $db->fetch_one_array($sqld);
				$html.=$rows['father'].',';
			}
		}
		$flowuser1=get_realname(apps_dep(substr($html, 0, -1)));
	}
	return $flowuser1;
}
function apps_dep($departmentid,$type){
	global $db;
	global $_USER;
	$html='';
	$depid=explode(',',$departmentid);
	for($i=0;$i<sizeof($depid);$i++){
		if($depid[$i]!=''){
			if($type!=''){
				$sqld = "SELECT ".$type." FROM ".DB_TABLEPRE."department  
						 WHERE id = '".$depid[$i]."'";
				$rows = $db->fetch_one_array($sqld);
				$html.=$rows[$type].',';
			}else{
				$sqld = "SELECT * FROM ".DB_TABLEPRE."department  
						 WHERE id = '".$depid[$i]."'";
				$rows = $db->fetch_one_array($sqld);
				$html.=$rows['persno'].','.$rows['persno1'].','.$rows['persno2'].','.$rows['persno3'].',';
			}
		}
	} 
	return substr($html, 0, -1);
}
//过滤审批人员
function flowuserdel($perid=0,$appid=0){
	global $db;
	global $_USER;
	$sql = "SELECT usernum FROM ".DB_TABLEPRE.DB_JT."app_personnel
	        WHERE perid=".$perid." and appid = '".$appid."'";
	$row = $db->fetch_one_array($sql);
	$usernum=str_replace(get_realname($_USER->id).',','',$row['usernum']);
	$db->query("UPDATE ".DB_TABLEPRE.DB_JT."app_personnel set usernum='".$usernum."'
	            WHERE perid=".$perid." and appid = '".$appid."' ");
}
?>