<?

function GradientLetter($text, $from='', $to='', $mode = 'hex') {
$text = iconv("UTF-8", "windows-1251", $text);
if ($mode == 'hex') {
$to = hexdec($to['0'].$to['1']).','.hexdec($to['2'].$to['3']).','.hexdec($to['4'].$to['5']);
$from = hexdec($from['0'].$from['1']).",".hexdec($from['2'].$from['3']).",".hexdec($from['4'].$from['5']);
}
if (empty($text)) return null; else $levels = strlen($text);
if (empty($from)) $from = array(0, 0, 255); else $from = explode(',', $from);
if (empty($to)) $to = array(255, 0, 0); else $to = explode(',', $to);	$output = null;
for ($i = 1; $i <= $levels; $i++) {
for ($ii = 0; $ii < 3; $ii++) {
$tmp[$ii] = $from[$ii] - $to[$ii];
$tmp[$ii] = floor($tmp[$ii] / $levels);
$rgb[$ii] = $from[$ii] - ($tmp[$ii] * $i);
if ($rgb[$ii] > 255) $rgb[$ii] = 255;
$rgb[$ii] = dechex($rgb[$ii]);
$rgb[$ii] = strtoupper($rgb[$ii]);
if (strlen($rgb[$ii]) < 2) $rgb[$ii] = '0'.$rgb[$ii];
		}
		$output .= '<span style="color: #'.$rgb['0'].$rgb['1'].$rgb['2'].'">'.$text[$i-1].'</span>';
		}
return iconv("windows-1251",  "UTF-8", $output);
}

function colorNick( $nick )
{
$count = mb_strlen( $nick, 'UTF-8' );
$a_colors = array('#FF0000','00FF00','#0000FF'
);
///'#AD1A1A',  'black ',  'green ',   'red ',    '#30CE3C ', 'blue','#000000',
///'#3030CE ', '#7AC8B1', '#F8DF0E ', '#654611', '#F100C6 '
for( $i = 0, $return = ''; $i < $count; $i++ )
$return .= '<span style="color:' . $a_colors[array_rand( $a_colors )] . ';">' . mb_substr( $nick, $i, 1, 'UTF-8' ) . '</span>';

return $return ;
}

function nikColor( $nick , $colornick)
{
$arr = explode('::',$colornick);
$count = mb_strlen( $nick, 'UTF-8' );
for( $i = 0, $return = ''; $i < $count; $i++ )
{
$s++;
if($arr[$s] == 1) {$color = '#FF0000'; $col = 1;}
elseif($arr[$s] == 2) {$color = '#ffa500'; $col = 2;}
elseif($arr[$s] == 3) {$color = '#ffff00'; $col = 3;}
elseif($arr[$s] == 4) {$color = '#00ff00'; $col = 4;}
elseif($arr[$s] == 5) {$color = '#42aaff'; $col = 5;}
elseif($arr[$s] == 6) {$color = '#0000ff'; $col = 6;}
elseif($arr[$s] == 7) {$color = '#8b00ff'; $col = 7;}
elseif($arr[$s] == 8) {$color = '#00CCFF'; $col = 8;}
elseif($arr[$s] == 9) {$color = '#00CCFF'; $col = 9;}
elseif($arr[$s] == 0 or $arr[$s] < 0 or $arr[$s] > 9) {$color = '#000000'; $col = 0;}
$return .= '<span style="color:' . $color . ';">' . mb_substr( $nick, $i, 1, 'UTF-8' ) . '</span>';
}
return $return ;
}


