<?php
 /*
 * 74cms 个人会员函数
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
if(!defined('IN_QISHI'))
{
 die('Access Denied!');
}
/*获取简历id
* @param $uid  	  	  简历对应的uid
* @return row['id']          返回简历对应的id值
*/
function get_pid($uid)
{
	global $db;
	$row = $db->getone("select id,uid from ".table('resume')." where uid = ".$uid.' limit 1'); 
	return $row['id'];
} 
//普通会员通过uid得到相应的parentuid
function get_parentuid($uid)
{
	global $db;
	$row = $db->getall("select * from ".table('members')." where uid = ".$uid.''); 
	return $row['0']['parentuid'];
}
/*获取简历信息
* @param $uid  	用户的ID
*/
function get_resume_info($uid)
{
	global $db;
	$uid=intval($uid);
	$info=$db->getone("select * from ".table('resume')." where  uid='{$uid}' LIMIT 1 ");
	return $info;
}
/*获取意向职位
* @param $pid  	 	  简历对应的id
* @return row                  返回简历意向职位
*/
function get_resume_jobs($pid)
{
	global $db;
	$pid=intval($pid);
	$sql = "select * from ".table('resume_jobs')." where pid='{$pid}'  LIMIT 20" ;
	return $db->getall($sql);
}
/*统计个人申请职位数
* @param $uid  	 	  个人uid
* @param $look               是否查看
* @return number           返回申请数目
*/
function count_personal_jobs_apply($uid,$look=NULL)
{
	global $db;
	$wheresql=" WHERE personal_uid='{$uid}' ";
	if(intval($look)>0)	$wheresql.=" AND is_look='{$look}' ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('personal_jobs_apply').$wheresql;
	return $db->get_total($total_sql);
}
/*统计个人邀请面试数
* @param $uid  	 	  个人uid
* @param $look               是否查看
* @return number           返回邀请数目
*/
function count_interview($uid,$look=NULL)
{
	global $db;
	$uid=intval($uid);
	$wheresql=" WHERE  resume_uid='{$uid}' ";
	if (intval($look)>0) $wheresql.=" AND  is_look=".intval($look);
	$total_sql="SELECT COUNT(*) AS num FROM ".table('company_interview')." {$wheresql}";
	return $db->get_total($total_sql);
}
/*统计个人会员的猎头顾问
* @param $uid  	 	  个人uid
* @return number           返回所属猎头数目
*/
function count_hunter($uid)
{
	global $db;
	$uid=intval($uid);
	$wheresql=" WHERE  resume_uid='{$uid}'  AND  state=1 AND entrust_type=2";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('entrust_hunter')." {$wheresql}";
	return $db->get_total($total_sql);
}
/*统计个人简历的下载次数
* @param $uid  	 	  个人uid
* @return number           返回下载次数
*/
function count_com_downresume($uid)
{
	global $db;
	$wheresql=" WHERE resume_uid='".intval($uid)."' ";
	$total=$db->get_total("SELECT COUNT(*) AS num FROM ".table('company_down_resume').$wheresql);
	return $total;
}
/*得到屏蔽企业
* @param $uid  	 	  个人uid
* @return number           返回下载次数
*/
function get_shield_company($uid)
{
	global $db;
	$row = $db->getall("select * from ".table('personal_shield_company')." where uid = ".$uid.' '); 
	return $row;
}
/*获取简历期望职位的id
* @param $uid  	  	  个人uid
* @return id   	             返回职位的id
*/
function get_interest_jobs_id_by_resume($uid)
{
	global $db;
	$uid=intval($uid);
	//通过resume_jobs 获取他感兴趣的职位的id
	$jobs_category = '';
	$query = $db->query("select distinct category from ".table('resume_jobs')." where uid=".$uid);
	while($ad = $db->fetch_array($query)){
		$jobs_category .= 'category = '.$ad['category'].' or ';
	}
	$jobs_category = trim($jobs_category,'or ');  
	if(!empty($jobs_category)){
		$interest_jobs = $db->getall("select distinct pid  from ".table('jobs_category')." where  ".$jobs_category); 
		return  $interest_jobs; 
	}else{
		return NULL;
	}
}
/*获取职位列表
* @param $offset  		  职位列表开始
* @param $perpage  	 	  职位列表显示个数
* @param $get_sql  	 	  sql语句
* @param $countresume  	  申请职位数
* @return $row_arr   	             返回职位列表
*/
function get_jobs($offset,$perpage,$get_sql= '',$countresume=false)
{
	global $db,$timestamp;
	$row_arr = array();
	if(isset($offset)&&!empty($perpage))
	{
	$limit=" LIMIT {$offset},{$perpage}";
	} 
	$result = $db->query($get_sql.$limit);
	while($row = $db->fetch_array($result))
	{
		$row['jobs_name_']=$row['jobs_name'];
		$row['jobs_name']=cut_str($row['jobs_name'],10,0,"...");
		if (!empty($row['highlight']))
		{
		$row['jobs_name']="<span style=\"color:{$row['highlight']}\">{$row['jobs_name']}</span>";
		}
		if($row['utype']=='1')
		{
			$row['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$row['id']));
		}else
		{
			$row['jobs_url']=url_rewrite('QS_hunter_jobsshow',array('id'=>$row['id']));
		}
		if($row['audit']==3){
			$row['status'] = 4;
			$row['status_cn'] = '未通过';
			$sql = "select reason from ".table('audit_reason')." where jobs_id=$row[id] ";
			$reason_arr=$db->getone($sql);
			$row['reason']=$reason_arr["reason"];
			$row['company']=$row['companyname'];
		}
		elseif($row['audit']==2){
			$row['status'] = 3;
			$row['status_cn'] = '审核中';
		}
		elseif($row['deadline']<time()){
			$row['status'] = 2;
			$row['status_cn'] = '已结束';
		}else{
			$row['status'] = 0;
			$row['status_cn'] = '正在发布';
		}
		if ($countresume)
		{
		$wheresql=" WHERE belong_uid='{$row['uid']}' AND jobs_id= '{$row['id']}'";
		$row['countresume']=$db->get_total("SELECT COUNT(*) AS num FROM ".table('personal_jobs_apply').$wheresql);
		}
		$row_arr[] = $row;
	}
	return $row_arr;
}
/*获取：工作经历
* @param $uid  	用户的ID
*/
function get_resume_work($uid,$pid)
{
	global $db;
	$sql = "select * from ".table('resume_work')." where pid='".$pid."' AND uid=".intval($uid)."" ; 
	$query = $db->query($sql);
	while($row = $db->fetch_array($query)){ 
		$row['diff_time_start'] = date('Y-m',$row['starttime']);
		if($row['today'] == '1'){
			$row['diff_time_end'] = '至今';
			$row['diff_time'] = timediff(date("Y-m-d",$row['starttime']),date("Y-m-d",time())); 
		}else{
			$row['diff_time_end'] = date('Y-m',$row['endtime']);
			$row['diff_time'] = timediff(date("Y-m-d",$row['starttime']),date("Y-m-d",$row['endtime'])); 
		}
		$d[] = $row;
	}
	return $d;
}  
/*获取：教育经历列表
* @param $uid  	用户的ID
*/ 
function get_resume_education($uid,$pid)
{
	global $db;
	if (intval($uid)!=$uid) return false;
	$sql = "SELECT * FROM ".table('resume_education')." WHERE  pid='".intval($pid)."' AND uid='".intval($uid)."' ";
	$query = $db->query($sql);
	while($row = $db->fetch_array($query)){ 
		$row['diff_time_start'] = date('Y-m',$row['starttime']);
		if($row['today'] == '1'){
			$row['diff_time_end'] = '至今';
			$row['diff_time'] = timediff(date("Y-m-d",$row['starttime']),date("Y-m-d",time())); 
		}else{
			$row['diff_time_end'] = date('Y-m',$row['endtime']);
			$row['diff_time'] = timediff(date("Y-m-d",$row['starttime']),date("Y-m-d",$row['endtime'])); 
		}
		$d[] = $row;
	}
	return $d; 
}
/*获取：项目经验列表
* @param $uid  	用户的ID
*/  
function get_resume_project($uid,$pid)
{
	global $db;
	$sql = "select * from ".table('resume_project')." where pid='".intval($pid)."' AND  uid='".intval($uid)."' ";
	$query = $db->query($sql);
	while($row = $db->fetch_array($query)){ 
		$row['diff_time_start'] = date('Y-m',$row['starttime']);
		if($row['today'] == '1'){
			$row['diff_time_end'] = '至今';
			$row['diff_time'] = timediff(date("Y-m-d",$row['starttime']),date("Y-m-d",time())); 
		}else{
			$row['diff_time_end'] = date('Y-m',$row['endtime']);
			$row['diff_time'] = timediff(date("Y-m-d",$row['starttime']),date("Y-m-d",$row['endtime'])); 
		}
		$d[] = $row;
	}
	return $d; 
} 
/*获取：培训经历列表
* @param $uid  	用户的ID
*/ 
function get_resume_language($uid,$pid)
{
	global $db;
	$sql = "select * from ".table('resume_language')." where pid='".intval($pid)."' AND  uid='".intval($uid)."' ";
	$query = $db->query($sql);
	while($row = $db->fetch_array($query)){ 
		$row['diff_time_start'] = date('Y-m',$row['starttime']);
		if($row['today'] == '1'){
			$row['diff_time_end'] = '至今';
			$row['diff_time'] = timediff(date("Y-m-d",$row['starttime']),date("Y-m-d",time())); 
		}else{
			$row['diff_time_end'] = date('Y-m',$row['endtime']);
			$row['diff_time'] = timediff(date("Y-m-d",$row['starttime']),date("Y-m-d",$row['endtime'])); 
		}
		$d[] = $row;
	}
	return $d; 
}
/*检查简历的完成程度,创建索引表，检测简历等级，
* @param $uid  	用户的ID
*/
function check_resume($uid,$pid)
{
	global $db,$timestamp,$_CFG;
	$uid=intval($uid);
	$pid=intval($pid);
	$percent=0;
	$resume_basic=get_resume_info($uid,$pid); 
	if (!empty($resume_basic))$percent=$percent+20; 			//基本信息+20
	$resume_intention=$resume_basic['intention_jobs_cn'];  	
	$evaluation=$resume_basic['evaluation'];  			
	if (!empty($resume_intention))$percent=$percent+15;			//求职意向 +15
	if (!empty($evaluation))$percent=$percent+10;				//自我描述 +10
	
	$resume_photo=$resume_basic['photo_img'];
	if (!empty($resume_photo))$percent=$percent+5; 				//简历照片 +5
	
	$resume_work=get_resume_work($uid,$pid);
	$resume_education=get_resume_education($uid,$pid); 
	if (!empty($resume_work))$percent=$percent+15;				//工作经历 +15
	if (!empty($resume_education))$percent=$percent+15;			//教育培训 +15
	 
	$resume_project=get_resume_project($uid,$pid);  
	if (!empty($resume_project))$percent=$percent+15;			//项目 +15

	$resume_language=get_resume_language($uid,$pid);
	if (!empty($resume_language))$percent=$percent+5;			//语言 +5	
	
	$setsqlarr['complete_percent']=$percent;
	  
	require_once(QISHI_ROOT_PATH.'include/splitword.class.php');
	$sp = new SPWord();
	$setsqlarr['key']=$resume_basic['intention_jobs_cn'].$resume_basic['recentjobs'].$resume_basic['evaluation'];		
	$setsqlarr['key']="{$resume_basic['fullname']} ".$sp->extracttag($setsqlarr['key']);
	$setsqlarr['key']=str_replace(","," ",$resume_basic['intention_jobs_cn'])." {$setsqlarr['key']} {$resume_basic['education_cn']}";
	$setsqlarr['key']=$sp->pad($setsqlarr['key']);
	if (!empty($resume_education))
	{
		foreach($resume_education as $li)
		{
		$setsqlarr['key']="{$li['school']} {$setsqlarr['key']} {$li['speciality']}";
		}
	}
	$setsqlarr['refreshtime']=$timestamp; 
	 
	//检测是否为高级简历
	if(($_CFG['elite_resume_complete_exp'] <= $resume_basic['experience']) && ($_CFG['elite_resume_complete_wage'] <= $resume_basic['wage_current']) && ($_CFG['elite_resume_complete_percent'] <= $setsqlarr['complete_percent'])){
	$setsqlarr['talent'] = '2';			//高级
	}else{
	$setsqlarr['talent'] = '1';			//低级
	}    
	updatetable(table('resume'),$setsqlarr,"uid='{$uid}' AND id='{$pid}'");  
	$j=get_resume_info($uid,$pid);  
	$j=array_map("addslashes", $j);
	$searchtab['uid']=$j['uid'];
	$searchtab['sex']=$j['sex'];
	$searchtab['birthdate']=$j['birthdate']; 
	$searchtab['wage']=$j['wage_hope'];
	$searchtab['education']=$j['education']; 
	$searchtab['experience']=$j['experience'];
	$searchtab['current']=$j['current'];
	$searchtab['refreshtime']=$j['refreshtime'];
	$searchtab['talent']=$j['talent'];  
	$searchtab['display']=$j['display'];
	$searchtab['key']=$j['key'];
	$searchtab['likekey']=$j['intention_jobs_cn'].','.$j['trade_cn'].','.$j['evaluation'].','.$j['fullname'];
	if(intval($setsqlarr['complete_percent']) >= 35)
	{
		updatetable(table('resume_search'),$searchtab,"uid='{$uid}' AND id='{$pid}'");
	}
	unset($searchtab); 	 
}
/*更新简历里的个人信息到members表当中
* @param $uid  	用户的ID
*/ 
function refresh_resume_to_members($uid)
{
	global $db;
	$jobs_info = get_resume_info($uid);
	$members_info = get_user_info($uid);

	if($jobs_info['telephone'] != $members_info['mobile']){
		$membersqlarr['mobile'] = $jobs_info['telephone']; 
		$membersqlarr['mobile_audit'] = '0';
	}  
	$membersqlarr['sex'] = $jobs_info['sex'];
	$membersqlarr['sex_cn'] = $jobs_info['sex_cn'];
	$membersqlarr['fullname'] = $jobs_info['fullname']; 
	updatetable(table('members'),$membersqlarr,"  uid='{$uid}'");  
}

//增加意向职位
function add_resume_jobs($pid,$uid,$str)
{
	global $db;
	$db->query("Delete from ".table('resume_jobs')." WHERE pid='".intval($pid)."'");
	$str=trim($str);
	$arr=explode(",",$str);
	if (is_array($arr) && !empty($arr))
	{
		foreach($arr as $a)
		{
		$a=explode(".",$a);
		$setsqlarr['uid']=intval($uid);
		$setsqlarr['pid']=intval($pid);
		$setsqlarr['topclass']=intval($a[0]);
		$setsqlarr['category']=intval($a[1]);
		$setsqlarr['subclass']=intval($a[2]);
			if (!inserttable(table('resume_jobs'),$setsqlarr))return false;
		}
	}
	return true;
}

//增加意向行业
function add_resume_trade($pid,$uid,$str)
{
	global $db;
	$db->query("Delete from ".table('resume_trade')." WHERE pid='".intval($pid)."'");
	$str=trim($str);
	$arr=explode(",",$str);
	if (is_array($arr) && !empty($arr))
	{
		foreach($arr as $a)
		{
		$a=explode(".",$a);
		$setsqlarr['uid']=intval($uid);
		$setsqlarr['pid']=intval($pid);
		$setsqlarr['trade']=intval($a[0]); 
			if (!inserttable(table('resume_trade'),$setsqlarr))return false;
		}
	}
	return true;
}
//增加意向地区
function add_resume_district($pid,$uid,$str)
{
	global $db;
	$db->query("Delete from ".table('resume_district')." WHERE pid='".intval($pid)."'");
	$str=trim($str);
	$arr=explode(",",$str);
	if (is_array($arr) && !empty($arr))
	{
		foreach($arr as $a)
		{
		$a=explode(".",$a);
		$setsqlarr['uid']=intval($uid);
		$setsqlarr['pid']=intval($pid);
		$setsqlarr['district']=intval($a[0]);
		$setsqlarr['sdistrict']=intval($a[1]);
			if (!inserttable(table('resume_district'),$setsqlarr))return false;
		}
	}
	return true;
} 
/*刷新简历
* @param $uid  	会员uid	  
* @return true/false   	            
*/
function refresh_resume($uid)
{
	global $db;
	$time=time();
	$uid=intval($uid);
	if (!$db->query("update  ".table('resume')."  SET refreshtime='{$time}'  WHERE uid='{$uid}'")) return false;
	if (!$db->query("update  ".table('resume_search')."  SET refreshtime='{$time}'  WHERE uid='{$uid}'")) return false; 
	write_memberslog($uid,2,1102,$_SESSION['username'],"/",0,"刷新了简历");
	return true;
} 
/*申请的职位
* @param $offset  		  职位列表开始
* @param $perpage  	 	  职位列表显示个数
* @param $get_sql  	 	  sql语句
* @return $row_arr   	             返回申请的职位列表
*/
function get_apply_jobs($offset,$perpage,$get_sql= '')
{
	global $db;
	$limit=" LIMIT ".intval($offset).','.intval($perpage);
	$select=" a.*,j.utype,j.jobs_name,j.id,j.addtime,j.company_id,j.companyname,j.company_addtime,j.wage_min,j.wage_max,j.district_cn,j.deadline,j.refreshtime,j.click";
	$sql="SELECT {$select} FROM ".table('personal_jobs_apply')." AS a{$get_sql} ORDER BY a.did DESC ".$limit;
	$result = $db->query($sql);
	while($row = $db->fetch_array($result))
	{
		$row['_jobs_name'] = cut_str($row['jobs_name'],10,0,'...');
		$row['_companyname'] = cut_str($row['companyname'],10,0,'...');
		if($row['utype']==1){
			$row['company_url']=url_rewrite('QS_companyshow',array('id'=>$row['company_id']));
			$row['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$row['jobs_id']));
		}else{
			$row['company_url']=url_rewrite('QS_hunter_show',array('id'=>$row['company_id']));
			$row['jobs_url']=url_rewrite('QS_hunter_jobsshow',array('id'=>$row['jobs_id']));
		}
		$row_arr[] = $row;
	}
	return $row_arr;
}
/*删除--申请的职位
* @param $del_id  	   删除职位的id
* @param $uid  	 	   会员uid 
* @return true   	             true/false
*/
function del_jobs_apply($del_id,$uid)
{
	global $db;
	$uidsql=" AND personal_uid=".intval($uid)." ";
	if (!is_array($del_id)) $del_id=array($del_id);
	$sqlin=implode(",",$del_id); 
	if (!preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin)) return false;
	$sql = "Delete from ".table('personal_jobs_apply')." WHERE did IN (".$sqlin.") ".$uidsql.""; 
	if (!$db->query($sql)) return false;
	write_memberslog($_SESSION['uid'],2,1302,$_SESSION['username'],"/",0,"删除了职位申请($sqlin)");
	return true;
}
/*面试邀请
* @param $offset  		  职位列表开始
* @param $perpage  	 	  职位列表显示个数
* @param $get_sql  	 	  sql语句
* @return $row_arr   	             返回面试邀请列表
*/
function get_invitation($offset,$perpage,$get_sql= '')
{
	global $db;
	$row_arr = array();
	$limit=" LIMIT ".intval($offset).','.intval($perpage);
	$select="i.*,j.utype,j.jobs_name,j.addtime,j.companyname,j.company_addtime,j.district_cn,j.wage_min,j.education_cn,j.wage_max,j.deadline,j.refreshtime,j.click";
	$sql="SELECT {$select} from ".table('company_interview')." AS i {$get_sql} ORDER BY did DESC {$limit}";
	$result = $db->query($sql);
	while($row = $db->fetch_array($result))
	{
		$row['_jobs_name'] = cut_str($row['jobs_name'],10,0,'...');
		$row['_companyname'] = cut_str($row['companyname'],10,0,'...');
		if($row['utype']==1)
		{
			$row['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$row['jobs_id']));
			$row['company_url']=url_rewrite('QS_companyshow',array('id'=>$row['company_id']));
		}
		else
		{
			$row['jobs_url']=url_rewrite('QS_hunter_jobsshow',array('id'=>$row['jobs_id']));
			$row['company_url']=url_rewrite('QS_hunter_show',array('id'=>$row['company_id']));
		}
		$row_arr[] = $row;
	} 
	return $row_arr;
}
/*删除--面试邀请
* @param $del_id  	   删除职位的id
* @param $uid  	   会员uid 
* @return true   	   true/false
*/
function del_invitation($del_id,$uid)
{
	global $db;
	$uidsql=" AND resume_uid=".intval($uid)." ";
	if (!is_array($del_id)) $del_id=array($del_id);
	$sqlin=implode(",",$del_id);
	if (!preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin)) return false;
	if (!$db->query("Delete from ".table('company_interview')." WHERE did IN (".$sqlin.") ".$uidsql."")) return false;
	write_memberslog($_SESSION['uid'],2,6002,$_SESSION['username'],"/",0,"删除了面试邀请($sqlin)");
	return true;
}
/*收藏的职位
* @param $offset  		  职位列表开始
* @param $perpage  	 	  职位列表显示个数
* @param $get_sql  	 	  sql语句
* @return $row_arr   	             返回收藏职位列表
*/
function get_favorites($offset,$perpage,$get_sql= '')
{
	global $db;
	$row_arr = array();
	$limit=" LIMIT {$offset},{$perpage}";
	$select=" f.*,j.utype,j.jobs_name,j.addtime as jobs_addtime,j.companyname,j.company_addtime,j.company_id,j.wage_min,j.wage_max,j.district_cn,j.education_cn,j.deadline,j.experience_cn,j.refreshtime,j.click";
	$sql = "SELECT {$select} FROM ".table('personal_favorites')." AS f {$get_sql} ORDER BY f.did DESC {$limit}";
	$result = $db->query($sql);
	while($row = $db->fetch_array($result))
	{
		if($row['utype']==1)
		{
			$row['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$row['jobs_id']));
		}
		else
		{
			$row['jobs_url']=url_rewrite('QS_hunter_jobsshow',array('id'=>$row['jobs_id']));
		}
		$row['_jobs_name'] = cut_str($row['jobs_name'],10,0,'...');
		$row['_companyname'] = cut_str($row['companyname'],10,0,'...');
		$row['company_url']=url_rewrite('QS_companyshow',array('id'=>$row['company_id']));
		$row_arr[] = $row;
	}
	return $row_arr;
}
/*删除  收藏职位
* @param $id  	   删除职位的id
* @param $uid  	   会员uid 
* @return true   	   true/false
*/
function del_favorites($id,$uid)
{
	global $db;
	$uidsql=" AND personal_uid=".intval($uid)."";
	if (!is_array($id)) $id=array($id);
	$sqlin=implode(",",$id); 
	if (!preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin)) return false;
	$sql="Delete from ".table('personal_favorites')." WHERE did IN (".$sqlin.") ".$uidsql."";
	write_memberslog($_SESSION['uid'],2,1202,$_SESSION['username'],"/",0,"删除了职位收藏($sqlin)");
	return $db->query($sql);
}
/*谁在关注我(简历查看记录表)
* @param $offset  		  职位列表开始
* @param $perpage  	 	  职位列表显示个数
* @param $get_sql  	 	  sql语句
* @return $row_arr   	             返回简历查看记录列表
*/
function get_attention($offset,$perpage,$get_sql= '')
{
	global $db;
	$limit=" LIMIT {$offset},{$perpage}";
	$time = intval(time());
	$sql = "SELECT * FROM ".table('view_resume')." as v {$get_sql} ORDER BY addtime DESC , v.id DESC {$limit}";
	$result = $db->query($sql);
	while($row = $db->fetch_array($result))
	{
		 //关注的若是 企业
		if($row['utype']=='1'){
			//由于关注我的可能是企业的子账号,所以在得到其企业基本信息的时候要用parentuid
			$parentuid = get_parentuid(intval($row['uid'])); 
			$company_profile = $db->getone("select * from ".table('company_profile')." where `uid`=".$parentuid);
			$row['uid'] = $company_profile['uid'];
			$row['name'] = $company_profile['companyname'];
			$row['name_url']=url_rewrite('QS_companyshow',array('id'=>$company_profile['id']));
			// 名字
			$row['name'] = cut_str($row['name'],20,0,"..");
			// 所在地区
			$row['district_cn'] = $company_profile['district_cn'];
			// 所属行业
			$row['trade_cn'] = $company_profile['trade_cn'];
			$row['_trade_cn'] = cut_str($row['trade_cn'],12,0,"...");
			// 在招职位
			$count=$db->get_total("SELECT COUNT(*) AS num FROM ".table('jobs')." WHERE utype=1 AND company_id={$company_profile['id']} AND audit=1 AND deadline>{$time} AND display=1 AND setmeal_deadline>{$time}  ");
			$row['count'] = $count;
			if($row['resumeid']){
				$downlog = $db->getone("select did from ".table('company_down_resume')." where resume_id={$row['resumeid']}  and company_uid={$company_profile['uid']}");
				if(intval($downlog)){
					// 是否下载
					$row['hasdown'] = 1;
				}else{
					$row['hasdown'] = 0;
				}
			}
		}
		 
		//关注的若是 猎头
		elseif($row['utype']=='3'){
			$hunter_profile = $db->getone("select * from ".table('hunter_profile')." where `uid`=".$row['uid']);
			$row['uid'] = $hunter_profile['uid'];
			$row['name'] = $hunter_profile['fullname'];
			$row['name_url']=url_rewrite('QS_hunter_show',array('id'=>$hunter_profile['id']));
			//名字
			$row['name'] = cut_str($row['name'],20,0,"..");
			//所在地区
			$row['district_cn'] = $hunter_profile['district_cn'];
			//擅长行业
			$row['trade_cn'] = $hunter_profile['trade_cn'];
			$row['_trade_cn'] = cut_str($row['trade_cn'],12,0,"...");
			//在招职位
			$count=$db->get_total("SELECT COUNT(*) AS num FROM ".table('jobs')." WHERE utype=3 AND uid=".$row['uid']." AND audit=1 AND deadline>{$time} AND display=1 AND setmeal_deadline>{$time}");
			$row['count'] = $count;
			if($row['resumeid']){
				$downlog = $db->getone("select did from ".table('hunter_down_resume')." where resume_id={$row['resumeid']}  and hunter_uid={$hunter_profile['uid']}");
				if(intval($downlog)){
					//是否下载
					$row['hasdown'] = 1;
				}else{
					$row['hasdown'] = 0;
				}
			}
		} 
		$row_arr[] = $row;
	} 
	return $row_arr;
} 

/*删除  			谁在关注我
* @param $id  	  	id
* @return true   	true/false
*/
function del_attention($id)
{
	global $db;
	if (!is_array($id)) $id=array($id);
	$sqlin=implode(",",$id); 
	if (!preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin)) return false;
	$sql="Delete from ".table('view_resume')." WHERE id IN (".$sqlin.") ";
	write_memberslog($_SESSION['uid'],2,1202,$_SESSION['username'],"/",0,"删除了关注我($sqlin)");
	return $db->query($sql);
}

