<?php


if($user['id'] != $ank['id'])
{
    $rasyArray = array(1,2,3,4,5);
    $check = mysql_result(mysql_query("SELECT COUNT(*) FROM `ava_resu` WHERE `user` = ".$user['id']." AND `ank` = ".$ank['id']), 0);
    
    if(isset($_GET['rasy']) && $check == 0 && in_array($_GET['rasy'], $rasyArray))
    {
        $var = (int)$_GET['rasy'];
        
        $sql = mysql_query("INSERT INTO `ava_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 `rati_ava` = `rati_ava` + ".$var." WHERE `id` = ".$ank['id']);
            mysql_query("INSERT INTO `jurnal` SET `id_user` = ".$user['id'].", `id_kont` = ".$ank['id'].", `time` = ".time().", `msg` = '".$egassem."'");
            echo "<span style='color: green;'>Голос засчитан!</span><br />";
        }
        else
        {
            echo "<span style='color: red;'>Произошла ошибка!</span><br />";
        }
    }
    if($check == 0)
    {
        echo 
        "
        <br/><a href='/info.php?id=".$ank['id']."&amp;rasy=1'>".img('rating_ava/1ss.png')."</a>|
        <a href='/info.php?id=".$ank['id']."&amp;rasy=2'>".img('rating_ava/2.png')."</a>|
        <a href='/info.php?id=".$ank['id']."&amp;rasy=3'>".img('rating_ava/3.png')."</a>|
        <a href='/info.php?id=".$ank['id']."&amp;rasy=4'>".img('rating_ava/4.png')."</a>|
        <a href='/info.php?id=".$ank['id']."&amp;rasy=5'>".img('rating_ava/5.png')."</a>
        <br />
        ";
     }
 
}
?>