<?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']) : 'download';
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=!empty($_GET['id'])?intval($_GET['id']):exit("出错了");
if($_SESSION['utype']=="1"){
	$down_resume_list_url = get_member_url(1,true)."company_recruitment.php?act=down_resume_list";
	$jobs_list_url = get_member_url(1,true)."company_jobs.php?act=jobs";
	if (check_down_resumeid($id,$_SESSION['parentuid']))
	{
		$str="<a href=\"".$down_resume_list_url."\">[查看我下载的简历]</a>";
		exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>您已经下载过此简历了！'.$str.'</div>
				</div> 
		</div>');
	}
}else{
	$down_resume_list_url = get_member_url(3,true)."hunter_recruitment.php?act=down_resume_list";
	$jobs_list_url = get_member_url(3,true)."hunter_jobs.php?act=jobs";
	if (check_down_resumeid($id,$_SESSION['uid']))
	{
		$str="<a href=\"".$down_resume_list_url."\">[查看我下载的简历]</a>";
		exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>您已经下载过此简历了！'.$str.'</div>
				</div> 
			</div>
		</div>');
	}
}
if ($_CFG['down_resume_limit']=="1")
{
	$user_jobs=$_SESSION['utype']=="1"?get_auditjobs($_SESSION['parentuid']):get_auditjobs($_SESSION['uid']);
	if (empty($user_jobs))
	{
		exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>你没有发布职位或审核未通过导致无法下载简历。<a href="'.$jobs_list_url.'">[职位管理]</a></div>
				</div> 
			</div>
		</div>');
	}
}
$resumeshow=get_resume_basic($id);
$resumeshow = array_map("addslashes", $resumeshow);
if($_SESSION['utype']=="1"){
	$setmeal=get_user_setmeal($_SESSION['parentuid']);
	$count_today = count_down_resume_times_today($_SESSION['parentuid'],$resumeshow['talent']);
	$down_num = $resumeshow['talent']=="1"?$setmeal['down_ordinary_resume_day']:$setmeal['down_senior_resume_day'];
	if($count_today>=$down_num && $down_num!=0){
		exit('<div class="floatContent">
			<div class="float_common_box">
				<div class="float_tips">
					<div>已经超出今天可下载简历数！</div>
				</div> 
			</div>
		</div>');
	}
}
$resumeshow['resume_name']=$resumeshow['fullname'];
if ($act=="download")
{
	if($_SESSION['utype']=="3"){
		$hunter_profile = get_hunter($_SESSION['uid']);
		$hunter_profile = array_map("addslashes", $hunter_profile);
		$hunter_level_id = $hunter_profile['level_meal'];
		$hunter_level_meal = get_hunter_level_meal($hunter_level_id);
		$down_per_day = $resumeshow['talent']=="2"?$hunter_level_meal['down_senior_resume']:$hunter_level_meal['down_junior_resume'];
		if(check_today_down_resume($down_per_day,$_SESSION['uid'],$resumeshow['talent']) && $down_per_day!=0){
			$resumeshow['talent']=="2"?exit("您今天的高级简历下载数已达上限！"):exit("您今天的初级简历下载数已达上限！");
		}
		$points_rule=get_cache('points_rule');
		$points=$resumeshow['talent']=='2'?$points_rule['hunter_down_senior_resume']['value']:$points_rule['hunter_down_ordinary_resume']['value'];
		$ptype=$resumeshow['talent']=='2'?$points_rule['hunter_down_senior_resume']['type']:$points_rule['hunter_down_ordinary_resume']['type'];
		$mypoints=get_user_points($_SESSION['uid']);
		if  ($mypoints<$points&&$ptype=="2")
		{
			exit('<div class="floatContent">
				<div class="float_common_box">
					<div class="float_tips">
						<div>积分不足，请先充值！</div>
					</div> 
				</div>
			</div>');
		}
	}elseif($_SESSION['utype']=="1"){
		$setmeal=get_user_setmeal($_SESSION['parentuid']);
		if (empty($setmeal) || ($setmeal['endtime']<time() && $setmeal['endtime']<>"0"))
		{
			$str="<a href=\"".$_CFG['site_dir']."user/company/company_index.php?act=show_setmeal\">[申请服务]</a>";
			exit('<div class="floatContent">
				<div class="float_common_box">
					<div class="float_tips">
						<div>您的服务已到期。您可以 '.$str.'</div>
					</div> 
				</div>
			</div>');
		}
		elseif ($resumeshow['talent']=='2')
		{
			if($setmeal['down_senior_resume']<=0){
				$str="<a href=\"".$_CFG['site_dir']."user/company/company_index.php?act=show_setmeal\">[申请服务]</a>";
				exit('<div class="floatContent">
					<div class="float_common_box">
						<div class="float_tips">
							<div>你下载高级人才简历数量已经超出了限制。您可以 '.$str.'</div>
						</div> 
					</div>
				</div>');
			}
			if(check_today_down_resume($setmeal['down_senior_resume_day'],$_SESSION['parentuid'],$resumeshow['talent']) && $setmeal['down_senior_resume_day']!=0){
				exit('<div class="floatContent">
					<div class="float_common_box">
						<div class="float_tips">
							<div>您今天的高级人才简历下载数已达上限！</div>
						</div> 
					</div>
				</div>');
			}
		}
		elseif ($resumeshow['talent']=='1')
		{
			if($setmeal['down_ordinary_resume']<=0){
				$str="<a href=\"".$_CFG['site_dir']."user/company/company_index.php?act=show_setmeal\">[申请服务]</a>";
				exit('<div class="floatContent">
					<div class="float_common_box">
						<div class="float_tips">
							<div>你下载初级人才简历数量已经超出了限制。您可以 '.$str.'</div>
						</div> 
					</div>
				</div>');
			}
			if(check_today_down_resume($setmeal['down_ordinary_resume_day'],$_SESSION['parentuid'],$resumeshow['talent']) && $setmeal['down_ordinary_resume_day']!=0){
				exit('<div class="floatContent">
					<div class="float_common_box">
						<div class="float_tips">
							<div>您今天的初级人才简历下载数已达上限！</div>
						</div> 
					</div>
				</div>');
			}
		}
		$points_rule=get_cache('points_rule');
		$points=$resumeshow['talent']=='2'?$points_rule['resume_download_advanced']['value']:$points_rule['resume_download']['value'];
		$ptype=$resumeshow['talent']=='2'?$points_rule['resume_download_advanced']['type']:$points_rule['resume_download']['type'];
		$mypoints=get_user_points($_SESSION['parentuid']);
		if  ($mypoints<$points&&$ptype=="2")
		{
			exit('<div class="floatContent">
					<div class="float_common_box">
						<div class="float_tips">
							<div>积分不足，请先充值！</div>
						</div> 
					</div>
				</div>');
		}
	}
?>
<script type="text/javascript">
$(".but100").hover(function(){$(this).addClass("but100_hover")},function(){$(this).removeClass("but100_hover")});

$("#ajax_download_r").click(function() {
		var id="<?php echo $id?>";
		var tsTimeStamp= new Date().getTime();
			$("#ajax_download_r").val("处理中...");
			$("#ajax_download_r").attr("disabled","disabled");
		$.get("<?php echo $_CFG['site_dir'] ?>user/user_download_resume.php", { "id":id,"time":tsTimeStamp,"act":"download_save"},
	 	function (data,textStatus)
	 	 {
			if (data=="ok")
			{
				$(".ajax_download_tip").hide();
				$("#ajax_download_table").hide();
				$("#download_ok").show();			 
				$("#download_ok .closed").click(function(){
					DialogClose();
					location.reload();
				});
			}
			else
			{
				$(".ajax_download_tip").hide();
				$("#ajax_download_table").hide();
				$("#download_ok").show();
				$(".float_auth_success").html(data);
			}
			$("#ajax_download_r").val("下载简历");
			$("#ajax_download_r").attr("disabled","");
	 	 })
});
function DialogClose()
{
	$("#FloatBg").hide();
	$("#FloatBox").hide();
}
</script>
<div class="ajax_download_tip"><?php echo $tip?></div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableall" id="ajax_download_table">
    <tr style="text-align: center">
		<td>
			<input type="button" name="Submit"  id="ajax_download_r" class="but130lan" value="下载简历" />
		</td>
    </tr>
</table>
<div class="floatContent" style="display:none" id="download_ok" >
	<div class="float_common_box" >
		<div class="float_auth_success">下载成功！<a href="<?php echo $down_resume_list_url;?>" >查看已下载简历</a></div>
	</div>
</div>
<?php
}
elseif ($act=="download_save")
{
	$ruser=get_user_info($resumeshow['uid']);
	$ruser = array_map("addslashes", $ruser);
	if($_SESSION['utype']=="3"){
		$points_rule=get_cache('points_rule');
		$points=$resumeshow['talent']=='2'?$points_rule['hunter_down_senior_resume']['value']:$points_rule['hunter_down_ordinary_resume']['value'];
		$ptype=$resumeshow['talent']=='2'?$points_rule['hunter_down_senior_resume']['type']:$points_rule['hunter_down_ordinary_resume']['type'];
		$level_rule=get_cache("hunter_level_rule");
		$level=$resumeshow['talent']=='2'?$level_rule['down_senior_resume']['value']:$level_rule['down_junior_resume']['value'];
		$ltype=$resumeshow['talent']=='2'?$level_rule['down_senior_resume']['type']:$level_rule['down_junior_resume']['type'];
		$mypoints=get_user_points($_SESSION['uid']);
		if  ($mypoints<$points&&$ptype="2")
		{
			exit("err");
		}else{
			if(add_down_resume($id,$_SESSION['uid'],$resumeshow['uid'],$resumeshow['resume_name']))
			{
				if ($points>0)
				{
				report_deal($_SESSION['uid'],$ptype,$points);
				level_deal($_SESSION['uid'],$ltype,$level);
				level_meal_deal($_SESSION['uid']);
				$user_points=get_user_points($_SESSION['uid']);
				$operator=$ptype=="1"?"+":"-";
				write_memberslog($_SESSION['uid'],3,4001,$_SESSION['username'],"积分{$operator}{$points},剩余:{$user_points}","0","下载了 {$ruser['username']} 发布的简历",1);
				}
			}
		}
		exit("ok");	
	}elseif($_SESSION['utype']=="1"){
		if ($resumeshow['talent']=='2')
		{
			$points_rule=get_cache('points_rule');
			$points=$resumeshow['talent']=='2'?$points_rule['resume_download_advanced']['value']:$points_rule['resume_download']['value'];
			$ptype=$resumeshow['talent']=='2'?$points_rule['resume_download_advanced']['type']:$points_rule['resume_download']['type'];
			$mypoints=get_user_points($_SESSION['parentuid']);
			if  ($mypoints<$points&&$ptype="2" || $setmeal['down_senior_resume']<=0)
			{
				exit("err");
			}else{
				if(add_down_resume($id,$_SESSION['parentuid'],$_SESSION['uid'],$resumeshow['uid'],$resumeshow['resume_name'],2))
				{
					action_user_setmeal($_SESSION['parentuid'],"down_senior_resume");
					if ($points>0)
					{
					report_deal($_SESSION['parentuid'],$ptype,$points);
					$setmeal=get_user_setmeal($_SESSION['parentuid']);
					$user_points=get_user_points($_SESSION['parentuid']);
					$operator=$ptype=="1"?"+":"-";
					write_memberslog($_SESSION['uid'],1,4001,$_SESSION['username'],"积分{$operator}{$points},剩余:{$user_points},套餐剩余:{$setmeal['down_senior_resume']}",$_SESSION['parentuid'],"下载了 {$ruser['username']} 发布的简历",1);
					}
				}
			}
			exit("ok");
		}
		else
		{
			$points_rule=get_cache('points_rule');
			$points=$resumeshow['talent']=='2'?$points_rule['resume_download_advanced']['value']:$points_rule['resume_download']['value'];
			$ptype=$resumeshow['talent']=='2'?$points_rule['resume_download_advanced']['type']:$points_rule['resume_download']['type'];
			$mypoints=get_user_points($_SESSION['parentuid']);
			if  ($mypoints<$points&&$ptype="2" || $setmeal['down_ordinary_resume']<=0)
			{
				exit("err");
			}else{
				if(add_down_resume($id,$_SESSION['parentuid'],$_SESSION['uid'],$resumeshow['uid'],$resumeshow['resume_name'],1))
				{
					action_user_setmeal($_SESSION['parentuid'],"down_ordinary_resume");
					if ($points>0)
					{
					report_deal($_SESSION['parentuid'],$ptype,$points);
					$setmeal=get_user_setmeal($_SESSION['parentuid']);
					$user_points=get_user_points($_SESSION['parentuid']);
					$operator=$ptype=="1"?"+":"-";
					write_memberslog($_SESSION['uid'],1,4001,$_SESSION['username'],"积分{$operator}{$points},剩余:{$user_points},套餐剩余:{$setmeal['down_ordinary_resume']}",$_SESSION['parentuid'],"下载了 {$ruser['username']} 发布的简历",1);
					}
				}
			}
			exit("ok");
		}
	}
}
?>