<?
/*
function clear_arena(){
$time=time();
///////
$req = mysql_querll("SELECT * FROM `arena` WHERE `timer`<'$time'");

While($inv = mysql_fetch_assoc($req))
{

mysql_querll("DELETE FROM `arena` WHERE id='$inv[id]'");//чистим заявки

}
}
*/

//function admin_mod($id){return ($id=='1' || $id=='18043' || $id=='911' || $id=='4' || $id=='12300' || $id=='3521');}

function admin_mod($id){return ($id=='1');}

function razdelen($num){
return number_format($num,0,'',"'");
}

function normal_number($num){
return number_format($num,0,'','');
}

function plat_rol($id, $znash){
global $ku;
if($ku['id']!=$id){$inf_rol = mysql_fetch_assoc(mysql_querll('SELECT `id`,`plat_rol_time`,`plat_rol` FROM `kolhoz_user` WHERE `id`="'.$id.'"'));
} else {$inf_rol = $ku;}
if($inf_rol['plat_rol_time']>time()){
if($inf_rol['plat_rol']=='blatnoy'){$dost = array('vhod_v_kh');}
if(in_array($znash,$dost)){return true;} else {return false;}
} else {return false;}
}

function plat_rol_name($id){
global $ku;
if($ku['id']!=$id){$inf_rol = mysql_fetch_assoc(mysql_querll('SELECT `id`,`plat_rol_time`,`plat_rol` FROM `kolhoz_user` WHERE `id`="'.$id.'"'));
} else {$inf_rol = $ku;}
if($inf_rol['plat_rol_time']>time()){
if($inf_rol['plat_rol']=='blatnoy'){return 'Блатной';}
else {return '';}
} else {return '';}
}
//============
function med($id){
$ank = mysql_fetch_assoc(mysql_querll('SELECT `date_last`,`level`,`status`,`time` FROM `kolhoz_user` WHERE `id`="'.$id.'"'));

if ($ank['time']>=3601*3 && $ank['time']<=3600*5){echo " <img width='14' height='17' src='/img/medal/1.png' alt='!'/> ";}//от 1ч до 5ч
if ($ank['time']>=3601*5 && $ank['time']<=3600*12){echo " <img width='14' height='17' src='/img/medal/2.png' alt='!'/> ";}//от 5ч до 12ч
if ($ank['time']>=3601*12 && $ank['time']<=3600*18){echo " <img width='14' height='17' src='/img/medal/3.png' alt='!'/> ";}//от 12ч до 18ч
if ($ank['time']>=3601*18 && $ank['time']<=3600*24){echo " <img width='14' height='17' src='/img/medal/4.png' alt='!'/> ";}//от 18ч до 24ч(1дн)
if ($ank['time']>=3601*24 && $ank['time']<=3600*30){echo " <img width='14' height='17' src='/img/medal/5.png' alt='!'/> ";}//от 24ч до 30ч
if ($ank['time']>=3601*30 && $ank['time']<=3600*40){echo " <img width='14' height='17' src='/img/medal/6.png' alt='!'/> ";}//от 30ч до 40ч
if ($ank['time']>=3601*40 && $ank['time']<=3600*48){echo " <img width='14' height='17' src='/img/medal/7.png' alt='!'/> ";}//от 40ч до 48ч(2дн)
if ($ank['time']>=3601*48 && $ank['time']<=3600*60){echo " <img width='14' height='17' src='/img/medal/8.png' alt='!'/> ";}//от 48ч до 60ч
if ($ank['time']>=3601*60 && $ank['time']<=3600*72){echo " <img width='14' height='17' src='/img/medal/9.png' alt='!'/> ";}//от 60 до 72(3дн)
if ($ank['time']>=3601*72 && $ank['time']<=3600*96){echo " <img src='/img/medal/10.gif' alt='!'/> ";}//от 72 до 96(4дн)
if ($ank['time']>=3601*96 && $ank['time']<=3600*120){echo " <img src='/img/medal/11.gif' alt='!'/> ";}//от 96 до 120(5дн)
if ($ank['time']>=3601*120 && $ank['time']<=3600*144){echo " <img src='/img/medal/12.gif' alt='!'/> ";}//от 120 до 144(6дн)
if ($ank['time']>=3601*144 && $ank['time']<=3600*168){echo " <img src='/img/medal/13.gif' alt='!'/> ";}//от 144 до 168(7дн)
if ($ank['time']>=3601*168 && $ank['time']<=3600*192){echo " <img src='/img/medal/14.gif' alt='!'/> ";}//от 168 до 192(8дн)
if ($ank['time']>=3601*192 && $ank['time']<=3600*216){echo " <img src='/img/medal/15.gif' alt='!'/> ";}//от 192 до 216(9дн)
if ($ank['time']>=3601*216 && $ank['time']<=3600*240){echo " <img src='/img/medal/16.gif' alt='!'/> ";}//от 216 до 240(10дн)

if ($ank['time']>=3601*240 && $ank['time']<=3600*264){echo " <img src='/img/medal/17.png' alt='!'/> ";}//от 120 до 144(11дн)
if ($ank['time']>=3601*264 && $ank['time']<=3600*288){echo " <img src='/img/medal/18.png' alt='!'/> ";}//от 144 до 168(12дн)
if ($ank['time']>=3601*288 && $ank['time']<=3600*312){echo " <img src='/img/medal/19.png' alt='!'/> ";}//от 168 до 192(13дн)
if ($ank['time']>=3601*312 && $ank['time']<=3600*336){echo " <img src='/img/medal/20.png' alt='!'/> ";}//от 192 до 216(14дн)
if ($ank['time']>=3601*336 && $ank['time']<=3600*360){echo " <img src='/img/medal/21.png' alt='!'/> ";}//от 216 до 240(15-16дн)


}
//==============

