<?php
/*
应用级函数
*/
function website_get_vip($msgid,$msgtime){
	global $obj_db;
	$arr_vip=array("vip_id"=>0,"vip_name"=>"","vip_days"=>0);
	$arr_list=array();
	if(is_array($msgid)){
		$str_ids=implode(",",$msgid);
		for($i=0;$i<$lng_count;$i++){
			if(!isset($msgtime[$i])) continue;
			if(!is_numeric($msgtime[$i])) $msgtime[$i]=strtotime($msgtime[$i]);
			$arr_time["id_".$msgid[$i]]=$msgtime[$i];
		}
	}else{
		if($msgid<1) return $arr_vip;
		$str_ids=$msgid;
		$arr_time["id_".$msgid]=$msgtime;
	}
	$lng_now_time=strtotime(date('Y-m-d'));
	$obj_result = $obj_db->query("SELECT vip_id,vip_name,vip_days FROM ".DB_PRE."hr_company_vip where vip_id in(".$str_ids.")");
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$lng_time=$obj_rs["vip_days"]*86400+$arr_time["id_".$obj_rs["vip_id"]];
		if($lng_time>$lng_now_time){
			$lng_time=$lng_time-$lng_now_time;
			$lng_day=intval($lng_time/86400);
			$obj_rs["vip_days"]=$lng_day;
		}else{
			$obj_rs["vip_days"]=0;
		}
		$arr_list["id_".$obj_rs["vip_id"]]=$obj_rs;
	}
	if($str_ids==$msgid && isset($arr_list["id_".$msgid]) ){
		$arr_vip=$arr_list["id_".$msgid];
	}else{
		$arr_vip=$arr_list;
	}
	return $arr_vip;

}
//初始化站点JS常量
function website_init_js(){
	$strx="<script>var cfg_web_url='".WEB_URL."';</script>";
	echo $strx;
}
function website_ads_list($msgposition="",$msgnum=5,$msgtype="",$msg_sp="",$is_js=0){
	global $obj_db;
	$str_where=" where 1";
	if($msgposition!=""){
		 $str_where.=" and ads_position='".$msgposition."'";
	}
	if($msgtype!=""){
		 $str_where.=" and ads_type='".$msgtype."'";
	}
	if($msgnum>0){
		$str_limit=" limit 0,".$msgnum;
	}else{
		$str_limit=" limit 0,5";
	}
	$str_sp_left="";
	$str_sp_right="";
	if($msg_sp!=""){
		$str_sp_left="<".$msg_sp.">";
		$str_sp_right="</".$msg_sp.">";
	}
	$str_sql="SELECT * FROM ".DB_PRE."other_ads".$str_where." order by ads_sort,ads_id desc".$str_limit;
	$obj_result = $obj_db->query($str_sql);
	$str_ads="";
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$str_ads.=$str_sp_left.$obj_rs["ads_content"].$str_sp_right;
	}
	if($is_js==0){
		echo $str_ads;
	}else{
		echo addslashes($str_ads);
	}

}
function website_ads_show($msg_id,$is_js=0){
	global $obj_db;
	$str_where=" where ads_id=".$msg_id;
	$str_sql="SELECT * FROM ".DB_PRE."other_ads".$str_where." limit 0,1";
	$obj_result = $obj_db->query($str_sql);
	if($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$str_ads=$obj_rs["ads_content"];
		if($is_js==0){
			echo $str_ads;
		}else{
			echo addslashes($str_ads);
		}
	}
}
function get_temp_job($msg_name,$msg_limit1,$msg_limit2,$msg_sort,$msg_where="",$msg_pagesize=0){
	global $obj_db,$sql_return;
	$msg_limit1=intval($msg_limit1);
	$msg_limit2=intval($msg_limit2);
	if($msg_limit1<0) $msg_limit1=0;
	if($msg_limit2<$msg_limit1) $msg_limit2=$msg_limit1+10;

	$obj_tab_company=new cls_tab_hr_company();
	$obj_tab_job=new cls_tab_hr_job();
	$arr_job=array();
	$str_where=" where job_user_id=company_user_id";
	if($msg_where!="") $str_where.=" and ".$msg_where;
	$str_limit=" limit ".$msg_limit1.",".$msg_limit2;
	if($msg_pagesize>0){
		global $get_page;
		(empty($get_page) || !is_numeric($get_page))? $get_page=1 : $get_pae=intval($get_page);
		$obj_rs  = $obj_db->get_one("SELECT count(1) as num FROM ".DB_PRE."hr_job,".DB_PRE."hr_company".$str_where);
		$int_total=$obj_rs["num"];
		$int_pages= ceil($int_total/$msg_pagesize);
		$get_page = min($int_pages, $get_page);
		$get_page = max($get_page, 1);
		$page_split_page=get_pages_html($int_total, $get_page, $msg_pagesize,format_url_query(array('page'=>'')));
		$int_offset = $msg_pagesize*($get_page-1);
		$str_limit = " limit ".$int_offset.",".$msg_pagesize;
		$sql_return[$msg_name]["page"]=$page_split_page;
	}

	$obj_result = $obj_db->query("SELECT a.job_id,a.job_user_id,a.job_name,a.job_num,a.job_validdate,a.job_area,a.job_degree,a.job_experience1,a.job_experience2,a.job_sex,a.job_hits,a.job_updatetime,a.job_pay1,a.job_pay2,b.company_name,b.company_id FROM ".DB_PRE."hr_job a,".DB_PRE."hr_company b".$str_where.$msg_sort.$str_limit);
	$lng_x=1;
	while($obj_rs = $obj_db->fetch_array($obj_result)){
		$obj_rs["url"]=$obj_tab_job->get_url($obj_rs["job_id"]);
		$obj_rs["updatetime"]=format_date($obj_rs["job_updatetime"],"Y-m-d");
		$obj_rs["company_url"]=$obj_tab_company->get_url($obj_rs["company_id"]);
		if($obj_rs["job_pay1"]==0&&$obj_rs["job_pay2"]==0){
			$obj_rs["pay"]="面议";
		}else{
			$obj_rs["pay"]=$obj_rs["job_pay1"]."~".$obj_rs["job_pay2"];
		}
		if($obj_rs["job_experience1"]==0&&$obj_rs["job_experience2"]==0){
			$obj_rs["experience"]="不限";
		}else if($obj_rs["job_experience1"]==0){
			$obj_rs["experience"]=$obj_rs["job_experience2"]." 年以下";
		}else if($obj_rs["job_experience2"]==0){
			$obj_rs["experience"]=$obj_rs["job_experience1"]." 年以上";
		}else{
			$obj_rs["experience"]=$obj_rs["job_experience1"]."~".$obj_rs["job_experience1"]." 年";
		}
		if($obj_rs["job_sex"]==""){
			$obj_rs["job_sex"]="不限";
		}
		if($obj_rs["job_num"]>0){
			$obj_rs["job_num"]=$obj_rs["job_num"]." 人";
		}else{
			$obj_rs["job_num"]="不限";
		}
		if($obj_rs["job_validdate"]>0){
			$obj_rs["job_validdate"]=format_date($obj_rs["job_validdate"],"Y-m-d");
		}else{
			$obj_rs["job_validdate"]="长期";
		}

		$arr_job[]=$obj_rs;
	}
	if($msg_pagesize>0){
		$sql_return[$msg_name]["list"]=$arr_job;
	}else{
		$sql_return[$msg_name]=$arr_job;
	}
}
function get_temp_company($msg_name,$msg_limit1,$msg_limit2,$msg_sort,$msg_where="",$msg_pagesize=0){
	global $obj_db,$sql_return;
	$msg_limit1=intval($msg_limit1);
	$msg_limit2=intval($msg_limit2);
	if($msg_limit1<0) $msg_limit1=0;
	if($msg_limit2<$msg_limit1) $msg_limit2=$msg_limit1+10;
	$str_limit=" limit ".$msg_limit1.",".$msg_limit2;

	$str_where=" where 1=1";
	if($msg_where!="") $str_where.=" and ".$msg_where;
	if($msg_pagesize>0){
		global $get_page;
		(empty($get_page) || !is_numeric($get_page))? $get_page=1 : $get_pae=intval($get_page);
		$obj_rs  = $obj_db->get_one("SELECT count(1) as num FROM ".DB_PRE."hr_company".$str_where);
		$int_total=$obj_rs["num"];
		$int_pages= ceil($int_total/$msg_pagesize);
		$get_page = min($int_pages, $get_page);
		$get_page = max($get_page, 1);
		$page_split_page=get_pages_html($int_total, $get_page, $msg_pagesize,format_url_query(array('page'=>'')));
		$int_offset = $msg_pagesize*($get_page-1);
		$str_limit = " limit ".$int_offset.",".$msg_pagesize;
		$sql_return[$msg_name]["page"]=$page_split_page;
	}
	$obj_tab_company=new cls_tab_hr_company();
	$arr_resume=array();
	$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_company ".$str_where.$msg_sort.$str_limit);
	$lng_x=1;
	while($obj_rs = $obj_db->fetch_array($obj_result)){
		$obj_rs["url"]=$obj_tab_company->get_url($obj_rs["company_id"]);
		$obj_rs["updatetime"]=format_date($obj_rs["company_updatetime"],"Y-m-d");
		$obj_rs["addtime"]=format_date($obj_rs["company_addtime"],"Y-m-d");
		$arr_resume[]=$obj_rs;
	}
	if($msg_pagesize>0){
		$sql_return[$msg_name]["list"]=$arr_resume;
	}else{
		$sql_return[$msg_name]=$arr_resume;
	}
}
function get_temp_company_job($msg_name,$msg_limit1,$msg_limit2,$msg_sort,$msg_where="",$msg_pagesize=0){
	global $obj_db,$sql_return;

	$obj_tab_job=new cls_tab_hr_job();
	$obj_tab_company=new cls_tab_hr_company();

	$arr_company=array();
	$arr_userid=array();
	$arr_job=array();
	$msg_limit1=intval($msg_limit1);
	$msg_limit2=intval($msg_limit2);
	if($msg_limit1<0) $msg_limit1=0;
	if($msg_limit2<$msg_limit1) $msg_limit2=$msg_limit1+10;
	$str_limit=" limit ".$msg_limit1.",".$msg_limit2;
	$str_where=" where company_pubtime>0";
	if($msg_where!="") $str_where.=" and ".$msg_where;
	if($msg_pagesize>0){
		global $get_page;
		(empty($get_page) || !is_numeric($get_page))? $get_page=1 : $get_pae=intval($get_page);
		$obj_rs  = $obj_db->get_one("SELECT count(1) as num FROM ".DB_PRE."hr_company".$str_where);
		$int_total=$obj_rs["num"];
		$int_pages= ceil($int_total/$msg_pagesize);
		$get_page = min($int_pages, $get_page);
		$get_page = max($get_page, 1);
		$page_split_page=get_pages_html($int_total, $get_page, $msg_pagesize,format_url_query(array('page'=>'')));
		$int_offset = $msg_pagesize*($get_page-1);
		$str_limit = " limit ".$int_offset.",".$msg_pagesize;
		$sql_return[$msg_name]["page"]=$page_split_page;
	}

	$obj_result = $obj_db->query("SELECT company_id,company_name,company_user_id,company_logo FROM ".DB_PRE."hr_company ".$str_where.$msg_sort.$str_limit);
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$arr_userid[]=$obj_rs["company_user_id"];
		$arr_job["id_".$obj_rs["company_user_id"]]="";
		$obj_rs["url"]=$obj_tab_company->get_url($obj_rs["company_id"]);
		$arr_new_company[]=$obj_rs;
	}

	$str_userid=implode(",",$arr_userid);
	$lng_x=($msg_limit2-$msg_limit1)*2;
	$obj_result = $obj_db->query("SELECT job_id,job_name,job_user_id FROM ".DB_PRE."hr_job where job_user_id in(".$str_userid.") order by job_updatetime desc limit 0,".$lng_x);
	$arr_x=array();
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$obj_rs["url"]=$obj_tab_job->get_url($obj_rs["job_id"]);
		if(isset($arr_job["id_".$obj_rs["job_user_id"]])&&$arr_job["id_".$obj_rs["job_user_id"]]!=""){
			if($arr_x["id_".$obj_rs["job_user_id"]]<3) $arr_job["id_".$obj_rs["job_user_id"]].="/<a href='".$obj_rs["url"]."' target='_blank' title='".$obj_rs["job_name"]."'>".$obj_rs["job_name"]."</a>";
		}else{
			$arr_job["id_".$obj_rs["job_user_id"]]="<a href='".$obj_rs["url"]."' target='_blank' title='".$obj_rs["job_name"]."'>".$obj_rs["job_name"]."</a>";
			$arr_x["id_".$obj_rs["job_user_id"]]=0;
		}
		$arr_x["id_".$obj_rs["job_user_id"]]=$arr_x["id_".$obj_rs["job_user_id"]]+1;
	}
	$arr_x=array();
	foreach($arr_new_company as $item){
		if(!isset($arr_job["id_".$item["company_user_id"]])) continue;
		$item["joblist"]=$arr_job["id_".$item["company_user_id"]];
		$arr_x[]=$item;
	}
	if($msg_pagesize>0){
		$sql_return[$msg_name]["list"]=$arr_x;
	}else{
		$sql_return[$msg_name]=$arr_x;
	}
}

