<?php
 /*
 * 74cms 生成word
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/../include/common.inc.php');
require_once(QISHI_ROOT_PATH.'include/mysql.class.php');
$db = new mysql($dbhost,$dbuser,$dbpass,$dbname);
unset($dbhost,$dbuser,$dbpass,$dbname);
$uid=intval($_GET['uid']);//简历所属会员的uid
$id=intval($_GET['resume_id']);
if ($_SESSION['uid']=='' || $_SESSION['username']=='')
{
	$resume_url=url_rewrite('QS_resumeshow',array('id'=>$id));
    header("Location:".url_rewrite('QS_index')."?url={$resume_url}");
	exit();
}
if($_SESSION['utype']=='2' && $_SESSION['uid']!=$uid){
	$flag=false;
}else{
	$flag=true;
}
if(!$flag) {showmsg('您没有权限！',1);exit();}
if($_SESSION['utype']=="1"){
	require_once(QISHI_ROOT_PATH.'include/fun_company.php');
	$setmeal = get_user_setmeal($_SESSION['parentuid']);
	if($setmeal['save_resume']=="0"){
		showmsg("您当前的套餐没有保存简历的权限！",1);
	}
}

$wheresql=" WHERE  id='{$id}'  AND uid='{$uid}' ";
$sql = "select * from ".table('resume').$wheresql." LIMIT  1";
$val=$db->getone($sql);
$val['doc_fullname'] = $val['fullname'];
if ($val)
{
	if($_SESSION['utype']=="1"){
		$setmeal=get_user_setmeal(intval($_SESSION['parentuid']));
		$setmeal['setmeal_name'] = cut_str($setmeal['setmeal_name'],3,0);
		$smarty->assign('setmeal',$setmeal);
		$count_today = count_view_resume_times_today($_SESSION['parentuid'],$val['talent']);
		$see_num = $val['talent']=="1"?$setmeal['see_ordinary_resume']:$setmeal['see_senior_resume'];
		if($count_today>=$see_num){
			$val['fullname'] = "*****";
			$val['telephone'] = "*****";
			$val['email'] = "*****";
		}
	}
	$sql = "select did,down_addtime from ".table('company_down_resume')." WHERE company_uid = {$_SESSION['uid']} AND resume_id='{$id}' LIMIT 1";
	$info=$db->getone($sql);
	if (empty($info))
	{
		$val['fullname'] = "*****";
		$val['telephone'] = "*****";
		$val['email'] = "*****";
	}
	$val['education_list']=get_resume_education($val['uid'],$val['id']);
	foreach ($val['education_list'] as $key => $value) {
		$totalsecond = $value['endtime']-$value['start'];
		$per_year_second = 3600*24*365;
		$per_month_second = 3600*24*30;
		if($totalsecond>0){
			$val['education_list'][$key]['duration'] = intval($totalsecond/$per_year_second)==0 ? intval($totalsecond/$per_month_second)."个月" : intval($totalsecond / $per_year_second)."年".intval(($totalsecond%$per_year_second)/$per_month_second)."个月";
		}else{
			$val['education_list'][$key]['duration'] = "未知";
		}
	}
	$val['work_list']=get_resume_work($val['uid'],$val['id']);
	foreach ($val['work_list'] as $key => $value) {
		$totalsecond = $value['endtime']-$value['start'];
		$per_year_second = 3600*24*365;
		$per_month_second = 3600*24*30;
		if($totalsecond>0){
			$val['work_list'][$key]['duration'] = intval($totalsecond/$per_year_second)==0 ? intval($totalsecond/$per_month_second)."个月" : intval($totalsecond / $per_year_second)."年".intval(($totalsecond%$per_year_second)/$per_month_second)."个月";
		}else{
			$val['work_list'][$key]['duration'] = "未知";
		}
	}
	$val['project_list']=get_resume_project($val['uid'],$val['id']);
	foreach ($val['project_list'] as $key => $value) {
		$totalsecond = $value['endtime']-$value['start'];
		$per_year_second = 3600*24*365;
		$per_month_second = 3600*24*30;
		if($totalsecond>0){
			$val['project_list'][$key]['duration'] = intval($totalsecond/$per_year_second)==0 ? intval($totalsecond/$per_month_second)."个月" : intval($totalsecond / $per_year_second)."年".intval(($totalsecond%$per_year_second)/$per_month_second)."个月";
		}else{
			$val['project_list'][$key]['duration'] = "未知";
		}
	}
	$val['language_list']=get_resume_language($val['uid'],$val['id']);
	$val['age']=date("Y")-$val['birthdate'];
	$val['tagcn']=preg_replace("/\d+/", '',$val['tag']);
	$val['tagcn']=preg_replace('/\,/','',$val['tagcn']);
	$val['tagcn']=preg_replace('/\|/','&nbsp;&nbsp;&nbsp;',$val['tagcn']);	
 	
	$htm='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title></title>
	<style>
		body{margin:0;padding:0;font-size: 12px;}
		table{border-collapse: collapse;width:980px;margin:0 auto;margin-top: 10px;line-height: 22px;}
	</style>
</head>
<body>
	<table width="980" border="2" align="center">
		<tbody>
			<tr bgcolor="#FAF7C1" height="40" align="left">
				<td width="250">简历编号：</td>
				<td width="250">'.$val["id"].'</td>
				<td width="250">更新时间：</td>
				<td width="250">'.date("Y-m-d",$val["refreshtime"]).'</td>
			</tr>
		</tbody>
	</table>
	<table width="980" border="0" align="center">
		<tbody>
			<tr height="40" align="left" style="border-bottom:2px solid #333;">
				<th width="250" style="font-size:16px;" align="left">个人信息</th>
			</tr>
		</tbody>
	</table>
	<table width="980" border="0" align="center">
		<tbody>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">姓名：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["fullname"].'</td>
				<td width="200" align="right" style="border:1px dashed #ccc">性别：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["sex_cn"].'</td>
			</tr>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">手机号码：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["telephone"].'</td>
				<td width="200" align="right" style="border:1px dashed #ccc">年龄：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["age"].'</td>
			</tr>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">电子邮件：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["email"].'</td>
				<td width="200" align="right" style="border:1px dashed #ccc">教育程度：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["education_cn"].'</td>
			</tr>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">工作年限：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["experience_cn"].'</td>
				<td width="200" align="right" style="border:1px dashed #ccc">婚姻状况：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["marriage_cn"].'</td>
			</tr>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">职业状态：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["current_cn"].'</td>
				<td width="200" align="right" style="border:1px dashed #ccc">所在地：</td>
				<td width="300" align="left" style="border:1px dashed #ccc">'.$val["residence_cn"].'</td>
			</tr>
		</tbody>
	</table>
	<table width="980" border="0" align="center">
		<tbody>
			<tr height="25">
				<th align="left" style="border:1px dashed #ccc" colspan="4">职业发展意向：</th>
			</tr>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">期望行业：</td>
				<td width="780" align="left" style="border:1px dashed #ccc">'.$val["trade_cn"].'</td>
			</tr>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">期望职位：</td>
				<td width="780" align="left" style="border:1px dashed #ccc">'.$val["intention_jobs_cn"].'</td>
			</tr>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">期望地点：</td>
				<td width="780" align="left" style="border:1px dashed #ccc">'.$val["district_cn"].'</td>
			</tr>
			<tr height="25">
				<td width="200" align="right" style="border:1px dashed #ccc">期望年薪：</td>
				<td width="780" align="left" style="border:1px dashed #ccc">'.$val["wage_hope"].'</td>
			</tr>
		</tbody>
	</table>';
	if($val["work_list"]){
		$htm .= '<table width="980" border="0" align="center">
				<tbody>
					<tr height="40" align="left" style="border-bottom:2px solid #333;">
						<th width="250" style="font-size:16px;">工作经验</th>
					</tr>
				</tbody>
			</table><table width="980" border="0" align="center">
		<tbody>';
		foreach ($val['work_list'] as $wli)
	 	 {
	 	 	$htm .= '<tr height="25">
						<th align="left" style="border:1px dashed #ccc" bgcolor="#EAEAEA">'.date("Y/m",$wli["starttime"]).' - '.date("Y/m",$wli["endtime"]).'</th>
						<th align="left" style="border:1px dashed #ccc" colspan="3" bgcolor="#EAEAEA">'.$wli["companyname"].'</th>
					</tr>
					<tr height="25">
						<td width="150" align="right" style="border:1px dashed #ccc">&nbsp;</td>
						<th width="480" align="left" style="border:1px dashed #ccc" bgcolor="#EAEAEA" colspan="2">'.$wli["jobs"].'</th>
					</tr>
					<tr height="25">
						<td width="150" align="right" style="border:1px dashed #ccc">&nbsp;</td>
						<td align="left" style="border:1px dashed #ccc" valign="top">工作职责：</td>
						<td align="left" style="border:1px dashed #ccc" colspan="2">
							'.$wli["content"].'
						</td>
					</tr>';
	 	 }
	 	 $htm .= '</tbody></table>';
	}
	if($val["education_list"]){
		$htm .= '<table width="980" border="0" align="center">
				<tbody>
					<tr height="40" align="left" style="border-bottom:2px solid #333;">
						<th width="250" style="font-size:16px;">教育经历</th>
					</tr>
				</tbody>
			</table><table width="980" border="0" align="center">
		<tbody>';
		foreach ($val['education_list'] as $eli)
	 	 {
	 	 	$htm .= '<tr height="25">
						<th align="left" style="border:1px dashed #ccc" width="500">'.$eli["school"].'  '.date("Y/m",$eli["starttime"]).'-';
			if(intval($eli["endtime"])==0)
			{
				$endtime=date("Y/m",time());
			}
			else
			{
				$endtime=date("Y/m",$eli["endtime"]);
			}
			$htm .=$endtime.'</th>
						<td align="left" style="border:1px dashed #ccc" width="240">'.$eli["speciality"].'</td>
						<td align="left" style="border:1px dashed #ccc" width="240">'.$eli["education_cn"].'</td>
					</tr>';
	 	 }
	 	 $htm .= '</tbody></table>';
	}
	if($val["project_list"]){
		$htm .= '<table width="980" border="0" align="center">
				<tbody>
					<tr height="40" align="left" style="border-bottom:2px solid #333;">
						<th width="250" style="font-size:16px;">项目经历</th>
					</tr>
				</tbody>
			</table><table width="980" border="0" align="center">
		<tbody>';
		foreach ($val['project_list'] as $pli)
	 	 {
	 	 	$htm .= '<tr height="25">
						<th align="left" style="border:1px dashed #ccc" bgcolor="#EAEAEA">'.date("Y/m",$pli["starttime"]).' - ';
			if(intval($eli["endtime"])==0)
			{
				$endtime=date("Y/m",time());
			}
			else
			{
				$endtime=date("Y/m",$eli["endtime"]);
			}		
			$htm .=$endtime.'</th>
						<th align="left" style="border:1px dashed #ccc" colspan="3" bgcolor="#EAEAEA">'.$pli["project_name"].'</th>
					</tr>
					<tr height="25">
						<td width="150" align="right" style="border:1px dashed #ccc">&nbsp;</td>
						<td align="left" style="border:1px dashed #ccc" valign="top">项目描述：</td>
						<td align="left" style="border:1px dashed #ccc" colspan="2">'.$pli["project_describe"].'</td>
					</tr>
					<tr height="25">
						<td width="150" align="right" style="border:1px dashed #ccc">&nbsp;</td>
						<td align="left" style="border:1px dashed #ccc" valign="top">项目职责：</td>
						<td align="left" style="border:1px dashed #ccc" colspan="2">'.$pli["project_duty"].'</td>
					</tr>';
	 	 }
	 	 $htm .= '</tbody></table>';
	}
	if($val["language_list"]){
		$htm .= '<table width="980" border="0" align="center">
				<tbody>
					<tr height="40" align="left" style="border-bottom:2px solid #333;">
						<th width="250" style="font-size:16px;">语言能力</th>
					</tr>
				</tbody>
			</table><table width="980" border="0" align="center">
		<tbody>';
		foreach ($val['language_list'] as $lli)
	 	 {
	 	 	$htm .= '<tr height="25">
						<th align="left" style="border:1px dashed #ccc">'.$lli["language_cn"].' | '.$lli["level_cn"].'</th>
					</tr>';
	 	 }
	 	 $htm .= '</tbody></table>';
	}
	if($val['specialty']){
		$htm .= '<table width="980" border="0" align="center">
					<tbody>
						<tr height="40" align="left" style="border-bottom:2px solid #333;">
							<th width="250" style="font-size:16px;">自我评价</th>
						</tr>
					</tbody>
				</table>
				<table width="980" border="0" align="center">
					<tbody>
						<tr height="25">
							<td align="left" style="border:1px dashed #ccc">
								'.$val["specialty"].'
							</td>
						</tr>
					</tbody>
				</table>';
	}
 $htm.='</body></html>';

header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache");   
header("Content-Type: application/doc"); 
header("Content-Disposition:attachment; filename=".$id.".doc"); 
echo $htm;
}
else
{
 showmsg('简历不存在！',1);
 exit();
}
function get_resume_education($uid,$pid)
{
	global $db;
	$sql = "SELECT * FROM ".table('resume_education')." WHERE uid='".intval($uid)."' AND pid='".intval($pid)."' ";
	return $db->getall($sql);
}
function get_resume_work($uid,$pid)
{
	global $db;
	$sql = "select * from ".table('resume_work')." where uid=".intval($uid)." AND pid='".$pid."' " ;
	return $db->getall($sql);
}
function get_resume_project($uid,$pid)
{
	global $db;
	$sql = "select * from ".table('resume_project')." where uid='".intval($uid)."' AND pid='".intval($pid)."'";
	return $db->getall($sql);
}
function get_resume_language($uid,$pid)
{
	global $db;
	$sql = "select * from ".table('resume_language')." where pid='".intval($pid)."' AND  uid='".intval($uid)."' ";
	return $db->getall($sql);
}
function count_view_resume_times_today($uid,$talent){
	global $db;
	$starttime = strtotime(date("Y-m-d"));
	$sql = "select count(*) as num from ".table('view_resume')." where uid=".$uid." and talent=".$talent." and addtime>=".$starttime." and uid!=".$uid;
	return $db->get_total($sql);
}
?>