function nc($id){
$ank = mysql_fetch_assoc(mysql_querll('SELECT `date_last`,`color_nick`,`elysium_open`,`nick`,`plat_rol_time`,`plat_rol`,`status` FROM `kolhoz_user` WHERE `id`="'.$id.'"'));

$sek = time()-30;
$min = time()-60;
$dmin = time()-120;
$tmin = time()-180;
$cmin = time()-240;
$pmin = time()-300;




if ($ank['date_last']>=$min  &&  $ank['date_last']<=$sek){
$off=" <img width='10' height='10' src='img/zvezda/1.png' alt='*'>";
}
elseif ($ank['date_last']>=$dmin  &&  $ank['date_last']<=$min){
$off=" <img width='10' height='10' src='img/zvezda/2.png' alt='*'>";
}
elseif ($ank['date_last']>=$tmin  &&  $ank['date_last']<=$dmin){
$off=" <img width='10' height='10' src='img/zvezda/3.png' alt='*'>";
}
elseif ($ank['date_last']>=$cmin  &&  $ank['date_last']<=$tmin){
$off=" <img width='10' height='10' src='img/zvezda/4.png' alt='*'>";
}
elseif ($ank['date_last']>=$pmin  &&  $ank['date_last']<=$cmin){
$off=" <img width='10' height='10' src='img/zvezda/5.png' alt='*'>";
}
elseif ($ank['date_last']>=$pmin  &&  $ank['date_last']<=$pmin){
$off=" <img width='10' height='10' src='img/zvezda/6.png' alt='*'>";
}
else $off="";


$test = time()-600;
$tar = time()-9999999*999;
if ($ank['date_last']>=$tar  &&  $ank['date_last']<=$test){
$offi="</span><span class='small minors'>";

}



if($ank['color_nick']!='' && $ank['elysium_open']==1){
return "<span class='nick".$ank['color_nick']."'>$offi".$ank['nick'].$off."</span>";
}
if($ank['color_nick']!=''){
return "<span class='nick".$ank['color_nick']."'>$offi".$ank['nick'].$off."</span>";
}
if($ank['plat_rol_time']>time()){
return "<span class='nick".($ank['plat_rol']=='blatnoy'?'Plat_rol_1':null)."'>$offi$ank[nick]$off</span>";
}

return "<span class='nick".($ank['status']==1?"Supporter":null)."".($ank['status']==2?"Moderator":null)."".($ank['status']==3?"Admin":null)."".($ank['status']==4?"Modf":null)."".($ank['status']==5?"Modc":null)."'>$offi$ank[nick]$off</span>";
}

