<?php 

/*
* $name описание действий объекта 
*/

if ($type == 'poll_vote' && $post['avtor'] != $user['id']) {
	$name = 'принял'.($avtor['pol'] == 1 ? '' : 'а').' участие в опросе ';
} elseif ($type == 'poll_like' && $post['avtor'] != $user['id']) {
	$name = 'считает классным опрос ';
} elseif ($type == 'poll' && $post['avtor'] != $user['id']) {
	$name = 'создал'.($avtor['pol'] == 1 ? '' : 'а').' новый опрос ';
}

/*
===============================
Новые опросы
===============================
*/
if ($type == 'poll' || $type == 'poll_like' || $type == 'poll_vote')
{
    ?>
    <style>
    .raquo {
      display: inline-block;
      height: 14px;
      width: 14px;
      border: 1px solid #7f7f7f;
      border-radius: 20px;
      -moz-border-radius: 20px;
      background-color: #ffffff;
      vertical-align: middle;
      text-align: center;
      line-height: 100%;
    }

    .raquo:hover {
      border: 1px solid #757575;
      background-color: #e9e9e9;
    }
    </style>
    <?
    
		$poll = mysql_fetch_assoc(mysql_query("SELECT * FROM `poll` WHERE `id` = '".$post['id_file']."'"));
		
		$ID = $poll['id'];

		if ($poll['id']) {
			echo '<div class="nav1">';
  		if ($post['ot_kogo']) {
  			echo user::avatar($avtor['id']) . user::nick($avtor['id'], 1, 1, 1) . ' <a href="user.settings.php?id=' . $avtor['id'] . '">[!]</a> ' . $name;
  			echo user::avatar($post['ot_kogo']) . user::nick($post['ot_kogo'], 1, 1, 1) . ' <a href="user.settings.php?id=' . $post['ot_kogo'] . '">[!]</a> ' . $s1 . vremja($post['time']) . $s2 . '<br />';
  		} else {
  		  echo user::avatar($avtor['id']) . user::nick($avtor['id'], 1, 1, 1) . ' <a href="user.settings.php?id=' . $avtor['id'] . '">[!]</a> ' . $name .  $s1 . vremja($post['time']) . $s2 . '<br />';
  		}
  		
      if ($type == 'poll_vote')
      {
      	$repost = mysql_fetch_assoc(mysql_query("SELECT * FROM `poll_votes` WHERE `id_user` = '" . $post['ot_kogo'] . "' AND `id_poll` = '" . $ID . "'"));	
      	$otvet = mysql_fetch_assoc(mysql_query("SELECT * FROM `poll_variant` WHERE `id` = '" . $repost['id_otvet'] . "' AND `id_poll` = '" . $ID . "'"));
      }
			echo '<a href="/plugins/poll/poll.php?id=' . $poll['id'] . '">' . output_text($poll['msg']) . '</a>';

			echo '</div>';

			if ($type == 'poll_vote') echo '<div class="mess"><font color="blue">' . user::nick($post['ot_kogo'], 0) . '</font> голосовал' . ($avtor['pol'] == 1 ? "" : "а").' за <b>' . text($otvet['otvet']) . '</b><br /></div>';

			if ($type == 'poll')
			{
				$q_POLL = mysql_query("SELECT * FROM `poll_variant` WHERE `id_poll` = '" . $poll['id'] . "' ORDER BY `num` ASC");
				
				$n = 0;

				while ($var = mysql_fetch_assoc($q_POLL))
				{
					$n++;
					$color = $n.$n.$n; 
					$color = $color.$color + $color + $color - ($color / 2);
					
					echo '<table style="border-bottom: 1px #b2b2b2 solid; padding: 2px; background:#d8d8d8;">';
					echo '<tr>';
					echo '<td>';
          
					if (mysql_result(mysql_query("SELECT COUNT(*) FROM `poll_votes` WHERE `id_user` = '$user[id]' AND `id_poll` = '$poll[id]'"), 0) == 0)
					{
            echo '<a href="?poll=' . $poll['id'] . '&amp;vote=' . $var['id'] . '&amp;page=' . $page . '"><span class="raquo"></span> <font color="#' . $color . '">' . htmlspecialchars($var['otvet']) . '</font></a>';
          } elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `poll_votes` WHERE `id_user` = '$user[id]' AND `id_otvet` = '$var[id]' AND `id_poll` = '$poll[id]'"), 0) == 1)
					{
            echo '<span class="raquo"><img src="/style/icons/ok.gif" alt="ok" /></span> <font color="#' . $color . '">' . htmlspecialchars($var['otvet']) . '</font>';
          } else {
            echo '<span class="raquo"><img src="/style/icons/delete.gif" alt="ok" /></span> <font color="#' . $color . '">' . htmlspecialchars($var['otvet']) . '</font>';
          }
					echo '</td>';
					
					echo '<td style="text-align:right;">';
					echo '(' . mysql_result(mysql_query("SELECT COUNT(*) FROM `poll_votes` WHERE `id_otvet` = '$var[id]' AND `id_poll` = '$poll[id]'"), 0) . ')';
					echo '</td>';
					echo '</tr>';
					echo '</table>';
				}
				
			}	else {
				echo '<div class="nav1">';
				echo '<a href="/plugins/poll/poll.php?id=' . $ID . '&amp;show">••• показать еще ?</a>';
				echo '</div>';
			}	
		} else {
			echo '<div class="nav1">';
			echo user::avatar($avtor['id']) . user::nick($avtor['id'], 1, 1, 1) . ' <a href="user.settings.php?id=' . $avtor['id'] . '">[!]</a> ' . $s1 . vremja($post['time']) . $s2 . '<br />';
			echo '</div>';
			echo '<div class="nav2">';
			echo 'Опрос уже удален =( ' . $s1 . vremja($post['time']) . $s2;
		}
}