<?php
define('THIS_SCRIPT', 'bank_news');
require_once 'global.php';
require_once('./bank_inc.php');
$lang = load_lang($lang, 'bank_news' );

if ($action == 'showone'){
	$istoptable = 0;
}
if ($boardid == 0){
	$arrNavMenu = array(
			0=>array('linktitle'=>$lang['strings1'])
	);
	$stats = $lang['strings1'];
	$istoptable = 0;
	head(1,0,0,$arrNavMenu);
}else{
	$stats = $boardinfo['boardtype'].' - '.$lang['strings1'];
	$gettitle = $lang['strings1'];
	$istoptable = 0;
	head();
}

$canpostann = $caneditann = $canmodifyusername = false;
if (($master == true || $superboardmaster == true || ($boardmaster == true && $boardid != 0)) && $groupsetting[25] == 1){
	$canpostann = true;
}
if ($founduserper == true && $groupsetting[25] == 1){
	$canpostann = true;
}elseif($founduserper == true && $groupsetting[25] == 0){
	$canpostann = false;
}
if (($master || $superboardmaster || $boardmaster) && $groupsetting[26] == 1){
	$caneditann = true;
}
if ($founduserper == true && $groupsetting[26] == 1){
	$caneditann = true;
}elseif($founduserper == true && $groupsetting[26] == 0){
	$caneditann = false;
}

switch($action){
	case 'addann':
		require_once printout('bank_news');
		break;
	case 'saveann':
		saveann();
		break;
	default:
		pagemain();
		break;
}

function pagemain(){
	global $dv,$db,$boardid,$action,$canpostann,$caneditann,$lang;
	if ($action == 'showone'){
		$showid = $GLOBALS['id'];
		if ($showid == '' || !is_numeric($showid)){
			$query=$db->query("select title,content,username,addtime,bgs from {$dv}bbsnews where boardid='$boardid' order by id desc Limit 1");
		}else{
			$query=$db->query("select title,content,username,addtime,bgs from {$dv}bbsnews where boardid='$boardid' And id='$showid'");
		}
	}else{
		$query=$db->query("select title,content,username,addtime,bgs from {$dv}bbsnews where boardid='$boardid' order by id desc");
	}
	include INC_PATH.'dv_code.php';
	require_once printout('bank_news');
}

function saveann(){
	global $dv,$db,$boardid,$action,$canpostann,$caneditann,$username,$title,$content,$bgs,$boardinfo,$lang,$idv_trasvar,$userinfo;
	$stmt = "SELECT money FROM {$dv}bankstatus WHERE userid=".$userinfo['userid']." and bankstatus=1 limit 1";
	if( $query = $db->query($stmt) ){
		$row = $db->fetch_array($query);
		$money = floatval($row['money']);
		
	}		
	//当前金币是否够发送公告
	$money < $idv_trasvar['news1money'] AND showmsg($lang['tpl.str44']) AND exit;
	if ($username == '' || $title == '' || $content == ''){
		showmsg($lang['strings4']);
	}


	$db->query("insert into {$dv}bbsnews (username,title,content,bgs,boardid,addtime) values ('$username','$title','$content','$bgs','$boardid','".TIME_NOW."')");
	if ($boardid == 0){
		$db->query("Insert Into {$dv}log (l_announceid,l_boardid,l_touser,l_username,l_content,l_ip,l_type,l_addtime) values (0,'$boardid','".$lang['tpl.str39']."','$GLOBALS[membername]','".$lang['tpl.str40']."','$GLOBALS[usertrueip]',3,'".TIME_NOW."')");
	}else{
		$db->query("insert into {$dv}log (l_announceid,l_boardid,l_touser,l_username,l_content,l_ip,l_type,l_addtime) values (0,'$boardid','".$lang['tpl.str39']."','$GLOBALS[membername]','".$lang['tpl.str41']." $boardinfo[boardtype]".$lang['tpl.str39']."','$GLOBALS[usertrueip]',3,'".TIME_NOW."')");
	}
	
	$db->query("update {$dv}bankstatus set  money=money-".$idv_trasvar['news1money']." WHERE userid=".$userinfo['userid']."");
	$db->query("insert into {$dv}banklog set userid=".$userinfo['userid'].",username='".$userinfo['username']."',acttime=now(),action='".$lang['tpl.str2']."'");
	require_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createforumlink();
	$mycache->createAll();
	showmsg($lang['strings5']);
}

//footer();
?>