function output_text($str,$user=0){
$uk=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$user'"));
$str=htmlentities($str, ENT_QUOTES, 'UTF-8'); // преобразуем все к нормальному перевариванию браузером
$q=mysql_querll("SELECT * FROM `kolhoz_smiles` ORDER BY `id` ASC");
while($post=mysql_fetch_array($q)){
$n=explode(',',$post['name']);
$nn=NULL;
foreach($n as $key => $value){
$str=str_replace($value,"<img src='img/smiles/$post[img]' alt='o'/>",$str);
}
}

$q=mysql_querll("SELECT * FROM `kolhoz_spam` ORDER BY `id` ASC");
while($post=mysql_fetch_array($q)){
$n=explode(',',$post['name']);
$nn=NULL;
foreach($n as $key => $value){
if($post['nadpis']==1){$str=str_replace($value,"<img src='img/spam/$post[img]' alt='o'/>",$str);}
else
if($post['nadpis']==0){$str=str_replace($value,"<b>[Реклама]</b>",$str);}}
}

if($uk['status']>0 || $uk['plat_rol_time']>time()){
$str=links($str); // обработка ссылок
if($uk['plat_rol_time']>time()){
$str="<span class='nick".($uk['plat_rol']=='blatnoy'?'Plat_rol_1':null)."'>$str</span>";
} else {
$str="<span class='nick".($uk['status']==1?"Supporter":null)."".($uk['status']==2?"Moderator":null)."".($uk['status']==3?"Admin":null)."".($uk['status']==4?"Modf":null)."".($uk['status']==5?"Modc":null)."'>$str</span>";
}
$bbcode=array();
$bbcode['/\[img](.+)\[\/img\]/isU']='<img src="$1"/>';
$bbcode['/\[color=(.+)\](.+)\[\/color\]/isU']='<span style="color:$1">$2</span>';
$bbcode['/\[i\](.+)\[\/i\]/isU']='<i>$1</i>';
$bbcode['/\[s\](.+)\[\/s\]/isU']='<s>$1</s>';
$bbcode['/\[b\](.+)\[\/b\]/isU']='<b>$1</b>';
$bbcode['/\[u\](.+)\[\/u\]/isU']='<u>$1</u>';
$bbcode['/\[size=([0-9]+)\](.+)\[\/size\]/isU']='<span style="font-size:$1px;">$2</span>';
if (count($bbcode)){$str= preg_replace(array_keys($bbcode), array_values($bbcode), $str);}
}
$str=br($str); // переносы строк
return stripslashes($str); // возвращаем обработанную строку
}

function cpgs($count){
$count=$count+1;
if($count>=0 && $count<=9)$cena=1;
elseif($count>=10 && $count<=19)$cena=2;
elseif($count>=20 && $count<=29)$cena=5;
elseif($count>=30 && $count<=39)$cena=10;
elseif($count>=40 && $count<=49)$cena=15;
elseif($count>=50 && $count<=59)$cena=20;
elseif($count>=60 && $count<=69)$cena=25;
elseif($count>=70 && $count<=79)$cena=50;
elseif($count>=80 && $count<=89)$cena=100;
elseif($count>=90 && $count<=99)$cena=250;
elseif($count>=100 && $count<=150)$cena=500;
elseif($count>=160 && $count<=200)$cena=1000;
else $cena=1500;
return $cena;
}

function on_k($id){
$usk = mysql_fetch_assoc(mysql_querll('SELECT `iconka`,`level`,`status`,`pol`,`date_last` FROM `kolhoz_user` WHERE `id`="'.$id.'"'));
$us=$usk;
$t = time() - 600;
if($usk['date_last']<=$t){

}
if($us['pol']==1){$i="2.png";}
if($us['pol']==0){$i="24.png";}

//if ($usk['pol'] == 1){echo "<img width='16' height='16' src='img/icons/on.png' alt='o'>";}
if(!empty($usk['iconka'])){$i = $usk['iconka'].'.png';}
$rez_ic = '<img src="img/iconka/'.$i.'" alt="o"/>';
return $rez_ic;
}

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?"$day д. ":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 rating($rating_qq){
$rating = normal_number($rating_qq);
$e=floor($rating/1000000000000000000);
$p=floor($rating/1000000000000000);
$t=floor($rating/1000000000000);
$g=floor($rating/1000000000);
$m=floor($rating/1000000);
$k=floor($rating/1000);

if($e!=0){
$e=$rating/1000000000000000000;
$rating=round($e,2);
$rating = $rating.'e';
}
elseif($p!=0){
$p=$rating/1000000000000000;
$rating=round($p,2);
$rating = $rating.'p';
}
elseif($t!=0){
$t=$rating/1000000000000;
$rating=round($t,2);
$rating = $rating.'t';
}
elseif($g!=0){
$g=$rating/1000000000;
$rating=round($g,2);
$rating = $rating.'g';
}
elseif($m!=0){
$m=$rating/1000000;
$rating=round($m,2);
$rating = $rating.'m';
}
elseif($k!=0){
$k=$rating/1000;
$rating=round($k,2);
$rating = $rating.'k';
}
else $rating=(int)$rating;
return $rating;
}

