Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

acp_reasons.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 11.74 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  /**
015  * @ignore
016  */
017  if (!defined('IN_PHPBB'))
018  {
019      exit;
020  }
021   
022  class acp_reasons
023  {
024      var $u_action;
025   
026      function main($id, $mode)
027      {
028          global $db, $user, $auth, $template, $cache;
029          global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
030          global $request;
031   
032          $user->add_lang(array('mcp', 'acp/posting'));
033   
034          // Set up general vars
035          $action = request_var('action', '');
036          $submit = (isset($_POST['submit'])) ? true : false;
037          $reason_id = request_var('id', 0);
038   
039          $this->tpl_name = 'acp_reasons';
040          $this->page_title = 'ACP_REASONS';
041   
042          $form_name = 'acp_reason';
043          add_form_key('acp_reason');
044   
045          $error = array();
046   
047          switch ($action)
048          {
049              case 'add':
050              case 'edit':
051   
052                  $reason_row = array(
053                      'reason_title'            => utf8_normalize_nfc(request_var('reason_title', '', true)),
054                      'reason_description'    => utf8_normalize_nfc(request_var('reason_description', '', true)),
055                  );
056   
057                  if ($submit)
058                  {
059                      if (!check_form_key($form_name))
060                      {
061                          $error[] = $user->lang['FORM_INVALID'];
062                      }
063                      // Reason specified?
064                      if (!$reason_row['reason_title'] || !$reason_row['reason_description'])
065                      {
066                          $error[] = $user->lang['NO_REASON_INFO'];
067                      }
068   
069                      $check_double = ($action == 'add') ? true : false;
070   
071                      if ($action == 'edit')
072                      {
073                          $sql = 'SELECT reason_title
074                              FROM ' . REPORTS_REASONS_TABLE . "
075                              WHERE reason_id = $reason_id";
076                          $result = $db->sql_query($sql);
077                          $row = $db->sql_fetchrow($result);
078                          $db->sql_freeresult($result);
079   
080                          if (strtolower($row['reason_title']) == 'other' || strtolower($reason_row['reason_title']) == 'other')
081                          {
082                              $reason_row['reason_title'] = 'other';
083                          }
084   
085                          if ($row['reason_title'] != $reason_row['reason_title'])
086                          {
087                              $check_double = true;
088                          }
089                      }
090   
091                      // Check for same reason if adding it...
092                      if ($check_double)
093                      {
094                          $sql = 'SELECT reason_id
095                              FROM ' . REPORTS_REASONS_TABLE . "
096                              WHERE reason_title = '" . $db->sql_escape($reason_row['reason_title']) . "'";
097                          $result = $db->sql_query($sql);
098                          $row = $db->sql_fetchrow($result);
099                          $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                  $sql = 'SELECT reason_order
286                      FROM ' . REPORTS_REASONS_TABLE . "
287                      WHERE reason_id = $reason_id";
288                  $result = $db->sql_query($sql);
289                  $order = $db->sql_fetchfield('reason_order');
290                  $db->sql_freeresult($result);
291   
292                  if ($order === false || ($order == 0 && $action == 'move_up'))
293                  {
294                      break;
295                  }
296                  $order = (int) $order;
297                  $order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);
298   
299                  $sql = 'UPDATE ' . REPORTS_REASONS_TABLE . '
300                      SET reason_order = ' . $order_total . ' - reason_order
301                      WHERE reason_order IN (' . $order . ', ' . (($action == 'move_up') ? $order - 1 : $order + 1) . ')';
302                  $db->sql_query($sql);
303   
304                  if ($request->is_ajax())
305                  {
306                      $json_response = new \phpbb\json_response;
307                      $json_response->send(array(
308                          'success'    => (bool) $db->sql_affectedrows(),
309                      ));
310                  }
311              break;
312          }
313   
314          // By default, check that order is valid and fix it if necessary
315          $sql = 'SELECT reason_id, reason_order
316              FROM ' . REPORTS_REASONS_TABLE . '
317              ORDER BY reason_order';
318          $result = $db->sql_query($sql);
319   
320          if ($row = $db->sql_fetchrow($result))
321          {
322              $order = 0;
323              do
324              {
325                  ++$order;
326   
327                  if ($row['reason_order'] != $order)
328                  {
329                      $sql = 'UPDATE ' . REPORTS_REASONS_TABLE . "
330                          SET reason_order = $order
331                          WHERE reason_id = {$row['reason_id']}";
332                      $db->sql_query($sql);
333                  }
334              }
335              while ($row = $db->sql_fetchrow($result));
336          }
337          $db->sql_freeresult($result);
338   
339          $template->assign_vars(array(
340              'U_ACTION'            => $this->u_action,
341              )
342          );
343   
344          // Reason count
345          $sql = 'SELECT reason_id, COUNT(reason_id) AS reason_count
346              FROM ' . REPORTS_TABLE . '
347              GROUP BY reason_id';
348          $result = $db->sql_query($sql);
349   
350          $reason_count = array();
351          while ($row = $db->sql_fetchrow($result))
352          {
353              $reason_count[$row['reason_id']] = $row['reason_count'];
354          }
355          $db->sql_freeresult($result);
356   
357          $sql = 'SELECT *
358              FROM ' . REPORTS_REASONS_TABLE . '
359              ORDER BY reason_order ASC';
360          $result = $db->sql_query($sql);
361   
362          while ($row = $db->sql_fetchrow($result))
363          {
364              $translated = false;
365              $other_reason = ($row['reason_title'] == 'other') ? true : false;
366   
367              // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
368              if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
369              {
370                  $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
371                  $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
372   
373                  $translated = true;
374              }
375   
376              $template->assign_block_vars('reasons', array(
377                  'REASON_TITLE'            => $row['reason_title'],
378                  'REASON_DESCRIPTION'    => $row['reason_description'],
379                  'REASON_COUNT'            => (isset($reason_count[$row['reason_id']])) ? $reason_count[$row['reason_id']] : 0,
380   
381                  'S_TRANSLATED'        => $translated,
382                  'S_OTHER_REASON'    => $other_reason,
383   
384                  'U_EDIT'        => $this->u_action . '&amp;action=edit&amp;id=' . $row['reason_id'],
385                  'U_DELETE'        => (!$other_reason) ? $this->u_action . '&amp;action=delete&amp;id=' . $row['reason_id'] : '',
386                  'U_MOVE_UP'        => $this->u_action . '&amp;action=move_up&amp;id=' . $row['reason_id'],
387                  'U_MOVE_DOWN'    => $this->u_action . '&amp;action=move_down&amp;id=' . $row['reason_id'])
388              );
389          }
390          $db->sql_freeresult($result);
391      }
392  }
393