function nik($ref=NULL,$link=NULL)
{
global $db, $user, $wap, $rm, $usid, $name, $set, $sid, $nk, $user_system, $time, $rmmaf, $mafiozi;

if(isset($ref)&&($ref!=$user_system)) $ref=check($ref);
 if ($ref!=$mafiozi){
        if (!ctype_digit($ref)) {
        $ruser = rus_to_k($ref);
        $result = $db->sql_query ("Select * from users where ruser = '".$ruser."' LIMIT 1;");
        } else {
        $result = $db->sql_query ("Select * from users where id = '".$ref."' LIMIT 1;");
		}

        $nik = $db->sql_fetchrow ($result);

if (!isset($user['id']))$time = (time()+$set['timesdvig']*60*60);/////тут засада.- 1 *60когда в админке время двигаешь:(
else if ($user['poias']!='') $time = ((time()-4*60*60)+$user['poias']*60);

if($whos = $db->sql_numrows($db->sql_query("SELECT * FROM `who` WHERE `user` = '".$nik['id']."'")))
{
if ($nik['xstatus']==1) $on_off='<img src="/img/online/gotov_boltat.png" alt="" />';
else if ($nik['xstatus']==2) $on_off='<img src="/img/online/zaniat.png" alt="" />';
else if ($nik['xstatus']==3) $on_off='<img src="/img/online/boleu.png" alt="" />';
else if ($nik['xstatus']==4) $on_off='<img src="/img/online/depressia.png" alt="" />';
else if ($nik['xstatus']==5) $on_off='<img src="/img/online/dumau.png" alt="" />';
else if ($nik['xstatus']==6) $on_off='<img src="/img/online/kuru.png" alt="" />';
else if ($nik['xstatus']==7) $on_off='<img src="/img/online/kushau.png" alt="" />';
else if ($nik['xstatus']==8) $on_off='<img src="/img/online/love.png" alt="" />';
else if ($nik['xstatus']==9) $on_off='<img src="/img/online/tv.png" alt="" />';
else if ($nik['xstatus']==10) $on_off='<img src="/img/online/music.png" alt="" />';
else if ($nik['xstatus']==11) $on_off='<img src="/img/online/vanna.png" alt="" />';
else if ($nik['xstatus']==12) $on_off='<img src="/img/online/tualet.png" alt="" />';
else if ($nik['xstatus']==13) $on_off='<img src="/img/online/sex.png" alt="" />';
else if ($nik['xstatus']==14) $on_off='<img src="/img/online/igrau.png" alt="" />';
else if ($nik['xstatus']==15) $on_off='<img src="/img/online/pivo.png" alt="" />';
else if ($nik['xstatus']==16) $on_off='<img src="/img/online/sonni.png" alt="" />';
else if ($nik['xstatus']==0){
if ($nik['sex']==1) $on_off='<img src="/img/online/man_on.gif" alt=""/>';
else if ($nik['sex']==0) $on_off='<img src="/img/online/woman_on.gif" alt="" />';
else $on_off='<img src="/img/online/on.gif" alt="" />';
}

}else{

if ($nik['sex']==1) $on_off='<img src="/img/online/man_off.gif" alt="" />';
else if ($nik['sex']==0) $on_off='<img src="/img/online/woman_off.gif" alt="" />';
else $on_off='<img src="/img/online/off.gif" alt="" />';

}



$color_nik = $nik['color_nik'];
$name = $nik['user'];

if ($user['ver']!='wml'){
////if ($nik['effnik']==1) $name = '<blink>'.$name.'</blink>';

if ($nik['color_nik'] >= 100 and $nik['color_nik'] <=233)
{
	if ($nik['color_nik'] == 100) $col ='808080';
	elseif ($nik['color_nik'] == 101) $col ='696969';
	elseif ($nik['color_nik'] == 102)$col ='000000';
	elseif ($nik['color_nik'] == 103)$col ='FFB6C1';
	elseif ($nik['color_nik'] == 104)$col ='FFC0CB';
	elseif ($nik['color_nik'] == 105)$col ='DB7093';
	elseif ($nik['color_nik'] == 106)$col ='FFF0F5';
	elseif ($nik['color_nik'] == 107)$col ='DA70D6';
	elseif ($nik['color_nik'] == 108)$col ='D8BFD8';
	elseif ($nik['color_nik'] == 109)$col ='EE82EE';
	elseif ($nik['color_nik'] == 110)$col ='DDA0DD';
	elseif ($nik['color_nik'] == 111)$col ='BA55D3';
	elseif ($nik['color_nik'] == 112)$col ='4B0082';
	elseif ($nik['color_nik'] == 113)$col ='9370DB';
	elseif ($nik['color_nik'] == 114)$col ='7B68EE';
	elseif ($nik['color_nik'] == 115)$col ='483D8B';
	elseif ($nik['color_nik'] == 116)$col ='6A5ACD';
	elseif ($nik['color_nik'] == 117)$col ='191970';
	elseif ($nik['color_nik'] == 118)$col ='F8F8FF';
	elseif ($nik['color_nik'] == 119)$col ='E6E6FA';
	elseif ($nik['color_nik'] == 120)$col ='6495ED';
	elseif ($nik['color_nik'] == 121)$col ='B0C4DE';
	elseif ($nik['color_nik'] == 122)$col ='778899';
	elseif ($nik['color_nik'] == 123)$col ='708090';
	elseif ($nik['color_nik'] == 124)$col ='F0F8FF';
	elseif ($nik['color_nik'] == 125)$col ='4682B4';
	elseif ($nik['color_nik'] == 126)$col ='87CEFA';
	elseif ($nik['color_nik'] == 127)$col ='87CEEB';
	elseif ($nik['color_nik'] == 128)$col ='ADD8E6';
	elseif ($nik['color_nik'] == 129)$col ='B0E0E6';
	elseif ($nik['color_nik'] == 130)$col ='5F9EA0';
	elseif ($nik['color_nik'] == 131)$col ='F0FFFF';
	elseif ($nik['color_nik'] == 132)$col ='E0FFFF';
	elseif ($nik['color_nik'] == 133)$col ='AFEEEE';
	elseif ($nik['color_nik'] == 134)$col ='2F4F4F';
	elseif ($nik['color_nik'] == 135)$col ='7FFFD4';
	elseif ($nik['color_nik'] == 136)$col ='66CDAA';
	elseif ($nik['color_nik'] == 137)$col ='F5FFFA';
	elseif ($nik['color_nik'] == 138)$col ='3CB371';
	elseif ($nik['color_nik'] == 139)$col ='2E8B57';
	elseif ($nik['color_nik'] == 140)$col ='F0FFF0';
	elseif ($nik['color_nik'] == 141)$col ='98FB98';
	elseif ($nik['color_nik'] == 142)$col ='90EE90';
	elseif ($nik['color_nik'] == 143)$col ='228B22';
	elseif ($nik['color_nik'] == 144)$col ='006400';
	elseif ($nik['color_nik'] == 145)$col ='8FBC8F';
	elseif ($nik['color_nik'] == 146)$col ='556B2F';
	elseif ($nik['color_nik'] == 147)$col ='6B8E23';
	elseif ($nik['color_nik'] == 148)$col ='FFFFF0';
	elseif ($nik['color_nik'] == 149)$col ='FFFFE0';
	elseif ($nik['color_nik'] == 150)$col ='FAFAD2';
	elseif ($nik['color_nik'] == 151)$col ='F5F5DC';
	elseif ($nik['color_nik'] == 152)$col ='BDB76B';
	elseif ($nik['color_nik'] == 153)$col ='EEE8AA';
	elseif ($nik['color_nik'] == 154)$col ='FFFACD';
	elseif ($nik['color_nik'] == 155)$col ='F0E68C';
	elseif ($nik['color_nik'] == 156)$col ='FFF8DC';
	elseif ($nik['color_nik'] == 157)$col ='FFFAF0';
	elseif ($nik['color_nik'] == 158)$col ='FDF5E6';
	elseif ($nik['color_nik'] == 159)$col ='F5DEB3';
	elseif ($nik['color_nik'] == 160)$col ='FFE4B5';
	elseif ($nik['color_nik'] == 161)$col ='FFEFD5';
	elseif ($nik['color_nik'] == 162)$col ='FFEBCD';
	elseif ($nik['color_nik'] == 163)$col ='FFDEAD';
	elseif ($nik['color_nik'] == 164)$col ='FAEBD7';
	elseif ($nik['color_nik'] == 165)$col ='D2B48C';
	elseif ($nik['color_nik'] == 166)$col ='DEB887';
	elseif ($nik['color_nik'] == 167)$col ='FFE4C4';
	elseif ($nik['color_nik'] == 168)$col ='FAF0E6';
	elseif ($nik['color_nik'] == 169)$col ='CD853F';
	elseif ($nik['color_nik'] == 170)$col ='FFDAB9';
	elseif ($nik['color_nik'] == 171)$col ='8B4513';
	elseif ($nik['color_nik'] == 172)$col ='FFF5EE';
	elseif ($nik['color_nik'] == 173)$col ='A0522D';
	elseif ($nik['color_nik'] == 174)$col ='FFA07A';
	elseif ($nik['color_nik'] == 175)$col ='E9967A';
	elseif ($nik['color_nik'] == 176)$col ='FFE4E1';
	elseif ($nik['color_nik'] == 177)$col ='FFFAFA';
	elseif ($nik['color_nik'] == 178)$col ='F08080';
	elseif ($nik['color_nik'] == 179)$col ='BC8F8F';
	elseif ($nik['color_nik'] == 180)$col ='CD5C5C';
	elseif ($nik['color_nik'] == 181)$col ='A52A2A';
	elseif ($nik['color_nik'] == 182)$col ='DC143C';
	elseif ($nik['color_nik'] == 183)$col ='FF69B4';
	elseif ($nik['color_nik'] == 184)$col ='FF1493';
	elseif ($nik['color_nik'] == 185)$col ='C71585';
	elseif ($nik['color_nik'] == 186)$col ='FF00FF';
	elseif ($nik['color_nik'] == 187)$col ='FF00FF';
	elseif ($nik['color_nik'] == 188)$col ='8B008B';
	elseif ($nik['color_nik'] == 189)$col ='800080';
	elseif ($nik['color_nik'] == 190)$col ='9400D3';
	elseif ($nik['color_nik'] == 191)$col ='9932CC';
	elseif ($nik['color_nik'] == 192)$col ='8A2BE2';
	elseif ($nik['color_nik'] == 193)$col ='0000FF';
	elseif ($nik['color_nik'] == 194)$col ='0000CD';
	elseif ($nik['color_nik'] == 195)$col ='00008B';
	elseif ($nik['color_nik'] == 196)$col ='000080';
	elseif ($nik['color_nik'] == 197)$col ='4169E1';
	elseif ($nik['color_nik'] == 198)$col ='1E90FF';
	elseif ($nik['color_nik'] == 199)$col ='00BFFF';
	elseif ($nik['color_nik'] == 200)$col ='00CED1';
	elseif ($nik['color_nik'] == 201)$col ='00FFFF';
	elseif ($nik['color_nik'] == 202)$col ='00FFFF';
	elseif ($nik['color_nik'] == 203)$col ='008B8B';
	elseif ($nik['color_nik'] == 204)$col ='008080';
	elseif ($nik['color_nik'] == 205)$col ='48D1CC';
	elseif ($nik['color_nik'] == 206)$col ='20B2AA';
	elseif ($nik['color_nik'] == 207)$col ='40E0D0';
	elseif ($nik['color_nik'] == 208)$col ='00FA9A';
	elseif ($nik['color_nik'] == 209)$col ='00FF7F';
	elseif ($nik['color_nik'] == 210)$col ='32CD32';
	elseif ($nik['color_nik'] == 211)$col ='00FF00';
	elseif ($nik['color_nik'] == 212)$col ='008000';
	elseif ($nik['color_nik'] == 213)$col ='7CFC00';
	elseif ($nik['color_nik'] == 214)$col ='7FFF00';
	elseif ($nik['color_nik'] == 215)$col ='ADFF2F';
	elseif ($nik['color_nik'] == 216)$col ='9ACD32';
	elseif ($nik['color_nik'] == 217)$col ='FFFF00';
	elseif ($nik['color_nik'] == 218)$col ='808000';
	elseif ($nik['color_nik'] == 219)$col ='FFD700';
	elseif ($nik['color_nik'] == 220)$col ='DAA520';
	elseif ($nik['color_nik'] == 221)$col ='B8860B';
	elseif ($nik['color_nik'] == 222)$col ='FFA500';
	elseif ($nik['color_nik'] == 223)$col ='FF8C00';
	elseif ($nik['color_nik'] == 224)$col ='F4A460';
	elseif ($nik['color_nik'] == 225)$col ='D2691E';
	elseif ($nik['color_nik'] == 226)$col ='FF4500';
	elseif ($nik['color_nik'] == 227)$col ='FF7F50';
	elseif ($nik['color_nik'] == 228)$col ='FF6347';
	elseif ($nik['color_nik'] == 229)$col ='FA8072';
	elseif ($nik['color_nik'] == 230)$col ='FF0000';
	elseif ($nik['color_nik'] == 231)$col ='B22222';
	elseif ($nik['color_nik'] == 232)$col ='8B0000';
	elseif ($nik['color_nik'] == 233)$col ='800000';
}

if ($nik['color_nik'] == 1) $name = GradientLetter($name, 'F90000', '00FF00');
elseif ($nik['color_nik'] == 2) $name = GradientLetter($name, 'FF0000', '000000');
elseif ($nik['color_nik'] == 3) $name = GradientLetter($name, 'EEE467', '384267');
elseif ($nik['color_nik'] == 4) $name = GradientLetter($name, 'F7FF0D', '1E49E6');
elseif ($nik['color_nik'] == 5) $name = GradientLetter($name, '000000', '00FF00');
elseif ($nik['color_nik'] == 6) $name = GradientLetter($name, 'EF33ED', 'EFCAF1');
elseif ($nik['color_nik'] == 7) $name = GradientLetter($name, '030303', '96A0A4');
elseif ($nik['color_nik'] == 8) $name = GradientLetter($name, '0000CD', '228B22');
elseif ($nik['color_nik'] == 9) $name = GradientLetter($name, '6B8E23', 'FF00FF');
elseif ($nik['color_nik'] == 10) $name = GradientLetter($name, '87CEEB', '000080');
elseif ($nik['color_nik'] == 11) $name = GradientLetter($name, 'FFD700', 'FF0000');
elseif ($nik['color_nik'] == 12) $name = GradientLetter($name, '6A5ACD', 'BC8F8F');
elseif ($nik['color_nik'] == 13) $name = colorNick($name);
if ($nik['color_nik'] == 1400) $name = nikColor($nik['user'],$nik['colornick']);

if ($nik['effnik']==2) 
{
	$name = '<b><span style="color: #background-color: #000000; text-shadow: -1px 0 Black, 0 1px Black, 1px 0 Black, 0 -1px Silver ; color: #'.$col.';  text-align: left; paddiing: 5px;">'.$name.'</span></b>';
}elseif($nik['color_nik']<233 or $nik['color_nik'] > 100)
{
	$name = ''.$name.'';
}else{
	$name = '<font color="#'.$col.'">'.$name.'</font>';
}


}

/*if ($user['ver']!='wml'){
////if ($nik['effnik']==1) $name = '<blink>'.$name.'</blink>';

if ($nik['color_nik']=='') $name = ''.$name.'';
else $name = '<font color="#'.$col.'">'.$name.'</font>';
}*/


if ($link==NULL)$link=''.H.$nik['id'].'';


if ($ref!=$user_system){ // Если не Систеа

if (isset($nik['id'])){ // Если пользователь существует

if ($user['pic_stat']==0){
if(!isset($rm) || isset($nk)){
return '<a href="/'.$link.'">'.$name.'</a>';
}else{
return '<a href="/'.$link.'">'.$name.'</a> ';
}
}else if ($user['pic_stat']==1){
if(!isset($rm) || isset($nk)){
return '<a href="/xstatus?nk='.$nik['id'].'">'.$on_off.'</a> <a href="/'.$link.'">'.$name.'</a>';
}else{
return '<a href="/xstatus?nk='.$nik['id'].'">'.$on_off.'</a> <a href="/'.$link.'">'.$name.'</a> ';
}

}else if ($user['pic_stat']==2){
if ($user['ver']!='wml'){
if(!isset($rm) || isset($nk)){
return '<a href="/xstatus?nk='.$nik['id'].'">'.$on_off.'</a> <a href="/'.$link.'">'.$name.'</a>';
}else{
return '<a href="/xstatus?nk='.$nik['id'].'">'.$on_off.'</a> <a href="/'.$link.'">'.$name.'</a> ';
}
}else{
if(!isset($rm) || isset($nk)){
return '<a href="/'.$link.'">'.$name.'</a>';
}else{
return '<a href="/'.$link.'">'.$name.'</a> ';
}
}
}else if ($user['pic_stat']==3){
if ($user['ver']=='wml'){
if(!isset($rm) || isset($nk)){
return '<a href="/xstatus?nk='.$nik['id'].'">'.$on_off.'</a> <a href="/'.$link.'">'.$name.'</a>';
}else{
return '<a href="/xstatus?nk='.$nik['id'].'">'.$on_off.'</a> <a href="/'.$link.'">'.$name.'</a> ';
}
}else{
if(!isset($rm) || isset($nk)){
return '<a href="/'.$link.'">'.$name.'</a>';
}else{
return '<a href="/'.$link.'">'.$name.'</a> ';
}
}
}


}else { // Пользователя нет
return '[Удален]';
}

}else{  // Система
return $ref;
}
}else return '<img src="'.H.'img/bot.gif" alt="" /> <a href="inside?rmmaf='.$rmmaf.'&amp;nk=0"><b>'.$ref.'</b></a> ';
}


