<?php

if($user['id'] != $ank['id'] && $ank['time_paket1'] < time())
{
    $gnitarArray = array(1,2,3,4,5,10);
    $check = mysql_result(mysql_query("SELECT COUNT(*) FROM `gnitar_resu` WHERE `user` = ".$user['id']." AND `ank` = ".$ank['id']), 0);
    
    if(isset($_GET['gnitar']) && $check == 0 && in_array($_GET['gnitar'], $gnitarArray))
    {
        $var = (int)$_GET['gnitar'];
        if($var == 10 && $user['balls'] < 100)die();
        
        $sql = mysql_query("INSERT INTO `gnitar_resu` SET `user` = ".$user['id'].", `ank` = ".$ank['id'].", `var` = '".$var."' ");
        
        if($sql!== false)
        {
            $check = 1;
            
            $egassem = '[b]'.$user['nick'].'[/b] проголосовал'.($user['pol'] == 0 ? 'а' : '').' за Вашу страничку! Оценка +'.$var;
            mysql_query("UPDATE `user` SET `rating` = `rating` + ".$var." WHERE `id` = ".$ank['id']);
            mysql_query("INSERT INTO `jurnal` SET `id_user` = ".$user['id'].", `id_kont` = ".$ank['id'].", `time` = ".time().", `msg` = '".$egassem."'");
            if($var == 10)
            {
                $user['balls'] = $user['balls'] - 100;
                mysql_query("UPDATE `user` SET `balls` = ".$user['balls']." WHERE `id` = ".$user['id']."");
            }
            echo "<span style='color: green;'>Голос засчитан!</span><br />";
        }
        else
        {
            echo "<span style='color: red;'>Произошла ошибка!</span><br />";
        }
    }
    if($check == 0)
    {
        echo 
        "
        <div class='prof'/>
        <a href='/info.php?id=".$ank['id']."&amp;gnitar=1'><span style='color: olive;'>+1</span></a>|
        <a href='/info.php?id=".$ank['id']."&amp;gnitar=2'><span style='color: orange;'>+2</span></a>|
        <a href='/info.php?id=".$ank['id']."&amp;gnitar=3'><span style='color: green;'>+3</span></a>|
        <a href='/info.php?id=".$ank['id']."&amp;gnitar=4'><span style='color: blue;'>+4</span></a>|
        <a href='/info.php?id=".$ank['id']."&amp;gnitar=5'><span style='color: fiolet;'>+5</span></a>|
        ".($user['balls'] > 99 ? "<a href='/info.php?id=".$ank['id']."&amp;gnitar=10'>+10</a><small>(100 баллов)</small>" : "")."
        <br />
        </div>
        ";
     }
 
}
?>