<?php
/*
	Dvbbs.php  - Version: 2.0.0
	Web: http://www.dvbbs.net
	Copyright: 2000-2006 Dvbbs.Net
	script file:board_setting.php
	Script Written by Lao Mi
	Function of the Page:论坛设置管理
	*/
define('THIS_SCRIPT', 'board_setting');
include_once 'global.php';
$lang = load_lang($lang, THIS_SCRIPT);
checklogin();
header("content-Type: text/html; charset=".$charset);
if ( strpos($sysinfo['flag'],'37,') === false ){
	head();
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
switch ($_GET['action']) {
	case 'new':
	head();
	new_setting();
	footer();
	break;
	case 'edit':
	edit_setting();
	break;
	case 'saveedit':
	require_once 'inc/board_setting.form.php';
		save_edit();
	break;
	default:
	case 'savenew':
	require_once 'inc/board_setting.form.php';
		save_new();
	break;
	case 'del':
	$query=$db->query('select setting_id from '.$dv.'board where setting_id='. intval($_GET['id']));
	if ($db->num_rows($query) <= 0) {
	$db->query("delete from ".$dv."fsettings  where s_class=1 and  c_orders=". intval($_GET['id']));
	head();
		show_msg($lang['page_title'],$lang['del_suc'],1,'','','board_setting.php');
	footer();
}else{
	head();
	show_msg($lang['page_title'],$lang['edit_err2'],0,'','','board_setting.php');
	footer();
}
	break;
	default:
	head();
	readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
	setting_list();
	footer();
}
function save_edit(){
	global $db,$post,$dv, $lang;
	ckeck_post('javascript:history.go(-1)');
	$type=$_POST['type'];
	$description=$_POST['description'];
	$setting='';
	for($i=0 ;$i< 103 ;$i++){;
        if($i==46&&$_POST['setting('.$i.')']==2)$_POST['setting('.$i.')']=intval($_POST['boardsetting46']);
		$setting.=split_replace($_POST['setting('.$i.')']).'<>';
	}
	$db->query("update ".$dv."fsettings set type='$type',setting='$setting',description='$description' where s_class=1 and  c_orders=". intval($_GET['id']));
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createAll();
	head();
		show_msg($lang['page_title'],$lang['save_suc'],1,'','','board_setting.php');
	footer();
	}
function save_new(){
	global $db,$post,$dv, $lang;
	ckeck_post('javascript:history.go(-1)');
	$type=$_POST['type'];
	$description=$_POST['description'];
	$setting='';
	for($i=0 ;$i< 102 ;$i++){
		 if($i==46&&$_POST['setting('.$i.')']==2)$_POST['setting('.$i.')']=intval($_POST['boardsetting46']);
		$setting.=split_replace($_POST['setting('.$i.')']).'<>';
	}
	$c_orders=1;
	//查找最小的可用编号$c_orders
	$query=$db->query('select c_orders from '.$dv.'fsettings where s_class=1 order by c_orders');
	while($c_order = $db->fetch_array($query)){
		if ($c_order['c_orders']==$c_orders){
			$c_orders++;
			}else{
			break;
			}
		}
	$db->query("Insert Into ".$dv."fsettings(type,description,setting,c_orders,s_class)values('$type','$description','$setting',$c_orders,1)");
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createAll();
	head();
		show_msg($lang['page_title'],$lang['new_suc'],1,'','','board_setting.php');
	footer();
	}
function setting_list(){
	global $db,$lang,$dv;
	$query=$db->query('select c_orders,type,description from '.$dv.'fsettings where s_class=1 order by c_orders');
	require_once printout('board_setting_list');
	}
function edit_setting(){
	global $lang,$restriction,$db,$dv;
	$nav='';
	for($i=1 ;$i< 5 ;$i++){
		$nav.=' <a href="#setting'.$i.'">'.$lang['page_a_'.$i].'</a> |';
	}
	$nav.=' <a href="#setting5">'.$lang['page_a_5'].'</a>';
	$nav.='<br />';
		for($i=6 ;$i< 9 ;$i++){
		$nav.=' <a href="#setting'.$i.'">'.$lang['page_a_'.$i].'</a> |';
	}
	$nav.=' <a href="#setting9">'.$lang['page_a_9'].'</a>';
	$submit=$lang['submit'];
	$form_tit1=$lang['page_tit_edit'];
	$query=$db->query("select c_orders,type,description,setting from ".$dv."fsettings where s_class=1 and  c_orders=". intval($_GET['id']));
	if ($db->num_rows($query) <= 0) {
		head();
		show_msg($lang['page_title'],$lang['edit_err1'],0,'','','board_setting.php');
		footer();
		exit;
		}
	head();
	readme($lang['page_title'],$lang['page_readme1'].$lang['nav2'].$nav,$lang['nav1']);
	$settings=$db->fetch_array($query);
	$description=htmlspecialchars($settings['description']);
	$type=htmlspecialchars($settings['type']);
	$action='?action=saveedit&amp;id='.stripslashes($_GET['id']);
	$setting=explode('<>',$settings['setting']);
	for($i=0 ;$i< 100 ;$i++){
		$setting[i]=htmlspecialchars(unsplit_replace($setting[i]));
	}
	require_once 'inc/board_setting.form.php';
	show_form($form);
	footer();
}
function new_setting(){
	global $lang,$restriction;
	$nav='';
	for($i=1 ;$i< 5 ;$i++){
		$nav.=' <a href="#setting'.$i.'">'.$lang['page_a_'.$i].'</a> |';
	}
	$nav.=' <a href="#setting5">'.$lang['page_a_5'].'</a>';
	$nav.='<br />';
		for($i=6 ;$i< 9 ;$i++){
		$nav.=' <a href="#setting'.$i.'">'.$lang['page_a_'.$i].'</a> |';
	}
	$nav.=' <a href="#setting9">'.$lang['page_a_9'].'</a>';
	readme($lang['page_title'],$lang['page_readme1'].$lang['nav2'].$nav,$lang['nav1']);
	$submit=$lang['submit'];
	$description='';
	$s_type=$lang['new_s_type'];
	$action='?action=savenew';
	$form_tit1=$lang['page_tit_new'];
	$setting=array('','','0','0','0','0','1','1','1','1'
	,'1','1','1','1','1','1','1','1','1','1'
	,'1','1','1','1','1','1','1','1','1','1'
	,'0','0','0','0','0','0','0','0','0','0'
	,'0','0','0','0','0','0','0','200','2','16384'
	,'1','gif|jpg|jpeg|bmp|png|rar|txt|zip|mid','1','10','10','0','0','0','0','300'
	,'20','10','1','0','','1','1','1','1','0'
	,'0','0','0','0','0','0','0','0','0','0'
	,'9','12','24','0','0','0','0','0','0','0'
	,'0','0','0','0','0','0','0','0','0','0'
	,'0','0','0','0','0','0','0','0','0','0'
	);
	require_once 'inc/board_setting.form.php';
	show_form($form);
}
?>