function rl2($lr){
$llr=$lr+1;
if($llr==2)$lr=25;
elseif($llr==3)$lr=75;
elseif($llr==4)$lr=150;
elseif($llr==5)$lr=300;
elseif($llr==6)$lr=500;
elseif($llr==7)$lr=1000;
elseif($llr==8)$lr=1500;
elseif($llr==9)$lr=3000;
elseif($llr==10)$lr=5000;
elseif($llr==11)$lr=7500;
elseif($llr==12)$lr=10000;
else $lr=0;
return $lr;
}

function minus_money($money){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `money` = '".($ku['money']-$money)."' WHERE `id` = '$ku[id]'");
return ($ku['money']-$money);
}

function minus_rubies($rubies){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']-$rubies)."' WHERE `id` = '$ku[id]'");
return ($ku['rubies']-$rubies);
}

function minus_zkl($zkl){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `zkl` = '".($ku['zkl']-$zkl)."' WHERE `id` = '$ku[id]'");
return ($ku['zkl']-$zkl);
}

function minus_euro($euro){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `euro` = '".($ku['euro']-$euro)."' WHERE `id` = '$ku[id]'");
return ($ku['euro']-$euro);
}

function plus_money($money){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$money)."' WHERE `id` = '$ku[id]'");
return ($ku['money']+$money);
}

function plus_almaz($almaz){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `almaz` = '".($ku['almaz']+$almaz)."' WHERE `id` = '$ku[id]'");
return ($ku['almaz']+$almaz);
}
//==

function plus_zima($zima){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `zima` = '".($ku['zima']+$zima)."' WHERE `id` = '$ku[id]'");
return ($ku['zima']+$zima);
}
//==
function plus_rating($rating){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `rating` = '".($ku['rating']+$rating)."' WHERE `id` = '$ku[id]'");
return ($ku['rating']+$rating);
}

function plus_zont($zont){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `zont` = '".($ku['zont']+$zont)."' WHERE `id` = '$ku[id]'");
return ($ku['zont']+$zont);
}

function plusa_money($money){
global $ank;
mysql_querll("UPDATE `kolhoz_user` SET `money` = '".($ank['money']+$money)."' WHERE `id` = '$ank[id]'");
return ($ank['money']+$money);
}

function plus_rubies($rubies){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+$rubies)."' WHERE `id` = '$ku[id]'");
return ($ku['rubies']+$rubies);
}

function plusa_rubies($rubies){
global $ank;
mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ank['rubies']+$rubies)."' WHERE `id` = '$ank[id]'");
return ($ank['rubies']+$rubies);
}

function cpw($count){
$count=$count+1;
if($count==1)$cena=25;
elseif($count==2)$cena=50;
elseif($count==3)$cena=100;
elseif($count==4)$cena=500;
elseif($count==5)$cena=1500;
elseif($count==6)$cena=3000;
else $cena=0;
return $cena;
}

function rl($lr){
$llr=$lr+1;
if($llr==2)$lr=1;
elseif($llr==3)$lr=3;
elseif($llr==4)$lr=5;
elseif($llr==5)$lr=10;
elseif($llr==6)$lr=25;
elseif($llr==7)$lr=50;
elseif($llr==8)$lr=100;
elseif($llr==9)$lr=250;
elseif($llr==10)$lr=500;
elseif($llr==11)$lr=1000;
elseif($llr==12)$lr=2000;
else $lr=0;
return $lr;
}

