root / tags / milestone_3 / phpBB / mcp.php
History | View | Annotate | Download (19.5 kB)
| 1 | <?php
|
|---|---|
| 2 | /**
|
| 3 | * |
| 4 | * @package mcp |
| 5 | * @version $Id: mcp.php 5247 2005-10-02 18:47:06Z acydburn $ |
| 6 | * @copyright (c) 2005 phpBB Group |
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | /**
|
| 12 | * @ignore |
| 13 | */ |
| 14 | define('IN_PHPBB', true); |
| 15 | $phpbb_root_path = './'; |
| 16 | $phpEx = substr(strrchr(__FILE__, '.'), 1); |
| 17 | include($phpbb_root_path . 'common.'.$phpEx); |
| 18 | include($phpbb_root_path . 'includes/functions_admin.'.$phpEx); |
| 19 | |
| 20 | /**
|
| 21 | * @package mcp |
| 22 | * MCP Module |
| 23 | */ |
| 24 | class module |
| 25 | {
|
| 26 | var $id = 0; |
| 27 | var $type; |
| 28 | var $name; |
| 29 | var $mode; |
| 30 | var $url; |
| 31 | |
| 32 | // Private methods, should not be overwritten
|
| 33 | function create($module_type, $module_url, $post_id, $topic_id, $forum_id, $selected_mod = false, $selected_submod = false) |
| 34 | {
|
| 35 | global $template, $auth, $db, $user, $config; |
| 36 | global $phpbb_root_path, $phpEx; |
| 37 | |
| 38 | $sql = 'SELECT module_id, module_title, module_filename, module_subs, module_acl |
| 39 | FROM ' . MODULES_TABLE . " |
| 40 | WHERE module_type = '{$module_type}' |
| 41 | AND module_enabled = 1 |
| 42 | ORDER BY module_order ASC";
|
| 43 | $result = $db->sql_query($sql); |
| 44 | |
| 45 | $i = 0; |
| 46 | while ($row = $db->sql_fetchrow($result)) |
| 47 | {
|
| 48 | // Authorisation is required for the basic module
|
| 49 | if ($row['module_acl']) |
| 50 | {
|
| 51 | $is_auth = false; |
| 52 | eval('$is_auth = (' . preg_replace(array('#acl_([a-z_]+)#e', '#cfg_([a-z_]+)#e'), array('(int) $auth->acl_get("\\1", ' . $forum_id . ')', '(int) $config["\\1"]'), trim($row['module_acl'])) . ');'); |
| 53 | |
| 54 | // The user is not authorised to use this module, skip it
|
| 55 | if (!$is_auth) |
| 56 | {
|
| 57 | continue;
|
| 58 | } |
| 59 | } |
| 60 | |
| 61 | $selected = ($row['module_filename'] == $selected_mod || $row['module_id'] == $selected_mod || (!$selected_mod && !$i)) ? true : false; |
| 62 | |
| 63 | // Get the localised lang string if available, or make up our own otherwise
|
| 64 | $module_lang = strtoupper($module_type) . '_' . $row['module_title']; |
| 65 | $template->assign_block_vars($module_type . '_section', array( |
| 66 | 'L_TITLE' => (isset($user->lang[$module_lang])) ? $user->lang[$module_lang] : ucfirst(str_replace('_', ' ', strtolower($row['module_title']))), |
| 67 | 'S_SELECTED' => $selected, |
| 68 | 'U_TITLE' => $module_url . '&i=' . $row['module_id']) |
| 69 | ); |
| 70 | |
| 71 | if ($selected) |
| 72 | {
|
| 73 | $module_id = $row['module_id']; |
| 74 | $module_name = $row['module_filename']; |
| 75 | |
| 76 | if ($row['module_subs']) |
| 77 | {
|
| 78 | $j = 0; |
| 79 | $submodules_ary = explode("\n", $row['module_subs']); |
| 80 | foreach ($submodules_ary as $submodule) |
| 81 | {
|
| 82 | if (!trim($submodule)) |
| 83 | {
|
| 84 | continue;
|
| 85 | } |
| 86 | |
| 87 | $submodule = explode(',', trim($submodule)); |
| 88 | $submodule_title = array_shift($submodule); |
| 89 | |
| 90 | $is_auth = true; |
| 91 | foreach ($submodule as $auth_option) |
| 92 | {
|
| 93 | eval('$is_auth = (' . preg_replace(array('#acl_([a-z_]+)#e', '#cfg_([a-z_]+)#e'), array('(int) $auth->acl_get("\\1", ' . $forum_id . ')', '(int) $config["\\1"]'), trim($auth_option)) . ');'); |
| 94 | |
| 95 | if (!$is_auth) |
| 96 | {
|
| 97 | break;
|
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if (!$is_auth) |
| 102 | {
|
| 103 | continue;
|
| 104 | } |
| 105 | |
| 106 | // Only show those rows we are able to access
|
| 107 | if (($submodule_title == 'post_details' && !$post_id) || |
| 108 | ($submodule_title == 'topic_view' && !$topic_id) || |
| 109 | ($submodule_title == 'forum_view' && !$forum_id)) |
| 110 | {
|
| 111 | continue;
|
| 112 | } |
| 113 | |
| 114 | $suffix = ($post_id) ? "&p=$post_id" : ''; |
| 115 | $suffix .= ($topic_id) ? "&t=$topic_id" : ''; |
| 116 | $suffix .= ($forum_id) ? "&f=$forum_id" : ''; |
| 117 | |
| 118 | $selected = ($submodule_title == $selected_submod || (!$selected_submod && !$j)) ? true : false; |
| 119 | |
| 120 | // Get the localised lang string if available, or make up our own otherwise
|
| 121 | $module_lang = strtoupper($module_type . '_' . $module_name . '_' . $submodule_title); |
| 122 | |
| 123 | $template->assign_block_vars("{$module_type}_section.{$module_type}_subsection", array( |
| 124 | 'L_TITLE' => (isset($user->lang[$module_lang])) ? $user->lang[$module_lang] : ucfirst(str_replace('_', ' ', strtolower($module_lang))), |
| 125 | 'S_SELECTED' => $selected, |
| 126 | 'ADD_ITEM' => $this->add_menu_item($row['module_filename'], $submodule_title), |
| 127 | 'U_TITLE' => $module_url . '&i=' . $module_id . '&mode=' . $submodule_title . $suffix) |
| 128 | ); |
| 129 | |
| 130 | if ($selected) |
| 131 | {
|
| 132 | $this->mode = $submodule_title; |
| 133 | } |
| 134 | |
| 135 | $j++;
|
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | $i++;
|
| 141 | } |
| 142 | $db->sql_freeresult($result); |
| 143 | |
| 144 | if (!$module_id) |
| 145 | {
|
| 146 | trigger_error('MODULE_NOT_EXIST'); |
| 147 | } |
| 148 | |
| 149 | $this->type = $module_type; |
| 150 | $this->id = $module_id; |
| 151 | $this->name = $module_name; |
| 152 | $this->url = "{$phpbb_root_path}mcp.$phpEx?sid={$user->session_id}"; |
| 153 | $this->url .= ($post_id) ? "&p=$post_id" : ''; |
| 154 | $this->url .= ($topic_id) ? "&t=$topic_id" : ''; |
| 155 | $this->url .= ($forum_id) ? "&f=$forum_id" : ''; |
| 156 | } |
| 157 | |
| 158 | function load($type = false, $name = false, $mode = false, $run = true) |
| 159 | {
|
| 160 | global $phpbb_root_path, $phpEx; |
| 161 | |
| 162 | if ($type) |
| 163 | {
|
| 164 | $this->type = $type; |
| 165 | } |
| 166 | |
| 167 | if ($name) |
| 168 | {
|
| 169 | $this->name = $name; |
| 170 | } |
| 171 | |
| 172 | if (!class_exists($this->type . '_' . $this->name)) |
| 173 | {
|
| 174 | require_once($phpbb_root_path . "includes/{$this->type}/{$this->type}_{$this->name}.$phpEx"); |
| 175 | |
| 176 | if ($run) |
| 177 | {
|
| 178 | if (!isset($this->mode)) |
| 179 | {
|
| 180 | $this->mode = $mode; |
| 181 | } |
| 182 | |
| 183 | eval("\$this->module = new {$this->type}_{$this->name}(\$this->id, \$this->mode, \$this->url);"); |
| 184 | if (method_exists($this->module, 'init')) |
| 185 | {
|
| 186 | $this->module->init();
|
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // Displays the appropriate template with the given title
|
| 193 | function display($page_title, $tpl_name) |
| 194 | {
|
| 195 | global $template; |
| 196 | |
| 197 | page_header($page_title);
|
| 198 | |
| 199 | $template->set_filenames(array( |
| 200 | 'body' => $tpl_name) |
| 201 | ); |
| 202 | |
| 203 | page_footer(); |
| 204 | } |
| 205 | |
| 206 | // Add Item to Submodule Title
|
| 207 | function add_menu_item($module_name, $mode) |
| 208 | {
|
| 209 | global $db, $user, $auth; |
| 210 | |
| 211 | if ($module_name != 'queue') |
| 212 | {
|
| 213 | return ''; |
| 214 | } |
| 215 | |
| 216 | $forum_id = request_var('f', 0); |
| 217 | if ($forum_id && $auth->acl_get('m_approve', $forum_id)) |
| 218 | {
|
| 219 | $forum_list = array($forum_id); |
| 220 | } |
| 221 | else
|
| 222 | {
|
| 223 | $forum_list = get_forum_list('m_approve'); |
| 224 | } |
| 225 | |
| 226 | switch ($mode) |
| 227 | {
|
| 228 | case 'unapproved_topics': |
| 229 | |
| 230 | $sql = 'SELECT COUNT(*) AS total |
| 231 | FROM ' . TOPICS_TABLE . ' |
| 232 | WHERE forum_id IN (' . implode(', ', $forum_list) . ') |
| 233 | AND topic_approved = 0';
|
| 234 | $result = $db->sql_query($sql); |
| 235 | $total_topics = $db->sql_fetchfield('total', 0, $result); |
| 236 | |
| 237 | return ($total_topics) ? $total_topics : $user->lang['NONE']; |
| 238 | break;
|
| 239 | |
| 240 | case 'unapproved_posts': |
| 241 | |
| 242 | $sql = 'SELECT COUNT(*) AS total |
| 243 | FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t |
| 244 | WHERE p.forum_id IN (' . implode(', ', $forum_list) . ') |
| 245 | AND p.post_approved = 0 |
| 246 | AND t.topic_id = p.topic_id |
| 247 | AND t.topic_first_post_id <> p.post_id';
|
| 248 | $result = $db->sql_query($sql); |
| 249 | $total_posts = $db->sql_fetchfield('total', 0, $result); |
| 250 | |
| 251 | return ($total_posts) ? $total_posts : $user->lang['NONE']; |
| 252 | break;
|
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // Public methods to be overwritten by modules
|
| 257 | function module() |
| 258 | {
|
| 259 | // Module name
|
| 260 | // Module filename
|
| 261 | // Module description
|
| 262 | // Module version
|
| 263 | // Module compatibility
|
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | function init() |
| 268 | {
|
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | function install() |
| 273 | {
|
| 274 | return false; |
| 275 | } |
| 276 | |
| 277 | function uninstall() |
| 278 | {
|
| 279 | return false; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /**
|
| 284 | */ |
| 285 | |
| 286 | // Start session management
|
| 287 | $user->session_begin();
|
| 288 | $auth->acl($user->data); |
| 289 | $user->setup('mcp'); |
| 290 | |
| 291 | $mcp = new module(); |
| 292 | |
| 293 | // Basic parameter data
|
| 294 | $mode = request_var('mode', ''); |
| 295 | $mode2 = (isset($_REQUEST['quick'])) ? request_var('mode2', '') : ''; |
| 296 | $module = request_var('i', ''); |
| 297 | |
| 298 | if (is_array($mode)) |
| 299 | {
|
| 300 | list($mode, ) = each($mode); |
| 301 | } |
| 302 | |
| 303 | if ($mode2) |
| 304 | {
|
| 305 | $mode = $mode2; |
| 306 | $action = ''; |
| 307 | unset($mode2); |
| 308 | } |
| 309 | |
| 310 | // Make sure we are using the correct module
|
| 311 | if ($mode == 'approve' || $mode == 'disapprove') |
| 312 | {
|
| 313 | $module = 'queue'; |
| 314 | } |
| 315 | |
| 316 | // Only Moderators can go beyond this point
|
| 317 | if (!$user->data['is_registered']) |
| 318 | {
|
| 319 | if ($user->data['is_bot']) |
| 320 | {
|
| 321 | redirect("index.$phpEx$SID");
|
| 322 | } |
| 323 | |
| 324 | login_box('', $user->lang['LOGIN_EXPLAIN_MCP']); |
| 325 | } |
| 326 | |
| 327 | $quickmod = (isset($_REQUEST['quickmod'])) ? true : false; |
| 328 | $action = request_var('action', ''); |
| 329 | $action_ary = request_var('action', array('' => 0)); |
| 330 | |
| 331 | if (sizeof($action_ary)) |
| 332 | {
|
| 333 | list($action, ) = each($action); |
| 334 | } |
| 335 | unset($action_ary); |
| 336 | |
| 337 | if ($action == 'merge_select') |
| 338 | {
|
| 339 | $mode = 'forum_view'; |
| 340 | } |
| 341 | |
| 342 | // Topic view modes
|
| 343 | if (in_array($mode, array('split', 'split_all', 'split_beyond', 'merge', 'merge_posts'))) |
| 344 | {
|
| 345 | $_REQUEST['action'] = $action = $mode; |
| 346 | $mode = 'topic_view'; |
| 347 | $quickmod = false; |
| 348 | } |
| 349 | |
| 350 | // Forum view modes
|
| 351 | if (in_array($mode, array('resync'))) |
| 352 | {
|
| 353 | $_REQUEST['action'] = $action = $mode; |
| 354 | $mode = 'forum_view'; |
| 355 | $quickmod = false; |
| 356 | } |
| 357 | |
| 358 | if (!$quickmod) |
| 359 | {
|
| 360 | $post_id = request_var('p', 0); |
| 361 | $topic_id = request_var('t', 0); |
| 362 | $forum_id = request_var('f', 0); |
| 363 | |
| 364 | if ($post_id) |
| 365 | {
|
| 366 | // We determine the topic and forum id here, to make sure the moderator really has moderative rights on this post
|
| 367 | $sql = 'SELECT topic_id, forum_id |
| 368 | FROM ' . POSTS_TABLE . " |
| 369 | WHERE post_id = $post_id"; |
| 370 | $result = $db->sql_query($sql); |
| 371 | $row = $db->sql_fetchrow($result); |
| 372 | $db->sql_freeresult($result); |
| 373 | |
| 374 | $topic_id = (int) $row['topic_id']; |
| 375 | $forum_id = (int) $row['forum_id']; |
| 376 | } |
| 377 | |
| 378 | if ($topic_id && !$forum_id) |
| 379 | {
|
| 380 | $sql = 'SELECT forum_id |
| 381 | FROM ' . TOPICS_TABLE . " |
| 382 | WHERE topic_id = $topic_id"; |
| 383 | $result = $db->sql_query($sql); |
| 384 | $row = $db->sql_fetchrow($result); |
| 385 | $db->sql_freeresult($result); |
| 386 | |
| 387 | $forum_id = (int) $row['forum_id']; |
| 388 | } |
| 389 | |
| 390 | // If we do not have a forum id and the user is not a super moderator (global options are set to false, even if the user is able to moderator at least one forum
|
| 391 | if (!$forum_id && !$auth->acl_get('m_')) |
| 392 | {
|
| 393 | $forum_list = get_forum_list('m_'); |
| 394 | |
| 395 | if (!sizeof($forum_list)) |
| 396 | {
|
| 397 | trigger_error('MODULE_NOT_EXIST'); |
| 398 | } |
| 399 | |
| 400 | // We do not check all forums, only the first one should be sufficiant.
|
| 401 | $forum_id = $forum_list[0]; |
| 402 | } |
| 403 | |
| 404 | // Instantiate module system and generate list of available modules
|
| 405 | $mcp->create('mcp', "mcp.$phpEx$SID", $post_id, $topic_id, $forum_id, $module, $mode); |
| 406 | |
| 407 | // Load and execute the relevant module
|
| 408 | $mcp->load('mcp', false, $mode); |
| 409 | exit;
|
| 410 | } |
| 411 | |
| 412 | switch ($mode) |
| 413 | {
|
| 414 | case 'lock': |
| 415 | case 'unlock': |
| 416 | case 'lock_post': |
| 417 | case 'unlock_post': |
| 418 | $mcp->load('mcp', 'main', $mode); |
| 419 | break;
|
| 420 | case 'make_sticky': |
| 421 | case 'make_announce': |
| 422 | case 'make_global': |
| 423 | case 'make_normal': |
| 424 | $mcp->load('mcp', 'main', $mode); |
| 425 | break;
|
| 426 | case 'fork': |
| 427 | case 'move': |
| 428 | $mcp->load('mcp', 'main', $mode); |
| 429 | break;
|
| 430 | case 'delete_post': |
| 431 | case 'delete_topic': |
| 432 | $mcp->load('mcp', 'main', $mode); |
| 433 | break;
|
| 434 | default:
|
| 435 | trigger_error("$mode not allowed as quickmod"); |
| 436 | } |
| 437 | |
| 438 | |
| 439 | |
| 440 | //
|
| 441 | // LITTLE HELPER
|
| 442 | |
| 443 | /**
|
| 444 | * Get simple topic data |
| 445 | */ |
| 446 | function get_topic_data($topic_ids, $acl_list = false) |
| 447 | {
|
| 448 | global $auth, $db; |
| 449 | $rowset = array(); |
| 450 | |
| 451 | if (implode(', ', $topic_ids) == '') |
| 452 | {
|
| 453 | return array(); |
| 454 | } |
| 455 | |
| 456 | $sql = 'SELECT f.*, t.* |
| 457 | FROM ' . TOPICS_TABLE . ' t |
| 458 | LEFT JOIN ' . FORUMS_TABLE . ' f ON t.forum_id = f.forum_id |
| 459 | WHERE t.topic_id IN (' . implode(', ', $topic_ids) . ')'; |
| 460 | $result = $db->sql_query($sql); |
| 461 | |
| 462 | while ($row = $db->sql_fetchrow($result)) |
| 463 | {
|
| 464 | if ($acl_list && !$auth->acl_get($acl_list, $row['forum_id'])) |
| 465 | {
|
| 466 | continue;
|
| 467 | } |
| 468 | |
| 469 | $rowset[$row['topic_id']] = $row; |
| 470 | } |
| 471 | |
| 472 | return $rowset; |
| 473 | } |
| 474 | |
| 475 | /**
|
| 476 | * Get simple post data |
| 477 | */ |
| 478 | function get_post_data($post_ids, $acl_list = false) |
| 479 | {
|
| 480 | global $db, $auth; |
| 481 | $rowset = array(); |
| 482 | |
| 483 | $sql = 'SELECT p.*, u.*, t.*, f.* |
| 484 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u, ' . TOPICS_TABLE . ' t |
| 485 | LEFT JOIN ' . FORUMS_TABLE . ' f ON f.forum_id = p.forum_id |
| 486 | WHERE p.post_id IN (' . implode(', ', $post_ids) . ') |
| 487 | AND u.user_id = p.poster_id |
| 488 | AND t.topic_id = p.topic_id';
|
| 489 | $result = $db->sql_query($sql); |
| 490 | |
| 491 | while ($row = $db->sql_fetchrow($result)) |
| 492 | {
|
| 493 | if ($acl_list && !$auth->acl_get($acl_list, $row['forum_id'])) |
| 494 | {
|
| 495 | continue;
|
| 496 | } |
| 497 | |
| 498 | if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id'])) |
| 499 | {
|
| 500 | // Moderators without the permission to approve post should at least not see them. ;)
|
| 501 | continue;
|
| 502 | } |
| 503 | |
| 504 | $rowset[$row['post_id']] = $row; |
| 505 | } |
| 506 | |
| 507 | return $rowset; |
| 508 | } |
| 509 | |
| 510 | /**
|
| 511 | * Get simple forum data |
| 512 | */ |
| 513 | function get_forum_data($forum_id, $acl_list = 'f_list') |
| 514 | {
|
| 515 | global $auth, $db; |
| 516 | $rowset = array(); |
| 517 | |
| 518 | $sql = 'SELECT * |
| 519 | FROM ' . FORUMS_TABLE . ' |
| 520 | WHERE forum_id ' . ((is_array($forum_id)) ? 'IN (' . implode(', ', $forum_id) . ')' : "= $forum_id"); |
| 521 | $result = $db->sql_query($sql); |
| 522 | |
| 523 | while ($row = $db->sql_fetchrow($result)) |
| 524 | {
|
| 525 | if ($acl_list && !$auth->acl_get($acl_list, $row['forum_id'])) |
| 526 | {
|
| 527 | continue;
|
| 528 | } |
| 529 | if ($auth->acl_get('m_approve', $row['forum_id'])) |
| 530 | {
|
| 531 | $row['forum_topics'] = $row['forum_topics_real']; |
| 532 | } |
| 533 | |
| 534 | $rowset[$row['forum_id']] = $row; |
| 535 | } |
| 536 | |
| 537 | return $rowset; |
| 538 | } |
| 539 | |
| 540 | /**
|
| 541 | * sorting in mcp |
| 542 | */ |
| 543 | function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, &$sort_order_sql, &$total, $forum_id = 0, $topic_id = 0, $where_sql = 'WHERE') |
| 544 | {
|
| 545 | global $db, $user, $auth, $template; |
| 546 | |
| 547 | $sort_days = request_var('sort_days', 0); |
| 548 | $min_time = ($sort_days) ? time() - ($sort_days * 86400) : 0; |
| 549 | |
| 550 | switch ($mode) |
| 551 | {
|
| 552 | case 'viewforum': |
| 553 | $type = 'topics'; |
| 554 | $default_key = 't'; |
| 555 | $default_dir = 'd'; |
| 556 | $sql = 'SELECT COUNT(topic_id) AS total |
| 557 | FROM ' . TOPICS_TABLE . " |
| 558 | $where_sql forum_id = $forum_id |
| 559 | AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ") |
| 560 | AND topic_last_post_time >= $min_time"; |
| 561 | |
| 562 | if (!$auth->acl_get('m_approve', $forum_id)) |
| 563 | {
|
| 564 | $sql .= 'AND topic_approved = 1'; |
| 565 | } |
| 566 | break;
|
| 567 | |
| 568 | case 'viewtopic': |
| 569 | $type = 'posts'; |
| 570 | $default_key = 't'; |
| 571 | $default_dir = 'a'; |
| 572 | $sql = 'SELECT COUNT(post_id) AS total |
| 573 | FROM ' . POSTS_TABLE . " |
| 574 | $where_sql topic_id = $topic_id |
| 575 | AND post_time >= $min_time"; |
| 576 | if (!$auth->acl_get('m_approve', $forum_id)) |
| 577 | {
|
| 578 | $sql .= 'AND post_approved = 1'; |
| 579 | } |
| 580 | break;
|
| 581 | |
| 582 | case 'unapproved_posts': |
| 583 | $type = 'posts'; |
| 584 | $default_key = 't'; |
| 585 | $default_dir = 'd'; |
| 586 | $sql = 'SELECT COUNT(post_id) AS total |
| 587 | FROM ' . POSTS_TABLE . " |
| 588 | $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_approve'))) . ') |
| 589 | AND post_approved = 0 |
| 590 | AND post_time >= ' . $min_time; |
| 591 | break;
|
| 592 | |
| 593 | case 'unapproved_topics': |
| 594 | $type = 'topics'; |
| 595 | $default_key = 't'; |
| 596 | $default_dir = 'd'; |
| 597 | $sql = 'SELECT COUNT(topic_id) AS total |
| 598 | FROM ' . TOPICS_TABLE . " |
| 599 | $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_approve'))) . ') |
| 600 | AND topic_approved = 0 |
| 601 | AND topic_time >= ' . $min_time; |
| 602 | break;
|
| 603 | |
| 604 | case 'reports': |
| 605 | $type = 'reports'; |
| 606 | $default_key = 'p'; |
| 607 | $default_dir = 'd'; |
| 608 | $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : ''; |
| 609 | |
| 610 | if ($topic_id) |
| 611 | {
|
| 612 | $where_sql .= ' p.topic_id = ' . $topic_id; |
| 613 | } |
| 614 | else if ($forum_id) |
| 615 | {
|
| 616 | $where_sql .= ' p.forum_id = ' . $forum_id; |
| 617 | } |
| 618 | else
|
| 619 | {
|
| 620 | $where_sql .= ' p.forum_id IN (' . implode(', ', get_forum_list('m_')) . ')'; |
| 621 | } |
| 622 | $sql = 'SELECT COUNT(r.report_id) AS total |
| 623 | FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p |
| 624 | $where_sql |
| 625 | AND p.post_id = r.post_id |
| 626 | $limit_time_sql"; |
| 627 | break;
|
| 628 | |
| 629 | case 'viewlogs': |
| 630 | $type = 'logs'; |
| 631 | $default_key = 't'; |
| 632 | $default_dir = 'd'; |
| 633 | $sql = 'SELECT COUNT(log_id) AS total |
| 634 | FROM ' . LOG_TABLE . " |
| 635 | $where_sql forum_id IN (" . (($forum_id) ? $forum_id : implode(', ', get_forum_list('m_'))) . ') |
| 636 | AND log_time >= ' . $min_time . ' |
| 637 | AND log_type = ' . LOG_MOD; |
| 638 | break;
|
| 639 | } |
| 640 | |
| 641 | $sort_key = request_var('sk', $default_key); |
| 642 | $sort_dir = request_var('sd', $default_dir); |
| 643 | $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); |
| 644 | |
| 645 | switch ($type) |
| 646 | {
|
| 647 | case 'topics': |
| 648 | $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); |
| 649 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); |
| 650 | |
| 651 | $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_replies_real' : 't.topic_replies'), 's' => 't.topic_title', 'v' => 't.topic_views'); |
| 652 | $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : ''; |
| 653 | break;
|
| 654 | |
| 655 | case 'posts': |
| 656 | $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); |
| 657 | $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); |
| 658 | $sort_by_sql = array('a' => 'u.username', 't' => 'p.post_id', 's' => 'p.post_subject'); |
| 659 | $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : ''; |
| 660 | break;
|
| 661 | |
| 662 | case 'reports': |
| 663 | $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); |
| 664 | $sort_by_text = array('p' => $user->lang['REPORT_PRIORITY'], 'r' => $user->lang['REPORTER'], 't' => $user->lang['REPORT_TIME']); |
| 665 | $sort_by_sql = array('p' => 'rr.reason_priority', 'r' => 'u.username', 't' => 'r.report_time'); |
| 666 | break;
|
| 667 | |
| 668 | case 'logs': |
| 669 | $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']); |
| 670 | $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']); |
| 671 | |
| 672 | $sort_by_sql = array('u' => 'l.user_id', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation'); |
| 673 | $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : ''; |
| 674 | break;
|
| 675 | } |
| 676 | |
| 677 | $sort_order_sql = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); |
| 678 | |
| 679 | $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = ''; |
| 680 | gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $sort_url); |
| 681 | |
| 682 | $template->assign_vars(array( |
| 683 | 'S_SELECT_SORT_DIR' => $s_sort_dir, |
| 684 | 'S_SELECT_SORT_KEY' => $s_sort_key, |
| 685 | 'S_SELECT_SORT_DAYS'=> $s_limit_days) |
| 686 | ); |
| 687 | |
| 688 | if (($sort_days && $mode != 'viewlogs') || $mode == 'reports' || $where_sql != 'WHERE') |
| 689 | {
|
| 690 | $result = $db->sql_query($sql); |
| 691 | $total = ($row = $db->sql_fetchrow($result)) ? $row['total'] : 0; |
| 692 | } |
| 693 | else
|
| 694 | {
|
| 695 | $total = -1; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | /**
|
| 700 | * Validate ids |
| 701 | */ |
| 702 | function check_ids(&$ids, $table, $sql_id, $acl_list = false) |
| 703 | {
|
| 704 | global $db, $auth; |
| 705 | |
| 706 | if (!is_array($ids) || !$ids) |
| 707 | {
|
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | // a small logical error, since global announcement are assigned to forum_id == 0
|
| 712 | // If the first topic id is a global announcement, we can force the forum. Though only global announcements can be
|
| 713 | // tricked... i really do not know how to prevent this atm.
|
| 714 | |
| 715 | // With those two queries we make sure all ids are within one forum...
|
| 716 | $sql = "SELECT forum_id FROM $table |
| 717 | WHERE $sql_id = {$ids[0]}"; |
| 718 | $result = $db->sql_query($sql); |
| 719 | $forum_id = (int) $db->sql_fetchfield('forum_id', 0, $result); |
| 720 | $db->sql_freeresult($result); |
| 721 | |
| 722 | if (!$forum_id) |
| 723 | {
|
| 724 | // Global Announcement?
|
| 725 | $forum_id = request_var('f', 0); |
| 726 | } |
| 727 | |
| 728 | if ($acl_list && !$auth->acl_get($acl_list, $forum_id)) |
| 729 | {
|
| 730 | trigger_error('NOT_AUTHORIZED'); |
| 731 | } |
| 732 | |
| 733 | if (!$forum_id) |
| 734 | {
|
| 735 | trigger_error('Missing forum_id, has to be in url if global announcement...'); |
| 736 | } |
| 737 | |
| 738 | $sql = "SELECT $sql_id FROM $table |
| 739 | WHERE $sql_id IN (" . implode(', ', $ids) . ") |
| 740 | AND (forum_id = $forum_id OR forum_id = 0)"; |
| 741 | $result = $db->sql_query($sql); |
| 742 | |
| 743 | $ids = array(); |
| 744 | while ($row = $db->sql_fetchrow($result)) |
| 745 | {
|
| 746 | $ids[] = $row[$sql_id]; |
| 747 | } |
| 748 | $db->sql_freeresult($result); |
| 749 | |
| 750 | return $forum_id; |
| 751 | } |
| 752 | |
| 753 | // LITTLE HELPER
|
| 754 | //
|
| 755 | |
| 756 | ?> |

