<?
include_once H.'/sys/inc/start.php';
include_once H.'/sys/inc/compress.php';
include_once H.'/sys/inc/sess.php';
include_once H.'/sys/inc/home.php';
include_once H.'/sys/inc/settings.php';
include_once H.'/sys/inc/db_connect.php';
include_once H.'/sys/inc/ipua.php';
include_once H.'/sys/inc/fnc.php';
include_once H.'/sys/inc/user.php';

include_once H.'/sys/inc/thead.php';



$set['title']='Фото участников';
title();
aut();

?>

<style>
.vpravo{
  position: absolute;
  right: 0px;
  top: 0px;
}
.end{display:inline-block;overflow:hidden}
.phcmp_i{margin-right:.3em;padding:.2em .3em;text-align:center;color:#fff;background-color:#61bf01;font-size:small}
.phcmp_i{display:inline-block;padding-right:1.5em;position:relative;overflow:hidden;margin-right:0}.n 
.phcmp_i:after{content:'';display:block;height:100%;width:1.5em;position:absolute;top:0;right:-.8em;background:#fff;
-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg)}.
</style>

<?



$id = intval($_GET['id']);
$fk=mysql_fetch_assoc(mysql_query("SELECT * FROM `fk` WHERE `id` = '".$id."' "));

if(!isset($id) or $fk['name'] == null){
header("Location: index.php?".SID); }



$fk_win=mysql_fetch_assoc(mysql_query("SELECT id_user FROM `fk_foto` WHERE `id_fk` = '".$id."' and `active` = '1' and `golosov` > '0' order by `golosov` DESC limit 1 "));

$fk_win2=mysql_fetch_assoc(mysql_query("SELECT id_user FROM `fk_foto` WHERE `id_user` != '".$fk_win['id_user']."' and `id_fk` = '".$id."' and `active` = '1' and `golosov` > '0' order by `golosov` DESC limit 1 "));

$fk_win3=mysql_fetch_assoc(mysql_query("SELECT id_user FROM `fk_foto` WHERE `id_user` != '".$fk_win['id_user']."' and `id_user` != '".$fk_win2['id_user']."' and `id_fk` = '".$id."' and `active` = '1' and `golosov` > '0' order by `golosov` DESC limit 1 "));



if($fk['images'] == null) { $images = '<img src="img/not.png"  alt="*" class="image" align="left" height="50" width="50" style="margin: -4px 8px 1px 0px;"/>'; }
else { $images = '<img src="images/'.$fk['images'].'"  alt="*" class="image" align="left" height="50" width="50" style="margin: -4px 8px 1px 0px;"/>'; }

if($fk['active'] == 0) { $end = '<span class="end">завершен</span>'; }
elseif($fk['active'] == 3) { $end = '<span class="end">голосование закрыто</span>'; }
elseif($fk['active'] == 1) { $end = '<span class="end">активен</span>'; }


echo'<div class="mess">
'.$images.'
<body class="noscroll n fixe"> <span class="phcmp_i">Конкурс</span>'.$end.'
<br/>'.$fk['name'].'<br/></div>';




echo '<div class="main"> Фото всех участников:</div>';


$sk = mysql_result(mysql_query("SELECT COUNT(id_fk) FROM `fk_foto` WHERE `id_fk` = '".$id."' "), 0);


if ($sk == 0)
{
echo '<div class="err">Никто не добавил фотографию! Будьте первыми ;) </div>';
}

// Фото участников
$proverka3 = mysql_result(mysql_query("SELECT COUNT(id_fk) FROM `fk_golos` WHERE `id_fk` = '".$id."' and `id_user` = '".$user['id']."' "),0);

if($fk['active'] == 0) { $srt = 'golosov'; }
else { $srt = 'time'; }