function cpg($count){
$count=$count+1;
if($count==5)$cena=1000;
elseif($count==6)$cena=2500;
elseif($count==7)$cena=3000;
elseif($count==8)$cena=5000;
elseif($count==9)$cena=7000;
elseif($count>=10 && $count<=12)$cena=8000;
elseif($count>=13 && $count<=20)$cena=9000;
elseif($count>=21 && $count<=25)$cena=10000;
elseif($count>=26 && $count<=27)$cena=13000;
elseif($count>=28 && $count<=29)$cena=20000;
elseif($count>=30 && $count<=35)$cena=50000;
elseif($count>=36 && $count<=40)$cena=100000;
elseif($count>=41 && $count<=49)$cena=5000000;
elseif($count>=50 && $count<=59)$cena=1000000;
elseif($count>=60 && $count<=69)$cena=3000000;
elseif($count>=70 && $count<=79)$cena=50000000;
elseif($count>=80 && $count<=89)$cena=80000000;
elseif($count>=90 && $count<=99)$cena=100000000;
elseif($count>=100 && $count<=109)$cena=300000000;
elseif($count>=110 && $count<=119)$cena=500000000;
elseif($count>=120 && $count<=129)$cena=800000000;
elseif($count>=130 && $count<=139)$cena=1000000000;
elseif($count>=140 && $count<=149)$cena=2000000000;
elseif($count>=150 && $count<=159)$cena=5000000000;
elseif($count>=160 && $count<=169)$cena=6000000000;
elseif($count>=170 && $count<=179)$cena=8000000000;
elseif($count>=180 && $count<=189)$cena=10000000000;
elseif($count>=190 && $count<=199)$cena=20000000000;
elseif($count>=200)$cena=26582000000;
else $cena=0;
return $cena;
}

//цены на шахты
function cpsh($count, $alm){
$count++;
if($alm == true){$cena = ($count*100000000)*7;}
elseif($count<4){$cena = $count*100;} else {$cena = $count*100000000;}
return $cena;
}

//цены на белты в алмазной
function cp_belts($count){
$result = $count+=1;
return $result;
}

function cpf($count){
$count=$count+1;
if($count==5)$cena=1000;
elseif($count==6)$cena=2500;
elseif($count==7)$cena=3000;
elseif($count==8)$cena=5000;
elseif($count==9)$cena=7000;
elseif($count>=10 && $count<=12)$cena=8000;
elseif($count>=13 && $count<=20)$cena=9000;
elseif($count>=21 && $count<=25)$cena=10000;
elseif($count>=26 && $count<=27)$cena=13000;
elseif($count>=28 && $count<=29)$cena=20000;
elseif($count>=30 && $count<=35)$cena=50000;
elseif($count>=36 && $count<=40)$cena=100000;
elseif($count>=41 && $count<=49)$cena=5000000;
elseif($count>=50 && $count<=59)$cena=1000000;
elseif($count>=60 && $count<=69)$cena=3000000;
elseif($count>=70 && $count<=79)$cena=50000000;
elseif($count>=80 && $count<=89)$cena=80000000;
elseif($count>=90 && $count<=99)$cena=100000000;
elseif($count>=100 && $count<=109)$cena=300000000;
elseif($count>=110 && $count<=119)$cena=500000000;
elseif($count>=120 && $count<=129)$cena=800000000;
elseif($count>=130 && $count<=139)$cena=1000000000;
elseif($count>=140 && $count<=149)$cena=2000000000;
elseif($count>=150 && $count<=159)$cena=5000000000;
elseif($count>=160 && $count<=169)$cena=6000000000;
elseif($count>=170 && $count<=179)$cena=8000000000;
elseif($count>=180 && $count<=189)$cena=10000000000;
elseif($count>=190 && $count<=199)$cena=20000000000;
elseif($count>=200)$cena=26582000000;
else $cena=0;
return $cena;
}


function err_game($msg)
{
echo "<div class='feedback'><ul class='feedbackPanel'><li class='feedbackPanelERROR'><span class='feedbackPanelERROR'>$msg</span></li></ul></div>";
}