function user($ref=NULL,$link=NULL)
{
global $db, $user, $ver, $rm, $usid, $name, $set, $sid,$time;

if(isset($ref)) $ref=check($ref);
if (!ctype_digit($ref)) {
$ruser = rus_to_k($ref);
$result = $db->sql_query ("Select * from users where ruser = '".$ruser."' LIMIT 1;");
} else {
$result = $db->sql_query ("Select * from users where id = '".$ref."' LIMIT 1;");
}
$nik = $db->sql_fetchrow ($result);

if ($link==NULL)return $nik['user'];
else if ($link==1) return '<a href="'.H.$nik['id'].'">'.$nik['user'].'</a>';

}

function NameUser($ref=NULL)
{
global $db, $user, $name, $set;

$r = abs(intval($ref));
if(isset($r) and $r != 0)
	{
		$result = $db->sql_query ("SELECT `user` FROM `users` WHERE `id` = '".$r."' LIMIT 1;");
		$nik = $db->sql_fetchrow ($result);
		return $nik['user'];
	}else
	{	
		return '<font color="red">'.$set['system'].'</font>';
	}
}

function user_inf($ref=NULL,$w=NULL)
{
global $db, $user, $ver, $rm, $usid, $name, $set, $sid,$time;
if(isset($ref)) $ref=check($ref);

if (!ctype_digit($ref)) {
$ruser = rus_to_k($ref);
$result = $db->sql_query ("Select * from users where ruser = '".$ruser."' LIMIT 1;");
} else {
$result = $db->sql_query ("Select * from users where id = '".$ref."' LIMIT 1;");
}
$nik = $db->sql_fetchrow ($result);

if ($w==NULL)return esc2($nik['id']);
else return esc2($nik[$w]);
}