$q=mysql_query("SELECT * FROM `fk_foto` WHERE `id_fk` = '".$id."' order by $srt DESC ");
while ($res = mysql_fetch_array($q)) {

$proverka = mysql_result(mysql_query("SELECT COUNT(*) FROM `fk_golos` WHERE `id_foto` = '".$res['id']."' and `id_user` = '".$user['id']."' "),0);

if(isset($user['id']) and $res['id_user'] != $user['id'] and $proverka == 0 and $proverka3 < $fk['skolko'] and $res['active'] == 1 and $fk['active'] == 1) { $golosov  = '<a href="?id='.$id.'&golos='.$res['id'].'"><img src="img/golos.png"> Голосовать</a>'; }

elseif($res['active'] == 0) {$golosov = '<font color="red">заблокировано</font>';}
elseif ( $proverka == 1 ) {  $golosov = '<img src="img/golos.png"> Ваш голос учтен!'; } 

elseif (!isset($user['id']) or $res['id_user'] == $user['id'] or $fk['active'] == 0 or $fk['active'] == 3 or $proverka3 == $fk['skolko']) { 
    $golosov = ($res['id_user'] == $user['id'] ? 'Это ваша фотография' : ''); 
}

?>
<div class="nav<?= ($num % 2 ? 1 : 0)?>" style="position: relative; padding: 6px;">
<?
if($fk_win['id_user'] == $res['id_user']) { echo '<span class="vpravo"><img src="img/win.png"></span>'; }
if($fk_win2['id_user'] == $res['id_user']) { echo '<span class="vpravo"><img src="img/win2.png"></span>'; }
if($fk_win3['id_user'] == $res['id_user']) { echo '<span class="vpravo"><img src="img/win3.png"></span>'; }
?>
  <table style="width: 100%;">
    <tr>
      <td style="width: 106px; vertical-align: top;">
        <a href="foto.php?id=<?= $res['id']?>">
          <img src="images/<?= $res['images']?>" alt="*" style="width: 100px;"/>
        </a> 
      </td>
      <td style="vertical-align: top;">
        <span class="page"><img src="img/top.png"> <?= des2num($res['golosov'], array('голос', 'голоса', 'голосов'))?></span>
        <br/> <?= $golosov?> <br/> 
      </td>
    </tr>
  </table>
</div>
<?
}
////////////////

if(isset($_GET['golos'])) {   

$proverka = mysql_result(mysql_query("SELECT COUNT(id_foto) FROM `fk_golos` WHERE `id_foto` = '".intval($_GET['golos'])."' and `id_user` = '".$user['id']."' "),0);


$fk_foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `fk_foto` WHERE `id` = '".intval($_GET['golos'])."' "));


if(isset($user['id']) and $fk_foto['id_user'] != $user['id'] and $proverka == 0 and $proverka3 < 3 and $fk_foto['active'] == 1 and $fk['active'] == 1) 
{ 

mysql_query("INSERT INTO `fk_golos` (`id_foto`, `id_fk`, `id_user`, `time`) values ('".intval($_GET['golos'])."', '".$id."', '".$user['id']."', '".$time."')");

mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) 
values('0', '".$fk_foto['id_user']."', 'За ваше фото проголосовали в фотоконкурсе [url=/plugins/foto.konkurs/foto.php?id=$_GET[golos]][b]$fk[name][/b][/url]', '$time')");

$vsego = mysql_result(mysql_query("SELECT COUNT(*) FROM `fk_golos` WHERE `id_foto` = '".intval($_GET['golos'])."'  "),0);

mysql_query("UPDATE `user` SET `balls` = `balls`+'".$fk['golosue']."'  where `id` =  '".$user['id']."'  ");

mysql_query("UPDATE `fk_foto` SET `golosov` = '".$vsego."' where `id` =  '".intval($_GET['golos'])."'  ");


header("Location: members.php?id=".$id."".SID); 

}



}

echo '<div class="foot"><img src="/style/icons/str2.gif"> <a href="konkurs.php?id='.$id.'">Назад</a></div>';

echo '<div class="foot"><img src="img/fk.png"> <a href="index.php">Фотоконкурсы</a></div>';

err();
include_once H.'/sys/inc/tfoot.php';
?>