function no_rubies($rubies){
echo "<div class='feedback'><ul><li class='title'>У Вас не хватает <span>рубинов</span>:<img width='16' height='16' src='img/icons/ruby.png' alt='o'> <span>".floor($rubies)."</span></li><li></li><li><img width='16' height='16' src='img/icons/ruby.png' alt='o'>
<a href='?payment'>Купить</a></li><li><img width='16' height='16' src='img/icons/converter.png' alt='o'> <a href='?converter'>Обменять</a></li></ul></div>";
}

function no_zkl($zkl){
echo "<div class='feedback'><ul><li class='title'>У Вас не хватает <span>Золотых ключей</span>:<img width='16' height='16' src='img/icons/zkl.png' alt='o'> <span>".floor($zkl)."</span></li><li></li><li><img width='16' height='16' src='img/icons/zkl.png' alt='o'>
<a href='?payment'>Купить</a></li></ul></div>";
}

function no_euro($euro){
echo "<div class='feedback'><ul><li class='title'>У Вас не хватает <span>Евро</span>:<img width='16' height='16' src='img/euro.png' alt='o'> <span>".floor($euro)."</span></li><li></li><li><img width='16' height='16' src='img/euro.png' alt='o'>
<a href='?payment'>Купить</a></li></ul></div>";
}

function no_money($money){
echo "<div class='feedback'><ul><li class='title'>У Вас не хватает <span>монет</span>:<img width='16' height='16' src='img/icons/money.png' alt='o'> <span>".floor($money)."</span></li><li></li><li><img width='16' height='16' src='img/icons/warehouse.png' alt='o'>
<a href='?warehouse'>Продать товар из амбара</a></li><li><img width='16' height='16' src='img/icons/converter.png' alt='o'> <a href='?converter'>Обменять</a></li></ul></div>";
}

function hsc($text){
return htmlspecialchars($text);
}

function update_mc($rating){
global $mc,$mcu,$ku,$time;
if($mcu){
$rating=$rating*1.6;
mysql_querll("UPDATE `kolhoz_collective` SET `rating` = '".($mc['rating']+$rating)."' WHERE `id` = '$mc[id]'");
mysql_querll("UPDATE `kolhoz_collective_user` SET `rating` = '".($mcu['rating']+$rating)."' WHERE `id` = '$mcu[id]'");
mysql_querll("INSERT INTO `kolhoz_collective_rating` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$rating', `time` = '$time'");
}
}

function podtv($yes_link,$no_link){
echo '<div class="event"><h1>Подтверждение</h1></div><div class="content"><ul class="block"><li><span class="title">Вы уверены?</span></li><li class="pt"><img alt="" width="16" height="16" src="img/icons/tick.png"> <a href="'.$yes_link.'"><span>Да, подтверждаю</span></a></li><li><img alt="" width="16" height="16" src="img/icons/cross.png"> <a href="'.$no_link.'"><span>
Нет, отказываюсь</span></a></li></ul>';
}

function no_money_ct($money){
global $mc;
echo "<div class='feedback'>\n
<ul>\n
<li class='title'>В колхозной кассе не хватает <span>монет</span>: <img width='16' height='16' src='img/icons/money.png' alt='o'> <span>".floor($money)."</span></li>\n
<li>В кассу может внести средства любой житель колхоза добровольно или через налоги.</li>\n
<li><a href='?collective=$mc[id]&cash'>Пополнить кассу</a></li>\n
<li><a href='?collective=$mc[id]&taxes'>В налоговую</a></li>\n
</ul>\n
</div>\n";
}

function no_rubies_ct($rubies){
global $mc;
echo "<div class='feedback'>\n
<ul>\n
<li class='title'>В колхозной кассе не хватает <span>рубинов</span>: <img width='16' height='16' src='img/icons/ruby.png' alt='o'> <span>".floor($rubies)."</span></li>\n
<li>В кассу может внести средства любой житель колхоза.</li>\n
<li><a href='?collective=$mc[id]&cash'>Пополнить кассу</a></li>\n
<li><a href='?collective=$mc[id]&flowerbed'>На клумбу</a></li>\n
</ul>\n
</div>\n";
}

function harvest($harvest){
echo "<div class='feedback'><img width='16' height='16' src='img/icons/seat.png' alt='o'>Собрано: <span>".floor($harvest)." шт.</span>";
echo "</div>";
}

