<?php

include('inc/daten.inc.php');

include ("inc/mail_class.php");
function error($text)
{
	echo "<div class=\"msg_error\" align=\"left\" id=\"msg\">".$text."</div>";
}
function succes($text)
{
	echo "<div class=\"msg_succes\" align=\"left\" id=\"msg\">".$text."</div>";	
}

function login()
{
	if(isset($_POST['submit']))
	{
		$username = replace($_POST['username']);
		$password = replace($_POST['password']);
		$sql = "SELECT * FROM account.account where login = '".$username."' AND password = PASSWORD('".$password."')";
		$res = mysql_query($sql);
		$row = mysql_fetch_assoc($res);
		//var_dump(mysql_num_rows($res));
		//var_dump($row);
		if ($row['status'] != 'BLOCK')
		{
			if(mysql_num_rows($res) > 0)
			{
				$_SESSION['user'] = $username;
				$_SESSION['pass'] = $password;
				$_SESSION['userid']= $row['id'];
				$_SESSION['admin'] = $row['web_admin'];
				//echo "<div class=\"msg_succes\" align=\"center\" style=\"width:150px;\">Logare reusita.</div>";
				header('Location: index.php');
			}
			else {
					echo "<div align='center'><font color='red'>Logare eronata.</font></div>";
					echo '<meta http-equiv="refresh" content="1;url=index.php">';
			}
		} else {
			echo "<div align='center'><font color='red'>Contul tau este banat.</font></div>";
			echo '<meta http-equiv="refresh" content="1;url=index.php">';
		}
		
	}
}
function loadcontent()
{
	if(isset($_GET['page']))
	{
		$page = replace($_GET['page']);

			include("module/".$page.".php");
	
		if(!file_exists("module/".$page.".php"))
		{
			$error=1;
			echo error("Modul inexistent sau indisponibil momentan.Va rugam reveniti!");

		}
	}
	else
	{
		if(isset($page) == NULL)
		{
			$page = 'acasa';
			include("module/".$page.".php");
		}
	}
}
function acc($usern,$opt)
{		
		$co = mysql_query("Select * from account.account where login='".$usern."'");
		$c = mysql_fetch_object($co);
		echo $c->$opt;

}
function count_ch($usern)
{
	$cc = mysql_query("Select * from account.account where login='".$usern."'");
	$cs = mysql_fetch_object($cc);
	$my = mysql_query("Select * from player.player where account_id='".$cs->account_id."'") or die(mysql_error());
	$crs = mysql_num_rows($my);
	echo $crs;
}
function clasa_c($clasa)
{
	if($clasa == "0" or $clasa == "4")
		{
            echo "Razboinic";
		}
		
		elseif($clasa == "1" or $clasa == "5")
		{
            echo "Ninja";
       }

		elseif($clasa == "2" or $clasa == "6")
		{
             echo "Sura";
       }
		
		elseif($clasa == "3" or $clasa == "7")
		{
       		echo "Saman";
       	}	
}
/*/
function align($alignment)
{
	if($alignment == "2000")
		{
            echo "Reborn 0";
		}
		
		elseif($alignment == "4000")
		{
            echo "Reborn I";
       }

		elseif($alignment == "8000")
		{
             echo "Reborn II";
       }
		
		elseif($alignment == "12000")
		{
       		echo "PVP";
       	}	
}
/*/
function align($alignment)
{	
if($alignment >= '20000')
	{		
	$grad =  "<font color='#01D758'><b>Reborn 0</b></font>";	
	}	
if($alignment >= '40000')
	{		
	$grad = "<font color='#DF73FF'><b>Reborn I</b></font>";	
	}
if($alignment >= '100000')
	{		
	$grad = "<font color='#884DA7'><b>Reborn II</b></font>";	
	}
if($alignment >= '120000')
	{		
	$grad = "<font color='#26C4EC'><b>PVP</b></font>";	
	}
	return $grad;
}

function nume_regat($empire)
{	
if($empire == '1')
	{		
	$regat =  "<img src=\"resurse/imagini/regate/1.png\" width=\"34\" alt=\"regat\" title=\"regat\">";	
	}	
	if($empire == '2')
	{		
	$regat = "<img src=\"resurse/imagini/regate/2.png\" width=\"34\" alt=\"regat\" title=\"regat\">";	
	}
	if($empire == '3')
	{		
	$regat = "<img src=\"resurse/imagini/regate/3.png\" width=\"34\" alt=\"regat\" title=\"regat\">";	
	}	
	return $regat;
}

