<?php
if(!$_SESSION['admin_id']){
	pe_goto("index.php");
}
$menumark = 'notice_list';
switch ($act) {
	//#####################@ 公告增加 @#####################//
	case 'add':
		$cache_noticeclass = cache::get('noticeclass');
		
		$seo = pe_seo('发布公告', '', '', 'admin');
		$action = 'admin.php?mod=notice&act=addsql';
		include(pe_tpl('notice_add.html'));
	break;
	//#####################@ 公告增加sql @#####################//
	case 'addsql':
		$_p_info['notice_atime'] = $_p_info['notice_atime'] ? strtotime($_p_info['notice_atime']) : time();		
		if ($db->pe_insert('notice', pe_dbhold($_p_info, array('notice_text')))) {
			pe_success('公告发布成功!', 'admin.php?mod=notice&act=list');
		}
		else {
			pe_error('公告发布失败...');
		}
	break;
	//#####################@ 公告修改 @#####################//
	case 'edit':
		$cache_noticeclass = cache::get('noticeclass');
		$info = $db->pe_select('notice', array('notice_id'=>$_g_id));

		$seo = pe_seo('修改公告', '', '', 'admin');
		$action = "admin.php?mod=notice&act=editsql&id={$_g_id}";
		include(pe_tpl('notice_add.html'));
	break;
	//#####################@ 公告修改sql @#####################//
	case 'editsql':
		$_p_info['notice_atime'] = $_p_info['notice_atime'] ? strtotime($_p_info['notice_atime']) : time();
		if ($db->pe_update('notice', array('notice_id'=>$_g_id), pe_dbhold($_p_info, array('notice_text')))) {
			pe_success('公告修改成功!', 'admin.php?mod=notice&act=list');
		}
		else {
			pe_error('公告修改失败...');
		}
	break;
	//#####################@ 公告删除sql @#####################//
	case 'delsql':
		if ($db->pe_delete('notice', array('notice_id'=>is_array($_p_notice_id) ? $_p_notice_id : $_g_id))) {
			pe_success('公告删除成功!');
		}
		else {
			pe_error('公告删除失败...');
		}
	break;
	//#####################@ 公告置顶sql @#####################//
	case 'statesql':
		if ($db->pe_update('notice', array('notice_id'=>is_array($_p_notice_id) ? $_p_notice_id : $_g_id), array('notice_state'=>intval($_g_state)))) {
			pe_success('公告状态更改成功!');
		}
		else {
			pe_error('公告状态更改失败...');
		}
	break;
	//#####################@ 公告列表sql @#####################//
	default :
		$cache_noticeclass = cache::get('noticeclass');

		$_g_keyword && $sqlwhere .= " and `notice_name` like '%{$_g_keyword}%'";
		$_g_noticeclass_id && $sqlwhere .= " and `noticeclass_id` = '{$_g_noticeclass_id}'";
		$sqlwhere .= " order by `notice_id` desc";
		$info_list = $db->pe_selectall('notice', $sqlwhere, '*', array(20, $_g_page));

		$seo = pe_seo('公告列表', '', '', 'admin');
		include(pe_tpl('notice_list.html'));
	break;
}
pe_result();
?>