Файл: CMS/core/admin/comments.php
Строк: 137
<?php
if (!defined('CMS')) { die('Access Denied!'); }
function gen_uri_type($type = '', $idk = '') {
global $types;
switch($type):
case 'news':
return '<a href="/news/' . gen_uri('news', $idk, RND) . '">' . $types[$type] . '</a><br />';
break;
case 'load':
return '<a href="/load/' . gen_uri('file', $idk, RND) . '">' . $types[$type] . '</a><br />';
break;
case 'battle':
return '<a href="/gallery/' . gen_uri('battle', $idk, RND) . '">' . $types[$type] . '</a><br />';
break;
case 'gallery':
return '<a href="/gallery/' . gen_uri('photo', $idk, RND) . '">' . $types[$type] . '</a><br />';
break;
case 'blog':
return '<a href="/blog/' . gen_uri('post', $idk, RND) . '">' . $types[$type] . '</a><br />';
break;
endswitch;
}
if (is_admin(array(101, 102, 103))) {
$types = array(
'all' => 'Все',
'news' => 'Новости',
'load' => 'Загруз центр',
'battle' => 'Фото битвы',
'gallery' => 'Галерея',
'blog' => 'Блоги',
);
$type = !empty($_GET['type']) ? check($_GET['type']) : 'all';
if (!empty($_POST['del'])) {
$del = intar($_POST['del']);
if (!empty($_GET['rnd']) && $_GET['rnd'] == $_SESSION['token']) {
if ($del > 0) {
$del = is_array($del) ? $del : array($del);
$del = implode(',', $del);
if ($type == 'news') {
$db->query("DELETE FROM ?_comments WHERE `comm_type` = 'news' AND `comm_id` IN(" . $del . ")");
$db->query("UPDATE ?_news SET `news_comments` = (SELECT COUNT(1) FROM ?_comments
WHERE ?_news.`news_id` = ?_comments.`comm_post` AND `comm_type` = 'news');");
$inSes->addMessage('Выбранные комментарии в новостях успешно удалены!', 'ok');
}
else if ($type == 'load') {
$db->query("DELETE FROM ?_comments WHERE `comm_type` = 'load' AND `comm_id` IN(" . $del . ")");
$db->query("UPDATE ?_downs SET `downs_comments` = (SELECT COUNT(1) FROM ?_comments
WHERE ?_downs.`downs_id` = ?_comments.`comm_post` AND `comm_type` = 'load');");
$inSes->addMessage('Выбранные комментарии в з.ц успешно удалены!', 'ok');
}
else if ($type == 'battle') {
$db->query("DELETE FROM ?_comments WHERE `comm_type` = 'battle' AND `comm_id` IN(" . $del . ")");
$db->query("UPDATE ?_users_battle SET `battle_comm` = (SELECT COUNT(1) FROM ?_comments WHERE ?_users_battle.`battle_id` = ?_comments.`comm_post` AND ?_comments.`comm_type` = 'battle');");
$inSes->addMessage('Выбранные комментарии в фото-битвах успешно удалены!', 'ok');
}
else if ($type == 'gallery') {
$db->query("DELETE FROM ?_comments WHERE `comm_type` = 'gallery' AND `comm_id` IN(" . $del . ")");
$db->query("UPDATE ?_users_photos SET `photo_comments` = (SELECT COUNT(1) FROM ?_comments WHERE ?_users_photos.`photo_id` = ?_comments.`comm_post` AND ?_comments.`comm_type` = 'gallery');");
$inSes->addMessage('Выбранные комментарии в галерее успешно удалены!', 'ok');
}
else if ($type == 'blog') {
$db->query("DELETE FROM ?_comments WHERE `comm_type` = 'blog' AND `comm_id` IN(" . $del . ")");
$db->query("UPDATE ?_blog_posts SET `blog_comments` = (SELECT COUNT(1) FROM ?_comments WHERE ?_blog_posts.`blog_id` = ?_comments.`comm_post` AND `comm_type` = 'blog');");
$inSes->addMessage('Выбранные комментарии в блогах успешно удалены!', 'ok');
}
else $inSes->addMessage('Ошибка! Неверно выбрана категория');
}
else $inSes->addMessage('Ошибка! Отстутствуют выбранные комментарии для удаления!');
}
else $inSes->addMessage('Ошибка! Неверный идентификатор сессии, повторите действие!');
redirect('?m=comments&type=' . $type . '&' . RND);
}
show_header('Последние комментарии');
$show = array();
foreach($types as $key => $val) {
if (!empty($_GET['type']) && $_GET['type'] == $key) $show[] = '<b>' . $val . '</b>';
else $show[] = '<a href="?m=comments&type=' . $key . '&' . RND . '">' . $val . '</a>';
}
echo '<div class="b">' . implode(', ', $show) . '</div>';
$onpage = !empty($config['comm_num']) ? num($config['comm_num']) : 10;
if ($page > 1) $from = ($page - 1) * $onpage; else $from = 0;
$_SESSION[SP]['comm'] = !empty($_SESSION[SP]['comm']) ? num($_SESSION[SP]['comm']) : 2;
$_SESSION[SP]['comm'] = (!empty($_GET['sort']) && in_array($_GET['sort'],array(1,2))) ? num($_GET['sort']) : num($_SESSION[SP]['comm']);
$order = ($_SESSION[SP]['comm'] == 1) ? 'DESC' : 'ASC';
if ($type == 'all') {
$coms = $db->selectPage( $total, "SELECT `c`.*, `v`.`visit_nowtime`, `u`.`users_gender`
FROM ?_comments `c` LEFT JOIN ?_users `u`
ON `c`.`comm_author` = `u`.`users_login`
LEFT JOIN ?_users_visit `v`
ON `c`.`comm_author` = `v`.`visit_user`
ORDER BY `c`.`comm_date` " . $order . "
LIMIT ?d, ?d", $from, $onpage );
}
else {
$coms = $db->selectPage( $total, "SELECT `c`.*, `v`.`visit_nowtime`, `u`.`users_gender`
FROM ?_comments `c` LEFT JOIN ?_users `u`
ON `c`.`comm_author` = `u`.`users_login`
LEFT JOIN ?_users_visit `v`
ON `c`.`comm_author` = `v`.`visit_user`
WHERE `c`.`comm_type` = ?
ORDER BY `c`.`comm_date` " . $order . "
LIMIT ?d, ?d", $type, $from, $onpage );
}
echo '<div class="b"><span><b>Комментарии</b> (' . num($total) . ')</span><br />';
echo 'Показывать новые: ';
if ($_SESSION[SP]['comm'] == 1) echo '<a href="?m=comments&sort=2&' . RND . '">вверху</a> | <b>внизу</b>';
else echo '<b>вверху</b> | <a href="?m=comments&sort=1&' . RND . '">внизу</a>';
echo '</div>';
if (!empty($coms) && $total > 0) {
if ($type <> 'all') {
echo '<form action="?m=comments&type=' . $type . '&rnd=' . $_SESSION['token'] . '" method="post" name="comments">';
}
$i = $from + 1;
foreach($coms as $com) {
$cid = num($com['comm_id']);
echo '<div class="b">';
echo '<div class="img">' . $i++ . '. ' . user_visit_icon($com['comm_author'], $com['users_gender'], $com['visit_nowtime']) . '</div>';
echo '<b>' . users_anketa($com['comm_author']) . '</b>';
echo '<div class="right"> (' . get_date(strtotime($com['comm_date'])) . ')</div><br />';
echo gen_uri_type($com['comm_type'], $com['comm_post']);
echo nl2br(bb_code($com['comm_text'])) . '<br />';
if ($type <> 'all') {
echo '<input type="checkbox" name="del[]" value="' . $cid . '" />';
}
if (!empty($config['anonymity'])) {
echo '<span class="data">(' . $com['comm_ua'] . ', ' . $com['comm_ip'] . ')</span>';
}
echo '</div>';
}
echo show_pages('?m=comments&type=' . $type);
if ($type <> 'all') {
echo '<div class="b">';
echo '<input type="checkbox" name="master_box" title="Отметить всё" onclick="javascript:ckeck_uncheck_all()">';
echo '<input type="submit" class="btns" value="Удалить выбранное" /></form></div>';
echo <<<JSCRIPT
<script language='JavaScript' type="text/javascript">
<!--
function ckeck_uncheck_all() {
var frm = document.comments;
if(frm.master_box.checked == true){ frm.master_box.checked = false; }
else{ frm.master_box.checked = true; }
for (var i=0;i<frm.elements.length;i++) {
var elmnt = frm.elements[i];
if (elmnt.type=='checkbox') {
if(frm.master_box.checked == true){ elmnt.checked=false; }
else{ elmnt.checked=true; }
}
}
}
-->
</script>
JSCRIPT;
}
}
else {
show_error('Комментарии не найдены!');
}
echo '<div class="b">' . icon('return.png') . ' <a href="?' . RND . '">В админку</a><br /></div>';
show_footer();
}
else {
redirect('/?' . RND);
}
?>