function recuperare_pw()
{

		if(isset($_POST['recuperare']))
		{
			$username = replace($_POST['username']);
			$email = replace($_POST['email']);
			if($username !=NULL && $email!=NULL)
			{
				if (md5($_POST['norobot']) == $_SESSION['randomnr2']) 
				{
				include("configurare.php");
				$ch = mysql_query("Select * from account.account where login='$username' and email='$email'");
					if(mysql_num_rows($ch) == 1)
					{		$rec = md5(rand(99999,9999999));
							mysql_query("Update account.account set passlost_token='$rec' where login='$username'");
							$to      = $email;
							$subject = 'Confirmare email!';
							$message = "
							
			Salut ".$username. "\r\n" ."
			Ai cerut resetarea parolei dar inainte de asta trebuie sa confirmi emailul.Click pe linkul de mai jos : ". "\r\n" ."
			http://metin2alaska.ro/index.php?page=recuperare-pw&cont=".$username."&cod=".$rec."
							";
							$headers = 'Acest mesaj a fost generat automat.Va rugam nu raspundeti.';
		
							new mail($to, $subject, $message, $headers);
							echo succes("Un email de confirmare a fost trimis.Urmeaza instructiunile primite.");
					} else { echo error("Contul sau email nu se potrivesc.");} 
				} else { echo error("SPAM!Introduceti corect codul din imagine."); }
			}
		}
}
function schimbare_pw()
{
	
	if(isset($_POST['passwordchangerequest']))
	{
		$log = $_SESSION['user'];
		include("configurare.php");
		$tr = mysql_fetch_object(mysql_query("Select * from account.account where login='$log'"));
		$cod = md5(rand(999,999999));
		mysql_query("Update account.account set passchange_token='$cod' where login='$log'");
		echo succes("Un email a fost trimis la ".$tr->email."");	
		$email = $tr->email;
		$to      = $email;
		$subject = 'Confirmare schimbare parola!';
		$message = "Pentru a confirma ca sunteti de acord cu schimbarea parolei accesati linkul de mai jos ". "\r\n" ."http://metin2alaska.ro/index.php?page=schimbare-pw&cod=".$cod."";
		new mail($to, $subject, $message);
	}
}
function schimbare_pw_confirmata()
{
	
	if(isset($_POST['SubmitLostPasswordCodeForm']))
	{
		$cont = $_SESSION['user'];
		$newpw = replace($_POST['newPassword']);
		if($newpw !=NULL)
		{
			mysql_query("Update account.account set password=PASSWORD('$newpw') where login='$cont'");
			mysql_query("Update account.account set passchange_token='1' where login='$cont'");
			$data = date("h:i:s d/m/Y");
			mysql_query("Insert into web.dev_player_log (account,data,actiune) values ('$cont','$data','Parola a fost schimbata in $newpw.')");
			echo succes("Parola a fost modificata cu succes.");
		} else { echo error("Introdu noua parola!"); }
	} else { }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function parola_depozit()
{
	
	if(isset($_POST['sendStoragePassword']))
	{
		$log = $_SESSION['user'];
		$s = mysql_fetch_object(mysql_query("Select id,email from account.account where login='$log'")) or die(mysql_error());
		$id = $s->id;
		$email = $s->email;
		$com = mysql_query("Select * from player.safebox where account_id='$id'");
		$dep = mysql_fetch_array($com);
		if($dep['password']==NULL)
		{
			$password = "000000";
		}
		else
		{
			$password = $dep['password'];
		}
		$to      = $email;
		$subject = 'Parola depozit!';
		$message = "Ati cerut parola dumneavoastra de la depozit.Aceasta este : ".$password."";
		new mail($to, $subject, $message);
		$data = date("h:i:s d/m/Y");
			mysql_query("Insert into web.dev_player_log (account,data,actiune) values ('$cont','$data','Recuperare parola depozit.')");
		echo succes("Parola a fost trimisa la ".$email.".");
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function cod_securitate()
{
	
	if(isset($_POST['sendSocialcodeDisplayLink']))
	{
	include("configurare.php");
		echo succes("Vei primi in cel mai scurt timp un email continand codul de stergere.");
		$log = $_SESSION['user'];
		$xx = mysql_fetch_object(mysql_query("Select * from account.account where login='$log'")) or die(mysql_error());
		$cod = $xx->social_id;
		$email = $xx->email;
		$to      = $email;
		$subject = 'Cod siguranta [stergere caractere]!';
		$message = "Salut ".$log."!". "\r\n" ."
		Pentru o siguranta mai mare, &Icirc;nainte de stergerea caracterului, este nevoie de introducerea unui cod special.". "\r\n" ."
		Codul tau este : ".$cod."". "\r\n" ."

		Memoreaza-l sau noteaza-l!". "\r\n" ."


		Toate cele bune". "\r\n" ."
		".$titlu.".";
		new mail($to, $subject, $message);
		$data = date("h:i:s d/m/Y");
			mysql_query("Insert into web.dev_player_log (account,data,actiune) values ('$cont','$data','Recuperare cod securitate.')");
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function sterge_cont()
{
	if(isset($_POST['accountdeletion_submit']))
	{
			echo succes("Vei primi in cel mai scurt timp un email.Urmeaza instructiunile cu atentie.");
			$log = $_SESSION['user'];
			$aa = mysql_fetch_object(mysql_query("Select * from account.account where login='$log'")) or die(mysql_error());
			$email = $aa->email;
			$cod = md5(rand(999,99999));
			$bb = mysql_query("Update account.account set stergere_account='$cod' where login='$log'");
			$to      = $email;
			include("configurare.php");
			$subject = 'Confirmare stergere account!';
			$message = "Salut ".$log."!". "\r\n" ."
			Ati solicitat stergerea contului dumneavoastra.Va rugam sa confirmati asta apasand pe linkul de mai jos.". "\r\n" ."
			http://metin2alaska.ro/index.php?page=stergere-cont&cont=".$log."&cod=".$cod."". "\r\n" ."
			Puteti anula stergerea contului in decurs de 7 zile din panou dumneavoastra de control!". "\r\n" ."


			Toate cele bune". "\r\n" ."
			".$titlu."";
			new mail($to, $subject, $message);
			
	}
}
function stergere_cont_final()
{
	if($_GET['cont']!=NULL && $_GET['cod']!=NULL)
	{
		$cod = replace($_GET['cod']);
		$log = $_SESSION['user'];
		$query = mysql_query("Select * from account.account where stergere_account='$cod' and login='$log'");
		if(mysql_num_rows($query)==1)
		{	
			$nextWeek = time() + (7 * 24 * 60 * 60);
			$delete = date("d/m/Y", $nextWeek);
			mysql_query("Update account.account set status='BLOCK', stergere_account='$delete' where login='$log'");
			echo succes("Contul tau va fi sters in 7 zile.");
			echo '<meta http-equiv="refresh" content="0;url=index.php?page=stergere-cont">';
		}
		else
		{
			echo error("ERROR");
			echo '<meta http-equiv="refresh" content="0;url=index.php?page=stergere-cont">';
		}
	}
}
function stergere_cont_cancel()
{
	if(isset($_POST['accountdeletion_cancel']))
	{
		$log = $_SESSION['user'];
		mysql_query("Update account.account set status='OK', stergere_account='' where login='$log'");
		echo succes("Ati anulat cu succes stergerea contului.");
		echo '<meta http-equiv="refresh" content="1;url=index.php?page=panou-user">';
	}
}
function debug()
{
if(isset($_GET['page']) && isset($_GET['debug']))
{
	$char = replace($_GET['debug']);
	$const = mysql_fetch_object(mysql_query("Select * from player.player where id='$char'"));
	$chek = mysql_fetch_object(mysql_query("Select * from account.account where id='".$const->account_id."'"));
	$aid = $chek->id;
	if(isset($_GET['debug'])) {
		
		  $sqlCmd = "SELECT * FROM player.player WHERE id='".$char."' AND account_id ='".$aid."'";
		  $sqlQry = mysql_query($sqlCmd);
		  if(mysql_num_rows($sqlQry)>0) 
		  {
			$resetPos = array();
 			$resetPos[1]['map_index']=1; // Rosu
  			$resetPos[1]['x']=468779;
  			$resetPos[1]['y']=962107;
  			$resetPos[2]['map_index']=21; // Galben
  			$resetPos[2]['x']=55700;
  			$resetPos[2]['y']=157900;
  			$resetPos[3]['map_index']=41; // Blue
  			$resetPos[3]['x']=969066;
  			$resetPos[3]['y']=278290;

			$getChar = mysql_fetch_object($sqlQry);
			$pid = $getChar->id;
			$query2 = mysql_query("SELECT * FROM player.player_index WHERE pid1='$pid' or pid2='$pid' or pid3='$pid' or pid4='$pid'") or die('ERROR');
$row2 = mysql_fetch_array($query2);
$empire = $row2['empire'];
			$lp = strtotime($getChar->timeStamp);
			$difSpielzeit = time()-$lp;
			$toGoTime = (5*60)-($difSpielzeit);
			$toGoMin = floor(($toGoTime)/60);
			$toGoSek = ($toGoTime)%60;	
			
			  $sqlUpdate = "UPDATE player.player SET map_index='".$resetPos['$empire']['map_index']."', x='".$resetPos[$empire]['x']."', y='".$resetPos[$empire]['y']."', 	exit_x='".$resetPos[$empire]['x']."', exit_y='".$resetPos[$empire]['y']."', exit_map_index='".$resetPos[$empire]['map_index']."', horse_riding='0' WHERE id='".$char."' LIMIT 1";
			  $updatePos = mysql_query($sqlUpdate) or die(mysql_error());
				  if($updatePos)
				   {
					echo succes("Caracterul a fost debugat cu succes");
					}
					 else 
					 { 
						echo error("O eroare a aparut in procesul de debugare.Incercati din nou.");
					 }
			  
	
			
		  }
		  else {
			echo'<p class="meldung">'._debug_error1_.'</p>';
		  }
		
	}
	echo'<p><a href="javascript:history.back()">&laquo; Inapoi</a></p>';
}
		

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function admin_debug()
{
if(isset($_GET['page']) && isset($_GET['debug']))
{
	$char = replace($_GET['debug']);
	$const = mysql_fetch_object(mysql_query("Select * from player.player where id='$char'"));
	$chek = mysql_fetch_object(mysql_query("Select * from account.account where id='".$const->account_id."'"));
	$aid = $chek->id;
	if(isset($_GET['debug'])) {
		
		  $sqlCmd = "SELECT * FROM player.player WHERE id='".$char."' AND account_id ='".$aid."'";
		  $sqlQry = mysql_query($sqlCmd);
		  if(mysql_num_rows($sqlQry)>0) 
		  {
			$resetPos = array();
 			$resetPos[1]['map_index']=1; // Rosu
  			$resetPos[1]['x']=468779;
  			$resetPos[1]['y']=962107;
  			$resetPos[2]['map_index']=21; // Galben
  			$resetPos[2]['x']=55700;
  			$resetPos[2]['y']=157900;
  			$resetPos[3]['map_index']=41; // Blue
  			$resetPos[3]['x']=969066;
  			$resetPos[3]['y']=278290;

			$getChar = mysql_fetch_object($sqlQry);
			$pid = $getChar->id;
			$query2 = mysql_query("SELECT * FROM player.player_index WHERE pid1='$pid' or pid2='$pid' or pid3='$pid' or pid4='$pid'") or die('ERROR');
$row2 = mysql_fetch_array($query2);
$empire = $row2['empire'];
			$lp = strtotime($getChar->timeStamp);
			$difSpielzeit = time()-$lp;
			$toGoTime = (5*60)-($difSpielzeit);
			$toGoMin = floor(($toGoTime)/60);
			$toGoSek = ($toGoTime)%60;	
			
			  $sqlUpdate = "UPDATE player.player SET map_index='".$resetPos['$empire']['map_index']."', x='".$resetPos[$empire]['x']."', y='".$resetPos[$empire]['y']."', 	exit_x='".$resetPos[$empire]['x']."', exit_y='".$resetPos[$empire]['y']."', exit_map_index='".$resetPos[$empire]['map_index']."', horse_riding='0' WHERE id='".$char."' LIMIT 1"  or die(mysql_error());
			  $updatePos = mysql_query($sqlUpdate) or die(mysql_error());
				  if($updatePos)
				   {
					echo succes("Caracterul a fost debugat cu succes");
					}
					 else 
					 { 
						echo error("O eroare a aparut in procesul de debugare.Incercati din nou.");
					 }
			  
	
			
		  }
		  else {
			echo'<p class="meldung">'._debug_error1_.'</p>';
		  }
		
	}
	
}
}
function nume_item($vnum)
{
	
	$q = mysql_query("Select * from player.item_proto where vnum='$vnum'");	
	$m = mysql_fetch_object($q);
	echo "<b>".$m->locale_name."</b>";
}



function search_caractere()
{
	if(isset($_POST['cauta']))
	{
		$char = r_text($_POST['caractere']);
		if($char!=NULL)
		{
			$qu = mysql_query("Select * from player.player where name like '%$char%'");	
			if(mysql_num_rows($qu) == 0)
			{
				echo error("<center><b>Jucatorul nu exista.</b></center>");	
			}
			else
			{	
				
				echo '<table width="100%" style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;">';
				echo '
			<tr>
				<td style="text-align:center; border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><a><b>Rang</b></a></td>
				<td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><a><b>Nume Jucator</b></a></td>
				<td style="text-align:center; border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><a><b>Regat</b></a></td>
				<td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><a><b>Nivel</b></a></td>
				<td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><a><b>EXP</b></a></td>
				<td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><a><b>Timp Jucat</b></a></td>
				<td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><a><b>Reborn</b></a></td>
				<td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><a><b>Status</b></a></td>
			</tr>';
				while($ch = mysql_fetch_object($qu))
				{
					$nr++;
					$acs = mysql_fetch_object(mysql_query("Select * from player.player where id='$ch->account_id'"));
					
			    $query2 = mysql_query("SELECT * FROM player.player_index WHERE pid1='$pid' or pid2='$pid' or pid3='$pid' or pid4='$pid'");
				$row2 = mysql_fetch_array($query2);
				$empire = $row2['empire'];
					
					
					
$GMLIST = array(''.$acs->name.''); // Agregar Nombres de los Gm's
for($i=0;$i<count($GMLIST);$i++)
{
$sqlCmd = mysql_fetch_array(mysql_query("SELECT *,count(*) as total_line FROM player.player WHERE name = '".$GMLIST[$i]."' AND DATE_SUB(NOW(), INTERVAL 5 MINUTE) < last_play LIMIT 1"));	
					
		
					
					echo '<tr>
					
					
                  <td style="text-align:center; border-color:#b79647; border-style:solid; padding:10px; border-width:1px;">'.$nr.'</td>
				  <td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><b><a href="index.php?page=detalii&char='.$ch->name.'">'.$ch->name.'</a></b></td>
				  <td align="center" style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;">'.nume_regat($empire).'</td>
				  <td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><b>'.$ch->level.'</b></td>
				  <td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><b>'.$ch->exp.'</b></td>
				  <td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><b>'.$ch->playtime.'</b></td>
				  <td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;"><b><center>'.align($ch->alignment).'</center></b></td>
				  <td style="border-color:#b79647; border-style:solid; padding:10px; border-width:1px;">				  
				  
		';
		
		
		
		
		
		if ($sqlCmd['total_line'] > 0){
echo "<img src='./resurse/user_online.gif'>";
}else{
echo "<img src='./resurse/user_offline.gif'>";
}
}
		
		echo '</td></tr>	
		</tr>';
		
				}
				echo '</table>';
			}
		}
	}
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function adauga_acces()
{
	if(isset($_POST['adauga']))
	{
		$utilizator = replace($_POST['utilizator']);
		$nivel = $_POST['nivel'];
		$mys = mysql_query("Select * from account.account where login='$utilizator'");
		if(mysql_num_rows($mys)>0)
		{
			if($utilizator!=NULL)
			{
				mysql_query("Update account.account set web_admin='$nivel' where login='$utilizator'");	
				echo succes("Nivel $nivel adaugat utilizatorului $utilizator");
				
			}
		}
		else {
			echo error("Utilizatorul nu exista");	
		}
	}

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function cauta_cont()
{
	if(isset($_POST['cauta']))
	{
		$cont = r_text($_POST['cont']);
		if($cont !=NULL)
		{
			$ques = mysql_query("Select * from account.account where login like '%$cont%'");
			if(mysql_num_rows($ques) ==0)
			{
				echo "Contul nu exista";	
			}
			else
			{
				echo '<table width="100%" border="0" align="center" cellspacing="1" cellpadding="1">';
				echo '<tr class="top"><td class="iR_stats_level">Userid</td><td class="iR_stats_level">Cont</td><td class="iR_stats_level">Email</td><td class="iR_stats_level">Data inregistrari</td><td class="iR_stats_level">Status</td><td>&nbsp;</td></tr>';
				while($cont = mysql_fetch_object($ques))
				{
					echo '<tr class="top"><td class="iR_stats_reset">'.$cont->id.'</td><td class="iR_stats_reset">'.$cont->login.'</td><td class="iR_stats_reset">'.$cont->email.'</td><td class="iR_stats_reset">'.$cont->create_time.'</td><td class="iR_stats_reset">'.$cont->status.'</td><td class="collect" align="center"><a href="index.php?page=edit_cont&cont='.$cont->id.'">Vizualizare</a></td></tr>';
				}
				echo '</table>';
			}
		}
	}
}
function cauta_caracter()
{
	if(isset($_POST['cauta']))
	{
		$char = r_text($_POST['caracter']);
		if($char!=NULL)
		{
			$qu = mysql_query("Select * from player.player where name like '%$char%'");	
			if(mysql_num_rows($qu) == 0)
			{
				echo error("Caracterul nu exista");	
			}
			else
			{	
				
				echo '<table width="100%" border="0" align="center" cellspacing="1" cellpadding="1">';
				echo '<tr class="top"><td class="iR_stats_level">Owner</td><td class="iR_stats_level">Nume</td><td class="iR_stats_level">Level</td><td class="iR_stats_level">Ip</td><td>&nbsp;</td></tr>';
				while($ch = mysql_fetch_object($qu))
				{
					
					$acs = mysql_fetch_object(mysql_query("Select * from account.account where id='$ch->account_id'"));
					echo '<tr class="top"><td class="iR_stats_reset"><a href="index.php?page=edit_cont&cont='.$ch->account_id.'">['.$ch->account_id.']'.$acs->login.'</a></td><td class="iR_stats_reset">'.$ch->name.'</td><td class="iR_stats_reset">'.$ch->level.'</td><td class="iR_stats_reset"><a href="index.php?page=cauta_ip&ip='.$ch->ip.'">'.$ch->ip.'</a></td><td class="collect" align="center"><a href="index.php?page=a_caracter&id='.$ch->id.'">Vizualizare</a></td></tr>';
				}
				echo '</table>';
			}
		}
	}
}
function ban_char()
{
	if(isset($_POST['baneaza']))
	{
		
		$cont = replace($_GET['cont']);
		$motiv = replace($_POST['motiv']);
		$perioada = $_POST['perioada'];
		$query2 = mysql_query("Select * from account.account where id='$cont'");
		$nrs = mysql_fetch_object($query2);
		if($motiv !=NULL && mysql_num_rows($query2)==1)
		{
			if($perioada =="saptamana")
			{
				$per = time() + (7 * 24 * 60 * 60);	
			}
			elseif($perioada=="luna")
			{
				$per = time() + (30 * 24 * 60 * 60);	
			}
			elseif($perioada=="zi")
			{
				$per = time() + (24 * 60 * 60);	
			}
			elseif($perioada=="3zi")
			{
				$per = time() + (3 * 24 * 60 * 60);	
			}
			$ban = date("d/m/Y", $per);
			$data = date("H:i:s d-M-y ");
			if($perioada != "permanent")
			{
				mysql_query("Update account.account set unban_date='$ban',motiv_ban='$motiv',status='BLOCK' where id='$cont'");
				echo succes("Contul a fost banat.La data ".$ban." contul va fi debanat automat");
				/* Ban LOG */
				mysql_query("Insert into web.dev_ban_log (admin,player,motiv,durata,data) values('".$_SESSION['user']."','$nrs->login','$motiv','$per','$data')") or die(mysql_error());
				
			}
			else
			{
				mysql_query("Update account.account set unban_date='PERMANENT',motiv_ban='$motiv',status='BLOCK' where id='$cont'");
				echo succes("Contul a fost banat PERMANENT.Acest ban va putea fi scos doar de un GM");	
				/* Ban LOG */
				mysql_query("Insert into web.dev_ban_log (admin,player,motiv,durata,data) values('".$_SESSION['user']."','$nrs->login','$motiv','PERMANENT','$data')") or die(mysql_error());
				
			}
		}
		else
		{
			echo error("Trebuie sa aveti un motiv pentru acest ban!");
		}
	}	
}
function debanare_cont()
{
	if(isset($_GET['debanare']))
	{
		$cont = replace($_GET['debanare']);
		$query2 = mysql_query("Select * from  account.account where id='$cont' and status='BLOCK'");
		$ct = mysql_fetch_object($query2);
		$data = date("H:i:s d-M-y ");
		if(mysql_num_rows($query2)==0)
		{
			echo error("Contul nu exista sau nu are ban!");	
		}
		else
		{
			mysql_query("Update account.account set motiv_ban='Debanare',status='OK',unban_date='' where id='$cont'");
			echo succes("Contul a fost debanat");
			mysql_query("Insert into web.dev_ban_log (admin,player,motiv,durata,data) values('".$_SESSION['user']."','$ct->login','Ban scos','UNBANNED','$data')"); // LOG UNBAN
			echo '<meta http-equiv="refresh" content="2;url=index.php?page=edit_cont&cont='.$cont.'">';
		}
	}
}
function plus_monezi()
{
	if(isset($_POST['adauga']))
	{
		if(isset($_GET['cont']))
		{
			$cont = replace($_GET['cont']);
			$cantitate = replace($_POST['cantitate']);
			$query2 = mysql_query("Select * from account.account where id='$cont'");
			$old = mysql_fetch_object($query2);
			if(mysql_num_rows($query2)==0)
			{
				echo error("Contul nu exista!");	
			}
			else
			{
				$ocoins = $old->coins;
				$coins = $cantitate + $ocoins;
				$data = date("H:i:s d-M-y ");
				mysql_query("Update account.account set coins='$coins' where id='$cont'");
				echo succes("".$cantitate." monezi au fost adaugate.Acum are in total ".$coins." monezi dragon");
				mysql_query("Insert into web.dev_log_monezi (data,admin,actiune) values ('$data','".$_SESSION['user']."','A adaugat ".$cantitate." monezi userului ".$old->login."')") or die(mysql_error()); // LOG
				echo '<meta http-equiv="refresh" content="1;url=index.php?page=edit_cont&cont='.$cont.'">';
			}
		}
	}
}
function editare_caracter()
{
	if(isset($_POST['salveaza']))
	{	
		$id = replace($_GET['id']);
		$qw = mysql_query("Select * from player.player where id='$id'");
		if(mysql_num_rows($qw)==0)
		{
			echo error("Caracterul nu exista");	
		}
		else
		{	
			$old = mysql_fetch_object($qw);
			$nume = r_text($_POST['nume']);
			$level = replace($_POST['level']);
			$clasa = $_POST['job'];
			$alignment = $_POST['alignment'];
			$rang = $_POST['rang'];
			$yang = replace($_POST['yang']);
			$st = replace($_POST['st']);
			$dx = replace($_POST['dx']);
			$iq = replace($_POST['iq']);
			$ht = replace($_POST['ht']);
			$data = date("h:i:s d/m/Y");
			if($nume !=NULL && $level!=NULL && $yang!=NULL && $st!=NULL && $dx!=NULL && $iq!=NULL && $ht!=NULL)
			{
				if($nume == $old->name && $rang =="")
				{
					mysql_query("Update player.player set level='$level',job='$clasa',gold='$yang',st='$st',dx='$dx',iq='$iq',ht='$ht' where id='$id'");	
					echo succes("Caracterul a fost editat cu succes!");
					mysql_query("Insert into web.dev_player_edit (data,admin,player,initial,final) values ('$data','".$_SESSION['user']."','".$old->name."','Nume : ".$old->name.", Level: ".$old->level.", St: ".$old->st.", Dx: ".$old->st.", Iq: ".$old->iq.", Ht: ".$old->ht."','Nume : $nume, Level: $level,, St: $st, Dx: $st, Iq: $iq, Ht: $ht')"); // LOG
					//echo '<meta http-equiv="refresh" content="1;url=index.php?page=edit_caracter&id='.$id.'">';
				}
				else
				{
					if($rang !="")
					{
						$nnm = mysql_query("Select * from player.player where name='$rang$nume'");
						if(mysql_num_rows($nnm) == 0)
						{
							mysql_query("Update player.player set name='$rang$nume',level='$level',job='$clasa',gold='$yang',st='$st',dx='$dx',iq='$iq',ht='$ht' where id='$id'");	
							echo succes("Caracterul a fost editat cu succes!Noul nume $rang$nume");
							mysql_query("Insert into web.dev_player_edit (data,admin,player,initial,final) values ('$data','".$_SESSION['user']."','".$old->name."','Nume : ".$old->name.", Level: ".$old->level.", St: ".$old->st.", Dx: ".$old->st.", Iq: ".$old->iq.", Ht: ".$old->ht."','Nume : $rang$nume, Level: $level, St: $st, Dx: $st, Iq: $iq, Ht: $ht')"); // LOG
							//echo '<meta http-equiv="refresh" content="1;url=index.php?page=edit_caracter&id='.$id.'">';
						}
						else
						{
							echo error("Numele ales exista deja in baza de date");	
						}
					}
					else
					{
						$nnm = mysql_query("Select * from player.player where name='$rang$nume'");
						if(mysql_num_rows($nnm) == 0)
						{
							mysql_query("Update player.player set name='$nume',level='$level',job='$clasa',gold='$yang',st='$st',dx='$dx',iq='$iq',ht='$ht' where id='$id'");	
							echo succes("Caracterul a fost editat cu succes!Noul nume $rang$nume");
							mysql_query("Insert into web.dev_player_edit (data,admin,player,initial,final) values ('$data','".$_SESSION['user']."','".$old->name."','Nume : ".$old->name.", Level: ".$old->level.", St: ".$old->st.", Dx: ".$old->st.", Iq: ".$old->iq.", Ht: ".$old->ht."','Nume : $rang$nume, Level: $level,  St: $st, Dx: $st, Iq: $iq, Ht: $ht')"); // LOG
							//echo '<meta http-equiv="refresh" content="1;url=index.php?page=edit_caracter&id='.$id.'">';
						}
						else
						{
							echo error("Numele ales exista deja in baza de date");	
						}
					}
				}
			}
			else
			{
				echo error("Nu lasati spatii goale");	
			}
		}
			
	}
}	

function cauta_ip()
{
	
	if(isset($_POST['cauta']))
	{
		$ip = replace($_POST['ip']);
		if($ip!=NULL)
		{
			$qu = mysql_query("Select * from player.player where ip like '%$ip%'") or die(mysql_error());	
			if(mysql_num_rows($qu) == 0)
			{
				echo error("Ip-ul nu exista");	
			}
			else
			{	
				
				echo '<table width="100%" border="0" align="center" cellspacing="1" cellpadding="1">';
				echo '<tr class="top"><td class="iR_stats_level">Ip</td><td class="iR_stats_level">Cont :: Caracter</td><td>&nbsp;</td></tr>';
				while($ch = mysql_fetch_object($qu))
				{
					$account = mysql_fetch_object(mysql_query("Select * from account.account where id='$ch->account_id'"));
					echo '<tr class="top">
					<td class="iR_stats_reset">'.$ch->ip.'</td>
					<td class="iR_stats_reset"><a href="index.php?page=edit_cont&cont='.$ch->account_id.'">'.$account->login.'</a> :: <a href="index.php?page=a_caracter&id='.$ch->id.'">'.$ch->name.'</a></td>
					<td class="collect"><a href="index.php?page=ban_ip&ip='.$ch->ip.'">Baneaza IP</a></td>
					<td class="collect"><a href="index.php?page=unban_ip&ip='.$ch->ip.'">Debaneaza IP</a></td>
					</tr>';
				}
				echo '</table>';
			}
		}
	}
	if(isset($_GET['ip']))
	{
		$ip = replace($_GET['ip']);
		if($ip!=NULL)
		{
			$qu = mysql_query("Select * from player.player where ip like '%$ip%'") or die(mysql_error());	
			if(mysql_num_rows($qu) == 0)
			{
				echo error("Ip-ul nu exista");	
			}
			else
			{	
				
				echo '<table width="100%" border="0" align="center" cellspacing="1" cellpadding="1">';
				echo '<tr class="top"><td class="iR_stats_level">Ip</td><td class="iR_stats_level">Cont :: Caracter</td><td>&nbsp;</td></tr>';
				while($ch = mysql_fetch_object($qu))
				{
					$account = mysql_fetch_object(mysql_query("Select * from account.account where id='$ch->account_id'"));
					echo '<tr class="top">
					<td class="iR_stats_reset">'.$ch->ip.'</td>
					<td class="iR_stats_reset"><a href="index.php?page=edit_cont&cont='.$ch->account_id.'">'.$account->login.'</a> :: <a href="index.php?page=a_caracter&id='.$ch->id.'">'.$ch->name.'</a></td>
					<td class="collect"><a href="index.php?page=ban_ip&ip='.$ch->ip.'">Baneaza IP</font></a></td>
					<td class="collect"><a href="index.php?page=unban_ip&ip='.$ch->ip.'">Debaneaza IP</a></td>
					</tr>';
				}
				echo '</table>';
			}
		}
	}
}
function ban_ip()
{
	$ip = replace($_GET['ip']);
	$qu = mysql_query("Select * from player.player where ip='$ip'") or die(mysql_error());	
	if(mysql_num_rows($qu) == 0)
			{
				echo error("
				
				<div class=\"postui post-title\">
	<h2><span>Cautare ip</span></h2>
</div>
<div class=\"postui post-con\">
<div class=\"con-wrap\">
				Ip-ul nu exista
				
			</div>						
</div> 							
<div class=\"postui post-end\"></div>			
				");	
			}
			else
			{
				$ban = "PERMANENT";
				$motiv = "BANIP";
				$data = date("H:i:s d-M-y ");
				while($inf = mysql_fetch_object($qu))
				{
					mysql_query("Update account.account set unban_date='$ban',motiv_ban='$motiv',status='BLOCK' where id='".$inf->account_id."'");
					/* Ban LOG */
				mysql_query("Insert into web.dev_ban_log (admin,player,motiv,durata,data) values('".$_SESSION['user']."','$inf->login','$motiv','$ban','$data')");
				$nr++;
				}
				echo succes("<div class=\"postui post-title\">
	<h2><span>Cautare ip</span></h2>
</div>
<div class=\"postui post-con\">
<div class=\"con-wrap\">
Conturile cu ip $ip au fost banate cu succes.Perioada ban : PERMANENT
		</div>						
</div> 							
<div class=\"postui post-end\"></div>
");
				mysql_query("Insert into web.web_log_banip (admin,actiune) values ('".$_SESSION['user']."','Conturile cu ip $ip au fost banate cu succes.Perioada ban : PERMANENT')"); // LOG
				echo '<meta http-equiv="refresh" content="2;url=index.php?page=cauta_ip">';
			}
}

function unban_ip()
{
	$ip = replace($_GET['ip']);
	$qu = mysql_query("Select * from player.player where ip='$ip'") or die(mysql_error());	
	if(mysql_num_rows($qu) == 0)
			{
				echo error("
				
				<div class=\"postui post-title\">
	<h2><span>Cautare ip</span></h2>
</div>
<div class=\"postui post-con\">
	<div class=\"con-wrap\">
				Ip-ul nu exista
				
			</div>						
</div> 							
<div class=\"postui post-end\"></div>");	
			}
			else
			{
				$ban = "PERMANENT";
				$motiv = "UNBAN";
				$data = date("H:i:s d-M-y ");
				while($inf = mysql_fetch_object($qu))
				{
					mysql_query("Update account.account set status='OK' where id='".$inf->account_id."'");
					/* Ban LOG */
				mysql_query("Insert into web.dev_ban_log (admin,player,motiv,data) values('".$_SESSION['user']."','$inf->login','$motiv','$data')");
				$nr++;
				}
				echo succes("<div class=\"postui post-title\">
	<h2><span>Cautare ip</span></h2>
</div>
<div class=\"postui post-con\">
	<div class=\"con-wrap\">Conturile cu ip $ip au fost debanate cu succes
		</div>						
</div> 							
<div class=\"postui post-end\"></div>");
				mysql_query("Insert into web.web_log_banip (admin,actiune) values ('".$_SESSION['user']."','Conturile cu ip $ip au fost debanate cu succes')"); // LOG
				echo '<meta http-equiv="refresh" content="2;url=index.php?page=cauta_ip">';
			}
}

function cauta_vnum()
{
	
	include('inc/daten.inc.php');
	if(isset($_POST['cauta']))
	{
		$vnum = replace($_POST['vnum']);
		$window = $_POST['locatie'];
		if($vnum!=NULL)
		{
			$sqlCmd=mysql_query("SELECT item.*,player.name,player.account_id,account.login 
        FROM player.item
        INNER JOIN player.player 
        ON player.id=item.owner_id 
        INNER JOIN account.account 
        ON account.id=player.account_id 
        WHERE item.vnum='".$vnum."' 
        AND window='".$window."'") or die(mysql_error());
       		 $sqlCmd2=mysql_query("SELECT item.*,account.id AS account_id,account.login
        FROM player.item
        INNER JOIN account.account 
        ON account.id=item.owner_id 
        WHERE item.vnum='".$vnum."' 
        AND window='".$window."'") or die(mysql_error());
			 $iss = mysql_num_rows($sqlCmd);
			 echo succes("$iss iteme gasite.");
			 echo '<table width="100%" border="0" align="center" cellspacing="1" cellpadding="1">';
				echo '<tr><td class="iR_stats_level">Owner</td><td class="iR_stats_level">id</td><td class="iR_stats_level">bonusuri</td></tr>';
				while($ch = mysql_fetch_object($sqlCmd))
				{
					
					echo '<tr>
					<td class="iR_stats_level">
					<a href="index.php?page=edit_cont&cont='.$ch->account_id.'">
					'.$ch->login.' :: '.$ch->name.'</a></td>
					<td class="iR_stats_level">'.$ch->id.'</td>
					<td class="iR_stats_level">';
					for($i=0;$i<7;$i++) {
            if($i==0) { $akBoni = $ch->attrtype0; $akWert = $ch->attrvalue0; }
            if($i==1) { $akBoni = $ch->attrtype1; $akWert = $ch->attrvalue1; }
            if($i==2) { $akBoni = $ch->attrtype2; $akWert = $ch->attrvalue2; }
            if($i==3) { $akBoni = $ch->attrtype3; $akWert = $ch->attrvalue3; }
            if($i==4) { $akBoni = $ch->attrtype4; $akWert = $ch->attrvalue4; }
            if($i==5) { $akBoni = $ch->attrtype5; $akWert = $ch->attrvalue5; }
            if($i==6) { $akBoni = $ch->attrtype6; $akWert = $ch->attrvalue6; }
            echo'#'.($i+1).'&nbsp;';
            if(isset($itemBoni[$akBoni])) {
              echo $itemBoni[$akBoni];
            }
            else {
              echo $akBoni;
            }
            echo':&nbsp;'.$akWert;
            echo "<br/>";
          
          }
					
					echo '</td></tr>';
				}
				echo '</table>';
			
		}
	}	
}
function cauta_item_id()
{
	if(isset($_POST['cauta']))
	{
		$id = replace($_POST['id']);
		 include('daten.inc.php');
		if($id !=NULL && is_numeric($id))
		{
			$ques = mysql_query("Select * from player.item where id='$id'");
			if(mysql_num_rows($ques) ==0)
			{
				echo error("Itemul nu exista");	
			}
			else
			{
				echo '<table width="100%" border="0" >';
    			while($item2 = mysql_fetch_object($ques))
	  			{
					echo "<tr>
			<td valign=\"top\" class=\"iR_stats_level\">".$item2->id."<br />
			 <a href=\"index.php?page=retrage_item&retrage=".$item2->id."\"><h5>RETRAGE</h5></a></td>
			<td valign=\"top\" class=\"iR_stats_reset\">".nume_item($item2->vnum)."</td>
			<td valign=\"top\" class=\"iR_stats_reset\">".$item2->count."</td>
			<td valign=\"top\" class=\"iR_stats_reset\">";
			for($i=0;$i<6;$i++) {
					if($i==0) { $akSocket = $item2->socket0; }
					if($i==1) { $akSocket = $item2->socket1; }
					if($i==2) { $akSocket = $item2->socket2; }
					if($i==3) { $akSocket = $item2->socket3; }
					if($i==4) { $akSocket = $item2->socket4; }
					if($i==5) { $akSocket = $item2->socket5; }
					echo'#'.($i+1).'&nbsp;';
					if(isset($itemSteine[$akSocket])) {
					  echo $itemSteine[$akSocket];
					}
					else {
					  echo $akSocket;
					}
					echo "<br>";
				  
				  }
			echo "</td>
			<td valign=\"top\" class=\"iR_stats_reset\">";
			 for($i=0;$i<7;$i++) {
					if($i==0) { $akBoni = $item2->attrtype0; $akWert = $item2->attrvalue0; }
					if($i==1) { $akBoni = $item2->attrtype1; $akWert = $item2->attrvalue1; }
					if($i==2) { $akBoni = $item2->attrtype2; $akWert = $item2->attrvalue2; }
					if($i==3) { $akBoni = $item2->attrtype3; $akWert = $item2->attrvalue3; }
					if($i==4) { $akBoni = $item2->attrtype4; $akWert = $item2->attrvalue4; }
					if($i==5) { $akBoni = $item2->attrtype5; $akWert = $item2->attrvalue5; }
					if($i==6) { $akBoni = $item2->attrtype6; $akWert = $item2->attrvalue6; }
					echo'#'.($i+1).'&nbsp;';
					if(isset($itemBoni[$akBoni])) {
					  echo $itemBoni[$akBoni];
					}
					else {
					  echo $akBoni;
					}
					echo':&nbsp;'.$akWert;
					echo "<br/>";
				  
				  }
			echo "</td>
			
		   
		  </tr>";
		
		 } echo "</table>
		";
			}
		}
	}
}
////////////////////////////////////////////////////////////////
//////////////////////////////////////De chemat pe prima pagina
////////////////////////////////////////////////////////////////
function auto_unban()
{
	
	$data = date("d/m/Y");
	$query = mysql_query("Select * from account.account where unban_date='$data'");
	while($cont = mysql_fetch_object($query))
	{
		mysql_query("Update account.account set unban_date='',motiv_ban='',status='OK' where id='$cont->id'") or die(mysql_error());
	}
	
	
}
function sterge_cont_automat()
{
	
	$data = date("d/m/Y");
	$query = mysql_query("Select * from account.account where stergere_account='$data'");
	while($cont = mysql_fetch_object($query))
	{
		mysql_query("Delete from account.account where id='$cont->id'");
	}
}
////////////////////////////////////////////////////////////////
//////////////////////////////////////De chemat pe prima pagina
////////////////////////////////////////////////////////////////
function adauga_admini()
{
	
	if(isset($_POST['submit']))
	{
		$cont = replace($_POST['cont']);
		$char = replace($_POST['caracter']);
		$acces = $_POST['mAuthority'];
		if($cont !=NULL && $char !=NULL)
		{
			mysql_query("Insert into common.gmlist (mAccount,mName,mAuthority) values ('$cont','$char','$acces')");
			echo succes("Caracterul $char apartinant contului $cont este acum $acces");
		}
	}
}
function check_donate()
{
	if(isset($_GET['cod']) && is_numeric($_GET['cod']) && $_GET['set_status']=="Valid")
	{
		$cod = replace($_GET['cod']);
		$admin = $_SESSION['user'];
		$query = mysql_query("Select * from web.donate where cod='$cod' and status='In curs de verificare'");
		if(mysql_num_rows($query)==1)
		{
			$fetch = mysql_fetch_object($query);
			$query2 = mysql_query("Select * from account.account where login='$fetch->cont'");
			$fetch2 = mysql_fetch_object($query2);
			$rasplata = $fetch->valoarea*4;
			$paid = $rasplata + $fetch2->coins;
			mysql_query("Update account.account set coins='$paid' where login='".$fetch->cont."'");
			mysql_query("Update web.donate set status='Valid',admin='$admin' where cod='$cod'");
			echo succes("Codul $cod a fost acum validat.Contul ".$fetch2->login." a fost acreditat cu ".$rasplata." MD.Acum are in total $paid.");
		}
		else
		{
			error("Codul deja validat.");	
		}
	}
	
	if(isset($_GET['cod']) && is_numeric($_GET['cod']) && $_GET['set_status']=="Invalid")
	{
		$cod = replace($_GET['cod']);
		$admin = $_SESSION['user'];
		$query = mysql_query("Select * from web.donate where cod='$cod' and status='In curs de verificare'");
		if(mysql_num_rows($query)==1)
		{
			
			mysql_query("Update web.donate set status='Invalid',admin='$admin' where cod='$cod'");
			echo succes("Codul $cod , apartinand contului ".$fetch2->login." a fost invalidat.");
		}
		else
		{
			error("Codul deja validat.");	
		}
	}
}
function retrage_item()
{
	if(isset($_GET['retrage']))
		{
			$ii = replace($_GET['retrage']);
			$m2pos = mysql_query("Select * from player.item where owner_id='".$_SESSION['userid']."' and window='MALL' order by pos desc limit 0,1");
			$positione = mysql_fetch_object($m2pos);
			$posact = $positione->pos;
			$error=0;
			$data = date("h:i:s d/M/Y");
			if($posact < 48 )
			{
				$posact=$posact+1;
				if($posact=='0')
					{
						$posact++;
					}
			}
			else
			{
				$error=1;
					 echo alert("Imi pare rau dar depozitul dumneavoastra este plin.");
			}
			if($error!=1)
			{
				mysql_query("UPDATE player.item SET owner_id='".$_SESSION['userid']."', window='MALL', pos='$posact' WHERE id='".$ii."'");
				echo succes("Itemul cu id ".$ii." a fost retras cu succes.");
				mysql_query("Insert into web.dev_log_retrage (data,admin,actiune) values ('$data','".$_SESSION['user']."','Itemul cu id ".$ii." a fost retras cu succes.')"); // LOG
			}
			
			
		}	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function a_parola()
{
	if(isset($_POST['schimba']))
	{
		if(isset($_GET['cont']) && is_numeric($_GET['cont']))
		{
			$cont = replace($_GET['cont']);
			if($cont!=NULL)
			{
				$check = mysql_query("Select * from account.account where id='$cont'");
				$ft = mysql_fetch_object($check);
				if(mysql_num_rows($check)==1)
				{
					$parola = replace($_POST['parola']);
					if($parola!=NULL)
					{
						mysql_query("Update account.account set password=password('$parola') where id='$cont'");
						echo succes("Noua parola a contului $ft->login este $parola.");
					}
				}
			}
			else
			{
				echo error("Alege un cont!");	
			}
		}
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function romana($var){
$new_var=str_replace("ã","a",$var);
$new_var=str_replace("â","a",$new_var);
$new_var=str_replace("Î","I",$new_var);
$new_var=str_replace("î","i",$new_var);
$new_var=str_replace("s","s",$new_var);
$new_var=str_replace("t","t",$new_var);
$new_var=str_replace("A","A",$new_var);
$new_var=str_replace("Â","I",$new_var);
$new_var=str_replace("S","S",$new_var);
$new_var=str_replace("T","T",$new_var);
$new_var=str_replace("þ","t",$new_var);
$new_var=str_replace("º","s",$new_var);
$new_var=str_replace("2147483647","-15",$new_var);
return $new_var;

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function img_item($item){			if (strlen($item) == 1){		$immagine_item = "resurse/images/item/0000".$item.".png";		}		if(strlen($item) == 2){		$immagine_item = "resurse/images/item/000".substr($item, 0, 1)."0.png";		}		if(strlen($item) == 3){		$immagine_item = "resurse/images/item/00".substr($item, 0, 2)."0.png";		}		if(strlen($item) == 4){   		$immagine_item = "resurse/images/item/0".substr($item, 0, 3)."0.png";		}		if(strlen($item) == 5){		$immagine_item = "resurse/images/item/".substr($item, 0, 4)."0.png";		}		if(strlen($item) == 6){		$immagine_item = "resurse/images/item/".substr($item, 0, 5)."0.png";		}		if(strlen($item) == 0){		$immagine_item = "resurse/images/item/error.png";		}		echo "<div align='center'><img src='$immagine_item' border='0px' alt='' align='center'  style='max-height:90px;'></div>";}

function resetare_parola()
{
	if(isset($_POST['reseteaza']))
	{
		$cont = replace($_GET['cont']);
		$password = substr(hash('sha512',rand()),0,7);
		$check = mysql_query("Select * from account.account where id='$cont'");
		if(mysql_num_rows($check)==0)
		{
			echo error("Contul nu exista.");
		}
		else
		{
			$query= mysql_query("Select * from account.account where id='$cont'");
			$conts = mysql_fetch_object($query);
			mysql_query("Update account.account set password=PASSWORD('$password') where id='$cont'");
			echo succes("".$conts->login." :: Noua parola $password a fost trimisa la email ".$conts->email.".");
			$to      = $conts->email;
			$subject = 'Noua parola!';
			$message = "Salut ".$conts->login."!". "\r\n" ."
			Ati solicitat o noua parola.". "\r\n" ."
			Parola este : ".$password."". "\r\n" ."
			
			Toate cele bune". "\r\n" ."
			Metin2Alaska.";
			new mail($to, $subject, $message);
			mysql_query("Insert into web.web_a_reseteaza_parola (admin,actiune) values ('".$_SESSION['user']."','A resetat parola.Noua parola : $password a fost trimisa userului prin mail.')"); // LOG
		}
	}
}	
function adauga_news()
{
	if(isset($_POST['adauga']))
	{
		$titlu = replace($_POST['titlu']);	
		$tip = $_POST['tip'];
		$continut = $_POST['elm1'];
		$data = date("h:i:s d/M/Y");
		if($titlu && $continut)
		{
			mysql_query("Insert into web.dev_news (data,tip,continut,titlu) values ('$data','$tip','$continut','$titlu')");
			echo succes("Stire adaugata cu succes!");	
		}
		else
		{
			echo error("Spatii libere");	
		}
	}
}
?>