<?php
!defined('IN_MYMPS') && exit('FORBIDDEN');
require_once MYMPS_DATA."/config.db.php";
require_once MYMPS_INC."/db.class.php";
require_once MYMPS_INC."/member.class.php";

$infoid = $infoid ? intval($infoid) : '';
!$infoid && write_msg('申请的职位信息主题ID不能为空!','olmsg');
$log = $member_log -> chk_in();

switch($log){
	case true:
		$msg = '<br>';
		$r		= $db -> getRow("SELECT * FROM `{$db_mymps}information` WHERE id = '$infoid'");
		if($db->getOne("SELECT COUNT(id) FROM `{$db_mymps}resume_post` WHERE userid = '$s_uid' AND infoid = '$r[id]'") > 0){
			$msg .= '<style>div{font-family:microsoft yahei;line-height:28px; font-size:14px; text-align:left; float:left; margin-bottom:30px; color:#585858;} span{margin-left:25px; margin-right:15px; display:block; float:left; height:64px; width:64px; background:url('.$mymps_global[SiteUrl].'/template/default/images/post/info_icons.png) 0 -128px no-repeat; margin-bottom:30px;}</style><span></span><div>您已经投递过简历给该职位啦！<br />查看 <a href=\''.$mymps_global[SiteUrl].'/member/?frame=home&m=resumePost\' target=_blank style=\'font-size:14px;\'>我的投递记录>></a></div>';
		} elseif($r['userid']) {
			if(!$s_uid) exit('无效的登录用户，请重新登录！');
			//判断是否创建了简历，
			$roww=$db->getRow("SELECT * FROM `{$db_mymps}resume` WHERE userid = '$s_uid'");
			$infouri=Rewrite('info',array('id'=>$r['id'],'dir_typename'=>$r['dir_typename'],'cityid'=>$r['cityid']));
			if($roww['id']){
				//如果创建了简历，判断今天投递了多少简历
				$havepost=$db->getOne("SELECT count(id) FROM `{$db_mymps}resume_post` WHERE userid = '$s_uid' AND begintime > '".mktime(0,0,0)."'");
				if($havepost>10){
					$msg .= '您今天已投递超过10封简历，请明天再投吧^_^';
				}else{
					require MYMPS_ROOT."/member/include/common.func.php";
					$db->query("INSERT INTO `{$db_mymps}resume_post` (infoid,title,infouri,resumeid,userid,touser,begintime)VALUES('$infoid','$r[title]','$infouri','$roww[id]','$s_uid','$r[userid]','$timestamp')");
					sendpm('admin',$r['userid'],'您发布的职位已有用户投递简历！','您发布的 <b>'.$r[title].'</b> ，已有用户投递简历，请前往《收到的简历》中查看！',1);
					$msg .= '<style>div{font-family:microsoft yahei;line-height:28px; font-size:14px; text-align:left; float:left; margin-bottom:30px; color:#585858;} span{margin-left:25px; margin-right:15px; display:block; float:left; height:64px; width:64px; background:url('.$mymps_global[SiteUrl].'/template/default/images/post/info_icons.png) 0 0 no-repeat; margin-bottom:30px;}</style><span></span><div>恭喜！已成功投递简历，请耐心等待用人单位回复！<br />查看 <a href=\''.$mymps_global[SiteUrl].'/member/?frame=home&m=resumePost\' target=_blank style=\'font-size:14px;\'>我的投递记录>></a>';
				}
			}else{
				$msg .= '<p style="height:30px;"></p><center><input title="创建简历后再申请职位" type="button" onclick="window.open(\''.$mymps_global[SiteUrl].'/member/?frame=home&m=base&ac=resume\')" style="cursor:pointer;border:none;background-color:#ff4500;color:white; border-radius:150px;text-decoration:none; padding:10px 30px;" value="+ 创建简历"></center><p style="height:30px;"></p>';
			}
		}else{
			$msg .= '<br><center style="color:red;">该职位由游客发布，无法投递简历，请直接联系发布人</center>';
		}
		echo $msg;
	break;
	
	default:
		$authcodesettings = read_static_cache('authcodesettings');
		$gourl = 'PostResume';
		include MYMPS_ROOT.'/template/box/login.tpl.php';
	
	break;
}

?>