<?php
include_once('persinfo_class.php');
function lifevyn($vyn){
return $vyn*6;
}
function clean_var($var) { #в hidden или в input неважно (в люб html)
 $var=str_replace('&', "&#38", $var);
 $var=str_replace(array('"',"'","`","<",">",'\\'), array('&quot;',"&#x27;","&#x60;","&#60","&#62","&#92"), $var);
 return $var;
}
function checkuplevel($id_person){

#update person set stat_points=0, mast_points=0, osob_points=0, money=0, id_step=0, level=0;truncate table pers_har;

if (!$id_person) {die;}
$res=db_use('query',"SELECT et.id_step, p.id_step as p_id_step, et.level_points, et.money, et.stat_points, et.vyn_points from person p left join exptable et ON p.exp >= et.need_exp 
where et.id_step > p.id_step AND p.id_person = '".$id_person."' 
ORDER BY et.id_step ASC;");
if (!mysql_num_rows($res)) {return;}
$level_points=0;$stat_points=0;$vyn_points=0;$money_points=0;
$res1=db_use('object',"select level from person where id_person='".$id_person."';");
$level=$res1->level;
for ($i=0;$i<mysql_num_rows($res);$i++) {
	$s=mysql_fetch_array($res);
	$level_points=$level_points+$s['level_points'];
	#echo 'level='.$level.' levpointsnew='.$level_points.' curlevpoints='.$s['level_points'].' level+levpoin=<br>';
	if ($s['level_points']>0) {
		$res2=db_use('query',"select id_har,har,initvalue from har where type=1 and minlevel='".($level+$level_points)."';");
		unset($i2);while ($i2<mysql_num_rows($res2)) {
			$i2++;$s2=mysql_fetch_array($res2);
			db_use('query',"update person set ".$s2['har']."='".$s2['initvalue']."' where id_person='".$id_person."';");
		}
	}
	$stat_points=$stat_points+$s['stat_points'];
	$vyn_points=$vyn_points+$s['vyn_points'];
	$money_points=$money_points+$s['money'];
	$id_step=$s['id_step'];
	$p_id_step=$s['p_id_step'];
	#die;
}
#echo "level_points".$level_points."<br />";
#echo "level=".$level."<br />";
#echo "p_id_step=".$p_id_step."<br />";
#echo "id_step=".$id_step."<br />";
#if ($level<1) {$level=-1;$level_points--;}
if ($p_id_step!=$id_step) {
	#if (!$p_id_step){	$level_points=$level_points-1;}
	#echo "update";#die;
$resc=db_use('object',"select p.level,p.id_referrer,u.login from person p left join users u on u.id_person=p.id_person where p.id_person='".$id_person."';");
$levelcur=$resc->level;$id_refer=$resc->id_referrer;$login=$resc->login;
switch ($levelcur+$level_points) {
case 0: $kr=0;break;
case 1: $kr=1;break;
case 2: $kr=5;break;
case 3: $kr=10;break;
case 4: $kr=15;break;
case 5: $kr=25;break;
case 6: $kr=50;break;
case 7: $kr=100;break;
case 8: $kr=200;break;
case 9: $kr=500;break;
default: $kr=0;break;
}
if ($id_refer && $kr && false) {
	$resc=db_use('array',"select p.id_referrer,u.login,p.id_person,p.blocked,p.align from person p left join users u on u.id_person=p.id_person where p.id_person='".$id_refer."'");
	if ($resc['id_person'] && $resc['blocked']<1 && (int)$resc['align']!=2) {
	new_chat_message5($id_refer,"Персонаж ".$login." достиг ".($levelcur+$level_points)." уровня. Переведены ".$kr." кр (Реферральная программа)");
	new_chat_message5(12,"Персонаж ".$login." достиг ".($levelcur+$level_points)." уровня. Переведены ".$kr." кр персонажу ".$resc['login']." (Реферральная программа)");
	db_use('query',"update person set money=money+".$kr." where id_person='".$id_refer."'");
	db_use('query',"insert into pals_delo(id_person,id_paladin,level,align,message,type) values('".$id_refer."','".$id_person."','".($levelcur+$level_points)."','50','Получил ".$kr." за [".(($levelcur+$level_points))."] левел персонажа ".$login.". (реферральная программа)','5')");	
	}
}

	


	db_use('query',"UPDATE person SET id_step='".$id_step."', 
stat_points=stat_points+".$stat_points.", money=money+".$money_points.", 
mast_points=mast_points+".$level_points.", 
osob_points=osob_points+".$level_points.", level=level+'".($level_points)."' where id_person='".$id_person."';");
if ($money_points) {
	new_chat_message5($id_person,"Получено аповых кредов: ".$money_points."");
}
#echo "UPDATE person SET id_step='".$id_step."', stat_points=stat_points+".$stat_points.", money=money+".$money_points.", mast_points=mast_points+".$level_points.", osob_points=osob_points+".$level_points.", level=level+'".$level_points."' where id_person='".$id_person."';";
	if ($vyn_points) {
		db_use('query',"UPDATE person set vyn=vyn+".$vyn_points." where id_person='".$id_person."';");
	}
}
}

function showpers($myinfo,$n,$pic) {
   echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"font-family: Tahoma; font-size: 13px;\" align=\"center\">
        <tr>
            <td nowrap rowspan=2 align=center>".($pic==3?'<SCRIPT>errtrap(\''.$myinfo->name.'\');</SCRIPT><SCRIPT>drwfl("'.$myinfo->name.'",'.$myinfo->id_person.',"'.$myinfo->level.'","'.$myinfo->align.'","'.$myinfo->clanname.'")</SCRIPT>':"<SCRIPT>drwfl(\"".$myinfo->name."\",".$myinfo->id_person.",\"".$myinfo->level."\",'".$myinfo->align."',\"".$myinfo->clanname."\")</SCRIPT>")."&nbsp;<span id=\"HP\"></span>&nbsp;
			<br>
 <table cellpadding=0 cellspacing=0 border=0 align=center>
    <tr>
    <td>
    <table cellpadding=0 cellspacing=0 border=0>
    <tr><td style=\"background-image: url(/img/main/pers/shlem.jpg)\">";showpic1($myinfo,9,$pic);echo "</td></tr>
    <tr><td style=\"background-image: url(/img/main/pers/orugee.jpg)\">";showpic1($myinfo,3,$pic);echo "</td></tr>
    <tr><td style=\"background-image: url(/img/main/pers/bron.jpg)\">";if ($myinfo->puton[4]) {showpic1($myinfo,4,$pic);} else {showpic1($myinfo,40,$pic);}echo "</td></tr>
    <tr><td style=\"background-image: url(/img/main/pers/poyas.jpg)\">";showpic1($myinfo,5,$pic);echo "</td></tr>
    </table>
    </td>
    <td bgcolor=#000000 width=3 valign=bottom>
    <img src=\"../i/misc/bk_life_loose.gif\" alt=\"Уровень жизни\" name=\"HP2\" width=\"3\" height=\"60\" id=\"HP2\"><br>";
	echo"<img src=\"../i/misc/bk_life_loose.gif\" alt=\"Уровень жизни\" name=\"HP1\" width=\"3\" height=\"1\" id=\"HP1\"></td>
    <td width=104 style=\"background-image:url('img/main/pers/obraz_bg.jpg');\" valign=bottom>
    <table cellpadding=0 cellspacing=0 border=0 height=100%>
    <tr><td valign=top height=100%><br /><br />";
	#<a href=\"/main.php?skills=1&rand=".rand(1,500000)."\">
	echo ($n==1?"<a href=\"/main.php?skills=1&rand=".rand(1,500000)."\">":"").($n==2?"<a href=\"/main.php?skills=1&rand=".rand(1,500000)."\">":"")."<img width=104 height=225 ".($n==1?"onmouseout='hideshow();'  onmouseover='fastshow(\"".$myinfo->name." (Перейти в \\\"Инвентарь\\\")\");' width=\"120\" height=\"220\" border=\"0\" oncontextmenu=\"top.returned(); event.returnValue=false;\"":($n==2?"onmouseout='hideshow();'  onmouseover='fastshow(\"".$myinfo->name." (Перейти в \\\"Умения\\\")\");' width=\"120\" height=\"220\" border=\"0\" oncontextmenu=\"top.returned(); event.returnValue=false;\"":""))." src=\"../i/chars/".$myinfo->sex."/".$myinfo->shadow."\">".($n>0?"</a>":"")."</td></tr>
    <tr><td valign=bottom>
    <table cellpadding=0 cellspacing=1 border=0>
    <tr>
    <td style=\"background-image: url(/img/main/pers/elik.jpg)\"><img src=\"img/main/pers/elik.jpg\"></td>
    <td style=\"background-image: url(/img/main/pers/elik.jpg)\"><img src=\"img/main/pers/elik.jpg\"></td>
    <td style=\"background-image: url(/img/main/pers/elik.jpg)\"><img src=\"img/main/pers/elik.jpg\"></td>
    </tr>
    <tr>
    <td style=\"background-image: url(/img/main/pers/elik.jpg)\">";showpic1($myinfo,14,$pic);echo"</td>
    <td style=\"background-image: url(/img/main/pers/elik.jpg)\">";showpic1($myinfo,15,$pic);echo"</td>
    <td style=\"background-image: url(/img/main/pers/elik.jpg)\">";showpic1($myinfo,16,$pic);echo"</td>
    </tr>
    </table>
    </td></tr>
    </table>
    </td>
    <td bgcolor=#000000 width=3 valign=bottom>
    <img src=\"img/main/pers/mana_head.jpg\"><br>
    <img src=\"img/main/pers/mana.jpg\" width=3 height=230>
    </td>
    <td>    <table cellpadding=0 cellspacing=0 border=0>
    <tr><td style=\"background-image: url(/img/main/pers/sergi.jpg)\">";showpic1($myinfo,1,$pic);echo "</td></tr>
    <tr><td style=\"background-image: url(/img/main/pers/ogerelie.jpg)\">";
	showpic1($myinfo,2,1);
	echo "</td></tr>
    <tr><td style=\"background-image: url(/img/main/pers/perchi.jpg)\">";showpic1($myinfo,11,$pic);echo "</td></tr>
    <tr><td style=\"background-image: url(/img/main/pers/naruchi.jpg)\">";showpic1($myinfo,13,$pic);echo "</td></tr>
    <tr><td><table cellspacing=0 cellpadding=0 border=0><tr>
	<td style=\"background-image: url(/img/main/pers/ring1.jpg)\">";showpic1($myinfo,6,$pic);echo"</td>
	<td style=\"background-image: url(/img/main/pers/ring2.jpg)\">";showpic1($myinfo,7,$pic);echo"</td>
	<td style=\"background-image: url(/img/main/pers/ring3.jpg)\">";showpic1($myinfo,8,$pic);echo"</td>
	</tr></table></td></tr>
    <tr><td style=\"background-image: url(/img/main/pers/schit.jpg)\">";showpic1($myinfo,10,$pic);echo "</td></tr>
    <tr><td style=\"background-image:/img/main/pers/sapogi.jpg\">";showpic1($myinfo,12,$pic);echo "</td></tr>
    </table>
</td>
   	";
if ($pic==1) {
echo"<td rowspan=2>&nbsp;&nbsp;</td>
    <td width=20>    <table cellpadding=0 cellspacing=0 border=0>";
for ($i=100;$i<=111;$i++) {					
		echo "<tr><td style=\"background-image:".($i==100?'slot_first':($i==111?'slot_last':'slots')).".jpg\">";
		showpic1($myinfo,$i,$pic);
		echo "</td></tr>";
}unset($i);
	echo"
    </table>
	</td>";
}
	echo"</tr>
</table>
	</td></tr></table>
	<SCRIPT>top.setHP(".$myinfo->life.",".$myinfo->maxlife().",".$myinfo->regeneration.");</SCRIPT>";
}
function showroom($room,$city,$r_name,$left,$top,$width,$height,$zindex,$img,$perehod,$gl_r_name) {
$in_r=getinroom($room,$city); 
echo"<div style=\"position:absolute; left:".$left."px; top:".$top."px; width:".$width."px; height:".$height."px; z-index:".$zindex."; filter:progid:DXImageTransform.Microsoft.Alpha( Opacity=100, Style=0);\"><img src=\"".$img."\" width=\"".$width."\" height=\"".$height."\" ".($perehod?"alt=\"\" class=\"aFilter\" onmouseover=\"imover(this)\" onmouseout=\"imout(this); hideshow();\" onclick=\"solo('".$room."')\" onmousemove=\"fastshow2('<strong>".$r_name."</strong><br />Сейчас в комнате: ".$in_r."');\" />":"alt=\"Проход через ".$gl_r_name."\" class=\"aFilter\" onmouseover=\"imover(this)\" onmouseout=\"imout(this); hideshow();\" onclick=\"alert('Проход через ".$gl_r_name."')\"  />")."</div>";
}
?>