function get_temp_resume($msg_name,$msg_limit1,$msg_limit2,$msg_sort,$msg_where="",$msg_pagesize=0){
	global $obj_db,$sql_return;
	$msg_limit1=intval($msg_limit1);
	$msg_limit2=intval($msg_limit2);
	if($msg_limit1<0) $msg_limit1=0;
	if($msg_limit2<$msg_limit1) $msg_limit2=$msg_limit1+10;
	$str_limit=" limit ".$msg_limit1.",".$msg_limit2;
	$str_where=" where resume_state>0";
	if($msg_where!="") $str_where.=" and ".$msg_where;
	if($msg_pagesize>0){
		global $get_page;
		(empty($get_page) || !is_numeric($get_page))? $get_page=1 : $get_pae=intval($get_page);
		$obj_rs  = $obj_db->get_one("SELECT count(1) as num FROM ".DB_PRE."hr_resume".$str_where);
		$int_total=$obj_rs["num"];
		$int_pages= ceil($int_total/$msg_pagesize);
		$get_page = min($int_pages, $get_page);
		$get_page = max($get_page, 1);
		$page_split_page=get_pages_html($int_total, $get_page, $msg_pagesize,format_url_query(array('page'=>'')));
		$int_offset = $msg_pagesize*($get_page-1);
		$str_limit = " limit ".$int_offset.",".$msg_pagesize;
		$sql_return[$msg_name]["page"]=$page_split_page;
	}

	$obj_tab_resume=new cls_tab_hr_resume();
	$arr_resume=array();
	$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_resume ".$str_where.$msg_sort.$str_limit);
	$lng_x=1;
	$arr_degree=$obj_tab_resume->degree;
	while($obj_rs = $obj_db->fetch_array($obj_result)){
		$obj_rs["age"]="";
		$lng_year_now=format_date(TIME,"Y");
		$lng_year=format_date($obj_rs["resume_birthday"],"Y");
		if($lng_year>0) $obj_rs["age"]=$lng_year_now-$lng_year;
		$obj_rs["degree"]=array_search($obj_rs["resume_degree"],$arr_degree);
		$obj_rs["updatetime"]=format_date($obj_rs["resume_updatetime"],"Y-m-d");
		$obj_rs["url"]=$obj_tab_resume->get_url($obj_rs["resume_id"]);
		$arr_resume[]=$obj_rs;
	}
	if($msg_pagesize>0){
		$sql_return[$msg_name]["list"]=$arr_resume;
	}else{
		$sql_return[$msg_name]=$arr_resume;
	}
}

