<?php
/*
 * 74cms 企业会员中心
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/company_common.php');
$smarty->assign('nav','jobs');
$act=trim($_GET["act"])?trim($_GET["act"]):"jobs";
if ($act=='jobs')
{
	$tabletype=intval($_REQUEST['tabletype']);
	//由于可以不同的账号登录,得确保职位是同一个公司发布的
	if($parentuid==$uid){
		$wheresql=" WHERE parentuid=".$parentuid." ";
	}else{
		$wheresql=" WHERE uid=".$uid." ";
	}
	$time = time();
	$orderby=" order by refreshtime desc";
	switch($tabletype){
		//全部职位
		case 1:
			$wheresql.='';
			break;
		//已结束(已过期的和暂停的)
		case 2:
			$wheresql.=" AND ((deadline<{$time} and deadline!=0) OR (display=2 AND finishtime<>'')) ";
			break;
		//审核中
		case 3:
			$wheresql.=" AND audit=2 ";
			break;
		//未通过
		case 4:
			$wheresql.=" AND audit=3 ";
			break;
		//正在发布
		default:
			$wheresql.=" AND audit=1 AND (deadline>{$time} or deadline=0) AND display=1 AND (setmeal_deadline>{$time} or setmeal_deadline=0) ";
			break;
	}
	//搜索条件
	$starttime = strtotime($_GET['starttime']);
	$endtime = strtotime($_GET['endtime']);
	$keyword = trim($_GET['keyword']);
	if($starttime>0)
	{
	$wheresql.=" AND addtime>".$starttime." ";
	}
	if($endtime>0)
	{
	$wheresql.=" AND addtime<".$endtime." ";
	}
	if($_GET['jobtype']!="")
	{
	$wheresql.=" AND jobs_type=".$_GET['jobtype']." ";
	}
	if($keyword!=""){
	$wheresql.=" AND jobs_name like '%".$keyword."%' ";
	}
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	//分页
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table('jobs').$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$offset=($page->nowindex-1)*$perpage;
	$smarty->assign('title','职位管理 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('act',$act);
	$smarty->assign('audit',$audit);
	//得到相应的职位
	$sql="SELECT * FROM ".table('jobs').$wheresql.$orderby;
	$total=$db->get_total("SELECT COUNT(*) AS num FROM ".table('jobs')." WHERE uid='{$uid}'");
	$smarty->assign('total',$total);
	$smarty->assign('jobs',get_jobs($offset,$perpage,$sql,true,true));
	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}
	$smarty->assign('points_rule',get_cache('points_rule'));
	$smarty->display('member_company/company_jobs.htm');
}
elseif ($act=='jobs_perform')
{
	global $_CFG;
	$yid =!empty($_POST['y_id'])?$_POST['y_id']:$_GET['y_id'];
	if(!check_jobs_permission($yid,$uid)){
		showmsg("你不可以操作非己职位！",1);
	}
	$points_rule=get_cache('points_rule');
    $jobs_num=count($yid);

	if (empty($yid))
	{
	showmsg("你没有选择职位！",1);
	}
	$refresh=!empty($_POST['refresh'])?$_POST['refresh']:$_GET['refresh'];
	$delete=!empty($_POST['delete'])?$_POST['delete']:$_GET['delete'];
	//刷新
    if ($refresh)
	{
		//限制刷新时间
		//最经一次的刷新时间
		if (empty($setmeal))
		{					
			showmsg("您还没有开通服务，请开通",1);
		}
		elseif ($setmeal['endtime']<time() && $setmeal['endtime']<>"0")
		{					
			showmsg("您的服务已经到期，请重新开通",1);
		}
		else
		{
			//刷新职位涉及到积分了
			if($points_rule['company_refresh_job']['value']>0)
			{
				//总共所需的积分
				$total_point=$jobs_num*$points_rule['company_refresh_job']['value'];
				if ($total_point>$points && $points_rule['company_refresh_job']['type']=="2")
				{
					showmsg("您的".$_CFG['points_byname']."不足，请先充值！",0);
				}
				//增减积分操作
				report_deal($parentuid,$points_rule['company_refresh_job']['type'],$total_point);
				$user_points=get_user_points($parentuid);
				$operator=$points_rule['company_refresh_job']['type']=="1"?"+":"-";
				write_memberslog($uid,1,2004,$_SESSION['username'],"积分{$operator}{$total_point},剩余{$user_points}",$parentuid,"刷新了{$jobs_num}条职位",1);
			}else{
				write_memberslog($uid,1,2004,$_SESSION['username'],"积分剩余{$user_points}",$parentuid,"刷新了{$jobs_num}条职位",0);
			}
		}
		refresh_jobs($yid,$parentuid);
		// write_refresh_log($parentuid,1001);			
		showmsg("刷新职位成功！",2);
	}
	//恢复
	elseif (!empty($_GET['display1']))
	{
	activate_jobs($yid,1,$parentuid);
	showmsg("设置成功！",2);
	}
	//结束(暂停)
	elseif (!empty($_GET['display2']))
	{
	activate_jobs($yid,2,$parentuid);
	showmsg("设置成功！",2);
	}
	//设置推广
	elseif (!empty($_GET['recommend1']))
	{
		if (empty($setmeal))
		{					
			showmsg("您还没有开通服务，请开通",1);
		}
		elseif ($setmeal['endtime']<time() && $setmeal['endtime']<>"0" && $setmeal_tg==0)
		{					
			showmsg("您的服务已经到期，请重新开通",1);
		}
		else
		{
			$points_rule=get_cache('points_rule');
			if($points_rule['company_tg_job']['value']>0)
			{	
				if($points_rule['company_tg_job']['value']>$points  &&  $points_rule['company_tg_job']['type']==2){
					showmsg("您的积分不足,不能推广职位!",1);
				}
				//增减积分操作
				report_deal($parentuid,$points_rule['company_tg_job']['type'],$points_rule['company_tg_job']['value']);
				$user_points=get_user_points($parentuid);
				$operator=$points_rule['company_tg_job']['type']=="1"?"+":"-";
				write_memberslog($uid,1,3004,$_SESSION['username'],"积分{$operator}{$total_point},剩余:{$user_points}",$parentuid,"推广职位",1);
			}
		}
		recommend_jobs($yid,1,$parentuid);
		showmsg("设置成功！",2);
	}
	//取消推广
	elseif (!empty($_GET['recommend2']))
	{
	recommend_jobs($yid,0,$parentuid);
	write_memberslog($uid,1,3006,$_SESSION['username'],"积分+0,剩余:{$points}",$parentuid,"取消推广职位",1);
	showmsg("设置成功！",2);
	}
}
// 选择发布哪种职位
elseif($act=="choose_addjobs")
{
	if (intval($company_info['nature'])!=0)
	{
		$smarty->assign('setmeal',$setmeal);
		$smarty->assign('points',$points);
		$smarty->assign('company_profile',$company_info);
		$smarty->display('member_company/company_choose_addjobs.htm');
	}
	else
	{
		$link[0]['text'] = "完善企业资料";
		$link[0]['href'] = 'company_info.php?act=company_profile';
		showmsg("为了达到更好的招聘效果，请先完善您的企业资料！",1,$link);
	}
}
//发布职位 初级职位
elseif ($act=='addjobs_junior')
{
	global $_CFG,$timestamp;
	if (intval($company_info['nature'])==0)
	{		
		$link[0]['text'] = "完善企业资料";
		$link[0]['href'] = 'company_info.php?act=company_profile';
		showmsg("为了达到更好的招聘效果，请先完善您的企业资料！",1,$link);
	}
	if ($setmeal['endtime']<$timestamp && $setmeal['endtime']<>"0")
	{					
		showmsg("您的服务已经到期，请重新开通",1);
	}
	if ($setmeal['jobs_ordinary']<=0)
	{
		showmsg("当前发布的初级职位已经超过了最大限制，请升级服务套餐！",1);
	}
	$points_rule=get_cache('points_rule');
	$total=0;
	if ($points_rule['company_set_job_ordinary']['type']=="2" && $points_rule['company_set_job_ordinary']['value']>0)
	{
	$total=$points_rule['company_set_job_ordinary']['value'];
	}
	if ($points_rule['jobs_daily']['type']=="2" && $points_rule['jobs_daily']['value']>0)
	{
		$total=$total+($_CFG['company_add_days']*$points_rule['jobs_daily']['value']);
		if ($total>$points)
		{
		showmsg("你的".$_CFG['points_byname']."不足！",0);
		}
	}
	if ($setmeal['endtime']<time() && $setmeal['endtime']<>"0")
	{					
		showmsg("您的服务已经到期，请重新开通",1);
	}
	if ($setmeal['jobs_ordinary']<=0)
	{
		showmsg("当前发布的初级职位已经超过了最大限制，请升级服务套餐！",1);
	}
	$points_rule=get_cache('points_rule');
	$total=0;
	if ($points_rule['company_set_job_ordinary']['type']=="2" && $points_rule['company_set_job_ordinary']['value']>0)
	{
	$total=$points_rule['company_set_job_ordinary']['value'];
	}
	if ($points_rule['jobs_daily']['type']=="2" && $points_rule['jobs_daily']['value']>0)
	{
	$total=$total+($_CFG['company_add_days']*$points_rule['jobs_daily']['value']);
	}
	if ($total>$points)
	{
	showmsg("你的".$_CFG['points_byname']."不足！",0);
	}
	$smarty->assign('jobs_templates',get_company_jobs_templates($uid));
	$smarty->assign('title','发布初级职位 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('company_profile',$company_info);
	$smarty->assign('setmeal',$setmeal);
	$smarty->assign('job_act',1);
	$smarty->display('member_company/company_addjobs_junior_senior.htm');
	
}
//发布职位 中高级
elseif ($act=='addjobs_senior')
{
	global $_CFG,$timestamp;
	if (intval($company_info['nature'])==0)
	{
		$link[0]['text'] = "完善企业资料";
		$link[0]['href'] = 'company_info.php?act=company_profile';
		showmsg("为了达到更好的招聘效果，请先完善您的企业资料！",1,$link);
	}
	if ($setmeal['endtime']<$timestamp && $setmeal['endtime']<>"0")
	{				
		showmsg("您的服务已经到期，请重新开通",1);
	}
	if ($setmeal['jobs_senior']<=0)
	{
		showmsg("当前发布的中高端职位已经超过了最大限制，请升级服务套餐！",1);
	}
	$points_rule=get_cache('points_rule');
	$total=0;
	if ($points_rule['company_set_job_senior']['type']=="2" && $points_rule['company_set_job_senior']['value']>0)
	{
	$total=$points_rule['company_set_job_senior']['value'];
	}
	if ($points_rule['jobs_daily']['type']=="2" && $points_rule['jobs_daily']['value']>0)
	{
		$total=$total+($_CFG['company_add_days']*$points_rule['jobs_daily']['value']);
		if ($total>$points)
		{
		showmsg("你的".$_CFG['points_byname']."不足，请充值后再发布！",1);
		}
	}
	$smarty->assign('jobs_templates',get_company_jobs_templates($uid));
	$smarty->assign('title','发布中高端职位 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('company_profile',$company_info);
	$smarty->assign('setmeal',$setmeal);
	$smarty->assign('job_act',2);
	$smarty->display('member_company/company_addjobs_junior_senior.htm');
}
// 发布职位 委托职位
elseif($act=="addjobs_entrust")
{
	global $_CFG,$timestamp;
	if (intval($company_info['nature'])==0)
	{
		$link[0]['text'] = "完善企业资料";
		$link[0]['href'] = 'company_info.php?act=company_profile';
		showmsg("为了达到更好的招聘效果，请先完善您的企业资料！",1,$link);
	}
	if ($setmeal['endtime']<$timestamp && $setmeal['endtime']<>"0")
	{					
		showmsg("您的服务已经到期，请重新开通",1);
	}
	if ($setmeal['jobs_entrust']<=0)
	{
		showmsg("当前发布的委托职位已经超过了最大限制，请升级服务套餐！",1);
	}
	$points_rule=get_cache('points_rule');
	$total=0;
	if ($points_rule['company_set_job_entrust']['type']=="2" && $points_rule['company_set_job_entrust']['value']>0)
	{
	$total=$points_rule['company_set_job_entrust']['value'];
	}
	if ($points_rule['jobs_daily']['type']=="2" && $points_rule['jobs_daily']['value']>0)
	{
		$total=$total+($_CFG['company_add_days']*$points_rule['jobs_daily']['value']);
		if ($total>$points)
		{
		showmsg("你的".$_CFG['points_byname']."不足，请充值后再发布！",1);
		}
	}
	$smarty->assign('jobs_templates',get_company_jobs_templates($uid));
	$smarty->assign('title','发布委托职位 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('company_profile',$company_info);
	$smarty->assign('setmeal',$setmeal);
	$smarty->assign('user_account',get_user_account($parentuid));
	$smarty->display('member_company/company_addjobs_entrust.htm');
	
}
//初级  中高级 职位保存
elseif ($act=='addjobs_save')
{
	global $_CFG,$timestamp;
	$job_act = intval($_POST['job_act'])>0?intval($_POST['job_act']):showmsg("参数错误！",1);
	switch($job_act){
		case 1:
			$add_jobs_max_points = $setmeal['jobs_ordinary_porint_all'];
			$company_set_job='company_set_job_ordinary';
			$jobs_ordinary="jobs_ordinary";
			$jobstype_name="初级";
			break;
		case 2:
			$add_jobs_max_points = $setmeal['jobs_senior_porint_all'];
			$company_set_job='company_set_job_senior';
			$jobs_ordinary="jobs_senior";
			$jobstype_name="中高端";
			break;
		default:
			$add_jobs_max_points = $setmeal['jobs_ordinary_porint_all'];
			$company_set_job='company_set_job_ordinary';
			$jobs_ordinary="jobs_ordinary";
			$jobstype_name="初级";
			break;
	}
	if ($setmeal['endtime']<$timestamp && $setmeal['endtime']<>"0")
	{					
		showmsg("您的服务已经到期，请重新开通",1);
	}
	if ($setmeal[$jobs_ordinary]<=0)
	{
		showmsg("当前发布的职位已经超过了最大限制，请升级服务套餐！",1);
	}
	$points_rule=get_cache('points_rule');
	$total=0;
	if ($points_rule[$company_set_job]['type']=="2" && $points_rule[$company_set_job]['value']>0)
	{
	$total=$points_rule[$company_set_job]['value'];
	}
	if ($points_rule['jobs_daily']['type']=="2" && $points_rule['jobs_daily']['value']>0)
	{
	$total=$total+($_CFG['company_add_days']*$points_rule['jobs_daily']['value']);
	}
	if ($total>$points)
	{
	showmsg("你的".$_CFG['points_byname']."不足，请充值后再发布！",1);
	}
	$setsqlarr['uid']=$uid;
	$setsqlarr['parentuid']=$parentuid;
	$setsqlarr['utype']=intval($_SESSION['utype']);
	$setsqlarr['companyname']=$company_info['companyname'];
	$setsqlarr['company_id']=$company_info['id'];
	$setsqlarr['companynature']=$company_info['nature'];
	$setsqlarr['companynature_cn']=$company_info['nature_cn'];
	$setsqlarr['company_addtime']=$company_info['addtime'];
	$setsqlarr['company_audit']=$company_info['audit'];
	$setsqlarr['setmeal_deadline']=$setmeal['endtime'];
	$setsqlarr['setmeal_id']=$setmeal['setmeal_id'];
	$setsqlarr['setmeal_name']=$setmeal['setmeal_name'];
	$setsqlarr['jobs_name']=!empty($_POST['jobs_name'])?trim($_POST['jobs_name']):showmsg('您没有填写职位名称！',1);
	check_word($_CFG['filter'],$_POST['jobs_name'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['category']=!empty($_POST['category_id'])?trim($_POST['category_id']):showmsg('您没有选择职位类别！',1);
	$setsqlarr['category_cn']=trim($_POST['category_cn']);
	$setsqlarr['district']=intval($_POST['district'])>0?intval($_POST['district']):showmsg('您没有选择地区！',1);
	$setsqlarr['sdistrict']=intval($_POST['sdistrict']);
	$setsqlarr['district_cn']=trim($_POST['district_cn']);
	$setsqlarr['department']=!empty($_POST['department'])?trim($_POST['department']):showmsg('您没有填写所属部门！',1);
	check_word($_CFG['filter'],$_POST['department'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['amount']=!empty($_POST['amount'])?intval($_POST['amount']):showmsg('请填写招聘人数！',1);
	$setsqlarr['reporter']=trim($_POST['reporter']);
	$setsqlarr['wage_min']=!empty($_POST['wage_min'])?intval($_POST['wage_min']):showmsg('请填写年薪下限！',1);
	$setsqlarr['wage_max']=!empty($_POST['wage_max'])?intval($_POST['wage_max']):showmsg('请填写年薪上限！',1);
	//发布初级职位
	if($job_act==1){
		if($setsqlarr['wage_min']>10 || $setsqlarr['wage_max']>10){
			showmsg("当前年薪已超出初级职位年薪上限！",1);
		}
		//jobs_type标识初级职位
		$setsqlarr['jobs_type']=0;
	}//发布中高端职位
	elseif($job_act==2){
		if($setsqlarr['wage_min']<10 || $setsqlarr['wage_max']<10){
			showmsg("当前年薪低于高级职位年薪下限！",1);
		}
		$setsqlarr['jobs_type']=1;
	}
	$setsqlarr['tag']=trim($_POST['tag']);
	$setsqlarr['age_min']=intval($_POST['age_min']);		
	$setsqlarr['age_max']=intval($_POST['age_max']);
	$setsqlarr['sex']=intval($_POST['sex']);
	$setsqlarr['sex_cn']=trim($_POST['sex_cn']);
	$setsqlarr['major']=trim($_POST['major']);
	$setsqlarr['experience']=intval($_POST['experience'])>0?intval($_POST['experience']):showmsg('您没有选择工作经验！',1);
	$setsqlarr['experience_cn']=trim($_POST['experience_cn']);
	$setsqlarr['education']=intval($_POST['education'])>0?intval($_POST['education']):showmsg('您没有选择学历！',1);
	$setsqlarr['education_cn']=trim($_POST['education_cn']);
	$setsqlarr['uec']=intval($_POST['uec']);	
	$setsqlarr['language']=trim($_POST['language']);
	$setsqlarr['language_cn']=trim($_POST['language_cn']);
	$setsqlarr['contents']=!empty($_POST['contents'])?trim($_POST['contents']):showmsg('您没有填写职位描述！',1);
	check_word($_CFG['filter'],$_POST['contents'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['trade']=$company_info['trade'];
	$setsqlarr['trade_cn']=$company_info['trade_cn'];
	$setsqlarr['scale']=$company_info['scale'];
	$setsqlarr['scale_cn']=$company_info['scale_cn'];
	$setsqlarr['email']=trim($_POST['email']);
	$setsqlarr['addtime']=$timestamp;
	$setsqlarr['deadline']=strtotime("".intval($_CFG['company_add_days'])." day");
	$setsqlarr['refreshtime']=$timestamp;
	$setsqlarr['key']=$setsqlarr['jobs_name'].$company_info['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_info['companyname']} ".$sp->extracttag($setsqlarr['key']);
	$setsqlarr['key']=$sp->pad($setsqlarr['key']);
	if ($company_info['audit']=="1")
	{
		$setsqlarr['audit']=intval($_CFG['audit_verifycom_addjob']);
	}
	else
	{
		$setsqlarr['audit']=intval($_CFG['audit_unexaminedcom_addjob']);
	}
	$setsqlarr_contact['contact']=$user['fullname'];
	$setsqlarr_contact['telephone']=$user['mobile'];
	$setsqlarr_contact['email']=trim($_POST['email']);
	//添加职位信息
	$pid=inserttable(table('jobs'),$setsqlarr,true);
	if(empty($pid)){
		showmsg("添加失败！",0);
	}else{
		//更新套餐
		action_user_setmeal($parentuid,$jobs_ordinary);
		//更新积分(更新之前得看发布职位是加积分还是减积分)
		if($points_rule[$company_set_job]['type']=='1'){
			//若是加积分还得判断是否超出每天发布初级/中高端职位最多奖励积分(求出此会员当天发布的职位数)
			$year = date("Y");
			$month = date("m");
			$day = date("d");
			$dayBegin = mktime(0,0,0,$month,$day,$year);//当天开始时间戳
			$dayEnd = mktime(23,59,59,$month,$day,$year);//当天结束时间戳
			$jobs_sql = "select count(*) as num from ".table('jobs')." where uid={$parentuid} and jobs_type=".$setsqlarr['jobs_type']." and addtime>{$dayBegin} and addtime<{$dayEnd}";
			$totaljobs = $db->get_total($jobs_sql);
			$today_points = intval($totaljobs)*$points_rule[$company_set_job]['value'];
			//当天所加积分 未 超出每天发布初级/中高端职位最多奖励积分
			if($today_points<=$add_jobs_max_points || $add_jobs_max_points==0){
				//更新积分
				action_user_points($parentuid,$points_rule[$company_set_job]['value'],'+');
			}
		}
		//减积分的情况
		else{
			//更新积分
			action_user_points($parentuid,$points_rule[$company_set_job]['value'],'-');
		}
		//写日志
		$setmeal=get_user_setmeal($parentuid);
		$user_points=get_user_points($parentuid);
		$operator=$points_rule[$company_set_job]['type']=="1"?"+":"-";
		write_memberslog(intval($uid),1,2001,$_SESSION['username'],"积分{$operator}{$points_rule[$company_set_job]['value']},剩余:{$user_points},套餐剩余:{$setmeal[$jobs_ordinary]}",$parentuid,"发布{$jobstype_name}职位:<strong>{$_POST['jobs_name']}</strong>",1);
	}
	//添加联系方式
	$setsqlarr_contact['pid']=$pid;
	!inserttable(table('jobs_contact'),$setsqlarr_contact)?showmsg("添加失败！",0):'';
	jobs_category_save($parentuid,$pid,$setsqlarr['category']);
	jobs_trade_save($parentuid,$pid,$setsqlarr['trade']);
	distribution_jobs($pid,$parentuid);
	$link[0]['text'] = "已发布职位";
	$link[0]['href'] = '?act=jobs';
	$link[1]['text'] = "继续发布职位";
	$link[1]['href'] = '?act=choose_addjobs';
	$link[3]['text'] = "会员中心首页";
	$link[3]['href'] = "company_index.php?";
	showmsg("发布成功！",2,$link);
}
//委托职位保存
elseif ($act=='add_entrust_jobs_save')
{
	global $_CFG,$timestamp;
	if ($setmeal['endtime']<$timestamp && $setmeal['endtime']<>"0")
	{					
		showmsg("您的服务已经到期，请重新开通",1);
	}
	if ($setmeal['jobs_entrust']<=0)
	{
		showmsg("当前发布的委托职位已经超过了最大限制，请升级服务套餐！",1);
	}
	$points_rule=get_cache('points_rule');
	$total=0;
	if ($points_rule['company_set_job_entrust']['type']=="2" && $points_rule['company_set_job_entrust']['value']>0)
	{
	$total=$points_rule['company_set_job_entrust']['value'];
	}
	if ($points_rule['jobs_daily']['type']=="2" && $points_rule['jobs_daily']['value']>0)
	{
	$total=$total+($_CFG['company_add_days']*$points_rule['jobs_daily']['value']);
	}
	if ($total>$points)
	{
	showmsg("你的".$_CFG['points_byname']."不足，请充值后再发布！",0);
	}
	$setsqlarr['uid']=$uid;
	$setsqlarr['parentuid']=$parentuid;
	$setsqlarr['utype']=intval($_SESSION['utype']);
	$setsqlarr['companyname']=$company_info['companyname'];
	$setsqlarr['company_id']=$company_info['id'];
	$setsqlarr['companynature']=$company_info['nature'];
	$setsqlarr['companynature_cn']=$company_info['nature_cn'];
	$setsqlarr['company_addtime']=$company_info['addtime'];
	$setsqlarr['company_audit']=$company_info['audit'];
	$setsqlarr['setmeal_deadline']=$setmeal['endtime'];
	$setsqlarr['setmeal_id']=$setmeal['setmeal_id'];
	$setsqlarr['setmeal_name']=$setmeal['setmeal_name'];
	$setsqlarr['jobs_name']=!empty($_POST['jobs_name'])?trim($_POST['jobs_name']):showmsg('您没有填写职位名称！',1);
	check_word($_CFG['filter'],$_POST['jobs_name'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['category']=!empty($_POST['category_id'])?trim($_POST['category_id']):showmsg('您没有选择职位类别！',1);
	$setsqlarr['category_cn']=trim($_POST['category_cn']);
	$setsqlarr['district']=intval($_POST['district'])>0?intval($_POST['district']):showmsg('您没有选择地区！',1);
	$setsqlarr['sdistrict']=intval($_POST['sdistrict']);
	$setsqlarr['district_cn']=trim($_POST['district_cn']);
	$setsqlarr['department']=!empty($_POST['department'])?trim($_POST['department']):showmsg('您没有填写所属部门！',1);
	check_word($_CFG['filter'],$_POST['department'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['amount']=!empty($_POST['amount'])?intval($_POST['amount']):showmsg('请填写招聘人数！',1);
	$setsqlarr['reporter']=trim($_POST['reporter']);
	$setsqlarr['wage_min']=!empty($_POST['wage_min'])?intval($_POST['wage_min']):showmsg('请填写年薪下限！',1);
	$setsqlarr['wage_max']=!empty($_POST['wage_max'])?intval($_POST['wage_max']):showmsg('请填写年薪上限！',1);
	$setsqlarr['jobs_type']=2;
	$setsqlarr['reward']=$_POST['reward']?$_POST['reward']:showmsg('请填写赏金!');
	
	$setsqlarr['tag']=trim($_POST['tag']);
	$setsqlarr['age_min']=intval($_POST['age_min']);		
	$setsqlarr['age_max']=intval($_POST['age_max']);
	$setsqlarr['sex']=intval($_POST['sex']);
	$setsqlarr['sex_cn']=trim($_POST['sex_cn']);
	$setsqlarr['major']=trim($_POST['major']);
	$setsqlarr['experience']=intval($_POST['experience'])>0?intval($_POST['experience']):showmsg('您没有选择工作经验！',1);
	$setsqlarr['experience_cn']=trim($_POST['experience_cn']);
	$setsqlarr['education']=intval($_POST['education'])>0?intval($_POST['education']):showmsg('您没有选择学历！',1);
	$setsqlarr['education_cn']=trim($_POST['education_cn']);
	$setsqlarr['uec']=intval($_POST['uec']);	
	$setsqlarr['language']=trim($_POST['language']);
	$setsqlarr['language_cn']=trim($_POST['language_cn']);
	$setsqlarr['contents']=!empty($_POST['contents'])?trim($_POST['contents']):showmsg('您没有填写职位描述！',1);
	check_word($_CFG['filter'],$_POST['contents'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['trade']=$company_info['trade'];
	$setsqlarr['trade_cn']=$company_info['trade_cn'];
	$setsqlarr['scale']=$company_info['scale'];
	$setsqlarr['scale_cn']=$company_info['scale_cn'];
	$setsqlarr['email']=trim($_POST['email']);
	$setsqlarr['addtime']=$timestamp;
	$setsqlarr['deadline']=strtotime("".intval($_CFG['company_add_days'])." day");
	$setsqlarr['refreshtime']=$timestamp;
	$setsqlarr['key']=$setsqlarr['jobs_name'].$company_info['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_info['companyname']} ".$sp->extracttag($setsqlarr['key']);
	$setsqlarr['key']=$sp->pad($setsqlarr['key']);
	if ($company_info['audit']=="1")
	{
		$setsqlarr['audit']=intval($_CFG['audit_verifycom_addjob']);
	}
	else
	{
		$setsqlarr['audit']=intval($_CFG['audit_unexaminedcom_addjob']);
	}
	$setsqlarr_contact['contact']=$user['fullname'];
	$setsqlarr_contact['telephone']=$user['mobile'];
	$setsqlarr_contact['email']=trim($_POST['email']);
	//添加职位信息
	$pid=inserttable(table('jobs'),$setsqlarr,true);
	if(empty($pid)){
		showmsg("添加失败！",0);
	}else{
		// 冻结账户资金
		if($setsqlarr['audit']==1)
		{
			action_user_account_blocked($parentuid,$setsqlarr['reward'],1);
			write_account_log($uid,$parentuid,1,$_SESSION['username'],"成功发布委托职位：".$setsqlarr['jobs_name'].",冻结保证金:".$setsqlarr['reward']."元","操作成功");
			$db->query("update ".table("jobs")." set is_bloked=1 where id=$pid and uid=$uid");
		}
		//更新套餐
		action_user_setmeal($parentuid,"jobs_entrust");
		//更新积分(更新之前得看发布职位是加积分还是减积分)
		if($points_rule['company_set_job_entrust']['type']=='1'){
			//若是加积分还得判断是否超出每天发布委托职位最多奖励积分(求出此会员当天发布的职位数)
			$year = date("Y");
			$month = date("m");
			$day = date("d");
			$dayBegin = mktime(0,0,0,$month,$day,$year);//当天开始时间戳
			$dayEnd = mktime(23,59,59,$month,$day,$year);//当天结束时间戳
			$jobs_sql = "select count(*) as num from ".table('jobs')." where uid={$parentuid} and jobs_type=2 and addtime>{$dayBegin} and addtime<{$dayEnd}";
			$totaljobs = $db->get_total($jobs_sql);
			$today_points = intval($totaljobs)*$points_rule['company_set_job_entrust']['value'];
			//当天所加积分 未 超出每天发布委托职位最多奖励积分
			if($today_points<=$setmeal['jobs_entrust_porint_all'] || $setmeal['jobs_entrust_porint_all']==0){
				//更新积分
				action_user_points($parentuid,$points_rule['company_set_job_entrust']['value'],'+');
			}
		}
		//减积分的情况
		else{
			//更新积分
			action_user_points($parentuid,$points_rule['company_set_job_entrust']['value'],'-');
		}
		//写日志
		$setmeal=get_user_setmeal($parentuid);
		$user_points=get_user_points($parentuid);
		$operator=$points_rule['company_set_job_entrust']['type']=="1"?"+":"-";
		write_memberslog($uid,1,2001,$_SESSION['username'],"积分{$operator}{$points_rule['company_set_job_entrust']['value']},剩余:{$user_points},套餐剩余:{$setmeal['jobs_entrust']}",$parentuid,"发布委托职位:<strong>{$_POST['jobs_name']}</strong>",1);
	}
	//添加联系方式
	$setsqlarr_contact['pid']=$pid;
	$setsqlarr_contact['contact']=$user['fullname'];
	$setsqlarr_contact['telephone']=$user['mobile'];
	$setsqlarr_contact['email']=trim($_POST['email']);
	!inserttable(table('jobs_contact'),$setsqlarr_contact)?showmsg("添加失败！",0):'';
	
	distribution_jobs($pid,$parentuid);
	$link[0]['text'] = "已发布职位";
	$link[0]['href'] = '?act=jobs';
	$link[1]['text'] = "继续发布职位";
	$link[1]['href'] = '?act=choose_addjobs';
	$link[3]['text'] = "会员中心首页";
	$link[3]['href'] = "company_index.php?";
	showmsg("发布成功！",2,$link);
}
//保存为职位模板
elseif($act == "ajax_save_jobs_templates"){
	$setsqlarr['uid']=$parentuid;
	$setsqlarr['title']=!empty($_POST['jobs_name'])?trim($_POST['jobs_name'])."的模板":exit('-1');
	$setsqlarr['jobs_name']=trim($_POST['jobs_name']);
	$setsqlarr['sex']=intval($_POST['sex']);
	$setsqlarr['sex_cn']=trim($_POST['sex_cn']);
	$setsqlarr['amount']=intval($_POST['amount']);
	$setsqlarr['category']=trim($_POST['category']);
	$setsqlarr['category_cn']=trim($_POST['category_cn']);
	$setsqlarr['district']=intval($_POST['district']);
	$setsqlarr['sdistrict']=intval($_POST['sdistrict']);
	$setsqlarr['district_cn']=trim($_POST['district_cn']);
	$setsqlarr['department']=trim($_POST['department']);
	$setsqlarr['reporter']=trim($_POST['reporter']);
	$setsqlarr['tag']=trim($_POST['tag']);
	$setsqlarr['education']=intval($_POST['education']);		
	$setsqlarr['education_cn']=trim($_POST['education_cn']);
	$setsqlarr['uec']=intval($_POST['uec']);	
	$setsqlarr['language']=trim($_POST['language']);		
	$setsqlarr['language_cn']=trim($_POST['language_cn']);
	$setsqlarr['experience']=intval($_POST['experience']);		
	$setsqlarr['experience_cn']=trim($_POST['experience_cn']);
	$setsqlarr['age_min']=intval($_POST['age_min']);
	$setsqlarr['age_max']=intval($_POST['age_max']);
	$setsqlarr['wage_min']=intval($_POST['wage_min']);
	$setsqlarr['wage_max']=intval($_POST['wage_max']);
	$setsqlarr['major']=trim($_POST['major']);
	$setsqlarr['contents']=trim($_POST['contents']);
	$setsqlarr['email']=trim($_POST['email']);
	$setsqlarr['addtime']=time();
	$pid=inserttable(table('company_jobs_templates'),$setsqlarr,true);
	if($pid>0){
		exit("1");
	}else{
		exit("-1");
	}
}
//选择模板
elseif($act == 'ajax_copy_templates'){
	$id = intval($_GET['id']);
	if($id<1){
		exit("-1");
	}
	$templates = get_company_jobs_templates_one($id,$uid);
	if(!empty($templates)){
		exit(json_encode($templates));
	}else{
		exit("-1");
	}
}
elseif($act=='ajax_job_templates_del'){
	$id=intval($_GET['id']);
	del_company_jobs_templates($id,intval($uid));
	$templates = get_company_jobs_templates(intval($uid));
	$html = "";
	if(!empty($templates)){
		foreach($templates as $value){
			$html .= "<tr height=\"25\">";
			$html .= "<td width=\"295\"><div class=\"temp_name\">".$value['title']."</div></td>";
			$html .= "<td class=\"link_blue\"><a class=\"del_tpl\" pid=".$value['id']." href=\"javascript:void(0);\">删除</a></td>";
			$html .= "</tr>";
		}
	}else{
		$html .= "<tr height=\"25\"><td width=\"295\"><div class=\"temp_name\">您还没有创建模板！</div></td><td class=\"link_blue\"></td></tr>";
	}
	exit($html);
}
//修改职位
elseif ($act=='editjobs')
{
	if(!check_jobs_permission(intval($_GET['id']),$uid)){
		showmsg("你不可以操作非己职位！",1);
	}
	$jobs=get_jobs_one(intval($_GET['id']),$parentuid);
	if($jobs['jobs_type']=="2"){
		showmsg("参数错误！",1);
	}
	if (empty($jobs)) showmsg("参数错误！",1);
	if ($setmeal['endtime']<time() && $setmeal['endtime']<>"0")
	{					
		showmsg("您的服务已经到期，请重新开通",1);
	}

	$smarty->assign('title','修改职位 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('jobs',$jobs);
	$smarty->display('member_company/company_editjobs_junior_senior.htm');
}
elseif ($act=='editjobs_save')
{
	if ($setmeal['endtime']<time() && $setmeal['endtime']<>"0")
	{					
		showmsg("您的服务已经到期，请重新开通",1);
	}
	$id=intval($_POST['id'])?intval($_POST['id']):showmsg("参数错误！",1);
	if(!check_jobs_permission($id,$uid)){
		showmsg("你不可以操作非己职位！",1);
	}
	//jobs_type标识初级职位
	$job_act = intval($_POST['job_act']);
	if($job_act!=1 && $job_act!=2){
		showmsg("参数错误！",1);
	}
	$setsqlarr['wage_min']=!empty($_POST['wage_min'])?intval($_POST['wage_min']):showmsg('请填写年薪下限！',1);
	$setsqlarr['wage_max']=!empty($_POST['wage_max'])?intval($_POST['wage_max']):showmsg('请填写年薪上限！',1);
	//发布初级职位
	if($job_act==1){
		if($setsqlarr['wage_min']>10 || $setsqlarr['wage_max']>10){
			showmsg("当前年薪已超出初级职位年薪上限！",1);
		}
	}//发布中高端职位
	elseif($job_act==2){
		if($setsqlarr['wage_min']<10 || $setsqlarr['wage_max']<10){
			showmsg("当前年薪低于高级职位年薪下限！",1);
		}
	}

	$setsqlarr['category']=trim($_POST['category_id']);
	$setsqlarr['category_cn']=trim($_POST['category_cn']);
	$setsqlarr['department']=!empty($_POST['department'])?trim($_POST['department']):showmsg('您没有填写所属部门！',1);
	check_word($_CFG['filter'],$_POST['department'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['amount']=!empty($_POST['amount'])?intval($_POST['amount']):showmsg('请填写招聘人数！',1);
	$setsqlarr['reporter']=trim($_POST['reporter']);
	check_word($_CFG['filter'],$_POST['reporter'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['tag']=trim($_POST['tag']);
	$setsqlarr['age_min']=intval($_POST['age_min']);		
	$setsqlarr['age_max']=intval($_POST['age_max']);
	$setsqlarr['sex']=intval($_POST['sex']);
	$setsqlarr['sex_cn']=trim($_POST['sex_cn']);
	$setsqlarr['major']=trim($_POST['major']);
	// $setsqlarr['experience']=intval($_POST['experience']);
	// $setsqlarr['experience_cn']=trim($_POST['experience_cn']);
	// $setsqlarr['education']=intval($_POST['education']);		
	// $setsqlarr['education_cn']=trim($_POST['education_cn']);
	$setsqlarr['uec']=intval($_POST['uec']);	
	$setsqlarr['language']=trim($_POST['language']);
	$setsqlarr['language_cn']=trim($_POST['language_cn']);
	$setsqlarr['contents']=!empty($_POST['contents'])?trim($_POST['contents']):showmsg('您没有填写职位描述！',1);
	check_word($_CFG['filter'],$_POST['contents'])?showmsg($_CFG['filter_tips'],0):'';
	$setsqlarr['email']=trim($_POST['email']);
	$setsqlarr['refreshtime']=time();
	$setsqlarr['key']=$setsqlarr['jobs_name'].$company_info['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_info['companyname']} ".$sp->extracttag($setsqlarr['key']);
	$setsqlarr['key']=$sp->pad($setsqlarr['key']);
	if (!updatetable(table('jobs'), $setsqlarr," id='{$id}' AND uid='{$parentuid}' ")) showmsg("保存失败！",0);
	jobs_category_save($parentuid,$pid,$_POST['category_id']);
	distribution_jobs($id,$parentuid);
	write_memberslog($uid,$_SESSION['utype'],2002,$_SESSION['username'],"/",$parentuid,"修改职位,职位ID：{$id}",0);
	showmsg("修改成功！",2);
}
unset($smarty);
?>