function first_function(){
echo "<div class='feedback'>Вы нашли <img width='16' height='16' src='img/icons/colors.png' alt='o'>  <span>зонтик</span></div>";
}

function harvest2($harvest2){
echo "<div class='feedback'><img width='16' height='16' src='img/icons/recipes.png' alt='o'>Готово: <span>".floor($harvest2)." банок</span></div>";
}

function harvest3($harvest3){
echo "<div class='feedback'>Вы нашли<img width='16' height='16' src='img/icons/colors.png' alt='o'> <span>зонтик</span>";
echo "</div>";
}

function ratingg($rating){
echo "<div class='feedback'><img width='16' height='16' src='img/icons/experience.png' alt='o'>Опыт +<span>".floor($rating)."</span></div>";
}


function money($money){
global $mc,$ku,$mcu;
echo "<div class='feedback'><img width='16' height='16' src='img/icons/money.png' alt='o'>Доход: <span>".floor($money)." монет.</span>";
if($mc['nalog']>0){
$nmoney=floor(($money/100)*$mc['nalog']);
mysql_querll("UPDATE `kolhoz_user` SET `umoney` = '0' WHERE `id` = '$ku[id]'");
echo " <span class='minor'>(колхозный налог <span><img
width='16' height='16' src='img/icons/money.png' alt='o'> <span class='title'>$nmoney</span></span>)</span>";
}
mysql_querll("UPDATE `kolhoz_user` SET `umoney` = '0' WHERE `id` = '$ku[id]'");
echo "</div>";
}

function msg_game($msg){
echo "<div class='feedback'><ul class='feedbackPanel'><li class='feedbackPanelINFO'><span class='feedbackPanelINFO'>".hsc($msg)."</span></li></ul></div>";
}

function br($msg,$br='<br />'){
return preg_replace("#((<br( ?/?)>)|\n|\r)+#i",$br, $msg);
} // переносы строк

function my_esc($str){
return mysql_real_escape_string($str);
}

function links_preg1($arr){
global $set;
if(preg_match('#^http://'.preg_quote($_SERVER['HTTP_HOST']).'#',$arr[1]) || !preg_match('#://#',$arr[1])){
return '<a href="'.$arr[1].'">'.$arr[2].'</a>';
} else {
return '<a'.($set['web']?' target="_blank"':null).' href="http://'.$_SERVER['HTTP_HOST'].'/?go='.base64_encode(html_entity_decode($arr[1])).'">'.$arr[2].'</a>';
}
}

function links_preg2($arr){
global $set;
if(preg_match('#^http://'.preg_quote($_SERVER['HTTP_HOST']).'#',$arr[2])){
return $arr[1].'<a href="'.$arr[2].'">'.$arr[2].'</a>'.$arr[4];
} else {
return $arr[1].'<a'.($set['web']?' target="_blank"':null).' href="http://'.$_SERVER['HTTP_HOST'].'/?go='.base64_encode(html_entity_decode($arr[2])).'">'.$arr[2].'</a>'.$arr[4];
}
}

function links($msg){
global $set;
$msg=preg_replace_callback('/\[url=(.+)\](.+)\[\/url\]/isU', 'links_preg1', $msg); 
$msg=preg_replace_callback('~(^|\s)([a-z]+://([^ \r\n\t`\'"]+))(\s|$)~iu', 'links_preg2', $msg);
return $msg;
}

function strlen2($str){
$rus=array('й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф','ы','в','а','п','р','о','л','д','ж','э','я','ч','с','м','и','т','ь','б','ю','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф','Ы','В','А','П','Р','О','Л','Д','Ж','Э','Я','Ч','С','М','И','Т','Ь','Б','Ю');
return strlen(str_replace($rus, '0', $str));
}

function page($k_page=1){ // Выдает текущую страницу
$page=1;
if (isset($_GET['page'])){
if ($_GET['page']=='end')$page=intval($k_page);elseif(is_numeric($_GET['page'])) $page=intval($_GET['page']);}
if ($page<1)$page=1;
if ($page>$k_page)$page=$k_page; return $page;}
 
function k_page($k_post=0,$k_p_str=10){ // Высчитывает количество страниц
if ($k_post!=0){$v_pages=ceil($k_post/$k_p_str);return $v_pages;}
else return 1;}
 
