<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?
include_once("req.php");
error_reporting(E_ALL ^ E_NOTICE);
array_walk($_REQUEST,"format_string");   
array_walk($_POST,"format_string");   
array_walk($_GET,"format_string");   
include_once("session_class.php");
include_once("persinfo_class.php");
include_once("edit_skills.php"); #skills_side1

# 5603.log
# id_event type/phrase,type/phrase
function logprint1($id_bat) {

$battle=db_use('array',"select * from battle where id_battle='".$id_bat."'");

$ended=($battle['complete']==2?TRUE:FALSE);$timeout=($battle['timeout_win']?TRUE:FALSE);$winner=$battle['team_winner'];
$st_time=$battle['start_time'];$endtime=$battle['end_time'];
$res=db_use('query',"select bl.* from battle_log bl where (bl.type_event=44 or bl.type_event=32 or bl.type_event=1) and bl.id_battle='".$id_bat."'");
$start_text='s,{часы}{бросили вызов}';
unset($i);while ($i<mysql_num_rows($res)) { 
		$i++;$s=mysql_fetch_array($res);
		if ($s['type_event']==44) {$start_text=str_replace('{часы}','{datetime},44-1 ',$start_text);}
		if ($s['type_event']==32) {$start_text=str_replace('{бросили вызов}','32-2',$start_text);}
}
$start_text=str_replace('{datetime}',$st_time,$start_text);
# инфа о игроках
$res=db_use('query',"
(select u.login,bu.userlevel,bu.starthp,bu.team,u.id_person,p.sex from battle_units bu left join users u on u.id_person=bu.id_person left join person p on p.id_person=u.id_person where bu.id_battle='".$id_bat."' and bu.id_person<100000) 
union 
(select b.name as login,bu.userlevel,bu.starthp,bu.team,b.id_maskperson as id_person,p.sex from battle_units bu 
left join bots b on b.id_bot=bu.id_person left join person p on p.id_person=b.id_maskperson where bu.id_battle='".$id_bat."' and bu.id_person>100000)");
unset($i);while ($i<mysql_num_rows($res)) { 
	$i++;$s=mysql_fetch_array($res);
	echo 'u,'.$s['team'].','.$s['login'].','.$s['userlevel'].','.$s['id_person'].','.$s['starthp'].','.$s['sex'].'<br />';
}
echo $start_text."<BR>";

$steps=db_use('query',"SELECT distinct bs.*,be.timestamp
FROM `battle_event` be left join battle_step bs on bs.id_battle=be.id_battle and bs.id_bstep=be.id_bstep
WHERE be.id_battle='".$id_bat."'
ORDER BY be.timestamp ".$asc.", be.id_event ".$asc."");
unset($i);while ($i<mysql_num_rows($steps)) {  # шаги в порядке результа
	$i++;$s=mysql_fetch_array($steps);
	unset($block1,$block2);$block1=array();$block2=array();
	$events=db_use('query',"select * from battle_event where event_logtype>0 and id_battle='".$id_bat."' and id_bstep='".$s['id_bstep']."' order by id_event ".$asc."");
	unset($ie);while ($ie<mysql_num_rows($events)) { 
		$ie++;$e=mysql_fetch_array($events);
		if ($e['type1']==1 && $e['type2']<1) {$block1[]=$e['block'];}
		if ($e['type1']==2 && $e['type2']<1) {$block2[]=$e['block'];}
	}	

	$events=db_use('query',"select * from battle_event where event_logtype>0 and id_battle='".$id_bat."' and id_bstep='".$s['id_bstep']."' order by id_event ".$asc."");
	unset($ie);while ($ie<mysql_num_rows($events)) { 
		$ie++;$e=mysql_fetch_array($events);
		$type=$e['event_logtype'];$id_ev=$e['id_event'];
		$r1=db_use('array',"SELECT bs.id_person1,bs.id_person2,bu.team as team1 FROM battle_event be 			
		left join battle_step bs on be.id_bstep=bs.id_bstep and be.id_battle=bs.id_battle 
		left join battle_units bu on bu.id_person=bs.id_person1 and be.id_battle=bs.id_battle 
		WHERE be.id_battle='".$id_bat."' and be.id_event='".$e['id_event']."';"); 
		if ($e['type1']==1) { # 1->2
			if (in_array('1',$block2)) {$bl='12';}
			if (in_array('2',$block2)) {$bl='23';}
			if (in_array('3',$block2)) {$bl='34';}
			if (in_array('4',$block2)) {$bl='45';}
			if (in_array('5',$block2)) {$bl='51';}
			if ($e['udar']==1) {
				if (in_array('1',$block2)) {$bl='12';}
				if (in_array('5',$block2)) {$bl='51';}
			}elseif ($e['udar']==2) {
				if (in_array('1',$block2)) {$bl='12';}
				if (in_array('2',$block2)) {$bl='23';}
			}elseif ($e['udar']==3) {
				if (in_array('2',$block2)) {$bl='23';}
				if (in_array('3',$block2)) {$bl='34';}
			}elseif ($e['udar']==4) {
				if (in_array('3',$block2)) {$bl='34';}
				if (in_array('4',$block2)) {$bl='45';}
			}elseif ($e['udar']==5) {
				if (in_array('4',$block2)) {$bl='45';}
				if (in_array('5',$block2)) {$bl='51';}
			}
		}else{
			if (in_array('1',$block1)) {$bl='12';}
			if (in_array('2',$block1)) {$bl='23';}
			if (in_array('3',$block1)) {$bl='34';}
			if (in_array('4',$block1)) {$bl='45';}
			if (in_array('5',$block1)) {$bl='51';}
			if ($e['udar']==1) {
				if (in_array('1',$block1)) {$bl='12';}
				if (in_array('5',$block1)) {$bl='51';}
			}elseif ($e['udar']==2) {
				if (in_array('1',$block1)) {$bl='12';}
				if (in_array('2',$block1)) {$bl='23';}
			}elseif ($e['udar']==3) {
				if (in_array('2',$block1)) {$bl='23';}
				if (in_array('3',$block1)) {$bl='34';}
			}elseif ($e['udar']==4) {
				if (in_array('3',$block1)) {$bl='34';}
				if (in_array('4',$block1)) {$bl='45';}
			}elseif ($e['udar']==5) {
				if (in_array('4',$block1)) {$bl='45';}
				if (in_array('5',$block1)) {$bl='51';}
			}
		}
		$team1=($r1['team1']);
		$team2=($r1['team1']==1?2:1);
		$ktoteam=($e['type1']==1?$team1:$team2);
		$kogoteam=($e['type1']==2?$team1:$team2);
			$kto=($e['type1']==1?$uname1:$uname2);
			$kogo=($e['type1']==2?$uname1:$uname2);
		echo 'l,'.$e['timestamp'].",".$s['id_bstep'].','.$id_ev.",".$ktoteam.",".$r1['id_person1'].','.$r1['id_person2'].",".$e['udar'].",".$bl.",".(0+$e['id']).','.(0+$e['damage']).','.(0+$e['hpold']).',';
		$r2=db_use('query',"select bl.id_phrase,bl.type_event from battle_log bl where bl.id_battle='".$id_bat."' and bl.id_event='".$id_ev."'");
	$tmp='';$j=0;
		while ($j<mysql_num_rows($r2)) { 
			$j++;$o=mysql_fetch_array($r2);
			echo ($o['type_event']?$o['type_event']:$o['type_phrase']).'-'.$o['id_phrase'].' ';
		}
		echo "<br />";
	}	#while event
}# while bstep

if ($asc=='desc') {echo '<hr>';echo $start_text."<BR>";} else {
	if ($ended) {
		echo 'e,'.$endtime.",".($timeout?'1':'0').','.($winner);
	}
}
}
function logfilewrite($text) {






return $text;

}
/*
$res=db_use('query',"
select bu.id_person,bu.exp,p.exp as myexp from battle_units bu left join person p on p.id_person=bu.id_person
where bu.id_battle >50000 
and bu.exp>0 and bu.id_person in 
(select id_person from stat_cheaters) order by bu.exp desc limit 22
");
unset($i);while ($i<mysql_num_rows($res)) {
	$i++;$s=mysql_fetch_array($res);echo $i.'/'.mysql_num_rows($res).':'.$s['id_person'].'<br />';
	db_use('query',"update person set level=-1,mudr=0,intel=0,duh=0,vol=0,boj=0, id_step=-1, level=-1,sil=3,lov=3,vyn=2,intu=3,stat_points=0,mast_points=0,osob_points=0, masw1=0,masw2=0,masw3=0,masw4=0,masw5=0,m_magic1=0,m_magic2=0,m_magic3=0,m_magic4=0,m_magic5=0,m_magic6=0,m_magic7=0 where id_person='".$s['id_person']."';");
 echo "update person set level=-1,mudr=0,intel=0,duh=0,vol=0,boj=0, id_step=-1, level=-1,sil=3,lov=3,vyn=2,intu=3,stat_points=0,mast_points=0,osob_points=0, masw1=0,masw2=0,masw3=0,masw4=0,masw5=0,m_magic1=0,m_magic2=0,m_magic3=0,m_magic4=0,m_magic5=0,m_magic6=0,m_magic7=0 where id_person='".$s['id_person']."';';<br />";
}
*/

$myid=58;
if ($_REQUEST['setokalhim'] && $myid==12) {
	db_use('query',"update alhim set ok=1 where id_alh='".$_REQUEST['a']."' and timest='".$_REQUEST['t']."' and id_person='".$_REQUEST['p']."' and CONCAT(kr)='".$_REQUEST['k']."'");

}
if($_REQUEST['alhim']){
	$res=db_use('array',"select u.login,p.id_person from person p left join users u on u.id_person=p.id_person where p.id_person='".$_REQUEST['id']."' and p.blocked=0");
	if (!$res['id_person']) { echo "Персонаж не найден или заблочен";}else{
		echo "Персонажу ".$res['login'].' передано/отнято кредов: '.$_REQUEST['kr'];
		db_use('query',"update person set money=money+'".$_REQUEST['kr']."' where id_person='".$_REQUEST['id']."';");
	db_use('query',"insert into chat (timestamp,id_room,nick,text,color,type) values(".time().",'0','".$_REQUEST['id']."','Переведены ".$_REQUEST['kr']." кр от Администрации','Black','5')");
	db_use('query',"insert into chat (timestamp,id_room,nick,text,color,type) values(".time().",'0','".$myid."','Переведены ".$_REQUEST['kr']." кр персонажу id=".$_REQUEST['id']."','Black','5')");
		db_use('query',"insert into alhim (id_alh,id_person,kr) values ('".$myid."','".$_REQUEST['id']."','".$_REQUEST['kr']."')");
	}
}
echo "<br /><br />";
$res=db_use('query',"select * from alhim order by timest desc limit 100");
$i=0;
unset($i);while ($i<mysql_num_rows($res)) { 
	$i++;$s=mysql_fetch_array($res);if ($s['ok']<1 && $s['id_alh']==$myid) {$bal=$bal+$s['kr'];}
	echo ($s['ok']?'<b>':'<font color=red>')."<small>".$s['timest'].",".$s['id_alh'].": ".$s['id_person']." * ".$s['kr']."</small>".($s['ok']?'</b>':($myid==12?'<a href=pal.php?setokalhim=1&t='.str_replace(' ','%20',$s['timest']).'&a='.$s['id_alh'].'&p='.$s['id_person'].'&k='.$s['kr'].'>+</a>':'').'</font>').'<br />';
}
echo "Мой баланс (должен мироздателю): ".($bal/500 * 0.90 ).' WMZ<br />';
echo "<br /><br />";
$res=db_use('query',"select * from alhim2 order by timest desc limit 100");
$i=0;$bal=0;
unset($i);while ($i<mysql_num_rows($res)) { 
	$i++;$s=mysql_fetch_array($res);$bal=$bal+$s['wmz'];
	echo "<small>".$s['timest'].",".$s['id_alh'].": "." ".$s['wmz']."</small>".'<br />';
}
?>
<form method="post" action=pal.php> 
Кому (id персонажа)<input type=text name=id><br />
Сколько кр (- значит отнять)<input type=text name=kr><br />
<input type=submit name=alhim value="Дать/отнять кредов"/>
</form>
<?

/*$text=logprint1(5043);
echo nl2br($text);

$res=db_use('query',"SELECT id_person from person where id_person>=2000");
unset($i);while ($i<mysql_num_rows($res)) {  # шаги в порядке результа
	$i++;$s=mysql_fetch_array($res);echo $i.'/'.mysql_num_rows($res).':'.$s['id_person'];
	$res2=db_use('query',"SELECT har,id_har from har where (id_har>=1 and id_har<=10) or (id_har>=19 and id_har<=30) or (id_har>=31 and id_har<=40)");
	unset($j);while ($j<mysql_num_rows($res2)) {  # шаги в порядке результа
		$j++;$s2=mysql_fetch_array($res2);
		echo ' '.$s2['har'];
		$res3=db_use('array',"SELECT value from pers_har where id_har='".$s2['id_har']."' and id_person='".$s['id_person']."'");
		echo '='.$res3['value'];
		if ($res3['value']>0) {
		db_use('query',"update person set ".$s2['har']."='".(0+$res3['value'])."' where id_person='".$s['id_person']."'");
		}
	}echo "<br />";
	#db_use('query',"ALTER TABLE `person` ADD `".$s['har']."` SMALLINT( 6 ) UNSIGNED;");
}
*/

/*
echo logfilewrite($text);
$res=db_use('query',"SELECT har from har where (id_har>=1 and id_har<=10) or (id_har>=19 and id_har<=30) or (id_har>=31 and id_har<=40)");
unset($i);while ($i<mysql_num_rows($res)) {  # шаги в порядке результа
	$i++;$s=mysql_fetch_array($res);
	#db_use('query',"ALTER TABLE `person` ADD `".$s['har']."` SMALLINT( 6 ) UNSIGNED;");
}
*/

/*
$res=db_use('query',"SELECT bu1.id_person,u.login,p.money, sum(bu1.exp) as sum1
FROM battle_units bu1
LEFT JOIN battle b ON b.id_battle = bu1.id_battle
LEFT JOIN battle_units bu ON bu.id_battle = b.id_battle
LEFT JOIN person p ON p.id_person = bu.id_person
left join users u on u.id_person=bu1.id_person
WHERE bu1.exp >50
AND b.owner_id = bu1.id_person
AND p.level =1
group by bu1.id_person");
echo ':'.mysql_num_rows($res);
unset($i);while ($i<mysql_num_rows($res)) {  # шаги в порядке результа
	$i++;$s=mysql_fetch_array($res);
	#echo "[".$s['id_person'];
		#db_use('query',"delete from pers_har where id_person='".$s['id_person']."';");
		#db_use('query',"update person set exp=exp-'".$s['sum1']."',id_step=0, level=-1, money=0, stat_points=0, mast_points=0, osob_points=0 where id_person='".$s['id_person']."';");
		#$inf=new persinfo($s['id_person']);
		#db_use('query',"update person set money=".$s['money']." where id_person='".$s['id_person']."';");
		echo $s['login'].'-'.$s['sum1'].'<br />';
}
*/
?>
</body>
</html>
