<?php
if(!$_SESSION['admin_id']){
	pe_goto("index.php");
}
$menumark = 'faq_list';
switch ($act) {
	//#####################@ 文章增加 @#####################//
	case 'add':
	    $faq_class = $db->pe_selectall('faqclass');
		$seo = pe_seo('发布文章', '', '', 'admin');
		$action = 'admin.php?mod=faq&act=addsql';
		include(pe_tpl('faq_add.html'));
	break;
	//#####################@ 文章增加sql @#####################//
	case 'addsql':
		$_p_info['faq_atime'] = $_p_info['faq_atime'] ? strtotime($_p_info['faq_atime']) : time();		
		if ($db->pe_insert('faq', pe_dbhold($_p_info, array('faq_text')))) {
			pe_success('文章发布成功!', 'admin.php?mod=faq&act=list');
		}
		else {
			pe_error('文章发布失败...');
		}
	break;
	//#####################@ 文章修改 @#####################//
	case 'edit':
		$info = $db->pe_select('faq', array('faq_id'=>$_g_id));
        $faq_class = $db->pe_selectall('faqclass');
		$seo = pe_seo('修改文章', '', '', 'admin');
		$action = "admin.php?mod=faq&act=editsql&id={$_g_id}";
		include(pe_tpl('faq_add.html'));
	break;
	//#####################@ 文章修改sql @#####################//
	case 'editsql':
		$_p_info['faq_atime'] = $_p_info['faq_atime'] ? strtotime($_p_info['faq_atime']) : time();
		if ($db->pe_update('faq', array('faq_id'=>$_g_id), pe_dbhold($_p_info, array('faq_text')))) {
			pe_success('文章修改成功!', 'admin.php?mod=faq&act=list');
		}
		else {
			pe_error('文章修改失败...');
		}
	break;
	//#####################@ 文章删除sql @#####################//
	case 'delsql':
		if ($db->pe_delete('faq', array('faq_id'=>is_array($_p_faq_id) ? $_p_faq_id : $_g_id))) {
			pe_success('文章删除成功!');
		}
		else {
			pe_error('文章删除失败...');
		}
	break;
	//#####################@ 文章置顶sql @#####################//
	case 'statesql':
		if ($db->pe_update('faq', array('faq_id'=>is_array($_p_faq_id) ? $_p_faq_id : $_g_id), array('faq_state'=>intval($_g_state)))) {
			pe_success('文章状态更改成功!');
		}
		else {
			pe_error('文章状态更改失败...');
		}
	break;
	//#####################@ 文章列表sql @#####################//
	default :
		$_g_keyword && $sqlwhere .= " and `faq_name` like '%{$_g_keyword}%'";
		$_g_category_id && $sqlwhere .= " and `category_id` = '{$_g_category_id}'";
		$sqlwhere .= " order by `faq_id` desc";
		$info_list = $db->pe_selectall('faq', $sqlwhere, '*', array(20, $_g_page));
        $faq_class = $db->pe_selectall('faqclass');
		$seo = pe_seo('文章列表', '', '', 'admin');
		include(pe_tpl('faq_list.html'));
	break;
}
pe_result();
?>