<?php
define('THIS_SCRIPT', 'upgrade_query_js.php');
include_once 'global.php';
include_once 'inc/httpdown.class.php';
define('UPGRADECONFIGPATH', CACHE_PATH.'upgrade.config.php');
if(is_readable(UPGRADECONFIGPATH))include(UPGRADECONFIGPATH);
$lang = load_lang($lang,'upgrade_query_js');
checklogin();
if ( strpos($sysinfo['flag'],',49') === false ){
	exit('');
}
PageLoad();
function Pageload(){
	global $db,$lang,$dv,$foruminfo;
	$bbsinfo=$foruminfo;
	if($bbsinfo['autoupgrade']==0)return true;
	$UPGRADE_SERVER=$bbsinfo["upgradeserver"];
	$UPGRADE_SERVER=str_replace("\\","/",$bbsinfo["upgradeserver"]);
	@substr($UPGRADE_SERVER,strlen($UPGRADE_SERVER)-1,1)!="/" AND $UPGRADE_SERVER.="/";
	if($bbsinfo['autoupgrade']!=1||($bbsinfo["last_query"]>0&&($bbsinfo["last_query"]+$bbsinfo["query_interval"])>time()))exit;
	$db->query("update `{$dv}sysupgrade` set last_query=".time());
	$lm=$bbsinfo["lastupdate"];
	if(empty($lm))$lm=$db->scalar("SELECT MAX(lastupdate) as lastupdate FROM `{$dv}sysfiles`");
	if(empty($lm))$lm=0;
	$updatestate=htmlentities (getfileurl($UPGRADE_SERVER."query.php?s={$bbsinfo["script"]}&v={$bbsinfo["version"]}&d={$bbsinfo["database"]}&c={$bbsinfo["charset"]}&e={$bbsinfo["encode"]}&l={$lm}",6));
	if($updatestate>0)include printout('upgrade_query_js');
}
?>

