<?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 丢失");
		$resume=app_get_resume($id);
		if (empty($resume))
		{
			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_resume_apply($resume['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);
		$.post("<?php echo $_CFG['site_dir'] ?>user/user_hunter_apply_resume.php", { "hunter_uid": <?php echo $hunter['uid'];?>,"resume_id":<?php echo $resume['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 "JL".$resume['id']?>"</span>的人才关注您<span></div>
		<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" style="margin-left:110px;" 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_resume" >查看已邀请的个人</a></div>
	</div>
</div>
<?php
}
elseif ($act=="app_save")
{
		
	$resume_id=isset($_POST['resume_id'])?$_POST['resume_id']:exit("出错了");
	$hunter_uid = intval($_SESSION['uid']);
	$hunter=get_hunter($hunter_uid);
	$resume=app_get_resume($resume_id);
	if (empty($resume))
	{
		exit("职位丢失");
	}
	$resume = array_map("addslashes",$resume);
	if (check_resume_apply($resume['id'],$hunter_uid))
	{
	exit("repeat");
	}
	// $addarr['hunter_uid']=$hunter_uid;
	// $addarr['hunter_id']=$hunter['id'];
	$addarr['hunter_name']=$hunter['fullname'];
	$addarr['resume_id']=$resume['id'];
	$addarr['resume_name']=$resume['fullname'];
	$addarr['resume_uid']=$resume['uid'];
	$addarr['addtime']=time();
	$addarr['entrust_type']=2;
	$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['resume_name']."对您经行关注");
		add_pms($addarr['resume_uid'],$insert_id,"猎头".$addarr['hunter_name']."邀请您对他进行关注");
		exit("ok");
	}
}
?>
