<?php
define('CURSCRIPT','faq');

require(dirname(__FILE__)."/global.php");
require(MYMPS_INC."/db.class.php");

if($admin_cityid) write_msg('您没有权限访问该页！');
!chk_adm_purview("purview_网站帮助")&& write_msg("很抱歉，您所在会员组没有当前菜单的操作权限！");

if($mymps_global['cfg_faqid']){
	$catid = $mymps_global['cfg_faqid'];
	/*$faqtotal=mymps_count("news","WHERE catid = '$catid'");
	if(empty($faqtotal)){
		$faq=$db->query("SELECT * FROM `{$db_mymps}faq` ORDER BY id DESC");
		while($r=$db->fetchRow($faq)){
			$hit = rand(100,200);
			$db->query("INSERT INTO `{$db_mymps}news` (`imgpath`,`cityid`,`title`,`content`,`catid`,`begintime`,`iscommend`,`hit`,`perhit`,`author`,`source`)VALUES('','1','$r[title]','$r[content]','$catid','$timestamp','1','$hit','1','','$mymps_global[SiteName]')");
		}
	}*/
}else{
	$catid = $db->getOne("SELECT catid FROM `{$db_mymps}channel` WHERE catname like '%帮助%'");
	if($catid){
		$db->query("INSERT INTO `my_config` (`description`,`value`,`type`)VALUES('cfg_faqid','$catid','config')");
	}else{
		$db->query("INSERT INTO {$db_mymps}channel (catname,if_view,title,keywords,description,parentid,catorder,dir_type) VALUES ('使用帮助','2','{city}使用帮助','{city}使用帮助','{city}使用帮助','0','0','bangzhu')");
		$catid = $db -> insert_id();
		$faq=$db->query("SELECT * FROM `{$db_mymps}faq` ORDER BY id DESC");
		while($r=$db->fetchRow($faq)){
			$p=mymps_count("news","WHERE title = '$r[title]'");
			if(empty($p)){
				$hit = rand(100,200);
				$db->query("INSERT INTO `{$db_mymps}news` (`imgpath`,`cityid`,`title`,`content`,`catid`,`begintime`,`iscommend`,`hit`,`perhit`,`author`,`source`)VALUES('','1','$r[title]','$r[content]','$catid','$timestamp','1','$hit','1','','$mymps_global[SiteName]')");
			}
		}
	}
}
if($catid){
	write_msg("","news.php?catid=$catid&cityid=$cityid");
}else{
	write_msg('请先在新闻栏目里添加 <b>使用帮助</b> 栏目','channel.php?part=add');
}

is_object($db) && $db->Close();
$db = $mymps_global = $part = $action = $here = NULL;
?>