<?php
defined('IN_HS') or exit('Access Denied');


$submenu = array
(
	array("<input class=btn type=button value=' 添加FAQ ' onclick=window.location='?mod=$mod&file=$file&action=add'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class=btn type=button value=' 帐号问题FAQ ' onclick=window.location='?mod=$mod&file=$file&action=manage&type=1'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class=btn type=button value=' 充值问题FAQ ' onclick=window.location='?mod=$mod&file=$file&action=manage&type=2'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class=btn type=button value=' 游戏问题FAQ ' onclick=window.location='?mod=$mod&file=$file&action=manage&type=3'>","#"),
);
$menu = adminmenu('客服FAQ管理', $submenu);

$action = $action ? $action : 'manage';

switch($action)
{

	case 'add':

    if($dosubmit)
    {
     if(!$type) showmessage('请选择FAQ类型');
     if(!$qfaq) showmessage('请填写FAQ标题');
     if(!$afaq) showmessage('请填写FAQ内容');
		 $check = $db->get_one("SELECT id FROM ".TABLE_FAQ." WHERE qfaq='$qfaq'");
		 if ($check) showmessage("已经有同名FAQ标题存在，请重新填写！");
		
		 
		 $db->query("INSERT INTO ".TABLE_FAQ." (`type`,`qfaq`,`afaq`,`hits`) VALUES ('$type','$qfaq','$afaq',0)");
		 showmessage('操作成功','?mod='.$mod.'&file='.$file.'&action=manage');
    }
    
    include admintpl('faq_add');
		break;

	case 'edit':
		$id = intval($id);
		if ($dosubmit)
		{
		 if(!$id) showmessage('非法操作');
     if(!$type) showmessage('请选择FAQ类型');
     if(!$qfaq) showmessage('请填写FAQ标题');
     if(!$afaq) showmessage('请填写FAQ内容');
		 if($qfaq != $oqfaq)
		 {
		 $check = $db->get_one("SELECT id FROM ".TABLE_FAQ." WHERE qfaq='$qfaq'");
		 if ($check) showmessage("已经有同名FAQ标题存在，请重新填写！");
		 }
		 $db->query("UPDATE ".TABLE_FAQ." SET `type`='$type',`qfaq`='$qfaq',`afaq`='$afaq' WHERE id='$id'");
		 showmessage('修改成功','?mod='.$mod.'&file='.$file.'&action=manage');
		}else{
		$result = $db->get_one("SELECT * FROM ".TABLE_FAQ." WHERE id=$id");
		@extract($result);

		}

	  include admintpl('faq_edit');
		break;
		

  case 'delete':
		 $id=intval($id);
		 if(!$id) showmessage('非法操作');
		 $db->query("DELETE FROM ".TABLE_FAQ." WHERE id='$id'");
		 cache_gamelist();
		 showmessage('操作成功！','?mod='.$mod.'&file='.$file.'');
		 break;

	case 'manage':

    if($type) $w="WHERE type=$type";
		$faqs = array();
		$result = $db->query("SELECT id,type,qfaq,hits FROM ".TABLE_FAQ." $w ORDER BY id");
		while($r = $db->fetch_array($result))
		{
			$faqs[] = $r;
		}
		
		include admintpl('faq');
		break;
}

?>