<?php



function time_left($tl)
{
$d=3600*24;
$day=floor($tl/$d);
$tl=$tl-($d*$day);

$hour=floor($tl/3600);
$tl=$tl-(3600*$hour);

$minute=floor($tl/60);
$tl=$tl-(60*$minute);

$second=floor($tl);

$dayt="".($day>0?"24 час. ":null)."";
$hourt="".($hour>0?"$hour час. ":null)."";
$minutet="".($minute>0?"$minute мин. ":null)."";
$secondt="".($second>0?"$second сек. ":null)."";
if($day>0)
{
$minutet=NULL;
$secondt=NULL;
}
if($hour>0 && $day==0)
{
$secondt=NULL;
$dayt=NULL;
}
return "$dayt$hourt$minutet$secondt";
}



function gtime($timediff=NULL)
{
$oneMinute=60;
$oneHour=60*60;
$oneDay=60*60*24;
$dayfield=floor($timediff/$oneDay);
$hourfield=floor(($timediff-$dayfield*$oneDay)/$oneHour);
$minutefield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour)/$oneMinute);
$secondfield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour-$minutefield*$oneMinute));
$sDaysLeft=$dayfield;
$sDaysText = "дн.";
$nDaysLeftLength =strlen($sDaysLeft);
$d_1=substr($sDaysLeft,-1,1);
if (substr($sDaysLeft,-2,1) != 1 && $nDaysLeftLength>1)
{
if ($d_1 == 2 || $d_1== 3 || $d_1== 4)
{
$sDaysText = "дн.";
}
elseif ($d_1== 1)
{
$sDaysText = "дн.";
}
}
if ($nDaysLeftLength==1)
{
if ($d_1==2 || $d_1== 3 || $d_1== 4)
{
$sDaysText = "дн.";
}
elseif ($d_1== 1)
{
$sDaysText = "дн.";
}
}
$sHoursLeft=$hourfield;
$sHoursText = "час.";
$nHoursLeftLength = strlen($sHoursLeft);
$h_1=substr($sHoursLeft,-1,1);
if (substr($sHoursLeft,-2,1) != 1 && $nHoursLeftLength>1)
{
if ($h_1== 2 || $h_1== 3 || $h_1== 4)
{
$sHoursText = "час.";
}
elseif ($h_1== 1)
{
$sHoursText = "час.";
}
}
if ($nHoursLeftLength==1)
{
if ($h_1== 2 || $h_1== 3 || $h_1== 4)
{
$sHoursText = "часа";
}
elseif ($h_1== 1)
{
$sHoursText = "час.";
}
}
$sMinsLeft =$minutefield;
$sMinsText = "мин.";
$nMinsLeftLength = strlen($sMinsLeft);
$m_1=substr($sMinsLeft,-1,1);
if ($nMinsLeftLength>1 && substr($sMinsLeft,-2,1) != 1)
{
if ($m_1== 2 || $m_1== 3 || $m_1== 4)
{
$sMinsText = "мин.";
}
else if ($m_1== 1)
{
$sMinsText = "мин.";
}
}
if ($nMinsLeftLength==1)
{
if ($m_1== 2 || $m_1==3 || $m_1== 4)
{
$sMinsText = "мин.";
}
elseif ($m_1== "1")
{
$sMinsText = "мин.";
}
}
$sSecsLeft = $secondfield;
$sSecsText = "сек.";
$s_1=substr($sSecsLeft,-1,1);
$nSecsLeftLength = strlen($sSecsLeft);
if (substr($sSecsLeft,-2,1)!= 1 && $nSecsLeftLength>1)
{
if ($s_1== 2 || $s_1== 3 || $s_1== 4)
{
$sSecsText = "сек.";
}
elseif ($s_1== 1)
{
$sSecsText = "сек.";
}
}
if ($nSecsLeftLength==1)
{
if ($s_1== 2 || $s_1== 3 || $s_1== 4)
{
$sSecsText = "сек.";
}
elseif ($sSecsLeft== "1")
{
$sSecsText = "сек.";
}
}
if ($sDaysLeft!=0)$sDaysLeft = $sDaysLeft.' '.$sDaysText.' ';
else $sDaysLeft = NULL ; $sDaysText=NULL;
if ($sHoursLeft!=0)$sHoursLeft = $sHoursLeft.' '.$sHoursText.' ';
else $sHoursLeft = NULL ; $sHoursText=NULL;
if ($sMinsLeft!=0)$sMinsLeft = $sMinsLeft.' '.$sMinsText.' ';
else $sMinsLeft = NULL ; $sMinsText=NULL;
if ($sSecsLeft!=0)$sSecsLeft = $sSecsLeft.' '.$sSecsText.' ';
else $sSecsLeft = NULL ; $sSecsText=NULL;

$displaystring="
".
$sDaysLeft." ".
$sDaysText." ".
$sHoursLeft." ".
$sHoursText." ".
$sMinsLeft." ".
$sMinsText." ".
$sSecsLeft." ".
$sSecsText;
echo $displaystring;
}



