<?php
define('THIS_SCRIPT', 'challenge');
include_once 'global.php';
$lang = load_lang($lang, 'challenge' );
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
main_load();
footer();
function main_load(){
	global $dv,$db,$lang,$action,$forum_chansetting;
	switch($action){
		case "note":
			hand_note();
		break;
		case "rss":
			rss_operation();
		break;
	}
include printout('challenge');
}
function hand_note(){
	global $lang,$dv,$db,$forum_chansetting3,$forum_chansetting4,$forum_chansetting6;
	$forum_chansetting3=intval($_POST['forum_chansetting3']);
	$forum_chansetting4=str_replace(" ","",$_POST['forum_chansetting4']);
	$forum_chansetting6=str_replace(" ","",$_POST['forum_chansetting6']);
	$sql=$db->query("SELECT forum_chansetting FROM {$dv}setup");
	$arr=$db->fetch_array($sql);
	$f_setting=explode(",",$arr['forum_chansetting']);
	$num=count($f_setting);
	for($i=0;$i<$num;$i++){
		if($i==3){
			$f_set.=$forum_chansetting3.",";
		}elseif($i==4){
			$f_set.=$forum_chansetting4.",";
		}elseif($i==6){
			$f_set.=$forum_chansetting6.",";
		}else{
			$f_set.=$f_setting[$i].",";
		}
	}
	$f_set=substr($f_set,0,-1);
	$upsql=$db->query("UPDATE {$dv}setup set forum_chansetting='".$f_set."'");
	require_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createForumSetting();		
	if($upsql){
		show_msg($lang['sys.info'],$lang['chall.info24'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}else{
		show_msg($lang['sys.info'],$lang['chall.info25'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
$db->free_result($sql);
}
function rss_operation(){
	global $lang,$dv,$db,$forum_chansetting14,$forum_chansetting2;
	$forum_chansetting14=intval(str_replace(" ","",$_POST['forum_chansetting14']));
	$forum_chansetting2=$_POST['forum_chansetting2'];
	$sql=$db->query("SELECT forum_chansetting,forum_challengepassword FROM {$dv}setup");
	$arr=$db->fetch_array($sql);
	$rss_str=explode(",",$arr['forum_chansetting']);
	$num=count($rss_str);
	for($i=0;$i<$num;$i++){
		if($i==2){
			$f_str.=$forum_chansetting2.",";
		}elseif($i==14){
			$f_str.=$forum_chansetting14.",";
		}else{
			$f_str.=$rss_str[$i].",";
		}
	}
	$f_str=substr($f_str,0,-1);
	$upsql=$db->query("UPDATE {$dv}setup set forum_chansetting='".$f_str."'");
	require_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createForumSetting();		
	if($upsql){
		show_msg($lang['sys.info'],$lang['chall.info28'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}else{
		show_msg($lang['sys.info'],$lang['chall.info29'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
$db->free_result($sql);
}
?>