[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

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

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


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6