<?php
 /*
 * 74cms 企业用户相关
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/../data/config.php');
require_once(dirname(__FILE__).'/include/admin_common.inc.php');
require_once(ADMIN_ROOT_PATH.'include/admin_company_fun.php');
require_once(ADMIN_ROOT_PATH.'include/upload.php');
$act = !empty($_GET['act']) ? trim($_GET['act']) : 'jobs';
if($act == 'jobs')
{
	check_permissions($_SESSION['admin_purview'],"jobs_show");
	$audit=intval($_GET['audit']);
	$deadline=intval($_GET['deadline']);
	$jobtype=intval($_GET['jobtype']);
	$tablename="jobs";
	if (empty($jobtype))
	{
		$jobtype=1;
		$_GET['jobtype']=1;
	}
	//有效职位
	if ($jobtype==1)
	{
		$wheresql=" WHERE utype=1 and job_status=1 and audit=1 ";
	}
	//无效职位
	else
	{
		$wheresql=" WHERE utype=1 and job_status=2 ";
	}
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$oederbysql=" order BY id DESC ";
	$wheresqlarr=array();
	$key=isset($_GET['key'])?trim($_GET['key']):"";
	$key_type=isset($_GET['key_type'])?intval($_GET['key_type']):"";
	if (!empty($key) && $key_type>0)
	{
		if     ($key_type===1)$wheresql=" WHERE jobs_name like '%{$key}%'";
		elseif ($key_type===2)$wheresql=" WHERE companyname like '%{$key}%'";
		elseif ($key_type===3 && intval($key)>0)$wheresql=" WHERE id =".intval($key);
		elseif ($key_type===4 && intval($key)>0)$wheresql=" WHERE company_id =".intval($key);
		elseif ($key_type===5 && intval($key)>0)$wheresql=" WHERE uid =".intval($key);
		$oederbysql="";
	}
	else
	{
		if ($audit>0)
		{
			$wheresql=empty($wheresql)?" WHERE audit= ".$audit:$wheresql." AND audit= ".$audit;
		}
		if (!empty($_GET['settr']))
		{
			$settr=strtotime("-".intval($_GET['settr'])." day");
			$wheresql=empty($wheresql)?" WHERE refreshtime> ".$settr:$wheresql." AND refreshtime> ".$settr;
			$oederbysql=" order BY refreshtime DESC ";
		}
		if (!empty($_GET['addsettr']))
		{
			$settr=strtotime("-".intval($_GET['addsettr'])." day");
			$wheresql=empty($wheresql)?" WHERE addtime> ".$settr:$wheresql." AND addtime> ".$settr;
			$oederbysql=" order BY addtime DESC ";
		}
		if($deadline==1)
		{
		$wheresql=empty($wheresql)?" WHERE deadline< ".time():$wheresql." AND deadline< ".time();
		$oederbysql=" order BY deadline DESC ";
		}
		elseif($deadline==2)
		{			
		$wheresql=empty($wheresql)?" WHERE deadline>  ".time():$wheresql." AND deadline> ".time();
		$oederbysql=" order BY deadline DESC ";
		}
		elseif($deadline>2)
		{
		$settr=strtotime("+{$deadline} day");
		$wheresql=empty($wheresql)?" WHERE deadline>".time()." AND  deadline< {$settr}":$wheresql." AND deadline>".time()." AND  deadline<{$settr} ";
		$oederbysql=" order BY deadline DESC ";
		}
		if (!empty($_GET['j_type']))
		{
			$j_type=intval($_GET['j_type']);
			if ($j_type==1)
			{
			$psql="jobs_type=0";
			$wheresql=empty($wheresql)?" WHERE {$psql} ":"{$wheresql} AND {$psql} ";
			}
			elseif ($j_type==2)
			{
			$psql="jobs_type=1";
			$wheresql=empty($wheresql)?" WHERE {$psql} ":"{$wheresql} AND {$psql} ";
			}
			elseif ($j_type==3)
			{
			$psql="jobs_type=2";
			$wheresql=empty($wheresql)?" WHERE {$psql} ":"{$wheresql} AND {$psql} ";
			}
			$oederbysql="";
		}
		 
	}
	$total_sql="SELECT COUNT(*) AS num FROM ".table($tablename).$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$total[1]=$db->get_total("SELECT COUNT(*) AS num FROM ".table('jobs')." WHERE  utype=1 and audit=1 ");
	$total[2]=$db->get_total("SELECT COUNT(*) AS num FROM ".table('jobs')." WHERE  utype=1 and audit=2 ");
	$total[3]=$db->get_total("SELECT COUNT(*) AS num FROM ".table('jobs')." WHERE  utype=1 and audit=3 ");
	$getsql="SELECT * FROM ".table($tablename)." ".$wheresql.$oederbysql;
	$jobs = get_jobs($offset,$perpage,$getsql);
	$smarty->assign('pageheader',"职位管理");
	$smarty->assign('jobs',$jobs);
	$smarty->assign('now',time());
	$smarty->assign('total',$total);
	$smarty->assign('page',$page->show(3));
	$smarty->assign('totaljob',$total_val);
	get_token();
	$smarty->display('company/admin_company_jobs.htm');
}
elseif($act == 'recommend_show')
{
	$id=intval($_GET['id']);//职位id
	$company_id=intval($_GET['company_id']);
	$wheresql=" and h.jobs_id=$id ";
	$joinsql=" left join ".table("resume")." as rj on rj.id=h.resume_id left join ".table("hunter_profile")." as p on h.uid=p.uid ";
	$sql="select * from ".table("jobs")." where id=$id ";
	$row=$db->getone($sql);
	$recommend_sql="select rj.*,h.did,h.recommend_addtime,h.recommend_state,p.fullname hunter_name from ".table("hunter_recommend")." as h ".$joinsql." where h.company_id=$company_id".$wheresql;
	$recommend_rst=$db->getall($recommend_sql);
	foreach ($recommend_rst as $key => $value)
	{
		$Y=date("Y",time());
		$value['age']=$Y-$value['birthdate'];
		$value['current_cn_']=cut_str($value['current_cn'],6,0);
		$value['resume_url']=url_rewrite('QS_resumeshow',array('id'=>$value['id']));
		$value['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$value['id']));
		$value['com_url']=url_rewrite('QS_companyshow',array('id'=>$value['company_id']));
		$recommend_rst[$key]=$value;
	}
	$row['recommend_list']=$recommend_rst;
	if($row['birthdate'])
	{
		$Y=date("Y",time());
		$row['age']=$Y-$row['birthdate'];
	}
	$smarty->assign('pageheader',"推荐记录详细");
	$smarty->assign('recommend_show',$row);
	$smarty->display('company/admin_company_recommend_list.htm');
}
/*
	同意操作
	@state 状态 默认0未处理,1已邀请面试,2已入职,3已拒绝
*/
elseif($act == "recommend_agree")
{
	$state=intval($_GET['state']);
	$did=intval($_GET['did']);
	$company_id=intval($_GET['company_id']);
	$sql="update ".table("hunter_recommend")." set recommend_state=$state where did=$did and company_id=$company_id ";
	// 积分，经验规则
	$points_rule=get_cache('points_rule');
	$level_rule=get_cache('hunter_level_rule');
	// 推荐信息
	$rec_row=$db->getone("select * from ".table("hunter_recommend")." where did=$did and company_id=$company_id ");
	// 猎头信息
	$hunter=get_hunter_one_uid($rec_row['uid']);
	//猎头会员信息
	$hunter_mem=get_user($rec_row['uid']);
	// 职位信息
	$jobs=$db->getone("select * from ".table('jobs')." where id=$rec_row[jobs_id] ");
	// 简历信息
	$resume=$db->getone("select * from ".table('resume')." where id=$rec_row[resume_id] ");
	// 推荐人才面试 增加经验
	if($state==1)
	{
		level_deal($hunter['uid'],$level_rule['interview']['type'],$level_rule['interview']['value']);
		level_meal_deal($hunter['uid']);
		write_memberslog($hunter['uid'],3,1403,$hunter_mem['username'],"经验".$level_rule['interview']['type'].$level_rule['interview']['value'],0,"您为【".$jobs['jobs_name']."】推荐的人才【".$resume['fullname']."】已被邀请面试！",$mode=1);
	}
	// 推荐人才入职,增加经验,增加赏金
	if($state==2)
	{
		// 猎头增加经验
		level_deal($hunter['uid'],$level_rule['hire']['type'],$level_rule['hire']['value']);
		level_meal_deal($hunter['uid']);
		write_memberslog($hunter['uid'],3,1404,$hunter_mem['username'],"经验".$level_rule['hire']['type'].$level_rule['hire']['value'],0,"您为【".$jobs['jobs_name']."】推荐的人才【".$resume['fullname']."】已成功入职！",$mode=1);
		//猎头增加 赏金
		$num=$jobs['reward']*$_CFG['hunter_reward'];
		action_user_account($hunter['uid'],3,$num,$action='1');
		write_account_log($hunter['uid'],0,3,"管理员","您为【".$jobs['jobs_name']."】推荐的人才【".$resume['fullname']."】已成功入职！获得赏金".$num,"操作成功");
		// 扣除企业冻结资金
		action_user_account_blocked($jobs['uid'],$jobs['reward'],$action="2");
		write_account_log($jobs['uid'],$jobs['parentuid'],1,"管理员",$hunter['fullname']."为您的职位【".$jobs['jobs_name']."】推荐的人才【".$resume['fullname']."】已成功入职！扣除冻结资金".$jobs['reward'],"操作成功");
		// 职位状态修改为已结束
		$db->query("update ".table('jobs')."  SET display='2',finishtime='{$timestamp}' WHERE id=$jobs[id]");
		distribution_jobs($jobs['id']);
	}
	!$db->query($sql)?adminmsg("操作失败！",2):adminmsg("操作成功！",1);

}
elseif($act == 'jobs_perform')
{
		check_token();
		$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:adminmsg("你没有选择职位！",1);
		if (!empty($_REQUEST['delete']))
		{
			check_permissions($_SESSION['admin_purview'],"jobs_del");
			$num=del_jobs($yid);
			if ($num>0)
			{
			adminmsg("删除成功！共删除".$num."行",2);
			}
			else
			{
			adminmsg("删除失败！",0);
			}
		}
		elseif (!empty($_POST['set_audit']))
		{
			check_permissions($_SESSION['admin_purview'],"jobs_audit");
			$audit=intval($_POST['audit']);
			if ($n=edit_jobs_audit($yid,$audit))
			{
			adminmsg("审核成功！响应行数 {$n}",2);			
			}
			else
			{
			adminmsg("审核成功！响应行数 0",1);
			}
		}
		elseif (!empty($_GET['refresh']))
		{
			if($n=refresh_jobs($yid))
			{
			adminmsg("刷新成功！响应行数 {$n}",2);
			}
			else
			{
			adminmsg("刷新失败！",0);
			}
		}
}
elseif($act == 'edit_jobs')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"jobs_edit");
	$id =!empty($_REQUEST['id'])?intval($_REQUEST['id']):adminmsg("你没有选择职位！",1);
	$smarty->assign('pageheader',"职位管理");
	$jobs=get_jobs_one($id);
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('jobs',$jobs);
	$smarty->display('company/admin_company_jobs_edit.htm');
}
elseif ($act=='editjobs_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"jobs_edit");
	$id=intval($_POST['id']);
	$company_profile=get_company_one_id($id);
	$setsqlarr['jobs_name']=trim($_POST['jobs_name'])?trim($_POST['jobs_name']):adminmsg('您没有填写职位名称！',1);
	$setsqlarr['display']=intval($_POST['display']);
	$setsqlarr['audit']=intval($_POST['audit']);
	$setsqlarr['department']=trim($_POST['department'])?trim($_POST['department']):adminmsg('您没有填写所属部门！',1);
	$setsqlarr['amount']=intval($_POST['amount']);
	$setsqlarr['education']=intval($_POST['education']);
	$setsqlarr['education_cn']=trim($_POST['education_cn']);
	$setsqlarr['experience']=intval($_POST['experience']);
	$setsqlarr['experience_cn']=trim($_POST['experience_cn']);
	$setsqlarr['category']=trim($_POST['category_id']);
	$setsqlarr['category_cn']=trim($_POST['category_cn']);
	$setsqlarr['district']=intval($_POST['district'])>0?intval($_POST['district']):adminmsg('您没有选择地区！',1);
	$setsqlarr['sdistrict']=intval($_POST['sdistrict']);
	$setsqlarr['district_cn']=trim($_POST['district_cn']);
	$setsqlarr['wage_min']=!empty($_POST['wage_min'])?intval($_POST['wage_min']):adminmsg('请填写税前年薪下限！',1);
	$setsqlarr['wage_max']=!empty($_POST['wage_max'])?intval($_POST['wage_max']):adminmsg('请填写税前年薪上限！',1);
	$job_type = intval($_POST['jobs_type']);
	// 初级职位
	if($job_type==0){
		if($setsqlarr['wage_min']>10 || $setsqlarr['wage_max']>10){
			adminmsg("当前年薪已超出初级职位年薪上限！",1);
		}
	}// 中高端职位
	elseif($job_type==1){
		if($setsqlarr['wage_min']<10 || $setsqlarr['wage_max']<10){
			adminmsg("当前年薪低于高级职位年薪下限！",1);
		}
	}
	//赏金职位
	elseif($job_type==2){
		$setsqlarr['reward']=!empty($_POST['reward'])?intval($_POST['reward']):adminmsg('请填写悬赏金额！',1);
	}
	$setsqlarr['age_min']=intval($_POST['age_min']);		
	$setsqlarr['age_max']=intval($_POST['age_max']);
	$setsqlarr['reporter']=trim($_POST['reporter']);
	$setsqlarr['major']=trim($_POST['major']);
	$setsqlarr['sex']=intval($_POST['sex']);
	$setsqlarr['sex_cn']=trim($_POST['sex_cn']);
	$setsqlarr['language']=trim($_POST['language']);
	$setsqlarr['language_cn']=trim($_POST['language_cn']);
	$setsqlarr['contents']=trim($_POST['contents'])?trim($_POST['contents']):adminmsg('您没有填写职位描述！',1);
	$setsqlarr['key']=$setsqlarr['jobs_name'].$company_profile['companyname'].$setsqlarr['category_cn'].$setsqlarr['district_cn'].$setsqlarr['contents'];
	require_once(QISHI_ROOT_PATH.'include/splitword.class.php');
	$sp = new SPWord();
	$setsqlarr['key']="{$setsqlarr['jobs_name']} {$company_profile['companyname']} ".$sp->extracttag($setsqlarr['key']);
	$setsqlarr['key']=$sp->pad($setsqlarr['key']);

	$setsqlarr_contact['contact']=trim($_POST['contact']);
	$setsqlarr_contact['telephone']=trim($_POST['telephone']);
	$setsqlarr_contact['email']=trim($_POST['email']);
	
	$wheresql=" id='".$id."' ";
	$tb1=$db->getone("select * from ".table('jobs')." where id='{$id}' LIMIT 1");
	if (!empty($tb1))
	{
		if (!updatetable(table('jobs'),$setsqlarr,$wheresql)) adminmsg("保存失败！",0);
	}
	$wheresql=" pid=".$id;
	if (!updatetable(table('jobs_contact'),$setsqlarr_contact,$wheresql)) adminmsg("保存失败！",0);
	$searchtab['sex']=$setsqlarr['sex'];
	$searchtab['district']=$setsqlarr['district'];
	$searchtab['sdistrict']=$setsqlarr['sdistrict'];
	$searchtab['education']=$setsqlarr['education'];
	$searchtab['experience']=$setsqlarr['experience'];
	$searchtab['wage_min']=$setsqlarr['wage_min'];
	$searchtab['wage_max']=$setsqlarr['wage_max'];
	updatetable(table('jobs_search_rtime'),$searchtab," id='{$id}'");
	updatetable(table('jobs_search_recommend'),$searchtab," id='{$id}'");
	updatetable(table('jobs_search_hot'),$searchtab," id='{$id}'");
	updatetable(table('jobs_search_scale'),$searchtab," id='{$id}'");
	$searchtab['key']=$setsqlarr['key'];
	updatetable(table('jobs_search_key'),$searchtab," id='{$id}' ");	
	unset($setsqlarr_contact,$setsqlarr);
	distribution_jobs($id);
	$link[0]['text'] = "返回职位列表";
	$link[0]['href'] = $_POST['url'];
	adminmsg("修改成功！",2,$link);
}
elseif($act == 'company_list')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"com_show");
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$oederbysql=" order BY c.id DESC ";
	$key=isset($_GET['key'])?trim($_GET['key']):"";
	$key_type=isset($_GET['key_type'])?intval($_GET['key_type']):"";
	if ($key && $key_type>0)
	{
		
		if     ($key_type===1)$wheresql=" WHERE c.companyname like '%{$key}%'";
		elseif ($key_type===2)$wheresql=" WHERE c.id ='".intval($key)."'";
		elseif ($key_type===3)$wheresql=" WHERE m.username like '{$key}%'";
		elseif ($key_type===4)$wheresql=" WHERE c.uid ='".intval($key)."'";
		elseif ($key_type===5)$wheresql=" WHERE c.address  like '%{$key}%'";
		elseif ($key_type===6)$wheresql=" WHERE c.telephone  like '{$key}%'";		
		$oederbysql="";
	}
	$_GET['audit']<>""? $wheresqlarr['c.audit']=intval($_GET['audit']):'';
	if (is_array($wheresqlarr)) $wheresql=wheresql($wheresqlarr);
	if (!empty($_GET['settr']))
	{
		$settr=strtotime("-".intval($_GET['settr'])." day");
		$wheresql=empty($wheresql)?" WHERE addtime> ".$settr:$wheresql." AND addtime> ".$settr;
	}
	$joinsql=" LEFT JOIN ".table('members')." AS m ON c.uid=m.uid  ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('company_profile')." AS c".$joinsql.$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$clist = get_company($offset,$perpage,$joinsql.$wheresql.$oederbysql);
	$smarty->assign('pageheader',"企业管理");
	$smarty->assign('clist',$clist);
	$smarty->assign('certificate_dir',$certificate_dir);
	 $smarty->assign('page',$page->show(3));
	$smarty->display('company/admin_company_list.htm');
}
elseif($act == 'company_perform')
{
	check_token();
	$u_id =!empty($_POST['y_id'])?$_POST['y_id']:adminmsg("你没有选择企业！",1);
	if ($_POST['delete'])
	{
		check_permissions($_SESSION['admin_purview'],"com_del");
		if ($_POST['delete_company']=='yes')
		{
		!del_company($u_id)?adminmsg("删除企业资料失败！",0):"";
		}
		if ($_POST['delete_jobs']=='yes')
		{
		!del_company_alljobs($u_id)?adminmsg("删除职位失败！",0):"";
		}
		if ($_POST['delete_jobs']<>'yes' && $_POST['delete_company']<>'yes')
		{
		adminmsg("未选择删除类型！",1);
		}
		adminmsg("删除成功！",2);
	}
	if (trim($_POST['set_audit']))
	{
	check_permissions($_SESSION['admin_purview'],"com_audit");
	$audit=$_POST['audit'];
	!edit_company_audit($u_id,intval($audit))?adminmsg("设置失败！",0):adminmsg("设置成功！",2);
	}
	elseif (!empty($_POST['set_refresh']))
		{
			if (empty($_POST['refresh_jobs']))
			{
			$refresjobs=false;
			}
			else
			{
			$refresjobs=true;
			}
			if($n=refresh_company($u_id,$refresjobs))
			{
			adminmsg("刷新成功！响应行数 {$n} 行",2);
			}
			else
			{
			adminmsg("刷新失败！",0);
			}
		}
}
elseif($act == 'edit_company_profile')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"com_edit");
	$yid =!empty($_REQUEST['id'])?intval($_REQUEST['id']):adminmsg("你没有选择企业！",1);
	$smarty->assign('pageheader',"企业管理");
	$company_profile=get_company_one_id($yid);
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('company_profile',$company_profile);
	$smarty->assign('certificate_dir',$certificate_dir);//营业执照路径
	$smarty->display('company/admin_company_profile_edit.htm');
}
elseif ($act=='company_profile_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"com_edit");
	$setsqlarr=array();
	$contents=array();
	$id=intval($_POST['id']);
	$setsqlarr['audit']=intval($_POST['audit']);
	$setsqlarr['companyname']=trim($_POST['companyname'])?trim($_POST['companyname']):adminmsg('您没有输入企业名称！',1);
	$setsqlarr['nature']=trim($_POST['nature'])?trim($_POST['nature']):adminmsg('您选择企业性质！',1);
	$setsqlarr['nature_cn']=trim($_POST['nature_cn'])?trim($_POST['nature_cn']):adminmsg('您选择企业性质！',1);
	$setsqlarr['scale']=trim($_POST['scale'])?trim($_POST['scale']):adminmsg('您选择公司规模！',1);
	$setsqlarr['scale_cn']=trim($_POST['scale_cn'])?trim($_POST['scale_cn']):adminmsg('您选择公司规模！',1);
	$setsqlarr['trade']=trim($_POST['trade'])?trim($_POST['trade']):adminmsg('您选择所属行业！',1);
	$setsqlarr['trade_cn']=trim($_POST['trade_cn'])?trim($_POST['trade_cn']):adminmsg('您选择所属行业！',1);
	$setsqlarr['tag']=trim($_POST['tag']);
	$setsqlarr['district_cn']=trim($_POST['district_cn'])?trim($_POST['district_cn']):adminmsg('您选择所属地区！',1);
	$setsqlarr['district']=intval($_POST['district']);
	$setsqlarr['sdistrict']=intval($_POST['sdistrict']);
	$setsqlarr['address']=trim($_POST['address']);
	$setsqlarr['contact']=trim($_POST['contact']);
	$setsqlarr['telephone']=trim($_POST['telephone']);
	$setsqlarr['email']=trim($_POST['email']);
	$setsqlarr['website']=trim($_POST['website']);
	//map
	$setsqlarr['map_x']=trim($_POST['x'])?trim($_POST['x']):adminmsg('请先在地图上标记我的位置！',1);
	$setsqlarr['map_y']=trim($_POST['y'])?trim($_POST['y']):adminmsg('请先在地图上标记我的位置！',1);
	$setsqlarr['map_zoom']=trim($_POST['zoom']); 
	//map end
	$setsqlarr['contents']=trim($_POST['contents'])?trim($_POST['contents']):adminmsg('请填写公司简介！',1);
	$wheresql=" id='".$id."' ";
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = $_POST['url'];
		if (updatetable(table('company_profile'),$setsqlarr,$wheresql))
		{
				$jobarr['companyname']=$setsqlarr['companyname'];
				$jobarr['trade']=$setsqlarr['trade'];
				$jobarr['trade_cn']=$setsqlarr['trade_cn'];
				$jobarr['scale']=$setsqlarr['scale'];
				$jobarr['scale_cn']=$setsqlarr['scale_cn'];
				if (!updatetable(table('jobs'),$jobarr," uid=".intval($_POST['cuid'])."")) adminmsg('修改职位部分出错！',0);
				//$soarray['trade']=$jobarr['trade'];
				$soarray['scale']=$jobarr['scale'];
				updatetable(table('jobs_search_scale'),$soarray," uid=".intval($_POST['cuid'])."");
				updatetable(table('jobs_search_rtime'),$soarray," uid=".intval($_POST['cuid'])."");
				updatetable(table('jobs_search_recommend'),$soarray," uid=".intval($_POST['cuid'])."");
				updatetable(table('jobs_search_hot'),$soarray," uid=".intval($_POST['cuid'])."");
				updatetable(table('jobs_search_key'),$soarray," uid=".intval($_POST['cuid'])."");
				company_trade_save(intval($_POST['cuid']),$id,$jobarr['trade']);
				$jobs = $db->getall("select id from ".table('jobs')." where parentuid=".intval($_POST['cuid']));
				foreach ($jobs as $key => $value) {
					jobs_trade_save(intval($_POST['cuid']),$value['id'],$setsqlarr['trade']);
				}
				unset($setsqlarr);
				adminmsg("保存成功！",2,$link);
		}
		else
		{
		unset($setsqlarr);
		adminmsg("保存失败！",0);
		}
}
elseif($act == 'edit_company_tpl')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"com_edit");
	$yid =!empty($_REQUEST['id'])?intval($_REQUEST['id']):adminmsg("你没有选择企业！",1);
	$smarty->assign('pageheader',"企业模板管理");
	$company_profile=get_company_one_id($yid);
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('imglist',get_company_img($yid));
	$smarty->assign('company_profile',$company_profile);
	$smarty->assign('certificate_dir',$certificate_dir);//营业执照路径
	$smarty->display('company/admin_company_tpl_edit.htm');
}
elseif($act == 'edit_company_tpl_save')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"com_edit");
	$thisuid=intval($_POST['cuid']);
	if ($_POST['tpl']!="")
	{
		$tplarr['tpl']=trim($_POST['tpl']);
	}
	elseif($_POST['tpl_id']!="" && $_POST['tpl_zdy'])
	{
		$tplarr['tpl']=trim($_POST['tpl_zdy']);
	}
	updatetable(table('company_profile'),$tplarr," uid='{$thisuid}'");
	updatetable(table('jobs'),$tplarr," parentuid='{$thisuid}'");
	unset($tplarr);
	adminmsg("修改模板成功！",2);
}
elseif($act == 'add_company_img'){
	get_token();
	check_permissions($_SESSION['admin_purview'],"com_edit");
	if($_FILES['company_banner']['name'])
	{
		$setsqlarr['uid']=intval($_POST['cuid'])>0?intval($_POST['cuid']):adminmsg("参数错误！",1);
		$setsqlarr['company_id']=intval($_POST['id'])>0?intval($_POST['id']):adminmsg("参数错误！",1);
		$upfiles_dir="../data/companyimg/original/".date("Y/m/d/");
		$thumb_dir="../data/companyimg/thumb/".date("Y/m/d/");
		make_dir($upfiles_dir);
		$company_banner=_asUpFiles($upfiles_dir, "company_banner", 1024*2, 'jpg/gif/png',true);
		$makefile=$upfiles_dir.$company_banner;
		make_dir($thumb_dir);
		makethumb($makefile,$thumb_dir,$thumbwidth,$thumbheight);
		$setsqlarr['img']=date("Y/m/d/").$company_banner;
		$setsqlarr['addtime']=$timestamp;
		!inserttable(table('company_img'),$setsqlarr)?adminmsg("上传失败！",0):adminmsg("上传成功！",2);
	}else{
		adminmsg("请上传图片！",1);
	}
}
elseif($act == 'del_company_img')
{
	check_permissions($_SESSION['admin_purview'],"com_edit");
	$id =!empty($_REQUEST['id'])?$_REQUEST['id']:adminmsg("你没有选择图片！",1);
	if (del_company_img($id)){adminmsg("删除成功！",2);}else{adminmsg("删除失败！",0);}
}
elseif($act == 'meal_members')
{
	get_token();
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$wheresql=" WHERE a.effective=1 ";
	$oederbysql=" order BY a.uid DESC ";
	$key=isset($_GET['key'])?trim($_GET['key']):"";
	$key_type=isset($_GET['key_type'])?intval($_GET['key_type']):"";
	if ($key && $key_type>0)
	{
		if     ($key_type===1)$wheresql.=" AND b.username = '{$key}'";
		elseif ($key_type===2)$wheresql.=" AND b.uid = '".intval($key)."' ";
		elseif ($key_type===3)$wheresql.=" AND b.email = '{$key}'";
		elseif ($key_type===4)$wheresql.=" AND b.mobile like '{$key}%'";
		$oederbysql="";
	}
	else
	{	
		if (!empty($_GET['setmeal_id']))
		{
			$setmeal_id=intval($_GET['setmeal_id']);
			$wheresql.=" AND a.setmeal_id=".$setmeal_id;
		}
		if (!empty($_GET['settr']))
		{
			$settr=intval($_GET['settr']);
			if ($settr==-1)
			{
			$wheresql.=" AND a.endtime<".time()." AND a.endtime>0 ";
			}
			else
			{
			$settr=strtotime("{$settr} day");
			$wheresql.="  AND a.endtime>".time()." AND a.endtime< {$settr}";
			}			
		}
	}
	$joinsql=" LEFT JOIN ".table('members')." as b ON a.uid=b.uid ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('members_setmeal')." as a ".$joinsql.$wheresql;
	//var_dump($total_sql);die;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$member = get_meal_members_list($offset,$perpage,$joinsql.$wheresql.$oederbysql);
	$smarty->assign('pageheader',"已购买套餐会员");
	$smarty->assign('member',$member);
	$smarty->assign('setmeal',get_setmeal());	
	$smarty->assign('page',$page->show(3));
	$smarty->display('company/admin_company_meal_members.htm');
}
elseif($act == 'meal_delay')
{
			$tuid =!empty($_REQUEST['tuid'])?$_REQUEST['tuid']:adminmsg("你没有选择会员！",1);
			$days=intval($_POST['days']);
			if (empty($days))
			{
			adminmsg("请填写要延长的天数！",0);
			}
			if($n=delay_meal($tuid,$days))
			{
			distribution_jobs_uid($tuid);
			adminmsg("延长有效期成功！响应行数 {$n}",2);
			}
			else
			{
			adminmsg("操作失败！",0);
			}
}
elseif($act == 'members_list')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"com_user_show");
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$wheresql=" WHERE m.utype=1 ";
	$oederbysql=" order BY m.uid DESC ";
	$key=isset($_GET['key'])?trim($_GET['key']):"";
	$key_type=isset($_GET['key_type'])?intval($_GET['key_type']):"";
	if ($key && $key_type>0)
	{
		if     ($key_type===1)$wheresql.=" AND m.username = '{$key}'";
		elseif ($key_type===2)$wheresql.=" AND m.uid = '".intval($key)."' ";
		elseif ($key_type===3)$wheresql.=" AND m.email = '{$key}'";
		elseif ($key_type===4)$wheresql.=" AND m.mobile like '{$key}%'";
		elseif ($key_type===5)$wheresql.=" AND c.companyname like '%{$key}%'";
		$oederbysql="";
	}
	else
	{	
		if (!empty($_GET['settr']))
		{
			$settr=strtotime("-".intval($_GET['settr'])." day");
			$wheresql.=" AND m.reg_time> ".$settr;
		}
		if (!empty($_GET['verification']))
		{
			if ($_GET['verification']=="1")
			{
			$wheresql.=" AND m.email_audit = 1";
			}
			elseif ($_GET['verification']=="2")
			{
			$wheresql.=" AND m.email_audit = 0";
			}
			elseif ($_GET['verification']=="3")
			{
			$wheresql.=" AND m.mobile_audit = 1";
			}
			elseif ($_GET['verification']=="4")
			{
			$wheresql.=" AND m.mobile_audit = 0";
			}
		}
		if (!empty($_GET['type']))
		{
			if ($_GET['type']=="1")
			{
			$wheresql.=" AND m.uid = m.parentuid";
			}
			elseif ($_GET['type']=="2")
			{
			$wheresql.=" AND m.uid != m.parentuid";
			}
		}
	}
	$joinsql=" LEFT JOIN ".table('company_profile')." as c ON m.parentuid=c.uid ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('members')." as m ".$joinsql.$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$member = get_member_list($offset,$perpage,$joinsql.$wheresql.$oederbysql);
	$smarty->assign('pageheader',"企业会员");
	$smarty->assign('member',$member);
	$smarty->assign('page',$page->show(3));
	$smarty->display('company/admin_company_user_list.htm');
}
elseif($act == 'delete_user')
{	
	check_token();
	check_permissions($_SESSION['admin_purview'],"com_user_del");
	$tuid =!empty($_REQUEST['tuid'])?$_REQUEST['tuid']:adminmsg("你没有选择会员！",1);
	if ($_POST['delete'])
	{
		if (!empty($_POST['delete_user']))
		{
		!delete_company_user($tuid)?adminmsg("删除会员失败！",0):"";
		}
		if (!empty($_POST['delete_company']))
		{
		!del_company($tuid)?adminmsg("删除企业资料失败！",0):"";
		}
		if (!empty($_POST['delete_jobs']))
		{
		!del_company_alljobs($tuid)?adminmsg("删除职位失败！",0):"";
		}
	adminmsg("删除成功！",2);
	}
}
elseif($act == 'members_add')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"com_user_add");
	$smarty->assign('pageheader',"企业会员");
	$smarty->assign('givesetmeal',get_setmeal(false));
	$smarty->assign('points',get_cache('points_rule'));
	$smarty->display('company/admin_company_user_add.htm');
}
elseif($act == 'members_add_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"com_user_add");
	require_once(ADMIN_ROOT_PATH.'include/admin_user_fun.php');
	if (strlen(trim($_POST['username']))<3) adminmsg('用户名必须为3位以上！',1);
	if (strlen(trim($_POST['password']))<6) adminmsg('密码必须为6位以上！',1);
	$sql['username'] = !empty($_POST['username']) ? trim($_POST['username']):adminmsg('请填写用户名！',1);
	$sql['password'] = !empty($_POST['password']) ? trim($_POST['password']):adminmsg('请填写密码！',1);	
	if ($sql['password']<>trim($_POST['password1']))
	{
	adminmsg('两次输入的密码不相同！',1);
	}
	$sql['utype'] = !empty($_POST['member_type']) ? intval($_POST['member_type']):adminmsg('你没有选择注册类型！',1);
	if (empty($_POST['email']) || !preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$_POST['email']))
	{
	adminmsg('电子邮箱格式错误！',1);
	}
	$sql['email']= trim($_POST['email']);
	if (get_user_inusername($sql['username']))
	{
	adminmsg('该用户名已经被使用！',1);
	}
	if (get_user_inemail($sql['email']))
	{
	adminmsg('该 Email 已经被注册！',1);
	}
	if(defined('UC_API'))
	{
		include_once(QISHI_ROOT_PATH.'uc_client/client.php');
		if (uc_user_checkname($sql['username'])<>"1")
		{
		adminmsg('该用户名已经被使用或者用户名非法！',1);
		exit();
		}
		elseif (uc_user_checkemail($sql['email'])<>"1")
		{
			adminmsg('该 Email已经被使用或者非法！',1);
			exit();
		}
		else
		{
			uc_user_register($sql['username'],$sql['password'],$sql['email']);
		}
	}
	$sql['pwd_hash'] = randstr();
	$sql['password'] = md5(md5($sql['password']).$sql['pwd_hash'].$QS_pwdhash);
	$sql['reg_time']=time();
	$sql['reg_ip']=$online_ip;
	$insert_id=inserttable(table('members'),$sql,true);
	//后台添加账号为主账号(uid 和 parentuid要一致)
	if(intval($insert_id)>0){
		if(!updatetable(table('members'),array('parentuid'=>intval($insert_id))," uid ={$insert_id}")){
			$db->query("DELETE FROM ".table('members')."  WHERE uid = {$insert_id}");
			adminmsg('添加企业会员发生错误！',1);
		}
	}else{
		adminmsg('添加企业会员失败！',1);
	}
	if($sql['utype']=="1")
	{
	$db->query("INSERT INTO ".table('members_points')." (uid) VALUES ('{$insert_id}')");
	$db->query("INSERT INTO ".table('members_setmeal')." (uid) VALUES ('{$insert_id}')");
		$regpoints_num=intval($_POST['regpoints_num']);
		if ($_POST['regpoints']=="y")
		{
		write_memberslog($insert_id,1,9001,$sql['username'],"<span style=color:#FF6600>注册会员系统自动赠送!(+{$regpoints_num})</span>");
		report_deal($insert_id,1,$regpoints_num);
		}
		$reg_service=intval($_POST['reg_service']);
		if ($reg_service>0)
		{
		$service=get_setmeal_one($reg_service);
		write_memberslog($insert_id,1,9002,$sql['username'],"开通服务({$service['setmeal_name']})");
		set_members_setmeal($insert_id,$reg_service);
		}			
	}
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = "?act=members_list";
	$link[1]['text'] = "继续添加";
	$link[1]['href'] = "?act=members_add";
	adminmsg('添加成功！',2,$link);
}
elseif($act == 'user_edit')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"com_user_edit");
	$company_user=get_user($_GET['tuid']);
	$smarty->assign('pageheader',"企业会员");
	$company_profile=get_company_one_uid($company_user['uid']);
	$company_user['tpl']=$company_profile['tpl'];
	$smarty->assign('company_user',$company_user);
	$smarty->assign('userpoints',get_user_points($company_user['uid']));
	$smarty->assign('setmeal',get_user_setmeal($company_user['uid']));
	$smarty->assign('givesetmeal',get_setmeal(false));
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->display('company/admin_company_user_edit.htm');
}
elseif($act == 'set_account_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"com_user_edit");
	require_once(ADMIN_ROOT_PATH.'include/admin_user_fun.php');
	$setsqlarr['username']=trim($_POST['username']);
	$setsqlarr['email']=trim($_POST['email']);
	$setsqlarr['email_audit']=intval($_POST['email_audit']);
	$setsqlarr['mobile']=trim($_POST['mobile']);
	$setsqlarr['mobile_audit']=intval($_POST['mobile_audit']);
	if ($_POST['qq_openid']=="1")
	{
	$setsqlarr['qq_openid']='';
	}
	$thisuid=intval($_POST['company_uid']);	
	if (strlen($setsqlarr['username'])<3) adminmsg('用户名必须为3位以上！',1);
	$getusername=get_user_inusername($setsqlarr['username']);
	if (!empty($getusername)  && $getusername['uid']<>$thisuid)
	{
	adminmsg("用户名 {$setsqlarr['username']}  已经存在！",1);
	}
	if (empty($setsqlarr['email']) || !preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$setsqlarr['email']))
	{
	adminmsg('电子邮箱格式错误！',1);
	}
	$getemail=get_user_inemail($setsqlarr['email']);
	if (!empty($getemail)  && $getemail['uid']<>$thisuid)
	{
	adminmsg("Email  {$setsqlarr['email']}  已经存在！",1);
	}
	if (!empty($setsqlarr['mobile']) && !preg_match("/^(13|15|18)\d{9}$/",$setsqlarr['mobile']))
	{
	adminmsg('手机号码错误！',1);
	}
	$getmobile=get_user_inmobile($setsqlarr['mobile']);
	if (!empty($setsqlarr['mobile']) && !empty($getmobile)  && $getmobile['uid']<>$thisuid)
	{
	adminmsg("手机号 {$setsqlarr['mobile']}  已经存在！",1);
	}
	if (updatetable(table('members'),$setsqlarr," uid=".$thisuid.""))
	{
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = $_POST['url'];
	adminmsg('修改成功！',2,$link);
	}
	else
	{
	adminmsg('修改失败！',1);
	}
}
elseif($act == 'userpoints_edit')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"com_user_edit");
	if (intval($_POST['points'])<1) adminmsg('请输入积分！',1);
	if (trim($_POST['points_notes'])=='') adminmsg('请填写积分操作说明！',1);
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = $_POST['url'];
	$user=get_user($_POST['company_uid']);
	$points_type=intval($_POST['points_type']);	
	$points=get_user_points($user['uid']);
	$t=$points_type==1?"+":"-";
	report_deal($user['uid'],$points_type,intval($_POST['points']));
	write_memberslog(intval($_POST['company_uid']),1,9001,$user['username']," 管理员操作积分({$t}{$_POST['points']})，(剩余:{$points})，备注：".$_POST['points_notes']);
	adminmsg('保存成功！',2);
}
elseif($act == 'set_setmeal_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"com_user_edit");

    if (intval($_POST['reg_service'])>0)
	{
		if (set_members_setmeal($_POST['company_uid'],$_POST['reg_service']))
		{
		$link[0]['text'] = "返回列表";
		$link[0]['href'] = $_POST['url'];
		adminmsg('操作成功！',2,$link);
		}
		else
		{
		adminmsg('操作失败！',1);
		}
	}
	else
	{
	adminmsg('请选择服务套餐！',1);
	}	
}
elseif($act == 'edit_setmeal_save')
{
	check_token();
       check_permissions($_SESSION['admin_purview'],"com_user_edit");
	$setsqlarr['jobs_ordinary']=$_POST['jobs_ordinary'];
	$setsqlarr['jobs_ordinary_porint_all']=$_POST['jobs_ordinary_porint_all'];
	$setsqlarr['jobs_senior']=$_POST['jobs_senior'];
	$setsqlarr['jobs_senior_porint_all']=$_POST['jobs_senior_porint_all'];
	$setsqlarr['jobs_entrust']=$_POST['jobs_entrust'];
	$setsqlarr['jobs_entrust_porint_all']=$_POST['jobs_entrust_porint_all'];
	$setsqlarr['search_ordinary_resume']=$_POST['search_ordinary_resume'];
	$setsqlarr['see_ordinary_resume']=$_POST['see_ordinary_resume'];
	$setsqlarr['down_ordinary_resume']=$_POST['down_ordinary_resume'];
	$setsqlarr['down_ordinary_resume_day']=$_POST['down_ordinary_resume_day'];
	$setsqlarr['search_senior_reusme']=$_POST['search_senior_reusme'];
	$setsqlarr['see_senior_resume']=$_POST['see_senior_resume'];
	$setsqlarr['down_senior_resume']=$_POST['down_senior_resume'];
	$setsqlarr['down_senior_resume_day']=$_POST['down_senior_resume_day'];
	$setsqlarr['interview_ordinary']=$_POST['interview_ordinary'];
	$setsqlarr['interview_senior']=$_POST['interview_senior'];
	$setsqlarr['account']=$_POST['account'];
	$setsqlarr['company_web']=$_POST['company_web'];
	$setsqlarr['save_resume']=$_POST['save_resume'];
	$setsqlarr['report_ordinary_resume']=$_POST['report_ordinary_resume'];
	$setsqlarr['report_senior_resume']=$_POST['report_senior_resume'];
	$setsqlarr['is_entrust_hunter']=$_POST['is_entrust_hunter'];
	$setsqlarr['added']=$_POST['added'];
	if ($_POST['days']<>"")
	{
			if (intval($_POST['days'])<>0)
			{
				$oldendtime=intval($_POST['oldendtime']);
				$setsqlarr['endtime']=strtotime("".intval($_POST['days'])." days",$oldendtime==0?time():$oldendtime);
			}
			if (intval($_POST['days'])=="0")
			{
				$setsqlarr['endtime']=0;
			}
	}
	$company_uid=intval($_POST['company_uid']);
	if ($company_uid)
	{
			if (!updatetable(table('members_setmeal'),$setsqlarr," uid=".$company_uid."")) adminmsg('修改出错！',0);
			if ($setsqlarr['endtime']<>"")
			{
				$setmeal_deadline['setmeal_deadline']=$setsqlarr['endtime'];
				if (!updatetable(table('jobs'),$setmeal_deadline," parentuid={$company_uid}"))adminmsg('修改出错！',0);
				distribution_jobs_uid($company_uid);
			}
	}
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = $_POST['url'];
	adminmsg('操作成功！',2,$link);
}
elseif($act == 'userpass_edit')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"com_user_edit");
	if (strlen(trim($_POST['password']))<6) adminmsg('新密码必须为6位以上！',1);
	require_once(ADMIN_ROOT_PATH.'include/admin_user_fun.php');
	$user_info=get_user_inusername($_POST['username']);
	$pwd_hash=$user_info['pwd_hash'];
	$md5password=md5(md5(trim($_POST['password'])).$pwd_hash.$QS_pwdhash);	
	if ($db->query( "UPDATE ".table('members')." SET password = '$md5password'  WHERE uid='".$user_info['uid']."'"))
	{
			if(defined('UC_API'))
			{
			include_once(QISHI_ROOT_PATH.'uc_client/client.php');
			uc_user_edit($user_info['username'],trim($_POST['password']),trim($_POST['password']),"",1);
			}
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = $_POST['url'];
	adminmsg('操作成功！',2,$link);
	}
	else
	{
	adminmsg('操作失败！',1);
	}
}
elseif($act == 'userstatus_edit')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"com_user_edit");
	if ($db->query( "UPDATE ".table('members')." SET status = '".intval($_POST['status'])."'  WHERE uid='".intval($_POST['userstatus_uid'])."'"))
	{
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = $_POST['url'];
	adminmsg('操作成功！',2,$link);
	}
	else
	{
	adminmsg('操作失败！',1);
	}
}
elseif($act == 'management')
{	
	$id=intval($_GET['id']);
	$u=get_user($id);
	if (!empty($u))
	{
		unset($_SESSION['uid']);
		unset($_SESSION['parentuid']);
		unset($_SESSION['username']);
		unset($_SESSION['utype']);
		unset($_SESSION['uqqid']);
		setcookie("QS[uid]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		setcookie("QS[parentuid]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		setcookie("QS[username]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		setcookie("QS[password]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		setcookie("QS[utype]","",time() - 3600,$QS_cookiepath, $QS_cookiedomain);
		unset($_SESSION['activate_username']);
		unset($_SESSION['activate_email']);
		
		$_SESSION['uid']=$u['uid'];
		$_SESSION['parentuid']=$u['parentuid'];
		$_SESSION['username']=$u['username'];
		$_SESSION['utype']=$u['utype'];
		$_SESSION['uqqid']="1";
		setcookie('QS[uid]',$u['uid'],0,$QS_cookiepath,$QS_cookiedomain);
		setcookie('QS[parentuid]',$u['parentuid'],0,$QS_cookiepath,$QS_cookiedomain);
		setcookie('QS[username]',$u['username'],0,$QS_cookiepath,$QS_cookiedomain);
		setcookie('QS[password]',$u['password'],0,$QS_cookiepath,$QS_cookiedomain);
		setcookie('QS[utype]',$u['utype'], 0,$QS_cookiepath,$QS_cookiedomain);
		header("Location:".get_member_url($u['utype']));
	}	
} 

elseif($act == 'consultant')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"consultant_show");
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$oederbysql=" order BY id DESC ";
	
	$total_sql="SELECT COUNT(*) AS num FROM ".table('consultant').$oederbysql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$clist = get_consultant($offset,$perpage,$oederbysql);
	$smarty->assign('pageheader',"顾问管理");
	$smarty->assign('clist',$clist);
	$smarty->assign('page',$page->show(3));
	$smarty->display('company/admin_consultant_list.htm');
}
elseif($act == 'consultant_add')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"consultant_add");
	$smarty->assign('pageheader',"顾问管理");
	$smarty->display('company/admin_consultant_add.htm');
}
elseif($act == 'consultant_add_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"consultant_add");
	$setsqlarr['name'] = !empty($_POST['name']) ? trim($_POST['name']):adminmsg('请填写姓名！',1);
	$setsqlarr['tel'] = !empty($_POST['tel']) ? trim($_POST['tel']):adminmsg('请填写联系电话！',1);	
	$setsqlarr['email'] = !empty($_POST['email']) ? trim($_POST['email']):adminmsg('请填写联系邮箱！',1);
	
	$insert_id=inserttable(table('consultant'),$setsqlarr,true);
	
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = "?act=consultant";
	$link[1]['text'] = "继续添加";
	$link[1]['href'] = "?act=consultant_add";
	adminmsg('添加成功！',2,$link);
}
elseif($act == 'consultant_edit')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"consultant_edit");
	$id=intval($_GET['id']);
	if(!$id){
		adminmsg("请选择顾问！",1);
	}
	$consultant = get_consultant_one($id);
	$smarty->assign('consultant',$consultant);
	$smarty->assign('pageheader',"顾问管理");
	$smarty->display('company/admin_consultant_edit.htm');
}
elseif($act == 'consultant_edit_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"consultant_edit");
	$id=intval($_POST['id']);
	if(!$id){
		adminmsg("请选择顾问！",1);
	}
	$setsqlarr['name'] = !empty($_POST['name']) ? trim($_POST['name']):adminmsg('请填写姓名！',1);
	$setsqlarr['tel'] = !empty($_POST['tel']) ? trim($_POST['tel']):adminmsg('请填写联系电话！',1);	
	$setsqlarr['email'] = !empty($_POST['email']) ? trim($_POST['email']):adminmsg('请填写联系邮箱！',1);
	
	updatetable(table('consultant'),$setsqlarr," id={$id} ");
	
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = "?act=consultant";
	$link[1]['text'] = "查看修改结果";
	$link[1]['href'] = "?act=consultant_edit&id={$id}";
	adminmsg('修改成功！',2,$link);
}
elseif($act == "consultant_del"){
	check_permissions($_SESSION['admin_purview'],"consultant_del");
	$id=intval($_GET['id']);
	if(!$id){
		adminmsg("请选择顾问！",1);
	}
	del_consultant($id);
	adminmsg("删除成功！",2);
}
elseif($act == 'order_list')
{	
	get_token();
	check_permissions($_SESSION['admin_purview'],"ord_show");
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	require_once(ADMIN_ROOT_PATH.'include/admin_pay_fun.php');
	$wheresql=" WHERE o.utype=1 ";
	$orderbysql=" order BY o.addtime DESC ";
	$key=isset($_GET['key'])?trim($_GET['key']):"";
	$key_type=isset($_GET['key_type'])?intval($_GET['key_type']):"";
	if ($key && $key_type>0)
	{
		if     ($key_type===1)$wheresql=" WHERE o.utype=1 AND c.huntername like '%{$key}%'";
		elseif ($key_type===2)$wheresql=" WHERE o.utype=1 AND m.username = '{$key}'";
		elseif ($key_type===3)$wheresql=" WHERE o.utype=1 AND o.oid ='".trim($key)."'";
		$orderbysql="";
	}
	else
	{	
		$wheresqlarr['o.utype']='1';
		!empty($_GET['is_paid'])? $wheresqlarr['o.is_paid']=intval($_GET['is_paid']):'';
		!empty($_GET['typename'])?$wheresqlarr['o.payment_name']=trim($_GET['typename']):'';
		if (is_array($wheresqlarr)) $wheresql=wheresql($wheresqlarr);
		
		if (!empty($_GET['settr']))
		{
			$settr=strtotime("-".intval($_GET['settr'])." day");
			$wheresql.=empty($wheresql)?" WHERE ": " AND ";
			$wheresql.="o.addtime> ".$settr;
		}
	}
	$joinsql=" left JOIN ".table('members')." as m ON o.uid=m.uid LEFT JOIN  ".table('company_profile')." as c ON o.uid=c.uid ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('order')." as o ".$joinsql.$wheresql;
  	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$orderlist = get_order_list($offset,$perpage,$joinsql.$wheresql.$orderbysql);
	$smarty->assign('pageheader',"订单管理");
	$smarty->assign('payment_list',get_payment(2));
	$smarty->assign('orderlist',$orderlist);
	$smarty->assign('page',$page->show(3));
	$smarty->display('company/admin_order_list.htm');
}
elseif($act == 'order_set')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"ord_set");
	$smarty->assign('pageheader',"订单管理");
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('payment',get_order_one($_GET['id']));
	$smarty->display('company/admin_order_set.htm');
}
elseif($act == 'order_set_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"ord_set");
		if (order_paid(trim($_POST['oid'])))
		{
		$link[0]['text'] = "返回列表";
		$link[0]['href'] = $_POST['url'];
		!$db->query("UPDATE ".table('order')." SET notes='".$_POST['notes']."' WHERE id=".intval($_GET['id'])."  LIMIT 1 ")?adminmsg('操作失败',1):adminmsg("操作成功！",2,$link);
		}
		else
		{
		adminmsg('操作失败',1);
		}
}
elseif($act == 'show_order')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"ord_show");
	$smarty->assign('pageheader',"订单管理");
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('payment',get_order_one($_GET['id']));
	$smarty->display('company/admin_order_show.htm');
}

