Файл: category.php
Строк: 181
<?php
require('core/start.php');
switch ($_GET['select']) {
default:
$data_head = array(
'title' => lang('all_music')
);
head($data_head);
?>
<div class="vse">
<span><?= lang('all_music') ?></span>
<a href="category.php?select=new"><?= lang('new_music') ?></a>
<a href="category.php?select=popular"><?= lang('popular') ?></a>
<a href="category.php?select=top"><?= lang('top_20') ?></a>
</div>
<?php
$count = mysqli_fetch_row(mysqli_query($db, "SELECT COUNT(*) FROM files"));
$total = $count[0];
$perpage = PERPAGE;
$count_pages = ceil($total / $perpage);
if (!$count_pages) {
$count_pages = 1;
}
if (!empty($_GET['page'])) {
$page = abs((int)$_GET['page']);
if (!$page) {
$page = 1;
}
} else {
$page = 1;
}
if ($page > $count_pages) {
$page = $count_pages;
}
$start_pos = ($page - 1) * $perpage;
$pagenation = pagenation($page, $count_pages);
$query = "SELECT * FROM files ORDER BY id DESC LIMIT $start_pos, $perpage";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
case 'top':
$data_head = array(
'title' => lang('top_20')
);
head($data_head);
?>
<div class="vse">
<a href="category.php"><?= lang('all_music') ?></a>
<a href="category.php?select=new"><?= lang('new_music') ?></a>
<a href="category.php?select=popular"><?= lang('popular') ?></a>
<span><?= lang('top_20') ?></span>
</div>
<?php
$query = "SELECT * FROM files WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) ORDER BY rating DESC LIMIT 20";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
case 'popular':
$data_head = array(
'title' => lang('popular_24_hour')
);
head($data_head);
?>
<div class="vse">
<a href="category.php"><?= lang('all_music') ?></a>
<a href="category.php?select=new"><?= lang('new_music') ?></a>
<span><?= lang('popular') ?></span>
<a href="category.php?select=top"><?= lang('top_20') ?></a>
</div>
<?php
$query = "SELECT rating.*, files.*
FROM rating
LEFT JOIN files
ON rating.track_id=files.id
WHERE date_rec >= DATE_SUB(CURRENT_DATE, INTERVAL 24 HOUR)
GROUP BY rating.track_id";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
case 'new':
$data_head = array(
'title' => lang('new_music')
);
head($data_head);
?>
<div class="vse">
<a href="category.php"><?= lang('all_music') ?></a>
<span><?= lang('new_music') ?></span>
<a href="category.php?select=popular"><?= lang('popular') ?></a>
<a href="category.php?select=top"><?= lang('top_20') ?></a>
</div>
<?php
$count = mysqli_fetch_row(mysqli_query($db, "SELECT COUNT(*) FROM files WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 DAY)"));
$total = $count[0];
$perpage = PERPAGE;
$count_pages = ceil($total / $perpage);
if (!$count_pages) {
$count_pages = 1;
}
if (!empty($_GET['page'])) {
$page = abs((int)$_GET['page']);
if (!$page) {
$page = 1;
}
} else {
$page = 1;
}
if ($page > $count_pages) {
$page = $count_pages;
}
$start_pos = ($page - 1) * $perpage;
$pagenation = pagenation($page, $count_pages);
$query = "SELECT * FROM files WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 DAY) ORDER BY id DESC LIMIT $start_pos, $perpage";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
case 'artist':
if (empty($_GET['name'])) {
redirect(HOME);
exit;
}
$artist = base64_decode($_GET['name']);
$artist = mysqli_escape_string($db, htmlspecialchars($artist));
$data_head = array(
'title' => $artist
);
head($data_head);
$count = mysqli_fetch_row(mysqli_query($db, "SELECT COUNT(*) FROM files WHERE artist LIKE '%".$artist."%' collate utf8_bin"));
$total = $count[0];
$perpage = PERPAGE;
$count_pages = ceil($total / $perpage);
if (!$count_pages) {
$count_pages = 1;
}
if (!empty($_GET['page'])) {
$page = abs((int)$_GET['page']);
if (!$page) {
$page = 1;
}
} else {
$page = 1;
}
if ($page > $count_pages) {
$page = $count_pages;
}
$start_pos = ($page - 1) * $perpage;
$pagenation = pagenation($page, $count_pages);
$query = "SELECT * FROM files WHERE artist LIKE '%".$artist."%' collate utf8_bin ORDER BY id DESC LIMIT $start_pos, $perpage";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
case 'year':
if (empty($_GET['year'])) {
redirect(HOME);
exit;
}
$year = abs((int)$_GET['year']);
$data_head = array(
'title' => $year
);
head($data_head);
$count = mysqli_fetch_row(mysqli_query($db, "SELECT COUNT(*) FROM files WHERE year = '".$year."'"));
$total = $count[0];
$perpage = PERPAGE;
$count_pages = ceil($total / $perpage);
if (!$count_pages) {
$count_pages = 1;
}
if (!empty($_GET['page'])) {
$page = abs((int)$_GET['page']);
if (!$page) {
$page = 1;
}
} else {
$page = 1;
}
if ($page > $count_pages) {
$page = $count_pages;
}
$start_pos = ($page - 1) * $perpage;
$pagenation = pagenation($page, $count_pages);
$query = "SELECT * FROM files WHERE year = '".$artist."' ORDER BY id DESC LIMIT $start_pos, $perpage";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
case 'genre':
if (empty($_GET['genre'])) {
redirect(HOME);
exit;
}
$genre = mysqli_escape_string($db, htmlspecialchars($_GET['genre']));
$data_head = array(
'title' => $genre
);
head($data_head);
$count = mysqli_fetch_row(mysqli_query($db, "SELECT COUNT(*) FROM files WHERE ganre = '".$genre."'"));
$total = $count[0];
$perpage = PERPAGE;
$count_pages = ceil($total / $perpage);
if (!$count_pages) {
$count_pages = 1;
}
if (!empty($_GET['page'])) {
$page = abs((int)$_GET['page']);
if (!$page) {
$page = 1;
}
} else {
$page = 1;
}
if ($page > $count_pages) {
$page = $count_pages;
}
$start_pos = ($page - 1) * $perpage;
$pagenation = pagenation($page, $count_pages);
$query = "SELECT * FROM files WHERE genre = '".$genre."' ORDER BY id DESC LIMIT $start_pos, $perpage";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
case 'last':
$data_head = array(
'title' => lang('download_last')
);
head($data_head);
$count = mysqli_fetch_row(mysqli_query($db, "SELECT COUNT(*) FROM files WHERE download_last_time > 0 ORDER BY download_last_time DESC"));
$total = $count[0];
$perpage = PERPAGE;
$count_pages = ceil($total / $perpage);
if (!$count_pages) {
$count_pages = 1;
}
if (!empty($_GET['page'])) {
$page = abs((int)$_GET['page']);
if (!$page) {
$page = 1;
}
} else {
$page = 1;
}
if ($page > $count_pages) {
$page = $count_pages;
}
$start_pos = ($page - 1) * $perpage;
$pagenation = pagenation($page, $count_pages);
$query = "SELECT * FROM files WHERE download_last_time > 0 ORDER BY download_last_time DESC LIMIT $start_pos, $perpage";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
case 'search':
if (empty($_SESSION['query'])) {
redirect(HOME);
exit;
}
$query_search = mysqli_escape_string($db, htmlspecialchars($_SESSION['query']));
$data_head = array(
'title' => 'Search: ' . $query_search
);
head($data_head);
$count = mysqli_fetch_row(mysqli_query($db, "SELECT COUNT(*) FROM files WHERE display_name LIKE '%".$query_search."%'"));
$total = $count[0];
$perpage = PERPAGE;
$count_pages = ceil($total / $perpage);
if (!$count_pages) {
$count_pages = 1;
}
if (!empty($_GET['page'])) {
$page = abs((int)$_GET['page']);
if (!$page) {
$page = 1;
}
} else {
$page = 1;
}
if ($page > $count_pages) {
$page = $count_pages;
}
$start_pos = ($page - 1) * $perpage;
$pagenation = pagenation($page, $count_pages);
$query = "SELECT * FROM files WHERE display_name LIKE '%".$query_search."%' LIMIT $start_pos, $perpage";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_assoc($result)) {
$track[$row['id']] = $row;
}
break;
}
if (empty($track)) {
echo '<div class="menu">'.lang('no_files').'</div>';
} else {
foreach ($track as $row) {
?>
<div class="menu">
<img src="screens/<?= $row['id'] ?>_mini.jpg" class="screen" alt=""/> <a href="track.php?id=<?= $row['id'] ?>"><?= $row['name'] ?></a> <?= getStars($row['rating']) ?><br />
<span><a href="category.php?select=artist&name=<?= base64_encode($row['artist']) ?>"><?= $row['artist'] ?></a></span>
</div>
<?php
}
}
if (!empty($pagenation)) {
echo $pagenation;
}
if ($_GET['select'] == 'search' && $_SESSION['query']) {
if (isset($_GET['reset'])) {
unset($_SESSION['query']);
redirect(HOME);
}
echo '<div class="link"><a href="category.php?select=search&reset">'.lang('reset_search').'</a></div>';
}
?>
<div class="link"><a href="<?= HOME ?>"><?= lang('home') ?></a></div>
<?php
footer();