<?php
// by Mike O. (mides), coolcms.org
$title = 'ЗЦ';
require_once '../includes/sys.php';
require_once '../includes/header.php';
$type = 'loads';
switch ($act) {
default:
echo '<div class="title">Загруз-центр';
if ($u['id']) {
echo ' (<a href="index.php?act=file_add">+файл</a>';
if (access(2)) {
echo ', <a href="index.php?act=mod">мод</a>';
}
echo ')';
}
echo '</div><div class="body">';
if ($u['id']) {
echo 'Мои: <a href="index.php?act=my">файлы</a>, <a href="index.php?act=comm_by&id='.$u['id'].'">комментарии</a><br />';
}
echo 'Новые: <a href="index.php?act=top&sort=time">файлы</a>, <a href="?act=comm_new">комментарии</a></div>';
$cats_r = mysql_query("SELECT `id`, `name` FROM `loads_cats` ORDER BY `name`");
if (mysql_num_rows($cats_r)) {
while ($cat = mysql_fetch_assoc($cats_r)) {
$loads = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `id_cat` = '$cat[id]' and `ok` = 1"), 0);
$loads_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `id_cat` = '$cat[id]' and `time` > '".(TIME-86400)."' and `ok` = 1"), 0);
if ($loads_new > 0) $new = '<span style="color:green">+'.$loads_new.'</span>';
echo '<div class="row"><a href="?act=cat&id='.$cat['id'].'"><img src="'.FLEVEL.'images/loads_folder.png"> '.$cat['name'].' ('.$loads.')';
$loads_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `id_cat` = '$cat[id]' and `time` > '".(TIME-86400)."' and `ok` = 1"), 0);
if ($loads_new > 0) echo ' <span style="color:green">+'.$loads_new.'</span>';
echo '</a></div>';
}
} else {
echo '<div class="body"><hr>Разделы не созданы<hr></div>';
}
echo '<div class="body"><a href="index.php?act=top">Топ файлов</a></div>'; //<a href="">Поиск</a>
break;
case 'cat':
$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `loads_cats` WHERE `id` = '$id'"));
if ($cat['name']) {
tp('<a href="?">ЗЦ</a>» '.$cat['name']);
$subcats_r = mysql_query("SELECT `id`, `name` FROM `loads_subcats` WHERE `id_cat` = '$id' ORDER BY `name`");
if (mysql_num_rows($subcats_r)) {
while ($subcat = mysql_fetch_assoc($subcats_r)) {
$loads = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `id_subcat` = '$subcat[id]' and `ok` = 1"), 0);
echo '<div class="row"><a href="?act=subcat&id='.$subcat['id'].'">'.$subcat['name'].' ('.$loads.')';
$loads_new = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `id_subcat` = '$subcat[id]' and`time` > '".(TIME-86400)."' and `ok` = 1"), 0);
if ($loads_new > 0) echo ' <span style="color:green">+'.$loads_new.'</span>';
echo '</a></div>';
//echo ', <a href="?act=subcat_update&id='.$subcat['id'].'">обн</a>';
}
} else {
echo 'Подразделы не созданы.';
}
} else {
error('Выбранный раздел не существует.');
}
echo '<div class="body"><a href="?">ЗЦ</a>» '.$cat['name'].'</div>';
break;
case 'subcat':
$subcat = mysql_fetch_assoc(mysql_query("SELECT `id_cat`, `name` FROM `loads_subcats` WHERE `id` = '$id'"));
if ($subcat['name']) {
$cat = mysql_fetch_assoc(mysql_query("SELECT `id`, `name` FROM `loads_cats` WHERE `id` = '$subcat[id_cat]'"));
echo '<div class="title"><a href="?">ЗЦ</a>» <a href="?act=cat&id='.$cat['id'].'">'.$cat['name'].'</a>» '.$subcat['name'].'</div>';
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `id_subcat` = '$id' and `ok` = 1"), 0);
if ($total > 0) {
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$loads_r = mysql_query("SELECT * FROM `loads` WHERE `id_subcat` = '$id' and `ok` = 1 ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
while ($load = mysql_fetch_assoc($loads_r)) {
$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads_comm` WHERE `id_loads` = '$load[id]'"), 0);
$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$load[id_subcat]'"));
echo '<div class="row">';
if ($load['time'] > (TIME - 86400)) {
echo '<b>';
}
echo '<a href="?act=view&id='.$load['id'].'">'.$load['name'].' ('.size(filesize('files/'.$subcat['path'].'/'.$load['file'])).')<br />Скачив.: '.$load['seen'].', комм.: '.$comm.'<br /></a>';
echo '</div>';
if ($load['time'] > (TIME - 86400)) {
echo '</b>';
}
}
} else {
echo '<div class="body">Пусто<hr></div>';
}
echo '<div class="body">';
navig($page, '?act=subcat&id='.$id.'&', $pages);
echo '<a href="?">ЗЦ</a>» <a href="?act=cat&id='.$cat['id'].'">'.$cat['name'].'</a>» '.$subcat['name'].'</div>';
} else {
error('Выбранный подраздел не существует.');
nav_main();
}
break;
case 'subcat_update':
$subcat_r = mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$id'");
$subcat = mysql_fetch_assoc($subcat_r);
tp('Обновление подраздела "'.$subcat['name'].'"');
$ftpfiles = glob('inc/loads/'.$subcat['path'].'/*', GLOB_NOSORT);
foreach ($ftpfiles as $ftpfile) {
$file = basename($ftpfile);
if (!mysql_num_rows(mysql_query("SELECT `id` FROM `loads` WHERE `id_subcat` = '$id' and `file` = '$file'"))) {
mysql_query("INSERT INTO `loads` SET `id_cat` = '$subcat[id_cat]', `id_subcat` = '$id', `id_user` = '$u[id]', `name` = '$file', `file` = '$file', `time` = '".TIME."', `ok` = 1");
echo 'Файл <u>'.$file.'</u> добавлен.<br />';
}
}
nav('?act=cat&id='.$subcat['id_cat']);
break;
case 'view':
$load = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads` WHERE `id` = '$id' and `ok` = 1"));
if ($load['id']) {
$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$load[id_subcat]'"));
$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_cats` WHERE `id` = '$subcat[id_cat]'"));
tp('<a href="?">ЗЦ</a>» <a href="?act=cat&id='.$cat['id'].'">'.$cat['name'].'</a>» <a href="?act=subcat&id='.$load['id_subcat'].'">'.$subcat['name'].'</a>»<br />'.$load['name']);
echo '<div class="body">';
if ($load['desc']) echo bb($load['desc']).'<br />';
if ($load['screen']) {
echo '<br />Скриншот:<br /><a href="screens/'.$load['screen'].'"><img src="../photos/resize.php?dir=loads/screens&name='.$load['screen'].'"></a><br />';
}
if ($load['author']) echo '<br />Автор файла: '.$load['author'];
if ($load['site'] and $load['author']) {
echo ' (<a href="http://'.$load['site'].'" target="_blank">http://'.$load['site'].'</a>)';
} elseif ($load['site']) {
echo '<br>Сайт: <a href="http://'.$load['site'].'" target="_blank">http://'.$load['site'].'</a>';
}
echo '<br />';
echo 'Добавлено: <a href="../other/profile.php?id='.$load['id_user'].'">'.username($load['id_user'], 0).'</a> ('.ccdate($load['time'], 0).')<br />';
echo 'Рейтинг: <b>'.$load['rating'].'</b> <a href="?act=rate&id='.$load['id'].'"><image src="../images/arrow_down.png" alt="arrow_down" /></a><a href="?act=rate&id='.$load['id'].'&ok=1""><image src="../images/arrow_up.png" alt="arrow_up" /></a><br /><br />';
$comm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads_comm` WHERE `id_loads` = '$load[id]'"), 0);
echo '<a href="?act=load&id='.$load['id'].'">Скачать ['.$load['seen'].']</a> ('.size(filesize('files/'.$subcat['path'].'/'.$load['file'])).')<br />
<a href="?act=comm&id='.$load['id'].'">Комментарии</a> ('.$comm.')<br /><br />';
if ($u['id']) echo 'Скопировать адрес:<br /><input name="file" type="text" value="'.HTTPHOME.'/loads/files/'.$subcat['path'].'/'.$load['file'].'" /><br />';
echo 'BB-код для форума:<br /><input name="bb_code" type="text" value="[url='.HTTPHOME.'/loads/?act=view&id='.$load['id'].']'.$load['name'].'[/url]" /><br />';
if (access(2)) echo '<br />- <a href="?act=file_edit&id='.$load['id'].'">Редактировать</a><br />';
if (access(3)) echo '- <a href="?act=file_del&id='.$load['id'].'">Удалить</a><br />';
echo '<br /><a href="?act=subcat&id='.$load['id_subcat'].'">'.$subcat['name'].'</a>» '.$load['name'].'</div>';
} else {
redirect('?');
}
break;
case 'load':
$load = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads` WHERE `id` = '$id'"));
if ($load['id']) {
$subcat = mysql_fetch_assoc(mysql_query("SELECT `path` FROM `loads_subcats` WHERE `id` = '$load[id_subcat]'"));
if (file_exists('files/'.$subcat['path'].'/'.$load['file'])) {
if ($u['id']) {
$seen_r = mysql_query("SELECT `id` FROM `seen` WHERE `type` = 'loads' and `id_data` = '$load[id]' and `id_user` = '$u[id]'");
if (!mysql_num_rows($seen_r)) {
mysql_query("INSERT INTO `seen` SET `type` = 'loads', `id_data` = '$load[id]', `id_user` = '$u[id]'");
mysql_query("UPDATE `loads` SET `seen` = (`seen`+1) WHERE `id` = '$load[id]'");
}
}
redirect('files/'.$subcat['path'].'/'.$load['file']);
} else {
redirect('?');
}
} else {
redirect('?');
}
break;
case 'file_add':
if ($ok) {
function getext($filename) {
return end(explode(".", $filename));
}
$current_ext = getext(basename($_FILES['file']['name']));
$allowed_ext = explode('|', $config['allowed_ext']);
if (!in_array($current_ext, $allowed_ext)) {
error('Запрещенный формат файла.');
nav('?act=file_add');
break;
}
$subcat_id = abs(intval($_POST['subcat']));
$name = check($_POST['name']);
$desc = check($_POST['desc']);
$author = check($_POST['author']);
$site = check($_POST['site']);
if (empty($subcat_id)) {
error('Не выбран подраздел.');
nav('?act=file_add');
break;
}
if (empty($name)) {
error('Не указано название.');
nav('?act=file_add');
break;
}
if (empty($_FILES['file']['name'])) {
error('Не выбран файл.');
nav('?act=file_add');
break;
}
$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$subcat_id'"));
if (!isset($subcat['id'])) {
error('Выбранный подраздел не существует.');
nav('?act=file_add');
break;
}
$file = $u['id'].'_'.check(basename($_FILES['file']['name']));
if (mysql_num_rows(mysql_query("SELECT `id` FROM `loads` WHERE `file` = '$file'"))) {
error('Такой файл уже есть в ЗЦ.');
nav('?act=file_add');
break;
}
copy($_FILES['file']['tmp_name'], 'files/'.$subcat['path'].'/'.$file);
mysql_query("INSERT INTO `loads` SET `id_cat` = '$subcat[id_cat]', `id_subcat` = '$subcat[id]', `id_user` = '$u[id]', `name` = '$name', `desc` = '$desc', `author` = '$author', `site` = '$site', `file` = '$file', `time` = '".time()."'");
$adm_r = mysql_query("SELECT `id` FROM `users` WHERE `access` > 1");
while ($adm = mysql_fetch_assoc($adm_r)) {
sendpm($adm['id'], 'Появился новый файл в ЗЦ. <a href="../loads/?act=mod">Проверьте</a>.');
}
info('Файл загружен. После модерации он появится в ЗЦ. Вы будете уведомлены.');
nav('?');
} else {
tp('<a href="?">ЗЦ</a>» Добавить файл');
echo '<div class="body"><form name="form" action="?act=file_add&ok=1" method="post" enctype="multipart/form-data" name="form">
Выберите <b>подраздел</b>*:<br /><select name="subcat">';
$cat_r = mysql_query("SELECT * FROM `loads_cats` ORDER BY `name`");
while ($cat = mysql_fetch_assoc($cat_r)) {
echo '<option value="0">'.$cat['name'].'</option>';
$subcat_r = mysql_query("SELECT * FROM `loads_subcats` WHERE `id_cat` = '$cat[id]' ORDER BY `name`");
while ($subcat = mysql_fetch_assoc($subcat_r)) {
echo '<option value="'.$subcat['id'].'">-- '.$subcat['name'].'</option>';
}
}
echo '</select><br />
Название(max50)*:<br /><input name="name" type="text" maxlength="50" /><br />
Описание:<br /><textarea name="desc" cols="" rows="4"></textarea><br />
Автор(max20):<br /><input name="author" type="text" maxlength="20" /><br />
Сайт(<del>http://</del>, max20):<br /><input name="site" type="text" maxlength="20" /><br />
Выбрать файл*:<br /><input name="file" type="file" size="file" /><br />';
if ($config['userimport']) {
echo '<u>ЛИБО</u> указать адрес для импорта, напр. http://coolcms.org/1.zip<br /><input name="url" type="text" /><br />';
}
echo '<input name="submit" type="submit" value="Ok" />
</form>';
nav('?');
}
break;
case 'file_edit':
if (access(2)) {
$load = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads` WHERE `id` = '$id'"));
if ($load['id']) {
if ($ok) {
if ($_POST['name']) {
$scat_current = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$load[id_subcat]'"));
if (empty($_POST['action'])){
unlink('files/'.$scat_current['path'].'/'.$load['file']);
mysql_query("DELETE FROM `loads` WHERE `id` = '$load[id]'");
mysql_query("DELETE FROM `loads_comm` WHERE `id_loads` = '$load[id]'");
redirect('?act=subcat&id='.$load['id_subcat']);
} else {
$scat_new_id = abs(intval($_POST['subcat']));
$scat_new = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$scat_new_id'"));
// updating old file (=deleting the old one, uploading a new one
// обновление (замена) файла (=удаление старого, загрузка нового)
if (!empty($_FILES['file']['name'])) {
$file_to_cp = $_FILES['file']['tmp_name'];
$file = rand(111, 999).check(basename($_FILES['file']['name']));
$copy = copy($file_to_cp, 'files/'.$scat_new['path'].'/'.$file);
if ($copy == TRUE) {
unlink('files/'.$scat_current['path'].'/'.$load['file']);
mysql_query("UPDATE `loads` SET `file` = '$file' WHERE `id` = '$load[id]'");
} else {
error('Не получилось обновить файл, возможно нет прав на запись на папку в ЗЦ');
nav('?act=file_edit&id='.$id);
}
} else {
// moving file if we have to | перемещение файла, если нужно
if ($scat_new_id != $scat_current['id']) {
$rename = rename('files/'.$scat_current['path'].'/'.$load['file'], 'files/'.$scat_new['path'].'/'.$load['file']);
if ($rename == FALSE) {
error('Не получилось переместить файл. Возможно папка, в которую хотите переместить файл, не существует или права доступа не позволяют делать запись.');
nav('?act=file_edit&id='.$id);
break;
}
}
}
$name = check($_POST['name']);
$desc = check($_POST['desc']);
$author = check($_POST['author']);
$site = check($_POST['site']);
// updating / adding screen
if (!empty($_FILES['screen']['name'])) {
$screen_to_cp = $_FILES['screen']['tmp_name'];
$screen = $load['id'].'_'.rand(11, 99).check(basename($_FILES['screen']['name']));
$copy_sc = copy($screen_to_cp, 'screens/'.$screen);
if ($copy_sc == TRUE) {
if (file_exists('screens/'.$load['screen'])) {
unlink('screens/'.$load['screen']);
}
mysql_query("UPDATE `loads` SET `screen` = '$screen' WHERE `id` = '$load[id]'");
} else {
$_SESSION['note'] = 'Скрин не загружен';
}
}
// updating file info | обновление инфо о файле
mysql_query("UPDATE `loads` SET `id_cat` = '$scat_new[id_cat]', `id_subcat` = '$scat_new[id]', `name` = '$name', `desc` = '$desc', `author` = '$author', `site` = '$site', `ok` = 1 WHERE `id` = '$id'");
if (empty($load['ok'])) {
sendpm($load['id_user'], 'Ваш файл <b><a href="../loads/?act=view&id='.$load['id'].'">'.$load['name'].'</a></b> был успешно промодерирован.');
}
redirect('?act=view&id='.$id);
}
} else {
redirect('?act=file_edit&id='.$id);
}
} else {
tp('<a href="?act=view&id='.$id.'">Файл</a>» Ред-е инфо о файле');
echo '<div class="body">Находится в:<br />
<form name="form" action="?act=file_edit&id='.$id.'&ok=1" method="post" enctype="multipart/form-data">
<select name="subcat">';
$subcat_r1 = mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$load[id_subcat]'");
$subcat1 = mysql_fetch_assoc($subcat_r1);
$cat1 = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_cats` WHERE `id` = '$subcat1[id_cat]'"));
echo '<option value="'.$subcat1['id'].'">'.$cat1['name'].'» '.$subcat1['name'].'</option>';
$subcat_r = mysql_query("SELECT * FROM `loads_subcats` WHERE `id` != '$load[id_subcat]' ORDER BY `id_cat`, `name`");
while ($subcat = mysql_fetch_assoc($subcat_r)) {
$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_cats` WHERE `id` = '$subcat[id_cat]'"));
echo '<option value="'.$subcat['id'].'">'.$cat['name'].'» '.$subcat['name'].'</option>';
}
echo '</select><br />
Обновить(заменить) файл:<br /><input name="file" type="file" size="file" /><br />';
if ($load['screen']) {
echo '<a href="screens/'.$load['screen'].'"><img src="../photos/resize.php?dir=loads/screens&name='.$load['screen'].'"></a><br />';
}
echo 'Обновить(или добавить) скрин:<br /><input name="screen" type="file" size="file" /><br />
Название(max50):<br /><input name="name" type="text" maxlength="50" value="'.$load['name'].'" /><br />
Описание:<br /> '.bbpanel('form', 'text').'<textarea name="desc" cols="" rows="3">'.$load['desc'].'</textarea><br />
Автор(max20):<br /><input name="author" type="text" maxlength="20" value="'.$load['author'].'" /><br />
Сайт(max20):<br /><input name="site" type="text" maxlength="20" value="'.$load['site'].'" /><br />
Действие:<br />
<select name="action">';
if (empty($load['ok'])) {
echo '<option value="1">Ред-ть, добавить в ЗЦ</option>';
} else {
echo '<option value="1">Ред-ть</option>';
}
echo '<option value="0">Удалить</option>
</select><br />
<input name="submit" type="submit" value="Ok" />
</form>
<br />
<a href="?act=view&id='.$load['id'].'">К файлу</a>
</div>
';
}
} else {
redirect('?');
}
} else {
redirect('?');
}
break;
case 'file_del':
if (access(3)) {
$load = mysql_fetch_assoc(mysql_query("SELECT `id`, `id_subcat`, `name`, `file` FROM `loads` WHERE `id` = '$id'"));
if ($load['id']) {
$subcat = mysql_fetch_assoc(mysql_query("SELECT `path` FROM `loads_subcats` WHERE `id` = '$load[id_subcat]'"));
if ($ok) {
unlink('files/'.$subcat['path'].'/'.$load['file']);
mysql_query("DELETE FROM `loads` WHERE `id` = '$load[id]'");
mysql_query("DELETE FROM `loads_comm` WHERE `id_loads` = '$load[id]'");
redirect('?act=subcat&id='.$load['id_subcat']);
} else {
tp('Подтвердите, пожалуйста');
echo '<div class="body">';
echo 'Вы действительно хотите удалить файл "<b>'.$load['name'].'</b>"?<br />
<form name="form" action="?act=file_del&id='.$id.'&ok=1" method="post">
<input name="submit" type="submit" value="Да" />
</form>
<br />
<a href="?act=view&id='.$load['id'].'">К файлу</a>
</div>';
}
} else {
redirect('?');
}
} else {
redirect('?');
}
break;
case 'mod':
if (!access(1)) {
redirect(HTTPHOME);
}
tp('<a href="?">ЗЦ</a>» Модерировать');
echo '<div class="body">';
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `loads` WHERE `ok` = 0"), 0);
if ($total > 0) {
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$loads_r = mysql_query("SELECT * FROM `loads` WHERE `ok` = 0 ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
while ($load = mysql_fetch_assoc($loads_r)) {
$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_subcats` WHERE `id` = '$load[id_subcat]'"));
echo '
<a href="?act=file_edit&id='.$load['id'].'">'.$load['name'].'</a> ('.size(filesize('files/'.$subcat['path'].'/'.$load['file'])).') <a href="files/'.$subcat['path'].'/'.$load['file'].'">скачать</a>';
if (access(3)) echo ', <a href="?act=file_del&id='.$load['id'].'">del</a>';
echo '<hr>';
}
navig($page, '?act=mod&', $pages);
} else {
echo 'Пусто.<br />';
}
echo '<a href="?">В ЗЦ</a></div>';
break;
case 'rate':
require_once '../includes/rate.php';
break;
case 'comm':
require_once '../includes/comm.php';
break;
case 'comm_add':
require_once '../includes/comm_add.php';
break;
case 'comm_reply':
require_once '../includes/comm_reply.php';
break;
case 'comm_edit':
require_once '../includes/comm_edit.php';
break;
case 'comm_del':
require_once '../includes/comm_del.php';
break;
case 'comm_by':
require_once '../includes/comm_by.php';
break;
case 'comm_new':
require_once '../includes/comm_new.php';
break;
case 'top':
require_once '../includes/top.php';
break;
case 'my':
require_once '../includes/my.php';
break;
}
require_once '../includes/tail.php';
?>