<?php
 /*
 * 74cms 申请职位
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/../include/common.inc.php');
$act = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'app';
require_once(QISHI_ROOT_PATH.'include/mysql.class.php');
require_once(QISHI_ROOT_PATH.'include/fun_user.php');
$db = new mysql($dbhost,$dbuser,$dbpass,$dbname);
if ($_SESSION['uid']=='' || $_SESSION['username']=='')
{
	$captcha=get_cache('captcha');
	$smarty->assign('verify_userlogin',$captcha['verify_userlogin']);
	$smarty->display('plus/ajax_login.htm');
	exit();
}
if ($_SESSION['utype']!='3')
{
	exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>必须是猎头会员可以申请职位推荐！</div>
				</div>
			</div>
		</div>');
}
require_once(dirname(__FILE__).'/../include/fun_hunter.php');
$user=get_user_info($_SESSION['uid']);
if ($user['status']=="2") 
{
	exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>您的账号处于暂停状态，请先联系网站管理员设为正常后进行操作！</div>
				</div>
			</div>
		</div>');
}
if ($act=="app")
{		
		$id=isset($_GET['id'])?$_GET['id']:exit("id 丢失");
		$jobs=app_get_jobs($id);
		if (empty($jobs))
		{
			exit('<div class="floatContent">
				<div class="float_common_box">
					<div class="float_tips">
						<div>申请推荐失败！</div>
					</div>
				</div>
			</div>');
		}
		$hunter=get_hunter(intval($_SESSION['uid']));
		if($hunter['card_audit']!=1 || $hunter['belongcompany_audit']!=1 || $hunter['avatars_audit']!=1)
		{
			exit('<div class="floatContent">
				<div class="float_common_box">
					<div class="float_tips">
						<div>您没有认证通过，请先认证后在进行此操作！</div>
					</div>
				</div>
			</div>');
		}
		if (check_jobs_apply($jobs['id'],$hunter['uid']))
		{
			exit('<div class="floatContent">
					<div class="float_common_box">
						<div class="float_tips">
							<div>您已经申请过此职位，不能重复申请!</div>
						</div>
					</div>
				</div>');
		}
?>
<script type="text/javascript">
$(".but80").hover(function(){$(this).addClass("but80_hover")},function(){$(this).removeClass("but80_hover")});
//验证
$("#ajax_app").die().live("click",function() {
		$("#app").hide();
		$("#waiting").show();
		var tsTimeStamp= new Date().getTime();
		 //alert(expire);
			 var jidArr=new Array();
			 $("#app :checkbox[checked]").each(function(index){jidArr[index]=$(this).val();});
		$.post("<?php echo $_CFG['site_dir'] ?>user/user_hunter_apply_jobs.php", { "hunter_uid": <?php echo $hunter['uid'];?>,"jobs_id":<?php echo $jobs['id']; ?>,"time":tsTimeStamp,"act":"app_save"},
	 	function (data,textStatus)
	 	 {
			if (data=="ok")
			{
				$(".ajax_app_tip").hide();
				$("#app").hide();
				$("#waiting").hide();
				$("#app_ok").show();
					$("#app_ok .closed").click(function(){
					});
			}
			else if(data=="repeat")
			{
				$("#app").hide();
				$("#waiting").hide();
				$("#app_ok").show();
				$(".float_auth_success").html("您已经申请过此职位，不能重复申请");
			}
			else
			{
				$("#app").hide();
				$("#waiting").hide();
				$("#app_ok").show();
				$(".float_auth_success").html("申请失败！"+data);
			}
	 	 })
});
function DialogClose()
{
	$("#FloatBg").hide();
	$("#FloatBox").hide();
}
</script> 
<div class="floatContent" id="app">
	<div class="float_common_box">
		<div class="float_top_tip ajax_app_tip">您正在申请为<span>"<?php echo $jobs['companyname']?>"</span>发布的职位<span>"<?php echo $jobs['jobs_name']?>"</span> 推荐人才</div>
		<table class="float_auth_table">
			<tbody>
				<tr height="40">
					<td align="right">要申请的职位：</td>
					<td>
						<div class="float_control">
							 <?php echo $jobs['jobs_name']?>
						</div>
					</td>
				</tr>
			</tbody>
		</table>
		<div class="float_btn_guoup">
			<input type="submit" value="提交" name="Submit2" class="float_but55lan" id="ajax_app">&nbsp;&nbsp;&nbsp;
			<input type="button" value="取消" class="float_but55hui DialogClose">
		</div>
	</div>
</div>
<div class="floatContent" style="display:none" id="waiting" >
	<div class="float_common_box" >
		<img src="<?php echo  $_CFG['site_template']?>images/30.gif"  border="0"/>
	</div>
</div>
<div class="floatContent" style="display:none" id="app_ok" >
	<div class="float_common_box" >
		<div class="float_auth_success">职位申请成功！<a href="<?php echo get_member_url(3,true)?>hunter_entrust.php?act=my_entrust_jobs" >查看已申请的职位</a></div>
	</div>
</div>
<?php
}
elseif ($act=="app_save")
{
		
	$jobsid=isset($_POST['jobs_id'])?$_POST['jobs_id']:exit("出错了");
	$hunter_uid = intval($_SESSION['uid']);
	$hunter=get_hunter($hunter_uid);
	$jobsarr=app_get_jobs($jobsid);
	if (empty($jobsarr))
	{
		exit("职位丢失");
	}
	$jobs = array_map("addslashes",$jobsarr);
	if (check_jobs_apply($jobs['id'],$hunter_uid))
	{
	exit("repeat");
	}
	// $addarr['hunter_uid']=$hunter_uid;
	// $addarr['hunter_id']=$hunter['id'];
	$addarr['hunter_name']=$hunter['fullname'];
	$addarr['jobs_id']=$jobs['id'];
	$addarr['jobs_type']=$jobs['jobs_type'];
	$addarr['jobs_name']=$jobs['jobs_name'];
	$addarr['company_uid']=$jobs['uid'];
	$addarr['company_puid']=$jobs['parentuid'];
	$addarr['company_id']=$jobs['company_id'];
	$addarr['company_name']=$jobs['companyname'];
	$addarr['addtime']=time();
	$addarr['entrust_type']=1;
	$addarr['is_apply']=1;
	$insert_id = inserttable(table('entrust_hunter'),$addarr,1);
	if ($insert_id)
	{
		// 写消息 企业和猎头 add_pms($uid,$entrust_id,$message)
		add_pms($hunter_uid,$insert_id,"您申请为".$addarr['company_name']."发布的职位:".$addarr['jobs_name']=$jobs['jobs_name']." 推荐人才");
		add_pms($addarr['company_uid'],$insert_id,"猎头".$addarr['hunter_name']."申请为您发布的职位:".$addarr['jobs_name']=$jobs['jobs_name']." 推荐人才");
		exit("ok");
	}
}
?>
