<?php
/**
* FILE_NAME : job.php
*
* @copyright Copyright (c) 2009 - 2010 www.dali.edu.cn
* @author DaLi University 2009 Graduation Design
* @package 招聘管理
* @subpackage
* @version Tue Oct 27 11:45:50 GMT 2009
*/

define('IN_WEB', TRUE);
	
require_once( str_replace('\\', '/', dirname(__FILE__)). '/include/global.php');

/* act操作项的初始化 */
if (empty($_REQUEST['act'])) {
    $_REQUEST['act'] = 'show';
} else {
    $_REQUEST['act'] = trim($_REQUEST['act']);
}

/*------------------------------------------------------ */
//-- 招聘列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'show')
{
	$sql = $query = $joblist = '';
	
	$sql = "SELECT * FROM {$dbprefix}job ORDER BY postdate DESC";
	$query = $DB->query($sql);
	while ($row = $DB->fetch_array($query)) {
		/*--  格式化时间  --*/
		$row['postdate'] = formatdate($_CFG['format_type'],$row['postdate']);
		/*--  招聘状态  --*/
		$row['jobstate'] = $row['jobstate'] ? "招聘中" : "已结束";
		$joblist[] = $row;
	}
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->assign("joblist", $joblist);
	
	$smarty->display("job.html");
}

/*------------------------------------------------------ */
//-- 增加招聘
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'add')
{
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->display("job_add.html");
}

/*------------------------------------------------------ */
//-- 增加招聘成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'addok')
{
	$job = $_REQUEST['job'];
	$sql = $query = '';
	
	/*--  插入信息  --*/
	$sql = "INSERT INTO {$dbprefix}job (id,jobtitle,count,academic,experience,address,jobstate,postdate,content) VALUE ('','".$job['jobtitle']."','".$job['count']."','".$job['academic']."','".$job['experience']."','".$job['address']."','".$job['jobstate']."','".$timestamp."','".$job['content']."')";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("招聘信息添加成功","job.php?act=show");
	} else {
		showmsg("招聘信息添加失败");
	}
}

/*------------------------------------------------------ */
//-- 编辑招聘信息
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'edit')
{
	$id = $_REQUEST['id'];
	
	$sql = $query = $row = '';
	$list = array();
	
	/*--  查询信息  --*/
	$sql = "SELECT * FROM {$dbprefix}job WHERE id = $id";
	$query = $DB->query($sql);
	$list = $DB->fetch_array($query);
	
	$smarty->assign("css_root", $css_root);
	$smarty->assign("web_url", $web_url);
	
	$smarty->assign("job_id",$list['id']);
	$smarty->assign("jobtitle",$list['jobtitle']);
	$smarty->assign("jobcount",$list['count']);
	$smarty->assign("jobacademic",$list['academic']);
	$smarty->assign("jobexperience",$list['experience']);
	$smarty->assign("jobaddress",$list['address']);
	$smarty->assign("jobstate",$list['jobstate']);
	$smarty->assign("jobcontent",$list['content']);
	
	$smarty->display("job_edit.html");
}

/*------------------------------------------------------ */
//-- 编辑招聘成功
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'editok')
{
	$job = $_REQUEST['job'];
	$sql = $query = '';
	
	/*--  修改信息  --*/
	$sql = "UPDATE {$dbprefix}job SET jobtitle = '".$job['jobtitle']."', count = '".$job['count']."',academic = '".$job['academic']."',experience = '".$job['experience']."',address = '".$job['address']."',jobstate = '".$job['jobstate']."',content = '".$job['content']."' WHERE id = '".$job['id']."'";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("招聘信息修改成功","job.php?act=show");
	} else {
		showmsg("招聘信息修改失败","job.php?act=show");
	}
}

/*------------------------------------------------------ */
//-- 删除招聘
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'remove')
{
	$id = $_REQUEST['id'];
	$sql = $query = '';
	
	/*--  删除信息  --*/
	$sql = "DELETE FROM {$dbprefix}job WHERE id = $id";
	$query = $DB->query($sql);
	
	if ($query) {
		showmsg("招聘信息删除成功","job.php?act=show");
	} else {
		showmsg("招聘信息删除失败","job.php?act=show");
	}
}
?>