<?php
function smarty_modifier_media_votes($media_id)
{
global $mysqli;
$sql = "SELECT * FROM user_votes WHERE media_id='$media_id'";
$query = $mysqli->query($sql);
$check = $query->num_rows;
if ($check == 0) {
	$rate['up'] = 0;
	$rate['down'] = 0;
	$rate['total'] = 0;
	$rate['total_percent'] = 0;
	$rate['percent'] = '0%';
	$rate['style'] = 'default';
} else {
	$rate['total'] = $check;
	$up = $mysqli->query("SELECT vote_up,media_id FROM user_votes WHERE vote_up='1' AND media_id='$media_id'");
	$rate['up'] = $up->num_rows;
	$rate['down'] = $rate['total']-$rate['up'];
	$percent = round(($rate['up']*100)/$rate['total']);
	$rate['total_percent'] = $percent;
	$rate['percent'] = $percent.'%';
	if ($percent >= 50) {
	$rate['style'] = 'success';		
	} else {
	$rate['style'] = 'danger';		
	}
	
	
}
return $rate;
}

?>