Location: PHPKode > scripts > Some Chess > some-chess/admin.php
<?php 
//		Some Chess, a PHP multi-player chess server.
//		Copyright (C) 2006 Jon Link
function adminPanel($VSid,$VSname,$showBackup,$showUpdate,$adminStr){ 
	$panel = '
		<div id="adminpanel">
		<h2>'.$adminStr[0].'</h2>
		<div class="admin" style="height:50px;">		
			<h3>Some Chess Options</h3>
			<a href="menu.php?do=options" class="butt">'.$adminStr[16].'</a>
		</div>		
		<form action="menu.php" method="post" class="admin" style="height:75px;">
		<h3>'.$adminStr[1].'</h3>
			<p><select name="killing" class="input">
				<option></option>';
			$numVS = count($VSid);
			for($i=0;$i<$numVS;++$i){
				$key	= $VSid[$i];
				$panel .= '<option value="'.$key.'|'.(str_replace(' ','_',$VSname[$key])).'">'.$VSname[$key].'</option>';
			}
	$panel.='
		</select></p>
			<input type="hidden" name="do" value="killPlayer" />
		<input type="submit" value="'.$adminStr[9].'" class="butt" />
		</form>
		<form action="menu.php" method="post" class="admin" style="height:100px;">
		<h3>'.$adminStr[2].'</h3>
			<p><select name="player" class="input">
				<option></option>';
			$numVS = count($VSid);
			for($i=0;$i<$numVS;++$i){
				$key	= $VSid[$i];
				$panel .= '<option value="'.$key.'|'.(str_replace(' ','_',$VSname[$key])).'">'.$VSname[$key].'</option>';
			}
	$panel.='
		</select></p>
			<p><select name="newPower" class="input">
				<option></option>
				<option value="0">Low</option>
				<option value="1">Basic</option>
				<option value="2">High</option>
				<option value="4">Admin</option>
			</select></p>
			<input type="hidden" name="do" value="chgPower" />
		<input type="submit" value="'.$adminStr[10].'" class="butt" />
		</form>';
	if($showBackup)$panel.='
		<form action="menu.php" method="post" class="admin" style="height:50px;">		
			<h3>'.$adminStr[15].'</h3>
			<input type="hidden" name="do" value="backup" />
			<input type="submit" value="'.$adminStr[11].'" class="butt" />
		</form>';
	if($showUpdate)$panel.='
		<form action="menu.php" method="post" class="admin" style="height:50px;">		
			<h3>'.$adminStr[8].'</h3>
			<input type="hidden" name="do" value="verCheck" />
			<input type="submit" value="'.$adminStr[11].'" class="butt" />
		</form>';
	$panel.='</div>';
	if($_SESSION['power']>3) return $panel;
}
function updateOptions($adminStr){
	$optQuery	= 'SELECT * FROM options WHERE id>0 ORDER BY id';
	$optResult 	= mysql_query($optQuery)or die('<div class="error">'.errorDBStr.' options</div>');
	$optCount	= mysql_num_rows($optResult);
	$data		= '<?php '."\r\n";	
	for($p=0;$p<$optCount;++$p){	
		$data	.= '$'.mysql_result($optResult,$p,'varName')."		= '".$_POST[mysql_result($optResult,$p,'optionName')]."'; \r\n";
		$query	= 'UPDATE options SET optionValue="'.$_POST[mysql_result($optResult,$p,'optionName')].'" WHERE id="'.($p+1).'"';
		mysql_query($query)or die('<div class="error">'.errorDBStr.' options (up3)</div>');
	}
	$data .= '@mysql_connect($host,$dbUser,$dbPass);'." \r\n".
'@mysql_select_db($database); '."\r\n".
'?>';
	$file = 'config.php';
	$done	= @file_put_contents($file,$data);
	if($done){
		echo '<div class="message">'.$adminStr[17].'</div>';
	}else{
		echo '<div class="error">'.$adminStr[18].'</div>';
	}
}
function killPlayer($killID,$adminStr){
	$queryKill 	= 'DELETE FROM players WHERE id="'.$killID.'"';
	mysql_query($queryKill) or die('<div class="error">'.errorDBStr.'player</div>');
	$queryKillGames	= 'DELETE FROM games WHERE (winner="0" OR winner="X") AND (whitePlayerID="'.$killID.'" OR blackPlayerID="'.$killID.'")';
	mysql_query($queryKillGames) or die('<div class="error">'.errorDBStr.'games</div>');
	return '<div class="message">'.$adminStr[3].'</div>';
}
function chgPower($playerID,$newPower,$adminStr){
	if(!$playerID || !isset($newPower)) return '<div class="error">'.$adminStr[4].'</div>';
	$queryPower = 'UPDATE players SET power="'.$newPower.'" WHERE id="'.$playerID.'"';
	mysql_query($queryPower) or die('<div class=error>'.errorDBStr.'player</div>');
	return '<div class="message">'.$adminStr[5].'</div>';
}
function versionCheck($adminStr){
	$contents	= file_get_contents('http://astrodogpress.org/chess/version.rss');
	$newVer		= preg_replace('/[\W\S\.]*<description>/','',$contents);
	$newVer		= preg_replace('/<\/description>[\W\S\.]*/','',$newVer);	
	if(ver2num(shortVer) < ver2num($newVer)){
		return '<div class="message">'.$adminStr[12].': <a href="http://astrodogpress.com/chess/" target="_NEW">'.$newVer.' ('.$adminStr[13].')</a></div>';
	}else{
		return'<div class="message">'.$adminStr[14].': '.shortVer.'</div>';
	}
}
function ver2num($ver){
	if(strpos($ver,'a')){
		$ver	= preg_replace('/[a-z]*/','',$ver);
		$ver	= $ver+10;
	}elseif(strpos($ver,'b')){
		$ver	= preg_replace('/[a-z]*/','',$ver);
		$ver	= $ver+20;	
	}elseif(strpos($ver,'rc')){
		$ver	= preg_replace('/[a-z]*/','',$ver);
		$ver 	= $ver+30;	
	}else{
		$ver	= $ver+40;	
	}
	$nums 		= explode('.',$ver);
	$ver		= $nums[0] + $nums[1];
	return $ver;
}
?>
Return current item: Some Chess