[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/ -> report.php (source)

   1  <?php
   2  /**
   3  *
   4  * @package phpBB3
   5  * @version $Id$
   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 = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  16  $phpEx = substr(strrchr(__FILE__, '.'), 1);
  17  include($phpbb_root_path . 'common.' . $phpEx);
  18  include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  19  
  20  // Start session management
  21  $user->session_begin();
  22  $auth->acl($user->data);
  23  $user->setup('mcp');
  24  
  25  $forum_id        = request_var('f', 0);
  26  $post_id        = request_var('p', 0);
  27  $pm_id            = request_var('pm', 0);
  28  $reason_id        = request_var('reason_id', 0);
  29  $report_text    = utf8_normalize_nfc(request_var('report_text', '', true));
  30  $user_notify    = ($user->data['is_registered']) ? request_var('notify', 0) : false;
  31  
  32  $submit = (isset($_POST['submit'])) ? true : false;
  33  
  34  if (!$post_id && (!$pm_id || !$config['allow_pm_report']))
  35  {
  36      trigger_error('NO_POST_SELECTED');
  37  }
  38  
  39  if ($post_id)
  40  {
  41      $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=$post_id") . "#p$post_id";
  42      $return_forum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
  43      $pm_id = 0;
  44  }
  45  else
  46  {
  47      $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
  48      $return_forum_url = '';
  49      $post_id = 0;
  50      $forum_id = 0;
  51  }
  52  
  53  // Has the report been cancelled?
  54  if (isset($_POST['cancel']))
  55  {
  56      redirect($redirect_url);
  57  }
  58  
  59  if ($post_id)
  60  {
  61      // Grab all relevant data
  62      $sql = 'SELECT t.*, p.*
  63          FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
  64          WHERE p.post_id = $post_id
  65              AND p.topic_id = t.topic_id";
  66      $result = $db->sql_query($sql);
  67      $report_data = $db->sql_fetchrow($result);
  68      $db->sql_freeresult($result);
  69  
  70      if (!$report_data)
  71      {
  72          trigger_error('POST_NOT_EXIST');
  73      }
  74  
  75      $forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
  76      $topic_id = (int) $report_data['topic_id'];
  77  
  78      $sql = 'SELECT *
  79          FROM ' . FORUMS_TABLE . '
  80          WHERE forum_id = ' . $forum_id;
  81      $result = $db->sql_query($sql);
  82      $forum_data = $db->sql_fetchrow($result);
  83      $db->sql_freeresult($result);
  84  
  85      if (!$forum_data)
  86      {
  87          trigger_error('FORUM_NOT_EXIST');
  88      }
  89  
  90      // Check required permissions
  91      $acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
  92  
  93      foreach ($acl_check_ary as $acl => $error)
  94      {
  95          if (!$auth->acl_get($acl, $forum_id))
  96          {
  97              trigger_error($error);
  98          }
  99      }
 100      unset($acl_check_ary);
 101  
 102      if ($report_data['post_reported'])
 103      {
 104          $message = $user->lang['ALREADY_REPORTED'];
 105          $message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
 106          $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
 107          trigger_error($message);
 108      }
 109  }
 110  else
 111  {
 112      // Grab all relevant data
 113      $sql = 'SELECT p.*, pt.*
 114          FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . " pt
 115          WHERE p.msg_id = $pm_id
 116              AND p.msg_id = pt.msg_id
 117              AND (p.author_id = " . $user->data['user_id'] . " OR pt.user_id = " . $user->data['user_id'] . ")";
 118      $result = $db->sql_query($sql);
 119      $report_data = $db->sql_fetchrow($result);
 120      $db->sql_freeresult($result);
 121  
 122      if (!$report_data)
 123      {
 124          $user->add_lang('ucp');
 125          trigger_error('NO_MESSAGE');
 126      }
 127  
 128      if ($report_data['message_reported'])
 129      {
 130          $message = $user->lang['ALREADY_REPORTED_PM'];
 131          $message .= '<br /><br />' . sprintf($user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
 132          trigger_error($message);
 133      }
 134  }
 135  
 136  if ($config['enable_post_confirm'] && !$user->data['is_registered'])
 137  {
 138      include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
 139      $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
 140      $captcha->init(CONFIRM_REPORT);
 141  }
 142  
 143  $error    = array();
 144  $s_hidden_fields = '';
 145  
 146  // Submit report?
 147  if ($submit && $reason_id)
 148  {
 149      if (isset($captcha))
 150      {
 151          $visual_confirmation_response = $captcha->validate();
 152          if ($visual_confirmation_response)
 153          {
 154              $error[] = $visual_confirmation_response;
 155          }
 156      }
 157  
 158      $sql = 'SELECT *
 159          FROM ' . REPORTS_REASONS_TABLE . "
 160          WHERE reason_id = $reason_id";
 161      $result = $db->sql_query($sql);
 162      $row = $db->sql_fetchrow($result);
 163      $db->sql_freeresult($result);
 164  
 165      if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
 166      {
 167          $error[] = $user->lang('EMPTY_REPORT');
 168      }
 169  
 170      if (!sizeof($error))
 171      {
 172          if (isset($captcha))
 173          {
 174              $captcha->reset();
 175          }
 176  
 177          $sql_ary = array(
 178              'reason_id'        => (int) $reason_id,
 179              'post_id'        => $post_id,
 180              'pm_id'            => $pm_id,
 181              'user_id'        => (int) $user->data['user_id'],
 182              'user_notify'    => (int) $user_notify,
 183              'report_closed'    => 0,
 184              'report_time'    => (int) time(),
 185              'report_text'    => (string) $report_text
 186          );
 187  
 188          $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 189          $db->sql_query($sql);
 190          $report_id = $db->sql_nextid();
 191  
 192          if ($post_id)
 193          {
 194              $sql = 'UPDATE ' . POSTS_TABLE . '
 195                  SET post_reported = 1
 196                  WHERE post_id = ' . $post_id;
 197              $db->sql_query($sql);
 198  
 199              if (!$report_data['topic_reported'])
 200              {
 201                  $sql = 'UPDATE ' . TOPICS_TABLE . '
 202                      SET topic_reported = 1
 203                      WHERE topic_id = ' . $report_data['topic_id'] . '
 204                          OR topic_moved_id = ' . $report_data['topic_id'];
 205                  $db->sql_query($sql);
 206              }
 207  
 208              $lang_return = $user->lang['RETURN_TOPIC'];
 209              $lang_success = $user->lang['POST_REPORTED_SUCCESS'];
 210          }
 211          else
 212          {
 213              $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
 214                  SET message_reported = 1
 215                  WHERE msg_id = ' . $pm_id;
 216              $db->sql_query($sql);
 217  
 218              $sql_ary = array(
 219                  'msg_id'        => $pm_id,
 220                  'user_id'        => ANONYMOUS,
 221                  'author_id'        => (int) $report_data['author_id'],
 222                  'pm_deleted'    => 0,
 223                  'pm_new'        => 0,
 224                  'pm_unread'        => 0,
 225                  'pm_replied'    => 0,
 226                  'pm_marked'        => 0,
 227                  'pm_forwarded'    => 0,
 228                  'folder_id'        => PRIVMSGS_INBOX,
 229              );
 230  
 231              $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 232              $db->sql_query($sql);
 233  
 234              $lang_return = $user->lang['RETURN_PM'];
 235              $lang_success = $user->lang['PM_REPORTED_SUCCESS'];
 236          }
 237  
 238          meta_refresh(3, $redirect_url);
 239  
 240          $message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
 241          if ($return_forum_url)
 242          {
 243              $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
 244          }
 245          trigger_error($message);
 246      }
 247      else if (isset($captcha) && $captcha->is_solved() !== false)
 248      {
 249          $s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields());
 250      }
 251  }
 252  
 253  // Generate the reasons
 254  display_reasons($reason_id);
 255  
 256  $page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
 257  
 258  if (isset($captcha) && $captcha->is_solved() === false)
 259  {
 260      $template->assign_vars(array(
 261          'S_CONFIRM_CODE'    => true,
 262          'CAPTCHA_TEMPLATE'    => $captcha->get_template(),
 263      ));
 264  }
 265  
 266  $template->assign_vars(array(
 267      'ERROR'                => (sizeof($error)) ? implode('<br />', $error) : '',
 268      'S_REPORT_POST'        => ($pm_id) ? false : true,
 269      'REPORT_TEXT'        => $report_text,
 270      'S_REPORT_ACTION'    => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id),
 271      'S_HIDDEN_FIELDS'    => (sizeof($s_hidden_fields)) ? $s_hidden_fields : null,
 272  
 273      'S_NOTIFY'            => $user_notify,
 274      'S_CAN_NOTIFY'        => ($user->data['is_registered']) ? true : false)
 275  );
 276  
 277  generate_forum_nav($forum_data);
 278  
 279  // Start output of page
 280  page_header($page_title);
 281  
 282  $template->set_filenames(array(
 283      'body' => 'report_body.html')
 284  );
 285  
 286  page_footer();
 287  
 288  ?>


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1