Размер файла: 4.8Kb
<?php
/**********************************
* @package: PerfCMS *
* @year: 2012 *
* @author: Artas *
* @link: http://perfcms.ru *
**********************************/
$locate = 'in_share';
if(!isset($_GET['id'])) { go('/share/'); }
$id = abs(intval($_GET['id']));
if($db->query("SELECT * FROM `share_files` WHERE `id` = '". $id ."'")->rowCount() == 0) {
$title = $lang->word('share');
require_once(SYS.'/view/header.php');
$tpl->div('menu', $lang->word('file_not_exists'));
$tpl->div('block', NAV.' <a href="/share/">'. $lang->word('share') .'</a><br/>' . HICO .' <a href="/">'. $lang->word('home') .'</a>');
require_once(SYS.'/view/footer.php');
exit;
}
$file_a = $db->query("SELECT * FROM `share_files` WHERE `id` = '". $id ."'")->fetch();
$file_ra = $db->query("SELECT * FROM `share_rating` WHERE `file_id` = '". $id ."' ORDER BY rating DESC")->fetch();
$file_ar = $db->query("SELECT * FROM `share_rating` WHERE `file_id` = '". $id ."'")->rowCount();
if(isset($_GET['act']) && $_GET['act'] == 'rate') {
$rates = abs(intval($_POST['rate']));
$rate = ($rates < 1 ? 1 : ($rates > 5 ? 5 : $rates));
$db->query("INSERT INTO `share_rating` SET `rating` = '". ($file_ra['rating']+$rate)."', `rated` = '". ($file_ra['rated']+1) ."', `user_id` = '". $user['id'] ."', `file_id` = '". $id."'");
header('location: /share/file/'.$file_a['id'].'/');
exit;
}
if(isset($_GET['delete_screen']) && file_exists(ROOT.'/files/preview/'.$file_a['path_name'].'.png') && ($user['id'] == $file_a['user_id'] || $user['level'] >= 4))
{
unlink(ROOT.'/files/preview/'.$file_a['path_name'].'.png');
header('location: /share/file/'.$file_a['id']);
exit;
}
$title = $file_a['name'] .' | '. $lang->word('share');
require_once(SYS .'/view/header.php');
$tpl->div('title', $file_a['name']);
$file_q = $db->query("SELECT * FROM `share_files` WHERE `id` = '". $id ."'");
while($file = $file_q->fetch()) {
if($file_ra['rating'] != 0) {
$rating = ($file_ra['rating']/$file_ra['rated']);
}
else {
$rating = 0;
}
echo '<div class="menu">
'.(preg_match('/jpeg|jpg|gif|png|bmp/i', $file['ext']) ? '<img style="border: 1px solid #000;" weight="80" height="60" src="/files/share/'. $file['path_name'] .'" alt="Screen" /><br/>'."\n" : (file_exists(ROOT.'/files/preview/'.$file['path_name'].'.png') ? '<a href="/files/preview/'.$file['path_name'].'.png"><img style="border: 1px solid #000;" weight="100" height="80" src="/files/preview/'.$file['path_name'].'.png" alt="Screen" /></a><br/>'."\n" : NULL)) .'
'. output($file['text']) .'
</div>
<div class="post">
'.img('download.png').' <a href="/share/download/'. $file['id'] .'/">'. $lang->word('download') .' '.strtoupper($file['ext']).'</a> ('.size($file['size']).')<br/>
'. NAV . $lang->word('uploader').': <a href="/user/'.$file['user_id'].'">'. tnick($file['user_id']) .'</a> ('.rtime($file['time']).')<br/>
'. img('globe.png') . $lang->word('downloaded').': '.$file['dload_times'].'<br/>
'.($user['id'] == $file['user_id'] || $user['level'] == 4 || $user['level'] >=6 ? img('delete.png') .' <a href="/share/delete_file/?file_id='. $file['id'] .'">'. $lang->word('delete').'</a><br/>
'.img('edit.png').' <a href="/share/edit_file/'. $file['id'].'/">'. $lang->word('edit') .'</a><br/>' : NULL).'
'.($user['id'] == $file['user_id'] || $user['level'] == 4 || $user['level'] >=6 ? (file_exists(ROOT.'/files/preview/'.$file['path_name'].'.png') ? img('image.png').' <a href="/share/file/'.$file['id'].'?delete_screen">'. $lang->word('screenshot_delete').'</a><br/>' : img('image.png').' <a href="/share/add_screen?file_id='.$file['id'].'">'. $lang->word('screenshot_add').'</a><br/>') : NULL) .'
</div>
<div class="post">
'.$lang->word('rating').': <b>'. round($rating, 1) .'</b><br/>
'.($db->query("SELECT * FROM `share_rating` WHERE `user_id` = '". $user['id'] ."' AND `file_id` = '". $file['id'] ."'")->rowCount() == 0 ?
'<form action="/share/file/'.$file['id'].'/?act=rate" method="post">
<select name="rate">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" value="'.$lang->word('vote').'" />
</form>' : NULL).'
</div>
';
}
$tpl->div('block', NAV.' <a href="/share/'. $file_a['id'] .'/comments/">'. $lang->word('comments') .'</a> ('. $db->query("SELECT * FROM `share_comms` WHERE `share_id` = '". $file_a['id'] ."'")->rowCount().')<br/>' . NAV.'<a href="/share/folder/'. $file_a['cat_id'] .'/">'. $db->query("SELECT name FROM `share_c` WHERE `id` = '". $file_a['cat_id'] ."'")->fetchColumn() .'</a><br/>' . NAV .'<a href="/share/">'. $lang->word('share') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home') .'</a>');
require_once(SYS .'/view/footer.php');
?>