<?
include '../config.php';
include '../func.php';
head();
aut();
ban();
if($error){ echo $error;
}else{
/////////////////////////////
mysql_query("UPDATE `profile` SET `online` = 'photo' WHERE `id` = '".$id_session."'");
echo "<div class=\"head\"><b>Фотоальбомы</b></div>";  


$photo_info = mysql_fetch_assoc(mysql_query("SELECT * FROM `photo_photos` WHERE `id` = '".num($_GET['photo'])."'"));

if($_GET['a']=='min1'){
    mysql_query ("Select * from photo_rayt_list WHERE (user_1 = '".$id_session."')and(user_2 = '".$photo_info['user']."')and(photo = '".num($_GET['photo'])."')");
    if(mysql_affected_rows()!=0) $error = "<div class='link1'>Вы уже голосовали</div>";
    
    if($error){
        echo $error;
    }else{
        $photo_info['reyt']=$photo_info['reyt']-1;
        mysql_query("UPDATE `photo_photos` SET `reyt` = '".$photo_info['reyt']."' WHERE `id` = '".num($_GET['photo'])."' "); 
        mysql_query("INSERT INTO `photo_rayt_list` SET `user_1` = '".$id_session."', `user_2` = '".$photo_info['user']."', `photo` = '".num($_GET['photo'])."'");
        echo '<div class="link1">Вы успешно проголосовали.' . div;
        
        if ($id_session != $photo_info['user']) {
        $msg = '<div class="link1">Вашу фотографию оценили на -1. Перейти к <b><a href="photo/photo.php?photo='.$photo_info['id'].'">фотографии</b></a>. Оценил(а): '.user($id_session).'. Дата: '.date2(time()).'';
        mysql_query("INSERT INTO `uvedom` SET  `msg` = '".$msg."', `md` = 'photo_reyt', `user_to` = '".$photo_info['user']."', `user_ot` = '".$id_session."', `date` = '".time()."', `status` = '1'");
        
}
    }
}

if($_GET['a']=='min2'){
    mysql_query ("Select * from photo_rayt_list WHERE (user_1 = '".$id_session."')and(user_2 = '".$photo_info['user']."')and(photo = '".num($_GET['photo'])."')");
    if(mysql_affected_rows()!=0) $error = "<div class='link1'>Вы уже голосовали";
    echo div;
    if($error){
        echo $error;
    }else{
        $photo_info['reyt']=$photo_info['reyt']-2;
        mysql_query("UPDATE `photo_photos` SET `reyt` = '".$photo_info['reyt']."' WHERE `id` = '".num($_GET['photo'])."' "); 
        mysql_query("INSERT INTO `photo_rayt_list` SET `user_1` = '".$id_session."', `user_2` = '".$photo_info['user']."', `photo` = '".num($_GET['photo'])."'");
        echo '<div class="link1">Вы успешно проголосовали.';
        echo div;
        if ($id_session != $photo_info['user']) {
        $msg = '<div class="link1">Вашу фотографию оценили на -2. Перейти к <b><a href="photo/photo.php?photo='.$photo_info['id'].'">фотографии</b></a>. Оценил(а): '.user($id_session).'. Дата: '.date2(time()).'';
        mysql_query("INSERT INTO `uvedom` SET  `msg` = '".$msg."', `md` = 'photo_reyt', `user_to` = '".$photo_info['user']."', `user_ot` = '".$id_session."', `date` = '".time()."', `status` = '1'");
       
 }
    }    
}

if($_GET['a']=='plus1'){
    mysql_query ("Select * from photo_rayt_list WHERE (user_1 = '".$id_session."')and(user_2 = '".$photo_info['user']."')and(photo = '".num($_GET['photo'])."')");
    if(mysql_affected_rows()!=0) $error = "<div class='link1'>Вы уже голосовали";
    echo div;
    if($error){
        echo $error;
    }else{
        $photo_info['reyt']=$photo_info['reyt']+1;
        mysql_query("UPDATE `photo_photos` SET `reyt` = '".$photo_info['reyt']."' WHERE `id` = '".num($_GET['photo'])."' "); 
        mysql_query("INSERT INTO `photo_rayt_list` SET `user_1` = '".$id_session."', `user_2` = '".$photo_info['user']."', `photo` = '".num($_GET['photo'])."'");
        echo '<div class="link1">Вы успешно проголосовали.</div>';
        if ($id_session != $photo_info['user']) {
        $msg = '<div class="link1">Вашу фотографию оценили на +1. Перейти к <b><a href="photo/photo.php?photo='.$photo_info['id'].'">фотографии</b></a>. Оценил(а): '.user($id_session).'. Дата: '.date2(time()).'';
        mysql_query("INSERT INTO `uvedom` SET  `msg` = '".$msg."', `md` = 'photo_reyt', `user_to` = '".$photo_info['user']."', `user_ot` = '".$id_session."', `date` = '".time()."', `status` = '1'");
        
}
    }       
}

if($_GET['a']=='plus2'){
    mysql_query ("Select * from photo_rayt_list WHERE (user_1 = '".$id_session."')and(user_2 = '".$photo_info['user']."')and(photo = '".num($_GET['photo'])."')");
    if(mysql_affected_rows()!=0) $error = "<div class='link1'>Вы уже голосовали";
    
    if($error){
        echo $error;
    }else{
        $photo_info['reyt']=$photo_info['reyt']+2;
        mysql_query("UPDATE `photo_photos` SET `reyt` = '".$photo_info['reyt']."' WHERE `id` = '".num($_GET['photo'])."' "); 
        mysql_query("INSERT INTO `photo_rayt_list` SET `user_1` = '".$id_session."', `user_2` = '".$photo_info['user']."', `photo` = '".num($_GET['photo'])."'");
        echo '<div class="link1">Вы успешно проголосовали.</div>';
        if ($id_session != $photo_info['user']) {
        $msg = 'В<div class="link1">ашу фотографию оценили на +2. Перейти к <b><a href="photo/photo.php?photo='.$photo_info['id'].'">фотографии</b></a>. Оценил(а): '.user($id_session).'. Дата: '.date2(time()).'';
        mysql_query("INSERT INTO `uvedom` SET  `msg` = '".$msg."', `md` = 'photo_reyt', `user_to` = '".$photo_info['user']."', `user_ot` = '".$id_session."', `date` = '".time()."', `status` = '1'");
        
}
    }       
}

}
pod_navig();
foot();
?>