function tags($var = '') {
    // Обработка ссылок и тэгов BBCODE в тексте//
    $var = preg_replace('#\[b\](.*?)\[/b\]#si', '<span style="font-weight: bold;">\1</span>', $var);
    $var = preg_replace('#\[i\](.*?)\[/i\]#si', '<span style="font-style:italic;">\1</span>', $var);
    $var = preg_replace('#\[u\](.*?)\[/u\]#si', '<span style="text-decoration:underline;">\1</span>', $var);
    $var = preg_replace('#\[del\](.*?)\[/del\]#si', '<span style="text-decoration: line-through;">\1</span>', $var);
    $var = preg_replace('#\[red\](.*?)\[/red\]#si', '<span style="color:LightCoral">\1</span>', $var);
    $var = preg_replace('#\[green\](.*?)\[/green\]#si', '<span style="color:green">\1</span>', $var);
    $var = preg_replace('#\[yellow\](.*?)\[/yellow\]#si', '<span style="color:yellow">\1</span>', $var);
    $var = preg_replace('#\[admin\](.*?)\[/admin\]#si', '<span style="color:#7afe4e">\1</span>', $var);

/////смайлы/////
$var = str_replace(array(':@)',':)'), '<img src="/img/smiles/).gif" alt="*"/>',      $var);


    return $var;


      

///
	
}

//////////////////////

 





////////////////////////////////////////////////////////////////////////////
$req = mysql_query("SELECT * FROM `block` WHERE   `tip` = '1' and `usr` = '$user[id]' LIMIT 1");
$avto = mysql_num_rows($req);
if ($avto==1) {
    $ban = mysql_fetch_array($req);

    if($ban[ban_time]<$time){
    mysql_query("DELETE FROM `block` WHERE `tip` = '1'  and `usr` = '$user[id]'");
    }}


$req = mysql_query("SELECT * FROM `block` WHERE `tip` = '2' and `usr`='$user[id]' LIMIT 1");
// //////////////////////////
$avto = mysql_num_rows($req);
if ($avto == 1) {
    $ban = mysql_fetch_array($req);

$req = mysql_query("SELECT * FROM `user` WHERE `id` = '$ban[nick]'");
$pic = mysql_fetch_array($req);

    if($ban[ban_time]<$time){
    mysql_query("DELETE FROM `block` WHERE `tip` = '2' and `usr`='$user[id]'");
    }else{
echo' <div class="title">
Бан</div>  <div class="empty_block">';
echo"<img src='img/images/arrow.png' alt='*'/> Ваш персонаж заблокирован!";
echo"<br><img src='img/images/arrow.png' alt='*'/> Модератором: $pic[login]<br>";
echo"<img src='img/images/arrow.png' alt='*'/> Причина: <i>$ban[text]</i><br>";

$time = time();
$ban[ban_time]= $ban[ban_time] -$time;
if($ban[ban_time]<60){
echo "<img src='img/images/arrow.png' alt='*'/> Время блокировки: $ban[ban_time] сек </div>";
include ("system/foot.php");
exit;
}elseif($ban[ban_time]>60 and $ban[ban_time]<3600){
$ban[ban_time]=round($ban[ban_time]/60);
echo "<img src='img/images/arrow.png' alt='*'/> Время блокировки: $ban[ban_time] мин </div>";
include ("system/foot.php");
exit;

}else{
$ban[ban_time]= round($ban[ban_time]/3600); блокировки:
echo "<img src='img/images/arrow.png' alt='*'/> Время блокировки: $ban[ban_time] час </div>";
include ("foot.php");
exit;
}
    }
    }


function bbcode($text){
 
 $search[] = "/\[color=(.+)\](.+)\[\/color\]/isU";
 $search[] = "/\[size=([1-6]{1})\](.+)\[\/size\]/isU";
 $search[] = "/\[i\](.+)\[\/i\]/isU";
 $search[] = "/\[u\](.+)\[\/u\]/isU";
 $search[] = "/\[b\](.+)\[\/b\]/isU";
 $replace[] = '<font color="\1">\2</font>';
 $replace[] = '<font size="\1">\2</font>';
 $replace[] = '<i>\1</i>';
 $replace[] = '<u>\1</u>';
 $replace[] = '<b>\1</b>';
 $text = preg_replace($search, $replace, $text);
 return $text;
}




function nastavnik($string){
$dir = opendir ("pic/nastavnik");
while ($file = readdir ($dir)) {
if (ereg (".png$", "$file")){
$file2=str_replace(".png","",$file);
$string=str_replace(":$file2",'<img src="pic/nastavnik/'.$file.'" alt="">',$string);
}}
closedir ($dir);
return $string;  }


function smiles($string){
$dir = opendir ("pic/smiles");
while ($file = readdir ($dir)) {
if (ereg (".gif$", "$file")){
$file2=str_replace(".gif","",$file);
$string=str_replace(":$file2",'<img src="pic/smiles/'.$file.'" alt="">',$string);
}}
closedir ($dir);
return $string;  }



function sec2day($sec=NULL)
{
$days = floor($sec/86400);
$hours = floor(($sec/3600)-$days*24);
$minuts = floor(($sec-$hours*3600-$days*86400)/60);
$seconds = $sec-($minuts*60+$hours*3600+$days*86400);

if ($days!=0)$days = $days.' дн. ';
else $days = NULL;
if ($hours!=0)$hours = $hours.' час. ';
else $hours = NULL;
if ($minuts!=0)$minuts = $minuts.' мин. ';
else $minuts = NULL;

$sectoday = $days.''.$hours.''.$minuts.''.$seconds.' сек.';

return $sectoday;
}
?>
