6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
26 function main($id, $mode)
28 global $db, $user, $auth, $template, $cache;
29 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
31 $user->add_lang(array('mcp', 'acp/posting'));
33 // Set up general vars
34 $action = request_var('action', '');
35 $submit = (isset($_POST['submit'])) ? true : false;
36 $reason_id = request_var('id', 0);
38 $this->tpl_name = 'acp_reasons';
39 $this->page_title = 'ACP_REASONS';
41 $form_name = 'acp_reason';
42 add_form_key('acp_reason');
52 'reason_title' => utf8_normalize_nfc(request_var('reason_title', '', true)),
53 'reason_description' => utf8_normalize_nfc(request_var('reason_description', '', true)),
58 if (!check_form_key($form_name))
60 $error[] = $user->lang['FORM_INVALID'];
63 if (!$reason_row['reason_title'] || !$reason_row['reason_description'])
65 $error[] = $user->lang['NO_REASON_INFO'];
68 $check_double = ($action == 'add') ? true : false;
70 if ($action == 'edit')
72 $sql = 'SELECT reason_title
73 FROM ' . REPORTS_REASONS_TABLE . "
74 WHERE reason_id = $reason_id";
75 $result = $db->sql_query($sql);
76 $row = $db->sql_fetchrow($result);
77 $db->sql_freeresult($result);
79 if (strtolower($row['reason_title']) == 'other' || strtolower($reason_row['reason_title']) == 'other')
81 $reason_row['reason_title'] = 'other';
84 if ($row['reason_title'] != $reason_row['reason_title'])
90 // Check for same reason if adding it...
93 $sql = 'SELECT reason_id
94 FROM ' . REPORTS_REASONS_TABLE . "
95 WHERE reason_title = '" . $db->sql_escape($reason_row['reason_title']) . "'";
96 $result = $db->sql_query($sql);
97 $row = $db->sql_fetchrow($result);
98 $db->sql_freeresult($result);
100 if ($row || ($action == 'add' && strtolower($reason_row['reason_title']) == 'other'))
102 $error[] = $user->lang['REASON_ALREADY_EXIST'];
109 if ($action == 'add')
112 $sql = 'SELECT MAX(reason_order) as max_reason_order
113 FROM ' . REPORTS_REASONS_TABLE;
114 $result = $db->sql_query($sql);
115 $max_order = (int) $db->sql_fetchfield('max_reason_order');
116 $db->sql_freeresult($result);
119 'reason_title' => (string) $reason_row['reason_title'],
120 'reason_description' => (string) $reason_row['reason_description'],
121 'reason_order' => $max_order + 1
124 $db->sql_query('INSERT INTO ' . REPORTS_REASONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
131 'reason_title' => (string) $reason_row['reason_title'],
132 'reason_description' => (string) $reason_row['reason_description'],
135 $db->sql_query('UPDATE ' . REPORTS_REASONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
136 WHERE reason_id = ' . $reason_id);
141 add_log('admin', 'LOG_REASON_' . $log, $reason_row['reason_title']);
142 trigger_error($user->lang['REASON_' . $log] . adm_back_link($this->u_action));
148 FROM ' . REPORTS_REASONS_TABLE . '
149 WHERE reason_id = ' . $reason_id;
150 $result = $db->sql_query($sql);
151 $reason_row = $db->sql_fetchrow($result);
152 $db->sql_freeresult($result);
156 trigger_error($user->lang['NO_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
160 $l_title = ($action == 'edit') ? 'EDIT' : 'ADD';
164 // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
165 if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason_row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason_row['reason_title'])]))
170 $template->assign_vars(array(
171 'L_TITLE' => $user->lang['REASON_' . $l_title],
172 'U_ACTION' => $this->u_action . "&id=$reason_id&action=$action",
173 'U_BACK' => $this->u_action,
174 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
176 'REASON_TITLE' => $reason_row['reason_title'],
177 'REASON_DESCRIPTION' => $reason_row['reason_description'],
179 'TRANSLATED_TITLE' => ($translated) ? $user->lang['report_reasons']['TITLE'][strtoupper($reason_row['reason_title'])] : '',
180 'TRANSLATED_DESCRIPTION'=> ($translated) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason_row['reason_title'])] : '',
182 'S_AVAILABLE_TITLES' => implode(', ', array_map('htmlspecialchars', array_keys($user->lang['report_reasons']['TITLE']))),
183 'S_EDIT_REASON' => true,
184 'S_TRANSLATED' => $translated,
185 'S_ERROR' => (sizeof($error)) ? true : false,
195 FROM ' . REPORTS_REASONS_TABLE . '
196 WHERE reason_id = ' . $reason_id;
197 $result = $db->sql_query($sql);
198 $reason_row = $db->sql_fetchrow($result);
199 $db->sql_freeresult($result);
203 trigger_error($user->lang['NO_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
206 if (strtolower($reason_row['reason_title']) == 'other')
208 trigger_error($user->lang['NO_REMOVE_DEFAULT_REASON'] . adm_back_link($this->u_action), E_USER_WARNING);
211 // Let the deletion be confirmed...
212 if (confirm_box(true))
214 $sql = 'SELECT reason_id
215 FROM ' . REPORTS_REASONS_TABLE . "
216 WHERE LOWER(reason_title) = 'other'";
217 $result = $db->sql_query($sql);
218 $other_reason_id = (int) $db->sql_fetchfield('reason_id');
219 $db->sql_freeresult($result);
221 switch ($db->sql_layer)
227 // Change the reports using this reason to 'other'
228 $sql = 'UPDATE ' . REPORTS_TABLE . '
229 SET reason_id = ' . $other_reason_id . ", report_text = CONCAT('" . $db->sql_escape($reason_row['reason_description']) . "\n\n', report_text)
230 WHERE reason_id = $reason_id";
233 // Standard? What's that?
237 // Change the reports using this reason to 'other'
238 $sql = "DECLARE @ptrval binary(16)
240 SELECT @ptrval = TEXTPTR(report_text)
241 FROM " . REPORTS_TABLE . "
242 WHERE reason_id = " . $reason_id . "
244 UPDATETEXT " . REPORTS_TABLE . ".report_text @ptrval 0 0 '" . $db->sql_escape($reason_row['reason_description']) . "\n\n'
246 UPDATE " . REPORTS_TABLE . '
247 SET reason_id = ' . $other_reason_id . "
248 WHERE reason_id = $reason_id";
256 // Change the reports using this reason to 'other'
257 $sql = 'UPDATE ' . REPORTS_TABLE . '
258 SET reason_id = ' . $other_reason_id . ", report_text = '" . $db->sql_escape($reason_row['reason_description']) . "\n\n' || report_text
259 WHERE reason_id = $reason_id";
262 $db->sql_query($sql);
264 $db->sql_query('DELETE FROM ' . REPORTS_REASONS_TABLE . ' WHERE reason_id = ' . $reason_id);
266 add_log('admin', 'LOG_REASON_REMOVED', $reason_row['reason_title']);
267 trigger_error($user->lang['REASON_REMOVED'] . adm_back_link($this->u_action));
271 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
284 $order = request_var('order', 0);
285 $order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);
287 $sql = 'UPDATE ' . REPORTS_REASONS_TABLE . '
288 SET reason_order = ' . $order_total . ' - reason_order
289 WHERE reason_order IN (' . $order . ', ' . (($action == 'move_up') ? $order - 1 : $order + 1) . ')';
290 $db->sql_query($sql);
295 // By default, check that order is valid and fix it if necessary
296 $sql = 'SELECT reason_id, reason_order
297 FROM ' . REPORTS_REASONS_TABLE . '
298 ORDER BY reason_order';
299 $result = $db->sql_query($sql);
301 if ($row = $db->sql_fetchrow($result))
308 if ($row['reason_order'] != $order)
310 $sql = 'UPDATE ' . REPORTS_REASONS_TABLE . "
311 SET reason_order = $order
312 WHERE reason_id = {$row['reason_id']}";
313 $db->sql_query($sql);
316 while ($row = $db->sql_fetchrow($result));
318 $db->sql_freeresult($result);
320 $template->assign_vars(array(
321 'U_ACTION' => $this->u_action,
326 $sql = 'SELECT reason_id, COUNT(reason_id) AS reason_count
327 FROM ' . REPORTS_TABLE . '
329 $result = $db->sql_query($sql);
331 $reason_count = array();
332 while ($row = $db->sql_fetchrow($result))
334 $reason_count[$row['reason_id']] = $row['reason_count'];
336 $db->sql_freeresult($result);
339 FROM ' . REPORTS_REASONS_TABLE . '
340 ORDER BY reason_order ASC';
341 $result = $db->sql_query($sql);
343 while ($row = $db->sql_fetchrow($result))
346 $other_reason = ($row['reason_title'] == 'other') ? true : false;
348 // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
349 if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
351 $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
352 $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
357 $template->assign_block_vars('reasons', array(
358 'REASON_TITLE' => $row['reason_title'],
359 'REASON_DESCRIPTION' => $row['reason_description'],
360 'REASON_COUNT' => (isset($reason_count[$row['reason_id']])) ? $reason_count[$row['reason_id']] : 0,
362 'S_TRANSLATED' => $translated,
363 'S_OTHER_REASON' => $other_reason,
365 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['reason_id'],
366 'U_DELETE' => (!$other_reason) ? $this->u_action . '&action=delete&id=' . $row['reason_id'] : '',
367 'U_MOVE_UP' => $this->u_action . '&action=move_up&order=' . $row['reason_order'],
368 'U_MOVE_DOWN' => $this->u_action . '&action=move_down&order=' . $row['reason_order'])
371 $db->sql_freeresult($result);