function friends($f1=NULL,$f2=NULL,$w=NULL)
{
global $db, $user, $ver, $rm, $usid, $name, $set, $sid,$time;
if(isset($f1)) $f1=check($f1);
if(isset($f2)) $f2=check($f2);
if(isset($w)) $w=check($w);
$f = $db->sql_fetchrow($db->sql_query("Select * from friends WHERE `user_id` = '$f2' and `fr_id` = '$f1' and yes = '1'"));
if ($w==NULL){
if ($f1!=$f2){
if (isset($f['id']))return '1';
else return '0';
}else{
return '1';
}

}else{
if (isset($f['id']))return $f[$w];
}
}

if (!defined('vb4')) die("");

function ignor($f1=NULL,$f2=NULL,$w=NULL)
{
global $db, $user, $ver, $rm, $usid, $name, $set, $sid,$time;
if(isset($f1)) $f1=check($f1);
if(isset($f2)) $f2=check($f2);
if(isset($w)) $w=check($w);
$f = $db->sql_fetchrow($db->sql_query("Select * from ignor WHERE `user_id` = '$f1' and `ig_id` = '$f2'"));
if ($w==NULL){
if ($f1!=$f2){
if (isset($f['id']))return '1';
else return '0';
}else{
return '0';
}

}else{
if (isset($f['id']))return $f[$w];
}
}