//获取 单条 工作经历
function get_resume_work_one($uid,$pid,$id)
{
	global $db;
	$sql = "select * from ".table('resume_work')." where id='".intval($id)."' AND pid='".intval($pid)."' AND uid='".intval($uid)."' LIMIT 1 ";
	return $db->getone($sql);
}

//获取：培训经历列表
function get_resume_training($uid,$pid)
{
	global $db;
	$sql = "select * from ".table('resume_training')." where pid='".intval($pid)."' AND  uid='".intval($uid)."' ";
	return $db->getall($sql);
}
//获取 单条 培训经历
function get_resume_training_one($uid,$pid,$id)
{
	global $db;
	$sql = "select * from ".table('resume_training')." where id='".intval($id)."' AND pid='".intval($pid)."'  AND uid='".intval($uid)."'  LIMIT 1 ";
	return $db->getone($sql);
} 
//获取 单条 教育经历
function get_resume_education_one($uid,$id)
{
	global $db;
	$sql = "select * from ".table('resume_education')." where id='".intval($id)."' AND uid='".intval($uid)."' LIMIT 1";
	return $db->getone($sql);
} 
//获取 单条 项目经验
function get_resume_project_one($uid,$pid,$id)
{
	global $db;
	$sql = "select * from ".table('resume_project')." where id='".intval($id)."' AND pid='".intval($pid)."'  AND uid='".intval($uid)."'  LIMIT 1 ";
	return $db->getone($sql);
}

