From 0dfa7fb0872e7ef2acdd1fdb0c5595fb7cca9c96 Mon Sep 17 00:00:00 2001 From: 8chan Admin Date: Sun, 16 Feb 2014 20:18:15 +0000 Subject: [PATCH] Global reports function --- inc/mod/pages.php | 25 +++++++++++++++++++------ mod.php | 1 + post.php | 3 ++- templates/mod/dashboard.html | 4 ++++ templates/report_delete.html | 1 + 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index f2426278..3926a013 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -100,13 +100,18 @@ function mod_dashboard() { cache::set('pm_unreadcount_' . $mod['id'], $args['unread_pms']); } - $query = prepare('SELECT COUNT(*) FROM ``reports``' . ($mod["type"] == "20" ? "WHERE board = :board" : "")); + $query = prepare('SELECT COUNT(*) AS `total_reports` FROM ``reports``' . ($mod["type"] == "20" ? " WHERE board = :board" : "")); - if ($mod['type'] == '20') + if ($mod['type'] == '20') { $query->bindValue(':board', $mod['boards'][0]); + } else { + $query = prepare('SELECT (SELECT COUNT(id) FROM reports WHERE global = 0) AS total_reports, (SELECT COUNT(id) FROM reports WHERE global = 1) AS global_reports'); + } $query->execute() or error(db_error($query)); - $args['reports'] = $query->fetchColumn(); + $row = $query->fetch(); + $args['reports'] = $row['total_reports']; + $args['global_reports'] = isset($row['global_reports']) ? $row['global_reports'] : false; if ($mod['type'] >= ADMIN && $config['check_updates']) { if (!$config['version']) @@ -1995,18 +2000,26 @@ function mod_rebuild() { )); } -function mod_reports() { +function mod_reports($global = false) { global $config, $mod; if (!hasPermission($config['mod']['reports'])) error($config['error']['noaccess']); - $query = prepare("SELECT * FROM ``reports`` " . ($mod["type"] == "20" ? "WHERE board = :board" : "") . " ORDER BY `time` DESC LIMIT :limit"); - $query->bindValue(':limit', $config['mod']['recent_reports'], PDO::PARAM_INT); + if ($mod['type'] == '20' and $global) + error($config['error']['noaccess']); + $query = prepare("SELECT * FROM ``reports`` " . ($mod["type"] == "20" ? "WHERE board = :board" : "") . " ORDER BY `time` DESC LIMIT :limit"); if ($mod['type'] == '20') $query->bindValue(':board', $mod['boards'][0]); + if ($global) { + $query = prepare("SELECT * FROM ``reports`` WHERE global = TRUE ORDER BY `time` DESC LIMIT :limit"); + } + + $query->bindValue(':limit', $config['mod']['recent_reports'], PDO::PARAM_INT); + + $query->execute() or error(db_error($query)); $reports = $query->fetchAll(PDO::FETCH_ASSOC); diff --git a/mod.php b/mod.php index f6a4aa0c..2648ceb2 100644 --- a/mod.php +++ b/mod.php @@ -55,6 +55,7 @@ $pages = array( '/rebuild' => 'secure_POST rebuild', // rebuild static files '/reports' => 'reports', // report queue + '/reports/(global)' => 'reports', // global report queue '/reports/(\d+)/dismiss(all)?' => 'secure report_dismiss', // dismiss a report '/IP/([\w.:]+)' => 'secure_POST ip', // view ip address diff --git a/post.php b/post.php index a839b64d..1f9abd4c 100644 --- a/post.php +++ b/post.php @@ -128,12 +128,13 @@ if (isset($_POST['delete'])) { '/' . $board['dir'] . $config['dir']['res'] . sprintf($config['file_page'], $thread ? $thread : $id) . ($thread ? '#' . $id : '') . ' for "' . $reason . '"' ); - $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)"); + $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason, :global)"); $query->bindValue(':time', time(), PDO::PARAM_INT); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR); $query->bindValue(':board', $board['uri'], PDO::PARAM_INT); $query->bindValue(':post', $id, PDO::PARAM_INT); $query->bindValue(':reason', $reason, PDO::PARAM_STR); + $query->bindValue(':global', isset($_POST['global']), PDO::PARAM_BOOL); $query->execute() or error(db_error($query)); } diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 5761c72c..239b9786 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -86,8 +86,12 @@
  • {% if reports > 0 %}{% endif %} {% trans 'Report queue' %} ({{ reports }}) + {% if reports > 0 %}{% endif %}  + {% if global_reports > 0 %}{% endif %} + {% if mod.type != 20 %}Global reports ({{global_reports}}){% endif %} {% if reports > 0 %}{% endif %}
  • + {% endif %} {% if mod|hasPermission(config.mod.view_banlist) %}
  • {% trans 'Ban list' %}
  • diff --git a/templates/report_delete.html b/templates/report_delete.html index 07221120..1c2a5c44 100644 --- a/templates/report_delete.html +++ b/templates/report_delete.html @@ -7,5 +7,6 @@
    + []