phpBB
Statistics
| Revision:

root / branches / phpBB-3_0_0 / phpBB / includes / acp / acp_reasons.php

History | View | Annotate | Download (11.1 kB)

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