//删除 屏蔽企业
function del_shield_company($uid,$keyword_id){
	global $db;
	if(!$db->query("delete from ".table('personal_shield_company')." where uid=".$uid." and id=".$keyword_id)) return false;
	return true;
}

// 获取个人 合作猎头
function get_personal_hunter($uid)
{
	global $db;
	$uid=intval($uid);
	$sql="select * from ".table("entrust_hunter")." where entrust_type=2 and state=1 and resume_uid=$uid ";
}
//检查该猎头是否委托过
function check_hunter_entrust($hunter_id,$uid)
{
	global $db;
	$sql = "select id from ".table('entrust_hunter')." WHERE hunter_id = '".intval($hunter_id)."' AND resume_uid='".intval($uid)."' LIMIT 1";
	return $db->getone($sql);
}
//查看是否纯在此职位，多级
function app_get_jobs($id)
{
	global $db;
	if (strpos($id,"-"))
	{
		$id=str_replace("-",",",$id);
		if (!preg_match("/^(\d{1,10},)*(\d{1,10})$/",$id)) return false;
	}
	else
	{
	$id=intval($id);
	}
	$sql = "select * from ".table('jobs')." WHERE id IN ({$id}) ";
	return $db->getall($sql);
} 
//得到当天申请职位数
function get_now_applyjobs_num($uid)
{
	global $db;
	$uid=intval($uid);
	$now = mktime(0,0,0,date("m"),date("d"),date("Y"));
	$wheresql=" WHERE personal_uid = '{$uid}' AND apply_addtime>{$now} ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('personal_jobs_apply').$wheresql;
	return $db->get_total($total_sql);
}
//检查该职位是否申请过
function check_jobs_apply($jobs_id,$resume_id,$p_uid)
{
	global $db;
	$sql = "select did from ".table('personal_jobs_apply')." WHERE personal_uid = '".intval($p_uid)."' AND jobs_id='".intval($jobs_id)."'  AND resume_id='".intval($resume_id)."' LIMIT 1";
	return $db->getone($sql);
}







 
/*时间差 相差几年几个月
* @param $date 1  	起始时间	 如：2014-10-28
* @param $date2  	结束时间  如：2014-12-28
*/
function timediff($date1,$date2){
	$date1_stamp=strtotime($date1);
	$date2_stamp=strtotime($date2);
	list($date_1['y'],$date_1['m'])=explode("-",date('Y-m',$date1_stamp));
	list($date_2['y'],$date_2['m'])=explode("-",date('Y-m',$date2_stamp));
	$month =  abs(($date_2['y']-$date_1['y'])*12 +$date_2['m']-$date_1['m']);
	$year =  floor($month/12);
	if($year == '0'){
		$time = $month.'月';
	}else{
		$sy_month = $month-($year*12);
		if($sy_month == '0'){
			$time = $year.'年';
		}else{
			$time = $year.'年'.$sy_month.'月';
		}
	}
	return $time;
 }
 //收藏职位
