<?php
/*
	Dvbbs.php  - Version: 2.0.0
	Web: http://www.dvbbs.net
	Copyright: 2000-2006 Dvbbs.Net
	script file:forum_ads.php
	Script Written by Lao Mi
	Function of the Page:广告管理
	*/
define('THIS_SCRIPT', 'forum_ads');
require_once 'global.php';
checklogin();
if ( strpos($sysinfo['flag'],'2,') === false ){
	head();
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
$lang=load_lang($lang, THIS_SCRIPT );

if (defined('MAIN_DOMAIN_NAME')) {
	$tmp = explode(' | ', $lang['form_nav']);
	$lang['form_nav'] = $tmp[0];
	$tmp_arr = array(
		'ads_type' => $_POST['ads_type'],	//	广告方案名称
		'description' => $_POST['description'],	//	广告方案说明
		'ads_top' => $_POST['ads_top'],	//	顶部广告代码
	);
	unset($_POST);
	$_POST =& $tmp_arr;
}

header("content-Type: text/html; charset=".$charset);
switch ($_GET['action']) {
	case '':
	ads_list();
	break;
	case 'new':
		newads();
	break;
	case 'savenew':
	require_once 'inc/forum_ads.form.php';
	app_ads();
	break;
	case 'saveedit':
	require_once 'inc/forum_ads.form.php';
	save_edit();
	break;
	case 'edit':
	ads_edit();
	break;
	case 'del':
		if ($inuse!=1){
			$query=$db->query('select ads_id from '.$dv.'board where ads_id='.intval($_GET['id']));
			if ($db->num_rows($query) > 0) {
				$inuse=1;
			}
		}
		if ($inuse!=1){
			del_ads();
		}
		else{
			head();
			show_msg($lang['page_title'],$lang['del_err'],0,'','','forum_ads.php',$lang['cmdback']);
			footer();
		}
		break;
	default:
	ads_list();
}
function del_ads() {
	global $dv,$db,$lang,$id;
	$db->query("delete from {$dv}fsettings where id=". intval($_GET['id']));
	head();
	show_msg($lang['page_title'],$lang['del_suc'],1,'','','forum_ads.php',$lang['cmdback']);
	footer();
}
function save_edit(){
	global $db,$post,$dv, $lang;
	ckeck_post('javascript:history.go(-1)');
	$ads_type=$_POST['ads_type'];
	$description=$_POST['description'];
	$ads_float_linkurl = preg_match('/^http:\/\//', $_POST['ads_float_linkurl']) ? $_POST['ads_float_linkurl'] : 'http://'.$_POST['ads_float_linkurl'];
	$ads_picad_linkurl = preg_match('/^http:\/\//', $_POST['ads_picad_linkurl']) ? $_POST['ads_picad_linkurl'] : 'http://'.$_POST['ads_picad_linkurl'];
	$ads_con=split_replace($_POST['ads_top']).'<>'.split_replace($_POST['ads_bottom'])
	.'<>'.split_replace($_POST['ads_float_on'])
	.'<>'.split_replace($_POST['ads_float_picurl'])
	.'<>'.split_replace($ads_float_linkurl)
	.'<>'.split_replace($_POST['ads_float_picwidth'])
	.'<>'.split_replace($_POST['ads_float_picheight'])
	.'<>'.split_replace($_POST['ads_picad_on'])
	.'<>'.split_replace($_POST['ads_picad_picurl'])
	.'<>'.split_replace($ads_picad_linkurl)
	.'<>'.split_replace($_POST['ads_picad_picwidth'])
	.'<>'.split_replace($_POST['ads_picad_picheight'])
	.'<>'.split_replace($_POST['ads_post_on'])
	.'<>'.split_replace($_POST['ads_post'])
	.'<>'.split_replace($_POST['ads_text_on'])
	.'<>'.split_replace($_POST['ads_text_board'])
	.'<>'.split_replace($_POST['ads_text_seting'])
	.'<>'.split_replace($_POST['ads_text'])
	.'<>'.split_replace($_POST['ads_content_post_on'])
	.'<>'.split_replace($_POST['ads_content_post'])
	.'<>'.split_replace($_POST['scrollads_on'])
	.'<>'.split_replace($_POST['scrollads']);
	$ads_con=str_replace('<!--','',str_replace('//-->','',$ads_con));
	$db->query("update ".$dv."fsettings set type='$ads_type',description='$description',setting='$ads_con' where s_class=2 and id=". intval($_GET['id']));
	require_once(INC_PATH.'BoardCache.class.php');
	$ads_cache =& new BoardCache($db);
	$ads_cache->createAll();
	$ads_cache->createForumSetting();
	head();
		show_msg($lang['page_title'],$lang['save_suc'],1,'','','forum_ads.php');
	footer();
	}
function app_ads(){
	global $db,$post,$dv, $lang;
	ckeck_post('javascript:history.go(-1)');
	$ads_type=$_POST['ads_type'];
	$description=$_POST['description'];
	$ads_con=split_replace($_POST['ads_top'])
	.'<>'.split_replace($_POST['ads_bottom'])
	.'<>'.split_replace($_POST['ads_float_on'])
	.'<>'.split_replace($_POST['ads_float_picurl'])
	.'<>'.split_replace($_POST['ads_float_linkurl'])
	.'<>'.split_replace($_POST['ads_float_picwidth'])
	.'<>'.split_replace($_POST['ads_float_picheight'])
	.'<>'.split_replace($_POST['ads_picad_on'])
	.'<>'.split_replace($_POST['ads_picad_picurl'])
	.'<>'.split_replace($_POST['ads_picad_linkurl'])
	.'<>'.split_replace($_POST['ads_picad_picwidth'])
	.'<>'.split_replace($_POST['ads_picad_picheight'])
	.'<>'.split_replace($_POST['ads_post_on'])
	.'<>'.split_replace($_POST['ads_post'])
	.'<>'.split_replace($_POST['ads_text_on'])
	.'<>'.split_replace($_POST['ads_text_board'])
	.'<>'.split_replace($_POST['ads_text_seting'])
	.'<>'.split_replace($_POST['ads_text'])
	.'<>'.split_replace($_POST['ads_content_post_on'])
	.'<>'.split_replace($_POST['ads_content_post'])
	.'<>'.split_replace($_POST['scrollads_on'])
	.'<>'.split_replace($_POST['scrollads']);
	$ads_con=str_replace('<!--','',str_replace('//-->','',$ads_con));
	$c_orders=1;
	//查找最小的可用空编号$c_orders
	$query=$db->query('select c_orders from '.$dv.'fsettings where s_class=2 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('$ads_type','$description','$ads_con',$c_orders,2)");
	head();
		show_msg($lang['page_title'],$lang['new_suc'],1,'','','forum_ads.php');
	footer();
	}
function ads_edit(){
	global $lang,$db,$restriction,$dv;
	$action='?action=saveedit&amp;id='.stripslashes($_GET['id']);
	$form_tit1=$lang['page_tit_edit'];
	$query=$db->query("select c_orders,type,setting,description from ".$dv."fsettings where s_class=2 and id=". intval($_GET['id']));
	if ($db->num_rows($query) <= 0) {
		head();
		show_msg($lang['page_title'],$lang['edit_err1'],0,'','','forum_ads.php');
		footer();
		exit;
		}
	$ads=$db->fetch_array($query);
	$ads_type=htmlspecialchars($ads['type']);
	$description=htmlspecialchars($ads['description']);
	$ads_con=explode('<>',$ads['setting']);
	$ads_top=htmlspecialchars(unsplit_replace($ads_con[0]));
	$ads_bottom=htmlspecialchars(unsplit_replace($ads_con[1]));
	$ads_float_on=htmlspecialchars(unsplit_replace($ads_con[2]));
	$ads_float_picurl=htmlspecialchars(unsplit_replace($ads_con[3]));
	$ads_float_linkurl=htmlspecialchars(unsplit_replace($ads_con[4]));
	$ads_float_picwidth=htmlspecialchars(unsplit_replace($ads_con[5]));
	$ads_float_picheight=htmlspecialchars(unsplit_replace($ads_con[6]));
	$ads_picad_on=htmlspecialchars(unsplit_replace($ads_con[7]));
	$ads_picad_picurl=htmlspecialchars(unsplit_replace($ads_con[8]));
	$ads_picad_linkurl=htmlspecialchars(unsplit_replace($ads_con[9]));
	$ads_picad_picwidth=htmlspecialchars(unsplit_replace($ads_con[10]));
	$ads_picad_picheight=htmlspecialchars(unsplit_replace($ads_con[11]));
	$ads_post_on=htmlspecialchars(unsplit_replace($ads_con[12]));
	$ads_post=htmlspecialchars(unsplit_replace($ads_con[13]));
	$ads_text_on=htmlspecialchars(unsplit_replace($ads_con[14]));
	$ads_text_board=htmlspecialchars(unsplit_replace($ads_con[15]));
	$ads_text_seting=htmlspecialchars(unsplit_replace($ads_con[16]));
	$ads_text=htmlspecialchars(unsplit_replace($ads_con[17]));
	$ads_content_post_on=htmlspecialchars(unsplit_replace($ads_con[18]));
	$ads_content_post=htmlspecialchars(unsplit_replace($ads_con[19]));
	$scrollads_on=htmlspecialchars(unsplit_replace($ads_con[20]));
	$srollads_info=htmlspecialchars(unsplit_replace($ads_con[21]));
	$submit=$lang['submit'];
	require_once 'inc/forum_ads.form.php';
	head();
	readme($lang['page_title'],$lang['page_readme'],$lang['nav'].$lang['form_nav']);
	show_form($form);
	footer();
	}
function ads_list(){
	global $db,$dv, $lang;
	head();
	readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
	$query=$db->query("select id,c_orders,type from ".$dv."fsettings where s_class=2 order by id");
	require_once printout('forum_ads');
	footer();
	}
function newads(){
	global $lang,$restriction;
	$action='?action=savenew';
	$form_tit1=$lang['page_tit_new'];
	$ads_type=$lang['new_type'];
	$description=$lang['new_type'].'['.get_datetime().']';
	$ads_top=stripslashes (htmlspecialchars ('<iframe src="http://server.dvbbs.net/dvbbs/dvbbs_soft_top.html" height="60" width="468" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>'));
	$ads_bottom=stripslashes (htmlspecialchars ('<iframe src="http://server.dvbbs.net/dvbbs/dvbbs_soft_end.html" height="60" width="468" marginwidth="0" marginheight="0"  frameborder="0" scrolling="no"></iframe>'));
	$ads_float_on=0;
	$ads_float_picurl='';
	$ads_float_linkurl='';
	$ads_float_picwidth=80;
	$ads_float_picheight=33;
	$ads_picad_on=0;
	$ads_picad_picurl='';
	$ads_picad_linkurl='';
	$ads_picad_picwidth=80;
	$ads_picad_picheight=33;
	$ads_post_on=0;
	$ads_post='<a href="http://www.dvbbs.net/buy.asp" target="_blank">{$lang["tpl.str1"]}</a><a href="http://www.safe888.com/" target="_blank"><font color="red">{$lang["tpl.str2"]}</font></a><a href="http://www.aspsky.cn" target="_blank"><font color="blue">{$lang["tpl.str3"]}</font></a><a href="http://bbs.dvbbs.net/dispbbs.asp?boardID=8&ID=1105850&page=1" target="_blank"><b><font color="#941AE6">{$lang["tpl.str4"]}</font></b></a>';
	$ads_post=str_replace(array('{$lang["tpl.str1"]}', '{$lang["tpl.str2"]}', '{$lang["tpl.str3"]}', '{$lang["tpl.str4"]}'), array($lang["tpl.str"], $lang["tpl.str2"], $lang["tpl.str3"], $lang["tpl.str4"]), $ads_post);
	$ads_post=stripslashes (htmlspecialchars ($ads_post));
	$ads_text_on=0;
	$ads_text_board=0;
	$ads_text_seting=4;
	$ads_text='<a href="http://www.dvbbs.net/buy.asp" target="_blank">{$lang["tpl.str1"]}</a><a href="http://www.safe888.com/" target="_blank"><font color="red">{$lang["tpl.str2"]}</font></a><a href="http://www.aspsky.cn" target="_blank"><font color="blue">{$lang["tpl.str3"]}</font></a><a href="http://www.linkidc.com" target="_blank"><font color="#941AE6">{$lang["tpl.str5"]}</font></a>';
	$ads_text=str_replace(array('{$lang["tpl.str1"]}', '{$lang["tpl.str2"]}', '{$lang["tpl.str3"]}', '{$lang["tpl.str5"]}'), array($lang["tpl.str1"], $lang["tpl.str2"], $lang["tpl.str3"], $lang["tpl.str5"]), $ads_text);
	$ads_text=stripslashes (htmlspecialchars ($ads_text));

	$ads_content_post_on=0;
	$ads_content_post='<a href="http://www.dvbbs.net/buy.asp" target="_blank">{$lang["tpl.str1"]}</a><a href="http://www.safe888.com/" target="_blank"><font color="red">{$lang["tpl.str2"]}</font></a><a href="http://www.aspsky.cn" target="_blank"><font color="blue">{$lang["tpl.str3"]}</font></a><a href="http://bbs.dvbbs.net/dispbbs.asp?boardID=8&ID=1105850&page=1" target="_blank"><b><font color="#941AE6">{$lang["tpl.str4"]}</font></b></a>';
	$ads_content_post=str_replace(array('{$lang["tpl.str1"]}', '{$lang["tpl.str2"]}', '{$lang["tpl.str3"]}', '{$lang["tpl.str4"]}'), array($lang["tpl.str"], $lang["tpl.str2"], $lang["tpl.str3"], $lang["tpl.str4"]), $ads_content_post);
	$ads_content_post=stripslashes (htmlspecialchars ($ads_content_post));

	$scrollads_on='0';

	$srollads_info='<a href="http://www.dvbbs.net/buy.asp" target="_blank">{$lang["tpl.str1"]}</a><a href="http://www.safe888.com/" target="_blank"><font color="red">{$lang["tpl.str2"]}</font></a><a href="http://www.aspsky.cn" target="_blank"><font color="blue">{$lang["tpl.str3"]}</font></a><a href="http://bbs.dvbbs.net/dispbbs.asp?boardID=8&ID=1105850&page=1" target="_blank"><b><font color="#941AE6">{$lang["tpl.str4"]}</font></b></a>';
	$srollads_info=str_replace(array('{$lang["tpl.str1"]}', '{$lang["tpl.str2"]}', '{$lang["tpl.str3"]}', '{$lang["tpl.str4"]}'), array($lang["tpl.str"], $lang["tpl.str2"], $lang["tpl.str3"], $lang["tpl.str4"]), $srollads_info);
	$srollads_info=stripslashes (htmlspecialchars ($srollads_info));

	$submit=$lang['submit'];
	require_once 'inc/forum_ads.form.php';
	head();
	readme($lang['page_title'],$lang['page_readme'],$lang['nav'].$lang['form_nav']);
	show_form($form);
	footer();
}
?>