function str($link='?',$k_page=1,$page=1){ // Вывод номеров страниц (только на первый взгляд кажется сложно ;))
if ($page<1)$page=1;
echo "<div class='block'>";
if ($page>1)echo "<a href=\"".$link."page=".($page-1)."\" title='Предыдущая страница (№".($page-1).")'>&#171; Назад </a> | ";
echo " ";
if ($page<$k_page)echo " <a href=\"".$link."page=".($page+1)."\" title='Следующая страница (№".($page+1).")'>Далее &#187;</a>";
echo "<br />\n";
if ($page!=1)echo "<a href=\"".$link."page=1\" title='Первая страница'>[&#171;&#171;]</a> ";
if ($page!=1)echo "<a href=\"".$link."page=1\" title='Страница №1'>[1]</a>";else echo "<b>[1]</b>";
for ($ot=-3; $ot<=3; $ot++){
if ($page+$ot>1 && $page+$ot<$k_page){
if ($ot==-3 && $page+$ot>2)echo " ..";
if ($ot!=0)echo " <a href=\"".$link."page=".($page+$ot)."\" title='Страница №".($page+$ot)."'>[".($page+$ot)."]</a>";else echo " <b>[".($page+$ot)."]</b>";
if ($ot==3 && $page+$ot<$k_page-1)echo " ..";}}
if ($page!=$k_page)echo " <a href=\"".$link."page=end\" title='Страница №$k_page'>[$k_page]</a>";elseif ($k_page>1)echo " <b>[$k_page]</b>";
if ($page!=$k_page)echo " <a href=\"".$link."page=end\" title='Последняя страница'>[&#187;&#187;]</a>";
echo "</div>\n";}

function vremja($num){
if((date("Y",$num)==date("Y"))&&(date("z",$num)==(date("z")-1))){$result = 'Вчера в '.date("H:i",$num);}
elseif((date("Y",$num)==date("Y"))&&(date("z",$num)==date("z"))){$result = 'Сегодня в '.date("H:i",$num);} else {
if(date("Y",$num)==date("Y")){$result_init = date("d M H:i",$num);} else {$result_init = date("d M Y в H:i",$num);}
$str_is = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$str_res = array('Янв','Фев','Мар','Апр','Май','Июн','Июл','Авг','Сен','Окт','Ноя','Дек');
$result = str_replace($str_is, $str_res, $result_init);}
return $result;
}

function rubies($rubies){
global $mc,$ku,$mcu;
echo "<div class='feedback'><img width='16' height='16' src='img/icons/ruby.png' alt='o'>Вы заработали: <span>".floor($rubies)." рубинов</span>";
if($mc['nalog']>0){
$nrubies=floor(($rubies/100)*$mc['nalog']);
mysql_querll("UPDATE `kolhoz_user` SET `urubies` = '0' WHERE `id` = '$ku[id]'");
echo " <span class='minor'>(колхозный налог <span><img
width='16' height='16' src='img/icons/ruby.png' alt='o'> <span class='title'>$nrubies</span></span>)</span>";
}
echo "</div>";
mysql_querll("UPDATE `kolhoz_user` SET `urubies` = '0' WHERE `id` = '$ku[id]'");
}

function passgen($k_simb=8, $types=3){
$password="";
$small="abcdefghijklmnopqrstuvwxyz";
$large="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$numbers="1234567890";
mt_srand((double)microtime()*1000000); 
for ($i=0; $i<$k_simb; $i++) { 
$type=mt_rand(1,min($types,3));
switch ($type) {
case 3:
$password.=$large[mt_rand(0,25)];
break;
case 2:
$password.=$small[mt_rand(0,25)];
break;
case 1:
$password.=$numbers[mt_rand(0,9)];
break;
}
}
return $password;
}
$passgen=passgen();

function update_ku($field,$value){
global $ku;
mysql_querll("UPDATE `kolhoz_user` SET `".$field."` = '".$value."' WHERE `id` = '$ku[id]'");
return $value;
}

function get_user($ku_id=0){
if ($ku_id==0){
$ank2['id']=0;
$ank2['nick']='Почтовый сервис';
$ank2['level']=10;
$ank2['pol']=0;
return $ank2;
}
}
?>