function aut($link = NULL) // только для зарегистрированиых
{
global $db, $user;
if (!isset($user['id']))
{
if ($link==NULL)$link=H.'aut?';
header("Location: $link".SID);exit;
}
}

function unaut($link = NULL) // только для незарегистрированых
{
global $db, $user;
if (isset($user['id']))
{
if ($link==NULL)$link=H.'index?';
header("Location: $link".SID);exit;
}
}

function levels($level=0,$link = NULL) // только для тех, у кого уровень доступа больше или равен $level
{
global $db, $user;
if (!isset($user['id']) || $user['level']<$level )
{
if ($link==NULL)$link='/index?';
header("Location: $link&".SID);exit;
}
}

function LevelsForum($level=0,$link = NULL) // только для тех, у кого уровень доступа больше или равен $level
{
global $db, $user;
if (!isset($user['id']) || $user['level']<$level)
{
	///if($user['id'] == 456){}else
	
		if ($link==NULL)$link='/index?';
		header("Location: $link&".SID);exit;
	
}
}
function LevelsObmennik($level=0,$link = NULL) // только для тех, у кого уровень доступа больше или равен $level
{
global $db, $user;
if (!isset($user['id']) || $user['level']<$level)
{
	///if($user['id'] == 477){}else
	
		if ($link==NULL)$link='/index?';
		header("Location: $link&".SID);exit;
	
}
}