function get_temp_article($msg_name,$msg_folder_ids="",$msg_limit1=0,$msg_limit2=10,$msg_where="",$msg_sort="",$msg_pagesize=0){
	global $obj_db,$sql_return;
	$msg_limit1=intval($msg_limit1);
	$msg_limit2=intval($msg_limit2);
	if($msg_limit1<0) $msg_limit1=0;
	if($msg_limit2<$msg_limit1) $msg_limit2=$msg_limit1+10;
	$str_limit=" limit ".$msg_limit1.",".$msg_limit2;
	$str_where=" where article_addtime<".TIME;
	if($msg_where!="") $str_where.=" and ".$msg_where;
	if($msg_pagesize>0){
		global $get_page;
		(empty($get_page) || !is_numeric($get_page))? $get_page=1 : $get_pae=intval($get_page);
		$obj_rs  = $obj_db->get_one("SELECT count(1) as num FROM ".DB_PRE."article".$str_where);
		$int_total=$obj_rs["num"];
		$int_pages= ceil($int_total/$msg_pagesize);
		$get_page = min($int_pages, $get_page);
		$get_page = max($get_page, 1);
		$page_split_page=get_pages_html($int_total, $get_page, $msg_pagesize,format_url_query(array('page'=>'')));
		$int_offset = $msg_pagesize*($get_page-1);
		$str_limit = " limit ".$int_offset.",".$msg_pagesize;
		$sql_return[$msg_name]["page"]=$page_split_page;
	}
	$obj_tab_article=new cls_tab_article();
	$obj_tab_channel=new cls_tab_article_channel();
	$arr_article=array();
	$obj_result = $obj_db->query("SELECT a.article_id,a.article_title,a.article_intro,a.article_addtime,article_channel_id,a.article_updatetime,a.article_pic,a.article_hits,a.article_folder_id,b.folder_name FROM ".DB_PRE."article a left join ".DB_PRE."article_folder b on a.article_folder_id=b.folder_id".$str_where.$msg_sort.$str_limit);
	$lng_x=1;
	while($obj_rs = $obj_db->fetch_array($obj_result)){
		$obj_rs["url"]=$obj_tab_channel->get_url($obj_rs["article_channel_id"],$obj_rs["article_id"],$obj_rs["article_addtime"]);
		$obj_rs["article_addtime"]=date("Y-m-d",$obj_rs["article_addtime"]);
		$arr_article[]=$obj_rs;
	}
	if($msg_pagesize>0){
		$sql_return[$msg_name]["list"]=$arr_article;
	}else{
		$sql_return[$msg_name]=$arr_article;
	}
}
?>