<?php
if(isset($_GET['buy']) && intval($_GET['buy'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `icon` WHERE `id` = '".intval($_GET['buy'])."' AND (`level` = '$ku[level]' OR `level` < '$ku[level]')"),0)!=0)
{
    
$icon=mysql_fetch_array(mysql_query("SELECT * FROM `icon` WHERE `id` = '".intval($_GET['buy'])."' AND  (`pol` = '$ku[pol]' or `pol` = '3')"));
    $buy2=mysql_fetch_array(mysql_query("SELECT * FROM `icon_user` WHERE `icon` = '".intval($_GET['buy'])."' AND  (`id_user` = '$ku[id]')"));
if($buy2<1)
{
if($ku['level']>=$icon['level'] && $ku['fermoney']>=$icon['fermoney'] && $ku['rubies']>=$icon['rubies'] && $ku['money']>=$icon['money'])
{
    if($icon['realexp']>=$ku['iconExp'])$exp=$icon['realexp'];
        if($icon['realexp']<$ku['iconExp'])$exp=$ku['iconExp'];
mysql_query("INSERT INTO `icon_user` SET `id_user` = '$ku[id]', `pol` = '$icon[pol]',  `icon` = '$icon[img]', `exp` = '$icon[realexp]'");
mysql_query("UPDATE `kolhoz_user` SET `fermoney` = `fermoney` - '$icon[fermoney]',`money` = `money` - '$icon[money]', `rubies` = `rubies` - '$icon[rubies]', `icon` = '$icon[img]', `iconExp` = '$exp'  WHERE `id` = '$ku[id]'");
$_SESSION['msg']='Иконка изменена!:)';
header("Location:/icon");

}
else
{
$_SESSION['msg']='Недостаточно валюты';
header("Location:/icon");
exit;
}
}
}
echo'<div class="event"><h1>Иконки <a href="/forum-350"><img src="https://cdn3.iconfinder.com/data/icons/social-7/500/Help_mark_query_question_support_talk-24.png"></a></h1></div>
<div class="block">Ваш бонус от иконки: <span class="title">'.$ku['iconExp'].' %</span></div>
<div class="block"><img width="20" src="/images/icon/7.png"> <a href="/me_icon"> Мои иконки</a></div><div class="block">';
    $k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM  `icon` WHERE (`pol` = '$ku[pol]' or `pol` = '3')"),0);
    if($k_post==0){
        echo "<div class='block'>пустo...</div>";
    }
    $set['p_str']=8;
    $k_page=k_page($k_post,$set['p_str']);
    $page=page($k_page);
    $start=$set['p_str']*$page-$set['p_str'];  
$result1 = mysql_query("SELECT * FROM `icon` WHERE (`pol` = '$ku[pol]' or `pol` = '3') ORDER BY `level` ASC LIMIT $start, 8");
while($msg = mysql_fetch_assoc($result1)){
    $buy=mysql_fetch_array(mysql_query("SELECT * FROM `icon_user` WHERE `icon` = '".intval($msg['img'])."' AND  (`id_user` = '$ku[id]')"));

  if($msg['rubies']<1 && $msg['money']<1 && $msg['fermoney']>0)$cena="<img width='16' height='16' src='images/fermoney.png' alt='o'> ".(strkol($msg['fermoney']))."";
   if($msg['rubies']>1 && $msg['money']<1 && $msg['fermoney']<1)$cena="<img width='16' height='16' src='images/icons/ruby.png' alt='o'> ".(strkol($msg['rubies']))."";
  if($msg['rubies']<1 && $msg['money']>1 && $msg['fermoney']<1)$cena="<img width='16' height='16' src='images/icons/money.png' alt='o'> ".(strkol($msg['money']))."";
  if($msg['rubies']<1 && $msg['money']<1 && $msg['fermoney']<1)$cena="<img width='16' height='16' src='images/icons/free.png' alt='o'> бесплатно";

  echo "<li style='padding-bottom:8px'>";
echo "<img width='35' height='35' src='images/icon/$msg[img].png' alt='o' class='portrait'>";
echo "<div class='smallsss'>";
if($buy<1){
echo "".($ku['level']>=$msg['level']?"<a href='/icon/buy-$msg[id]'>":null)."<span>".hsc($msg['name'])."</span>".($ku['level']>=$msg['level']?"</a>":null)." <span class='minor'>, ".($ku['level']>=$msg['level']?"цена: </span><span><span class='title'>$cena</span></span>":"доступно с $msg[level] уровня</span>")."</div>
";
}else{
echo "<a href='/me_icon/select-$buy[id]'>Выбрать</a></div>";
}
echo"<div class='smallss minor'> Бонус опыта: <span class='title'>".($msg['exp'])."</span></div></li>";

}

echo "</ul>";

    if ($k_page>1)
    {
        echo'</div><div class="block">';

        str("?icon&",$k_page,$page); // Вывод страниц
    echo'</div>';
    }
    echo "</div>";

?>