<?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']) : 'invited';
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']!='1'&& $_SESSION['utype']!='3')
{
	exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>必须是企业会员/猎头会员才可以邀请面试！</div>
				</div> 
			</div>
		</div>');
}
if($_SESSION['utype']=="1"){
	require_once(QISHI_ROOT_PATH.'include/fun_company.php');
	$user=get_user_info($_SESSION['parentuid']);
}elseif($_SESSION['utype']=="3"){
	require_once(QISHI_ROOT_PATH.'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>');
}
$id=isset($_GET['id'])?intval($_GET['id']):exit("err");

$user_jobs=$_SESSION['utype']=="1"?get_auditjobs($_SESSION['parentuid']):get_auditjobs($_SESSION['uid']);

if (count($user_jobs)==0)
{
	exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>邀请失败，你没有发布招聘信息或者信息没有审核通过！</div>
				</div> 
			</div>
		</div>');
}
if($_SESSION['utype']=="1"){
	if(!check_down_resumeid($id,$_SESSION['parentuid'])){
		exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>邀请失败，请先下载简历！</div>
				</div> 
			</div>
		</div>');
	}
}else{
	if(!check_down_resumeid($id,$_SESSION['uid'])){
		exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>邀请失败，请先下载简历！</div>
				</div> 
			</div>
		</div>');
	}
}
$resume=$db->getone("select * from ".table('resume')." WHERE id ='{$id}'  LIMIT 1");
$resume = array_map("addslashes",$resume);

