Файл: InstantSocial/uploud/components/users/rratings/_drawrating.php
Строк: 159
<?php
/*
--------------------------------------------------------- */
function rating_bar($id,$units='',$static='') {
$inCore = cmsCore::getInstance();
$inCore->loadClass('config'); //конфигурация
$inCore->loadClass('db');
$inCore->loadClass('user');
$inUser = cmsUser::getInstance();
$inUser->update();
$inDB = cmsDatabase::getInstance();
$is_user = $inUser->id ;
$rating_unitwidth= '30';
//set some variables
if (!$units) {$units = 10;}
if (!$static) {$static = FALSE;}
// get votes, values, ips for the current rating bar
$sql = "SELECT total_votes, total_value FROM cms_rratings WHERE id='$id' ";
$query= $inDB->query($sql);
// insert the id in the DB if it doesn't exist already
if ((!$inDB->num_rows($query)) ) {
$sql = "INSERT INTO cms_rratings (`id`,`total_votes`, `total_value`) VALUES ('$id', '0', '0')";
$result = $inDB->query($sql);
}
$numbers=$inDB->fetch_assoc($query);
if ($numbers['total_votes'] < 1) {
$count = 0;
} else {
$count=$numbers['total_votes'];
}
$current_rating=$numbers['total_value'];
if ($count==1) {
$tense='голос';
} else if ($count<=4 AND $count>=2) {
$tense='голосa';
} else {
$tense='голосов';
}
//$tense=($count==1) ? "голос" : "голосов"; //plural form votes/vote
//$tense=($count==2) ? "голоса" : "голосов"; //plural form votes/vote
// determine whether the user has voted, so we know how to draw the ul/li
$sql = "SELECT u_id FROM cms_rratings_users WHERE u_id='$is_user' AND vot_id='$id' ";
$resu = $inDB->query($sql);
if ($inDB->error()) { return false; }
$voted=$inDB->fetch_assoc($resu);
$sql = "SELECT * FROM cms_user_photos WHERE user_id='$is_user' AND id='$id' ";
$re = $inDB->query($sql);
if ($inDB->error()) { return false; }
$myphoto=$inDB->fetch_assoc($re);
// now draw the rating bar
$rating_width = @number_format($current_rating/$count,1)*$rating_unitwidth;
$rating1 = @number_format($current_rating/$count,1);
$rating2 = @number_format($current_rating/$count,2);
if ($static == 'static') {
$static_rater = array();
$static_rater[] .= "n".'<div class="ratingblock">';
$static_rater[] .= '<div id="unit_long'.$id.'">';
$static_rater[] .= '<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
$static_rater[] .= '<li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
$static_rater[] .= '</ul>';
$static_rater[] .= '<p class="static">'.$id.'. Рейтинг: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast) <em>Это постоянно.</em></p>';
$static_rater[] .= '</div>';
$static_rater[] .= '</div>'."nn";
return join("n", $static_rater);
} else {
$rater ='';
$rater.='<div class="ratingblock">';
$rater.='<div id="unit_long'.$id.'">';
$rater.=' <ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
$rater.=' <li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
for ($ncount = 1; $ncount <= $units; $ncount++) { // loop from 1 to the number of units
if(!$voted &&!$myphoto&&$is_user != '0') { // if the user hasn't yet voted, draw the voting stars
$rater.='<li><a href="db.php?j='.$ncount.'&q='.$id.'&t='.$ip.'&c='.$units.'" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';
}
}
$ncount=0; // resets the count
$rater.=' </ul>';
$rater.=' <p';
if($voted){ $rater.=' class="voted"'; }
$rater.='>Рейтинг: <strong>'.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.')';
$rater.=' </p>';
$rater.='</div>';
$rater.='</div>';
return $rater;
}
}
?>