elseif($act == 'order_notes_save')
{
	check_token();
	$link[0]['text'] = "返回列表";
	$link[0]['href'] = $_POST['url'];
	!$db->query("UPDATE ".table('order')." SET  notes='".$_POST['notes']."' WHERE id='".intval($_GET['id'])."'")?adminmsg('操作失败',1):adminmsg("操作成功！",2,$link);
}
elseif($act == 'order_del')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"ord_del");
	$id =!empty($_REQUEST['id'])?$_REQUEST['id']:adminmsg("你没有选择项目！",1);
	if (del_order($id))
	{
	adminmsg("取消成功！",2,$link);
	}
	else
	{
	adminmsg("取消失败！",1);
	}
}
// 提现管理 提现列表
elseif($act=="account_withdrawal_list")
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"account_withdrawal");
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	require_once(ADMIN_ROOT_PATH.'include/admin_pay_fun.php');
	$wheresqlarr['o.utype']=1;
	$orderbysql=" order BY o.addtime DESC ";
	!empty($_GET['state'])? $wheresqlarr['o.state']=intval($_GET['state']):'';
	!empty($_GET['typename'])?$wheresqlarr['o.extract_pay_type']=trim($_GET['typename']):'';
	if (is_array($wheresqlarr)) $wheresql=wheresql($wheresqlarr);
	
	if (!empty($_GET['settr']))
	{
		$settr=strtotime("-".intval($_GET['settr'])." day");
		$wheresql.=empty($wheresql)?" WHERE ": " AND ";
		$wheresql.="o.addtime> ".$settr;
	}
	
	$joinsql=" left JOIN ".table('members')." as m ON o.uid=m.uid LEFT JOIN  ".table('company_profile')." as c ON o.uid=c.uid ";
	$total_sql="SELECT COUNT(*) AS num FROM ".table('account_withdrawal')." as o ".$joinsql.$wheresql;
  	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$orderlist = get_withdrawal_list($offset,$perpage,$joinsql.$wheresql.$orderbysql);
	$smarty->assign('pageheader',"提现管理");
	$smarty->assign('payment_list',get_payment(2));
	$smarty->assign('orderlist',$orderlist);
	$smarty->assign('page',$page->show(3));
	$smarty->display('company/admin_withdrawal_list.htm');
}
//  提现管理 提现设置
elseif($act=="account_withdrawal_set")
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"account_withdrawal");
	$smarty->assign('pageheader',"提现管理");
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('payment',get_withdrawal_one(intval($_GET['id'])));
	$smarty->display('company/admin_withdrawal_set.htm');
}
elseif($act == 'account_withdrawal_set_save')
{
	check_token();
	check_permissions($_SESSION['admin_purview'],"account_withdrawal");
	if (withdrawal_set(trim($_POST['id'])))
	{
		$link[0]['text'] = "返回列表";
		$link[0]['href'] = $_POST['url'];
		adminmsg("操作成功！",2,$link);
	}
	else
	{
		adminmsg('操作失败',1);
	}
}
elseif($act == 'account_withdrawal_show')
{
	get_token();
	check_permissions($_SESSION['admin_purview'],"account_withdrawal");
	$smarty->assign('pageheader',"提现管理");
	$smarty->assign('url',$_SERVER["HTTP_REFERER"]);
	$smarty->assign('payment',get_withdrawal_one($_GET['id']));
	$smarty->display('company/admin_withdrawal_show.htm');
}
?>