Файл: modules/user/rating.php
Строк: 144
<?php
/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2013-2014, Taras Chornyi, Sergiy Mazurenko, Ivan Kotliar
* @link http://perf-engine.net
* @package PerfEngine
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
if ($db->query("SELECT * FROM `users` WHERE `id` = '". abs(intval($_GET['id'])) ."' LIMIT 1")->rowCount() == 0)
{
header('Location: /pages/not_found');
exit();
}
$usr = $db->query("SELECT * FROM `users` WHERE `id` = '". abs(intval($_GET['id'])) ."' LIMIT 1")->fetch();
$voted = $db->query("SELECT time FROM `users_rating` WHERE `user_id` = '".$usr['id']."' AND `from_id` = '". User::Id() ."' ORDER BY time DESC")->fetchColumn();
$voted = $voted + 604800;
if(User::id() != $usr['id'] && User::logged() && isset($_POST['send']) && $_GET['act']== 'send' && $voted <= time())
{
$text = substr(input($_POST['text']), 0, 200);
$rating = input($_POST['rating']);
if ($rating == 'plus' or $rating == 'minus') {
$db->query("INSERT INTO `users_rating` SET `plus` = '".($rating == 'plus' ? '1' : null)."', `minus` = '".($rating == 'minus' ? '-1' : null)."', `user_id` = '". $usr['id'] ."', `from_id` = '".User::Id()."', `text` = '".$text."', `time` = '".time()."'");
$db->query("INSERT INTO `notify` SET `user_id` = '". $usr['id'] ."', `from_id` = '". User::Id() ."', `type` = 'notify_change_rating', `request_id` = '/user/rating/".$usr['id']."', `read` = '0', `time` = '". time() ."'");
$_SESSION['rating_ok'] = 'ok';
redirect('/user/rating/'.$usr['id']);
}
}
$title = _t('rating');
include_header($title);
$tpl->div('title', '<b>'._t('rating') .' '. $usr['nick'].'</b>');
if ($_SESSION['rating_ok'] == 'ok') {
echo '<div class="block">'._t('rating_ok') .'</div>';
$_SESSION['rating_ok'] = false;
}
echo '<div class="post">';
$rating_plus = $db->query("SELECT * FROM `users_rating` WHERE `plus` != '0' AND `user_id` = '". $usr['id'] ."'")->rowCount();
$rating_minus = $db->query("SELECT * FROM `users_rating` WHERE `minus` != '0' AND `user_id` = '". $usr['id'] ."'")->rowCount();
$rating = $rating_plus - $rating_minus;
echo img('rating.png').'<u>'._t('rating').':</u> <b>'.($rating > 0 ? '<span class="green">+'.$rating.'</span>' : ($rating < 0 ? '<span class="red">'.$rating.'</span>' : $rating)).'</b> (<span class="green">'.$rating_plus.'</span>/<span class="red">'.$rating_minus.'</span>)';
$cou = $db->query("SELECT * FROM `users_rating` WHERE `user_id` = '".$usr['id']."'")->rowCount();
$count = $cou ? round(100 / $cou * $rating_plus, 1) : 0;
echo '<div class="rating"><span style="width: '.($cou == 0 ? '50' : $count).'%"></span></div>';
echo '</div>';
if (User::id() != $usr['id'] && User::logged()) {
if ($voted > time()) {
echo '<div class="block">'. _t('rating_stop') .'</div>';
} else {
echo '<div class="post">
<form action="/user/rating/'. $usr['id'].'/?act=send" method="post">
<textarea rows="5" cols="30" name="text"></textarea><br/>
<select name="rating">
<option value="plus">'. _t('plus') .'</option>
<option value="minus">'. _t('minus') .'</option>
</select>
<input name="send" type="submit" value="'. _t('send') .'" />
</form>
</div>';
}
}
$rating_c = $db->query("SELECT * FROM `users_rating` WHERE `user_id` = '". $usr['id'] ."'")->rowCount();
$pages = new Paginator($rating_c, $ames);
if($rating_c == 0)
{
$tpl->div('menu', _t('not_rating'));
}
else
{
$rat = $db->query("SELECT * FROM `users_rating` WHERE `user_id` = '". $usr['id'] ."' ORDER BY time DESC LIMIT $start, $ames");
while($r = $rat->fetch())
{
$tpl->div('post', nick($r['from_id'], ($r['plus'] != 0 ? '<span class="green"><b>'. _t('plus') .'</b></span><br />' : '<span class="red"><b>'. _t('minus') .'</b></span><br />').($r['text'] != '' ? $r['text'].'<br />' : null).($r['time'] != 0 ? '<small>'.rtime($r['time']).'</small>' : null), true));
}
$pages->view();
}
$tpl->div('block', img('back.png').' <a href="/user/profile/'.$usr['id'].'">'. _t('back') .'</a><br/>'. HICO .'<a href="/">'. _t('home').'</a>');
include_footer();
?>