if ($act=="invited")
{	
if($_SESSION['utype']=="1"){
	$interview_list_url = get_member_url(1,true)."company_recruitment.php?act=interview_list";
}else{
	$interview_list_url = get_member_url(3,true)."hunter_recruitment.php?act=interview_list";
}
?>
<script type="text/javascript">
$(".but100").hover(function(){$(this).addClass("but100_hover")},function(){$(this).removeClass("but100_hover")});
$("#but_invited").click(function() 
{
		var id="<?php echo $id?>";
		if ($("#ajax_invited_table :radio[checked]").length==0)
		{
		alert("请选择面试职位！");
		}
		else
		{
			$("#but_invited").val("处理中...");
			$("#but_invited").attr("disabled","disabled");
			var tsTimeStamp= new Date().getTime();
			$.get("<?php echo $_CFG['site_dir'] ?>user/user_invited.php", {"jobs_id": $("#ajax_invited_table :radio[checked]").val(),"id":id,"notes":$("#notes").val(),"time":tsTimeStamp,"act":"invited_save"},
			function (data,textStatus)
			 {
				if (data=="ok")
				{
				$(".ajax_invited_tip").hide();
				$("#ajax_invited_table").hide();
				$("#invited_ok").show();				 
						$("#invited_ok .closed").click(function(){
							DialogClose();
						});
				}
				else if (data=="repeat")
				{
				$(".ajax_invited_tip").hide();
				$("#ajax_invited_table").hide();
				$("#invited_ok").show();
				$(".float_auth_success").html("您已经邀请过此人才，不能重复邀请！");
				}
				else
				{
				$(".ajax_invited_tip").hide();
				$("#ajax_invited_table").hide();
				$("#invited_ok").show();
				$(".float_auth_success").html(data);
				}
				$("#but_invited").val("提交");
				$("#but_invited").attr("disabled","");
			 })
		}	 
});
function DialogClose()
{
	$("#FloatBg").hide();
	$("#FloatBox").hide();
}
</script>
<div class="floatContent" id="ajax_invited_table">
	<div class="float_common_box">
		<table class="float_auth_table">
			<tbody>
				<tr height="40">
					<td align="right">面试职位：</td>
					<td>
						<div class="float_control">
							<?php 
							foreach ($user_jobs as $list)
							{
							?>
							<label> <input name="jobs_id" type="radio"  id="jobs_id" value="<?php echo $list['id']?>" /><?php echo $list['jobs_name']?></label><br />
							<?php
							}
							?>
						</div>
					</td>
				</tr>
				<tr height="40">
					<td align="right">其他描述：</td>
					<td>
						<div class="float_control">
							<textarea name="notes" id="notes" style="width:300px; height:80px;"></textarea>
					          <br />
					        其他说明填写：面试携带证件，联系人，乘车路线等...<br />
						</div>
					</td>
				</tr>
			</tbody>
		</table>
		<div class="float_btn_guoup">
			<input type="submit" value="提交" name="Submit2" class="float_but55lan" id="but_invited">&nbsp;&nbsp;&nbsp;
			<input type="button" value="取消" class="float_but55hui DialogClose">
		</div>
	</div>
</div>
<div class="floatContent" style="display:none" id="invited_ok" >
	<div class="float_common_box" >
		<div class="float_auth_success">邀请成功！<a href="<?php echo $interview_list_url;?>" >查看我发起的面试邀请</a></div>
	</div>
</div>
<?php
}
elseif ($act=="invited_save")
{
	$jobs_id=isset($_GET['jobs_id'])?intval($_GET['jobs_id']):exit("err");
	$notes=isset($_GET['notes'])?trim($_GET['notes']):"";
	if($_SESSION['utype']=="1"){
		if (check_interview($id,$jobs_id,$_SESSION['parentuid']))
		{
		exit("repeat");
		}
	}else{
		if (check_interview($id,$jobs_id,$_SESSION['uid']))
		{
		exit("repeat");
		}
	}
	$jobs=get_jobs_one($jobs_id);
	$jobs = array_map("addslashes",$jobs);
	$addarr['resume_id']=$resume['id'];
	$addarr['resume_addtime']=$resume['addtime'];
	$addarr['resume_name']=$resume['fullname'];
	$addarr['resume_uid']=$resume['uid'];
	$addarr['belong_id']=$jobs['company_id'];
	$addarr['belong_addtime']=$jobs['company_addtime'];
	$addarr['belong_uid']=$_SESSION['uid'];
	$addarr['belong_name']=$jobs['companyname'];
	if($jobs['utype']=="1"){
		$addarr['belong_parentuid']=$_SESSION['parentuid'];
	}
	
	$addarr['jobs_id']=$jobs['id'];
	$addarr['jobs_name']=$jobs['jobs_name'];
	$addarr['jobs_addtime']=$jobs['addtime'];	
	$addarr['notes']= $notes;
	$addarr['is_look']= 1;
	$addarr['interview_addtime']=time();
	$user=get_user_info($resume['uid']);
	$resume_user=get_user_info($resume['uid']);
	$resume_user = array_map("addslashes", $resume_user);
	inserttable(table('company_interview'),$addarr);
	if($_SESSION['utype']=="3"){
		//写日志
		write_memberslog($_SESSION['uid'],3,6001,$_SESSION['username'],"/",0,"邀请 {$resume_user['username']} 面试",0);
	}else{
		//写日志
		write_memberslog($_SESSION['uid'],1,6001,$_SESSION['username'],"/",intval($_SESSION['parentuid']),"邀请 {$resume_user['username']} 面试",0);
	}	
	$mailconfig=get_cache('mailconfig');
	$sms=get_cache('sms_config');
	if ($mailconfig['set_invite']=="1" && $resume_user['email_audit']=="1")
	{
		dfopen("{$_CFG['site_dir']}plus/asyn_mail.php?uid={$_SESSION['uid']}&key=".asyn_userkey($_SESSION['uid'])."&act=set_invite&companyname={$jobs['companyname']}&email={$resume_user['email']}");				
	}
	//sms
	if ($sms['open']=="1"  && $sms['set_invite']=="1"  && $resume_user['mobile_audit']=="1")
	{
		dfopen("{$_CFG['site_dir']}plus/asyn_sms.php?uid={$_SESSION['uid']}&key=".asyn_userkey($_SESSION['uid'])."&act=set_invite&companyname={$jobs['companyname']}&mobile={$resume_user['mobile']}");		
	}
	exit("ok");
	//sms
}
?>