[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/includes/acp/ -> acp_reasons.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  class acp_reasons
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $db, $user, $auth, $template, $cache;
  29          global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  30          global $request;
  31  
  32          $user->add_lang(array('mcp', 'acp/posting'));
  33  
  34          // Set up general vars
  35          $action = request_var('action', '');
  36          $submit = (isset($_POST['submit'])) ? true : false;
  37          $reason_id = request_var('id', 0);
  38  
  39          $this->tpl_name = 'acp_reasons';
  40          $this->page_title = 'ACP_REASONS';
  41  
  42          $form_name = 'acp_reason';
  43          add_form_key('acp_reason');
  44  
  45          $error = array();
  46  
  47          switch ($action)
  48          {
  49              case 'add':
  50              case 'edit':
  51  
  52                  $reason_row = array(
  53                      'reason_title'            => utf8_normalize_nfc(request_var('reason_title', '', true)),
  54                      'reason_description'    => utf8_normalize_nfc(request_var('reason_description', '', true)),
  55                  );
  56  
  57                  if ($submit)
  58                  {
  59                      if (!check_form_key($form_name))
  60                      {
  61                          $error[] = $user->lang['FORM_INVALID'];
  62                      }
  63                      // Reason specified?
  64                      if (!$reason_row['reason_title'] || !$reason_row['reason_description'])
  65                      {
  66                          $error[] = $user->lang['NO_REASON_INFO'];
  67                      }
  68  
  69                      $check_double = ($action == 'add') ? true : false;
  70  
  71                      if ($action == 'edit')
  72                      {
  73                          $sql = 'SELECT reason_title
  74                              FROM ' . REPORTS_REASONS_TABLE . "
  75                              WHERE reason_id = $reason_id";
  76                          $result = $db->sql_query($sql);
  77                          $row = $db->sql_fetchrow($result);
  78                          $db->sql_freeresult($result);
  79  
  80                          if (strtolower($row['reason_title']) == 'other' || strtolower($reason_row['reason_title']) == 'other')
  81                          {
  82                              $reason_row['reason_title'] = 'other';
  83                          }
  84  
  85                          if ($row['reason_title'] != $reason_row['reason_title'])
  86                          {
  87                              $check_double = true;
  88                          }
  89                      }
  90  
  91                      // Check for same reason if adding it...
  92                      if ($check_double)
  93                      {
  94                          $sql = 'SELECT reason_id
  95                              FROM ' . REPORTS_REASONS_TABLE . "
  96                              WHERE reason_title = '" . $db->sql_escape($reason_row['reason_title']) . "'";
  97                          $result = $db->sql_query($sql);
  98                          $row = $db->sql_fetchrow($result);
  99                          $db->sql_freeresult($result);
 100  
 101                          if ($row || ($action == 'add' && strtolower($reason_row['reason_title']) == 'other'))
 102                          {
 103                              $error[] = $user->lang['REASON_ALREADY_EXIST'];
 104                          }
 105                      }
 106  
 107                      if (!sizeof($error))
 108                      {
 109                          // New reason?
 110                          if ($action == 'add')
 111                          {
 112                              // Get new order...
 113                              $sql = 'SELECT MAX(reason_order) as max_reason_order
 114                                  FROM ' . REPORTS_REASONS_TABLE;
 115                              $result = $db->sql_query($sql);
 116                              $max_order = (int) $db->sql_fetchfield('max_reason_order');
 117                              $db->sql_freeresult($result);
 118  
 119                              $sql_ary = array(
 120                                  'reason_title'            => (string) $reason_row['reason_title'],
 121                                  'reason_description'    => (string) $reason_row['reason_description'],
 122                                  'reason_order'            => $max_order + 1
 123                              );
 124  
 125                              $db->sql_query('INSERT INTO ' . REPORTS_REASONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
 126  
 127                              $log = 'ADDED';
 128                          }
 129                          else if ($reason_id)
 130                          {
 131                              $sql_ary = array(
 132                                  'reason_title'            => (string) $reason_row['reason_title'],
 133                                  'reason_description'    => (string) $reason_row['reason_description'],
 134                              );
 135  
 136                              $db->sql_query('UPDATE ' . REPORTS_REASONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
 137                                  WHERE reason_id = ' . $reason_id);
 138  
 139                              $log = 'UPDATED';
 140                          }
 141  
 142                          add_log('admin', 'LOG_REASON_' . $log, $reason_row['reason_title']);
 143                          trigger_error($user->lang['REASON_' . $log] . adm_back_link($this->u_action));
 144                      }
 145                  }
 146                  else if ($reason_id)
 147                  {
 148                      $sql = 'SELECT *
 149                          FROM ' . REPORTS_REASONS_TABLE . '
 150                          WHERE reason_id = ' . $reason_id;
 151                      $result = $db->sql_query($sql);
 152                      $reason_row = $db->sql_fetchrow($result);
 153                      $db->sql_freeresult($result);
 154  
 155                      if (!$reason_row)
 156                      {
 157                          trigger_error($user->lang['NO_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
 158                      }
 159                  }
 160  
 161                  $l_title = ($action == 'edit') ? 'EDIT' : 'ADD';
 162  
 163                  $translated = false;
 164  
 165                  // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
 166                  if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason_row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason_row['reason_title'])]))
 167                  {
 168                      $translated = true;
 169                  }
 170  
 171                  $template->assign_vars(array(
 172                      'L_TITLE'        => $user->lang['REASON_' . $l_title],
 173                      'U_ACTION'        => $this->u_action . "&amp;id=$reason_id&amp;action=$action",
 174                      'U_BACK'        => $this->u_action,
 175                      'ERROR_MSG'        => (sizeof($error)) ? implode('<br />', $error) : '',
 176  
 177                      'REASON_TITLE'            => $reason_row['reason_title'],
 178                      'REASON_DESCRIPTION'    => $reason_row['reason_description'],
 179  
 180                      'TRANSLATED_TITLE'        => ($translated) ? $user->lang['report_reasons']['TITLE'][strtoupper($reason_row['reason_title'])] : '',
 181                      'TRANSLATED_DESCRIPTION'=> ($translated) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason_row['reason_title'])] : '',
 182  
 183                      'S_AVAILABLE_TITLES'    => implode($user->lang['COMMA_SEPARATOR'], array_map('htmlspecialchars', array_keys($user->lang['report_reasons']['TITLE']))),
 184                      'S_EDIT_REASON'            => true,
 185                      'S_TRANSLATED'            => $translated,
 186                      'S_ERROR'                => (sizeof($error)) ? true : false,
 187                      )
 188                  );
 189  
 190                  return;
 191              break;
 192  
 193              case 'delete':
 194  
 195                  $sql = 'SELECT *
 196                      FROM ' . REPORTS_REASONS_TABLE . '
 197                      WHERE reason_id = ' . $reason_id;
 198                  $result = $db->sql_query($sql);
 199                  $reason_row = $db->sql_fetchrow($result);
 200                  $db->sql_freeresult($result);
 201  
 202                  if (!$reason_row)
 203                  {
 204                      trigger_error($user->lang['NO_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
 205                  }
 206  
 207                  if (strtolower($reason_row['reason_title']) == 'other')
 208                  {
 209                      trigger_error($user->lang['NO_REMOVE_DEFAULT_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
 210                  }
 211  
 212                  // Let the deletion be confirmed...
 213                  if (confirm_box(true))
 214                  {
 215                      $sql = 'SELECT reason_id
 216                          FROM ' . REPORTS_REASONS_TABLE . "
 217                          WHERE LOWER(reason_title) = 'other'";
 218                      $result = $db->sql_query($sql);
 219                      $other_reason_id = (int) $db->sql_fetchfield('reason_id');
 220                      $db->sql_freeresult($result);
 221  
 222                      switch ($db->get_sql_layer())
 223                      {
 224                          // The ugly one!
 225                          case 'mysqli':
 226                          case 'mysql4':
 227                          case 'mysql':
 228                              // Change the reports using this reason to 'other'
 229                              $sql = 'UPDATE ' . REPORTS_TABLE . '
 230                                  SET reason_id = ' . $other_reason_id . ", report_text = CONCAT('" . $db->sql_escape($reason_row['reason_description']) . "\n\n', report_text)
 231                                  WHERE reason_id = $reason_id";
 232                          break;
 233  
 234                          // Standard? What's that?
 235                          case 'mssql':
 236                          case 'mssql_odbc':
 237                          case 'mssqlnative':
 238                              // Change the reports using this reason to 'other'
 239                              $sql = "DECLARE @ptrval binary(16)
 240  
 241                                      SELECT @ptrval = TEXTPTR(report_text)
 242                                          FROM " . REPORTS_TABLE . "
 243                                      WHERE reason_id = " . $reason_id . "
 244  
 245                                      UPDATETEXT " . REPORTS_TABLE . ".report_text @ptrval 0 0 '" . $db->sql_escape($reason_row['reason_description']) . "\n\n'
 246  
 247                                      UPDATE " . REPORTS_TABLE . '
 248                                          SET reason_id = ' . $other_reason_id . "
 249                                      WHERE reason_id = $reason_id";
 250                          break;
 251  
 252                          // Teh standard
 253                          case 'postgres':
 254                          case 'oracle':
 255                          case 'sqlite':
 256                          case 'sqlite3':
 257                              // Change the reports using this reason to 'other'
 258                              $sql = 'UPDATE ' . REPORTS_TABLE . '
 259                                  SET reason_id = ' . $other_reason_id . ", report_text = '" . $db->sql_escape($reason_row['reason_description']) . "\n\n' || report_text
 260                                  WHERE reason_id = $reason_id";
 261                          break;
 262                      }
 263                      $db->sql_query($sql);
 264  
 265                      $db->sql_query('DELETE FROM ' . REPORTS_REASONS_TABLE . ' WHERE reason_id = ' . $reason_id);
 266  
 267                      add_log('admin', 'LOG_REASON_REMOVED', $reason_row['reason_title']);
 268                      trigger_error($user->lang['REASON_REMOVED'] . adm_back_link($this->u_action));
 269                  }
 270                  else
 271                  {
 272                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 273                          'i'            => $id,
 274                          'mode'        => $mode,
 275                          'action'    => $action,
 276                          'id'        => $reason_id))
 277                      );
 278                  }
 279  
 280              break;
 281  
 282              case 'move_up':
 283              case 'move_down':
 284  
 285                  if (!check_link_hash($request->variable('hash', ''), 'acp_reasons'))
 286                  {
 287                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 288                  }
 289  
 290                  $sql = 'SELECT reason_order
 291                      FROM ' . REPORTS_REASONS_TABLE . "
 292                      WHERE reason_id = $reason_id";
 293                  $result = $db->sql_query($sql);
 294                  $order = $db->sql_fetchfield('reason_order');
 295                  $db->sql_freeresult($result);
 296  
 297                  if ($order === false || ($order == 0 && $action == 'move_up'))
 298                  {
 299                      break;
 300                  }
 301                  $order = (int) $order;
 302                  $order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);
 303  
 304                  $sql = 'UPDATE ' . REPORTS_REASONS_TABLE . '
 305                      SET reason_order = ' . $order_total . ' - reason_order
 306                      WHERE reason_order IN (' . $order . ', ' . (($action == 'move_up') ? $order - 1 : $order + 1) . ')';
 307                  $db->sql_query($sql);
 308  
 309                  if ($request->is_ajax())
 310                  {
 311                      $json_response = new \phpbb\json_response;
 312                      $json_response->send(array(
 313                          'success'    => (bool) $db->sql_affectedrows(),
 314                      ));
 315                  }
 316              break;
 317          }
 318  
 319          // By default, check that order is valid and fix it if necessary
 320          $sql = 'SELECT reason_id, reason_order
 321              FROM ' . REPORTS_REASONS_TABLE . '
 322              ORDER BY reason_order';
 323          $result = $db->sql_query($sql);
 324  
 325          if ($row = $db->sql_fetchrow($result))
 326          {
 327              $order = 0;
 328              do
 329              {
 330                  ++$order;
 331  
 332                  if ($row['reason_order'] != $order)
 333                  {
 334                      $sql = 'UPDATE ' . REPORTS_REASONS_TABLE . "
 335                          SET reason_order = $order
 336                          WHERE reason_id = {$row['reason_id']}";
 337                      $db->sql_query($sql);
 338                  }
 339              }
 340              while ($row = $db->sql_fetchrow($result));
 341          }
 342          $db->sql_freeresult($result);
 343  
 344          $template->assign_vars(array(
 345              'U_ACTION'            => $this->u_action,
 346              )
 347          );
 348  
 349          // Reason count
 350          $sql = 'SELECT reason_id, COUNT(reason_id) AS reason_count
 351              FROM ' . REPORTS_TABLE . '
 352              GROUP BY reason_id';
 353          $result = $db->sql_query($sql);
 354  
 355          $reason_count = array();
 356          while ($row = $db->sql_fetchrow($result))
 357          {
 358              $reason_count[$row['reason_id']] = $row['reason_count'];
 359          }
 360          $db->sql_freeresult($result);
 361  
 362          $sql = 'SELECT *
 363              FROM ' . REPORTS_REASONS_TABLE . '
 364              ORDER BY reason_order ASC';
 365          $result = $db->sql_query($sql);
 366  
 367          while ($row = $db->sql_fetchrow($result))
 368          {
 369              $translated = false;
 370              $other_reason = ($row['reason_title'] == 'other') ? true : false;
 371  
 372              // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
 373              if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
 374              {
 375                  $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
 376                  $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
 377  
 378                  $translated = true;
 379              }
 380  
 381              $template->assign_block_vars('reasons', array(
 382                  'REASON_TITLE'            => $row['reason_title'],
 383                  'REASON_DESCRIPTION'    => $row['reason_description'],
 384                  'REASON_COUNT'            => (isset($reason_count[$row['reason_id']])) ? $reason_count[$row['reason_id']] : 0,
 385  
 386                  'S_TRANSLATED'        => $translated,
 387                  'S_OTHER_REASON'    => $other_reason,
 388  
 389                  'U_EDIT'        => $this->u_action . '&amp;action=edit&amp;id=' . $row['reason_id'],
 390                  'U_DELETE'        => (!$other_reason) ? $this->u_action . '&amp;action=delete&amp;id=' . $row['reason_id'] : '',
 391                  'U_MOVE_UP'        => $this->u_action . '&amp;action=move_up&amp;id=' . $row['reason_id'] . '&amp;hash=' . generate_link_hash('acp_reasons'),
 392                  'U_MOVE_DOWN'    => $this->u_action . '&amp;action=move_down&amp;id=' . $row['reason_id'] . '&amp;hash=' . generate_link_hash('acp_reasons'))
 393              );
 394          }
 395          $db->sql_freeresult($result);
 396      }
 397  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1