function add_favorites($id,$uid)
{
	global $db,$timestamp;
		if (strpos($id,"-"))
		{
			$id=str_replace("-",",",$id);
			if (!preg_match("/^(\d{1,10},)*(\d{1,10})$/",$id)) return false;
		}
		else
		{
		$id=intval($id);
		}
	$sql = "select * from ".table('jobs')." WHERE id IN ({$id}) "; 
	$jobs=$db->getall($sql);
	$i=0;
	foreach($jobs as $list)
	{
		$sql1 = "select jobs_id from ".table('personal_favorites')." where jobs_id=".$list['id']." AND personal_uid=".$uid."  LIMIT 1";
		if ($db->getone($sql1))
		{
		continue;
		}
		$setsqlarr['personal_uid']=$uid;
		$setsqlarr['jobs_id']=$list['id'];
		$setsqlarr['jobs_name']=addslashes($list['jobs_name']);
		$setsqlarr['addtime']=$timestamp;
		inserttable(table('personal_favorites'),$setsqlarr);
		$i=$i+1;
	}
	return $i;
}
function to_hunter_favorites($id,$hunter_uid)
{
	global $db,$_CFG;
	$timestamp=time();
	if (strpos($id,"-")) $id=explode("-",$id);
	if  (!is_array($id)) $id=array($id);
		$i=0;
		foreach ($id as $v) 
		{
			$v=intval($v);
			if (!check_favorites($v,$hunter_uid))
			{
				$db->query("INSERT INTO ".table('hunter_favorites')." (resume_id,hunter_uid,favorites_addtime) VALUES ('{$v}','{$hunter_uid}','{$timestamp}')");
				$i++;
			}
		}
		return $i;
}
//检测人才库中是否已经存在
function check_favorites($resume_id,$hunter_uid)
{
	global $db;
	$hunter_uid=intval($hunter_uid);
	$resume_id=intval($resume_id);
	$sql = "select * from ".table('hunter_favorites')." WHERE hunter_uid ='{$hunter_uid}' AND resume_id='{$resume_id}' LIMIT 1";
	$info=$db->getone($sql);
	if (empty($info))
	{
	return false;
	}
	else
	{
	return true;
	}
}
/*
	@删除委托信息
	@$del_id 记录id
	@$uid  猎头会员uid
*/
function del_entrust($del_id,$uid)
{
	global $db;
	$return=0;
	$uidsql=" AND resume_uid=".intval($uid)."";
	if (!is_array($del_id)) $del_id=array($del_id);
	$sqlin=implode(",",$del_id);
	if (preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin))
	{
	if (!$db->query("Delete from ".table('entrust_hunter')." WHERE id IN ({$sqlin}) {$uidsql}")) return false;
	$return=$return+$db->affected_rows();
	}
	return $return;
}
/*
	@删除推荐记录
	@$del_id 记录id
	@$uid 个人会员uid
*/
function del_recommend($del_id,$uid)
{
	global $db;
	$return=0;
	$uidsql=" AND personal_uid=".intval($uid)."";
	if (!is_array($del_id)) $del_id=array($del_id);
	$sqlin=implode(",",$del_id);
	if (preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin))
	{
	if (!$db->query("Delete from ".table('hunter_recommend')." WHERE did IN ({$sqlin}) {$uidsql}")) return false;
	$return=$return+$db->affected_rows();
	}
	return $return;
}
?>