function posts_add()
{
global $db, $user;

if (isset($user['id']))
{
$user['posts']++;
$user['dayp']++;
$db->sql_query("UPDATE `users` SET `posts` = '$user[posts]', dayp = '$user[dayp]' WHERE `id` = '$user[id]';");
}
}

function postsf_add()
{
global $db, $user;

if (isset($user['id']))
{
$user['postsf']++;
$user['posts']++;
$user['dayp']++;
$db->sql_query("UPDATE `users` SET `postsf` = '$user[postsf]',`posts` = '$user[posts]', dayp = '$user[dayp]' WHERE `id` = '$user[id]';");
}
}

function cred_add()
{
global $db, $user;

if (isset($user['id']))
{
$user['credits']++;
$user['daya']++;
$db->sql_query("UPDATE `users` SET `credits` = '$user[credits]', `daya` = '$user[daya]' WHERE `id` = '$user[id]';");
}
}

function who_add($rm=0,$room = NULL)
{
	global $db, $user, $time, $set,$ip,$soft,$soft_opera,$size_display,$inpass;
	$db->sql_query("DELETE FROM `who` WHERE `user` = '".$user['id']."'");
	$db->sql_query("DELETE FROM `who` WHERE `time` < '".((int)$time-$set['time_aut'])."'");
		if (isset($user['id']))
		{
			if($user['id']!=0 and $user['inviz']!=1)
			{
				$db->sql_query("INSERT INTO `who` (user,time,room,rm,inps) values ('".$user['id']."', '".$time."', '".$room."', '".$rm."', '".$inpass."')");
				$db->sql_query('UPDATE `users` SET `onl` = "'.$time.'", `user_ip` = "'.$ip.'", `user_soft` = "'.$soft.'",`user_soft_opera` = "'.$soft_opera.'",`size_display` = "'.$size_display.'"  WHERE `id` = "'.$user['id'].'";');
			}
			if($user['viz']!=date("d"))$db->sql_query('UPDATE `users` SET `viz` = "'.date("d").'", `daya` = "0", `dayp` = "0"  WHERE `id` = "'.$user['id'].'";');

		}
}

function medal($user=NULL)
{
global $db, $set;
$user = check($user);
$adm = $db->sql_fetchrow($db->sql_query("SELECT * from `users` where `id`='$user' limit 1;"));
if ($adm['balls']>=500 ){echo "<img src='/img/medal_bronze.gif' alt=''/>";
}else
if ($adm['balls']>=1000){echo "<img src='/img/medal_silver.gif' alt=''/>";
}else{
if ($adm['balls']>=5000)echo "<img src='/img/medal_gold.gif' alt=''/>";}
}

?>