<?php
// Версия 1.05
define('BB_SCRIPT', 'forum');
define('BB_ROOT', './');
require __DIR__ . '/common.php';
$page_cfg['load_tpl_vars'] = array(
'post_icons',
);
$user->session_start(array('req_login' => true));
// Сортировка в таблицах
$page_cfg['use_tablesorter'] = true;
// Предпросмотр на ajax'е
$page_cfg['include_bbcode_js'] = true;
$tracking_topics = get_tracks('topic');
// Кол-во тем на странице
$tor_topics_per_page = $bb_cfg['posts_per_page'];
if ($req_tpp = abs(intval(@$_REQUEST['tpp'])) AND in_array($req_tpp, $bb_cfg['allowed_posts_per_page'])) {
$tor_topics_per_page = $req_tpp;
}
$select_tpp = '';
foreach ($bb_cfg['allowed_posts_per_page'] as $tpp) {
$select_tpp[$tpp] = $tpp;
}
$start = isset($_GET['start']) ? abs(intval($_GET['start'])) : '0';
$status = isset($_GET['st']) ? $_GET['st'] : '0';
$user_id = $userdata['user_id'];
if ($status == 'gold') {
$where_status = "AND tor.tor_type = 1";
}
elseif ($status == 'silver') {
$where_status = "AND tor.tor_type = 2";
}
elseif ($status == 'bronz') {
$where_status = "AND tor.tor_type = 0";
}
elseif (preg_match("/^[0-9]+$/", $status)) {
$where_status = "AND tor.tor_status = $status";
}
else {
bb_die(':(');
}
if($userdata['user_level'] == USER) {
meta_refresh('./', '3');
bb_die($lang['NOT_MODERATOR']);
}
if($userdata['user_level'] == GROUP_MEMBER) {
meta_refresh('./', '3');
bb_die($lang['NOT_MODERATOR']);
}
// Исключаем вывод с ненужных форумов
$trash_forums = $bb_cfg['trash_forum_id'] ? $bb_cfg['trash_forum_id'] : '0';
//
$url = ("mod.php?st=$status");
$auth_table = ($userdata['user_level'] == ADMIN) ? "" : ", ". BB_AUTH_ACCESS_SNAP ." aa";
$auth_access = ($userdata['user_level'] == ADMIN) ? "" : "AND aa.user_id = $user_id AND tor.forum_id = aa.forum_id AND aa.forum_perm = 8";
//
$sql = "SELECT COUNT(tor.topic_id) as tor_count
FROM ". BB_BT_TORRENTS ." tor $auth_table
WHERE tor.forum_id != ($trash_forums)
$auth_access
$where_status";
if ( !($result = DB()->sql_query($sql)) ) {
bb_die('Could not obtain count topic');
}
$row = DB()->sql_fetchrow($result);
$tor_count = ( $row['tor_count'] ) ? $row['tor_count'] : 0;
DB()->sql_freeresult($result);
if ($tor_count) {
$sql = "SELECT tor.*, t.*, f.forum_name,f.forum_parent, u.username, u.user_rank, u.user_level
FROM ". BB_BT_TORRENTS ." tor, ". BB_TOPICS ." t, ". BB_FORUMS ." f, ". BB_USERS ." u $auth_table
WHERE t.topic_id = tor.topic_id
AND t.topic_poster = u.user_id
AND f.forum_id = t.forum_id
AND f.forum_id != ($trash_forums)
$auth_access
$where_status
GROUP BY tor.topic_id
ORDER BY tor.reg_time DESC
LIMIT $start, $tor_topics_per_page";
if ( !($result = DB()->sql_query($sql)) ) {
bb_die('Could not obtain topic information');
}
$tor = DB()->sql_fetchrowset($result);
if ($tor) {
$template->assign_block_vars('tor_topics', array());
for ($i = 0; $i < count($tor); $i++) {
$username = $tor[$i]['username'];
$rank = $tor[$i]['user_rank'];
$topic_poster = ($tor[$i]['topic_poster'] == IS_GUEST ) ? ( ($username != '' ) ? $username . ' ' : $lang['GUEST'] . ' ' ) : '<a class="genmed" href="' . (BB_ROOT . "profile.php?mode=viewprofile&" . POST_USERS_URL . '=' . $tor[$i]['topic_poster']) . '"><b>'.profile_url(array('username' => $username, 'user_rank' => $rank)) .'</b></a>';
// Gold/Silver releases mod
$is_gold = '';
if ($bb_cfg['gold_silver_enabled']) {
if ($tor[$i]['tor_type'] == TOR_TYPE_GOLD)
{
$is_gold = '<img src="images/tor_gold.gif" width="16" height="15" title="'.$lang['GOLD'].'" /> ';
}
elseif ($tor[$i]['tor_type'] == TOR_TYPE_SILVER)
{
$is_gold = '<img src="images/tor_silver.gif" width="16" height="15" title="'.$lang['SILVER'].'" /> ';
}
}
// END Gold/Silver releases mod
// Иконка темы
$is_unread = is_unread($tor[$i]['topic_last_post_time'], $tor[$i]['topic_id'], $tor[$i]['forum_id']);
$row_class = (!($i % 2)) ? 'row2' : 'row1';
if (@$parent_id = $tor[$i]['forum_parent']) {
if (!$forums = $datastore->get('cat_forums')) {
$datastore->update('cat_forums');
$forums = $datastore->get('cat_forums');
}
}
$template->assign_block_vars('tor', array(
'PARENT_FORUM_HREF' => ($parent_id) ? FORUM_URL . $parent_id : '',
'PARENT_FORUM_NAME' => ($parent_id) ? htmlCHR($forums['f'][$parent_id]['forum_name']) : '',
'ROW_CLASS' => $row_class,
'POST_ID' => $tor[$i]['post_id'],
'TOPIC_ID' => $tor[$i]['topic_id'],
'TOPIC_TITLE' => wbr($tor[$i]['topic_title']),
'TOPIC_REPLIES' => $tor[$i]['topic_replies'],
'REG_TIME' => bb_date($tor[$i]['reg_time']),
'REG_TIME_BACK' => delta_time($tor[$i]['reg_time']),
'FORUM_TITLE' => wbr($tor[$i]['forum_name']),
'TOPIC_POSTER' => $topic_poster,
'U_FORUM' => (BB_ROOT . "viewforum.php?" . POST_FORUM_URL . '=' . $tor[$i]['forum_id']),
'U_TOPIC' => (BB_ROOT . "viewtopic.php?" . POST_TOPIC_URL . '=' . $tor[$i]['topic_id']),
'TOR_STATUS_ICON' => isset($tor['tor_status']) ? $bb_cfg['tor_icons'][$tor['tor_status']] : '',
'TOR_STATUS_TEXT' => isset($tor['tor_status']) ? $lang['TOR_STATUS_NAME'][$tor['tor_status']] : '',
'TOR_STATUS' => $tor[$i]['tor_status'],
'TOR_TYPE' => $is_gold,
'TOR_FROZEN' => ($tor[$i]['tor_status'] == TOR_STATUS_FROZEN || $tor[$i]['tor_status'] == 1 || $tor[$i]['tor_status'] == 4 || $tor[$i]['tor_status'] == 5 || $tor[$i]['tor_status'] == 6 || $tor[$i]['tor_status'] == 7 || $tor[$i]['tor_status'] == 9 || $tor[$i]['tor_status'] == 11),
'DL_CLASS' => isset($tor[$i]['dl_status']) ? $dl_link_css[$tor[$i]['dl_status']] : 'genmed',
'IS_UNREAD' => $is_unread,
'TOPIC_ICON' => get_topic_icon($tor[$i], $is_unread),
'PAGINATION' => ($tor[$i]['topic_status'] == TOPIC_MOVED) ? '' : build_topic_pagination(TOPIC_URL . $tor[$i]['topic_id'], $tor[$i]['topic_replies'], $bb_cfg['posts_per_page']),
));
unset($forums);
}
$pagination = generate_pagination($url, $tor_count, $tor_topics_per_page, $start);
$template->assign_vars(array(
'PAGINATION' => $pagination,
'PAGE_NUMBER' => sprintf($lang['PAGE_OF'], ( floor( $start / $tor_topics_per_page ) + 1 ), ceil( $tor_count / $tor_topics_per_page )),
'U_PER_PAGE' => $url,
'PER_PAGE' => $tor_topics_per_page,
));
}
DB()->sql_freeresult($result);
}
else
{
$template->assign_block_vars('no_tor_topics', array());
}
// Основная ф-ция обновления статуса и типа раздачи
if ( isset($_POST['topic_id']) ) {
$topic_ids = implode(",", $_POST['topic_id']);
$status = $_POST['status'];
switch($status) {
case 'set_gold':
case 'set_silver':
case 'unset_silver_gold':
if ($status == 'set_silver') {
$type = TOR_TYPE_SILVER;
}
elseif ($status == 'set_gold') {
$type = TOR_TYPE_GOLD;
}
else {
$type = 0;
}
$sql = "UPDATE ". BB_BT_TORRENTS ." SET tor_type = $type WHERE topic_id IN ($topic_ids)";
if ( !($result = DB()->sql_query($sql)) ) {
bb_die("Could not update torrent type");
}
meta_refresh($url, '2');
$message = sprintf($lang['MODERATE_PANEL_TYPE'], $type, '<a class="gen" href="'. $url .'">', '</a>');
bb_die($message);
break;
case 'lock':
case 'unlock':
$lock = ($status == 'lock');
$new_topic_status = ($lock) ? TOPIC_LOCKED : TOPIC_UNLOCKED;
$sql = "UPDATE ". BB_TOPICS ." SET topic_status = $new_topic_status WHERE topic_id IN ($topic_ids)";
if ( !($result = DB()->sql_query($sql)) ) {
bb_die("Could not update topic LOCK-status");
}
$status_text = ($lock) ? $lang['TOPICS_LOCKED'] : $lang['TOPICS_UNLOCKED'];
meta_refresh($url, '2');
$message = sprintf($lang['MODERATE_PANEL_TEXT'], $status_text, '<a class="gen" href="'. $url .'">', '</a>');
bb_die($message);
break;
case 'down':
case 'undown':
$set_download = ($status == 'down');
$new_dl_type = ($set_download) ? TOPIC_DL_TYPE_DL : TOPIC_DL_TYPE_NORMAL;
$sql = "UPDATE ". BB_TOPICS ." SET topic_dl_type = $new_dl_type WHERE topic_id IN ($topic_ids)";
if ( !($result = DB()->sql_query($sql)) ) {
bb_die("Could not update topic DL-status");
}
$status_text = ($set_download) ? $lang['TOPICS_DOWN_SETS'] : $lang['TOPICS_DOWN_UNSETS'];
meta_refresh($url, '2');
$message = sprintf($lang['MODERATE_PANEL_TEXT'], $status_text, '<a class="gen" href="'. $url .'">', '</a>');
bb_die($message);
break;
case 'delete':
require(INC_DIR .'functions_admin.php');
topic_delete($topic_ids);
meta_refresh($url, '2');
$message = sprintf($lang['MODERATE_PANEL_TEXT'], $lang['TOPICS_REMOVED'], '<a class="gen" href="'. $url .'">', '</a>');
bb_die($message);
break;
case 'tor_delete':
require(INC_DIR .'functions_torrent.php');
$sql = "SELECT attach_id FROM ". BB_BT_TORRENTS ." WHERE topic_id IN ($topic_ids)";
if ( !($result = DB()->sql_query($sql)) ) {
bb_die("Could not update torrent type");
}
while ( $row = DB()->sql_fetchrow($result) ) {
tracker_unregister($row['attach_id']);
}
meta_refresh($url, '2');
$message = sprintf($lang['MODERATE_PANEL_TOR_DEL'], $lang['TOPICS_REMOVED'], '<a class="gen" href="'. $url .'">', '</a>');
bb_die($message);
break;
case 'post_pin':
case 'post_unpin':
$pin = ($status == 'post_pin');
$new_topic_status = ($pin) ? 1 : 0;
var_dump($pin);
$sql = "
SELECT topic_id, topic_title
FROM ". BB_TOPICS ."
WHERE topic_id IN ($topic_ids)
AND topic_show_first_post != ". TOPIC_MOVED ."
AND topic_show_first_post != $new_topic_status
LIMIT 1
";
$topic_csv = array();
foreach (DB()->fetch_rowset($sql) as $row) {
$topic_csv[] = $row['topic_id'];
$log_topics[$row['topic_id']] = $row['topic_title'];
}
if (!$topic_csv = get_id_csv($topic_csv)) {
bb_die($lang['NONE_SELECTED']);
}
DB()->query("
UPDATE ". BB_TOPICS ." SET
topic_show_first_post = $new_topic_status
WHERE topic_id IN($topic_csv)
");
$msg = ($pin) ? $lang['POST_PINNED'] : $lang['POST_UNPINNED'];
bb_die($msg);
break;
default:
$sql = "UPDATE ". BB_BT_TORRENTS ." SET tor_status = $status, checked_time = ". time() .", checked_user_id = $user_id WHERE topic_id IN ($topic_ids)";
if ( !($result = DB()->sql_query($sql)) ) {
bb_die("Could not update torrent status");
}
switch($status) {
case 0:
$status_text = '<span class="tor-not-approved">'. $lang['TOR_NOT_APPROVED'] .'</span>';
break;
case 1:
$status_text = '<span class="tor-closed">'. $lang['TOR_CLOSED'] .'</span>';
break;
case 2:
$status_text = '<span class="tor-approved">'. $lang['TOR_APPROVED'] .'</span>';
break;
case 3:
$status_text = '<span class="tor-need-edit">'. $lang['TOR_NEED_EDIT'] .'</span>';
break;
case 4:
$status_text = '<span class="tor-no-desc">'. $lang['TOR_NO_DESC'] .'</span>';
break;
case 5:
$status_text = '<span class="tor-dup">'. $lang['TOR_DUP'] .'</span>';
break;
case 6:
$status_text = '<span class="tor-closed-cp">'. $lang['TOR_CLOSED_CPHOLD'] .'</span>';
break;
case 7:
$status_text = '<span class="tor-consumed">'. $lang['TOR_CONSUMED'] .'</span>';
break;
case 8:
$status_text = '<span class="tor-approved">'. $lang['TOR_DOUBTFUL'] .'</span>';
break;
case 9:
$status_text = '<span class="tor-checking">'. $lang['TOR_CHECKING'] .'</span>';
break;
case 10:
$status_text = '<span class="tor-dup">'. $lang['TOR_TMP'] .'</span>';
break;
case 11:
$status_text = '<span class="tor-dup">'. $lang['TOR_PREMOD'] .'</span>';
break;
}
meta_refresh($url, '2');
$message = sprintf($lang['MODERATE_PANEL_TYPE'], $status_text, '<a class="gen" href="'. $url .'">', '</a>');
bb_die($message);
break;
}
}
$template->assign_vars(array(
'PAGE_TITLE' => $lang['MODERATE_PANEL'],
'SELECT_TPP' => ($select_tpp) ? build_select('tpp', $select_tpp, $tor_topics_per_page, null, null, 'onchange="$(\'#tpp\').submit();"') : '',
'L_NO_MATCH' => $lang['NO_MATCH'],
'L_DOWN' => $lang['SET_DL_STATUS'],
'L_UNDOWN' => $lang['UNSET_DL_STATUS'],
'L_TOR_DELETE' => $lang['BT_UNREG_FROM_TRACKER'],
'ST_0' => ($status == 0) ? 'selected="selected"' : '',
'ST_1' => ($status == 1) ? 'selected="selected"' : '',
'ST_2' => ($status == 2) ? 'selected="selected"' : '',
'ST_3' => ($status == 3) ? 'selected="selected"' : '',
'ST_4' => ($status == 4) ? 'selected="selected"' : '',
'ST_5' => ($status == 5) ? 'selected="selected"' : '',
'ST_6' => ($status == 6) ? 'selected="selected"' : '',
'ST_7' => ($status == 7) ? 'selected="selected"' : '',
'ST_8' => ($status == 8) ? 'selected="selected"' : '',
'ST_9' => ($status == 9) ? 'selected="selected"' : '',
'ST_10' => ($status == 10) ? 'selected="selected"' : '',
'ST_11' => ($status == 11) ? 'selected="selected"' : '',
'ST_G' => ($status == 'gold') ? 'selected="selected"' : '',
'ST_S' => ($status == 'silver') ? 'selected="selected"' : '',
'SHOW_JUMPBOX' => true,
));
print_page('mod.tpl');
?>