$config to phpbb::$config
[phpbb.git] / phpBB / modules / acp / acp_words.php
blob87989640ec48dbf7d54f1cf119348b4d72eb0f69
1 <?php
2 /**
4 * @package acp
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 if (!defined('IN_PHPBB'))
16 exit;
19 /**
20 * @todo [words] check regular expressions for special char replacements (stored specialchared in db)
21 * @package acp
23 class acp_words
25 var $u_action;
27 function main($id, $mode)
29 global $db, $user, $auth, $template;
31 $user->add_lang('acp/posting');
33 // Set up general vars
34 $action = request_var('action', '');
35 $action = (phpbb_request::is_set_post('add')) ? 'add' : ((phpbb_request::is_set_post('save')) ? 'save' : $action);
37 $s_hidden_fields = '';
38 $word_info = array();
40 $this->tpl_name = 'acp_words';
41 $this->page_title = 'ACP_WORDS';
43 $form_name = 'acp_words';
44 add_form_key($form_name);
46 switch ($action)
48 case 'edit':
49 $word_id = request_var('id', 0);
51 if (!$word_id)
53 trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
56 $sql = 'SELECT *
57 FROM ' . WORDS_TABLE . "
58 WHERE word_id = $word_id";
59 $result = $db->sql_query($sql);
60 $word_info = $db->sql_fetchrow($result);
61 $db->sql_freeresult($result);
63 $s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
65 case 'add':
67 $template->assign_vars(array(
68 'S_EDIT_WORD' => true,
69 'U_ACTION' => $this->u_action,
70 'U_BACK' => $this->u_action,
71 'WORD' => (isset($word_info['word'])) ? $word_info['word'] : '',
72 'REPLACEMENT' => (isset($word_info['replacement'])) ? $word_info['replacement'] : '',
73 'S_HIDDEN_FIELDS' => $s_hidden_fields)
76 return;
78 break;
80 case 'save':
82 if (!check_form_key($form_name))
84 trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
86 $word_id = request_var('id', 0);
87 $word = utf8_normalize_nfc(request_var('word', '', true));
88 $replacement = utf8_normalize_nfc(request_var('replacement', '', true));
90 if (!$word || !$replacement)
92 trigger_error($user->lang['ENTER_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
95 $sql_ary = array(
96 'word' => $word,
97 'replacement' => $replacement
100 if ($word_id)
102 $db->sql_query('UPDATE ' . WORDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE word_id = ' . $word_id);
104 else
106 $db->sql_query('INSERT INTO ' . WORDS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
109 phpbb::$acm->destroy('word_censors');
111 $log_action = ($word_id) ? 'LOG_WORD_EDIT' : 'LOG_WORD_ADD';
112 add_log('admin', $log_action, $word);
114 $message = ($word_id) ? $user->lang['WORD_UPDATED'] : $user->lang['WORD_ADDED'];
115 trigger_error($message . adm_back_link($this->u_action));
117 break;
119 case 'delete':
121 $word_id = request_var('id', 0);
123 if (!$word_id)
125 trigger_error($user->lang['NO_WORD'] . adm_back_link($this->u_action), E_USER_WARNING);
128 if (confirm_box(true))
130 $sql = 'SELECT word
131 FROM ' . WORDS_TABLE . "
132 WHERE word_id = $word_id";
133 $result = $db->sql_query($sql);
134 $deleted_word = $db->sql_fetchfield('word');
135 $db->sql_freeresult($result);
137 $sql = 'DELETE FROM ' . WORDS_TABLE . "
138 WHERE word_id = $word_id";
139 $db->sql_query($sql);
141 phpbb::$acm->destroy('word_censors');
143 add_log('admin', 'LOG_WORD_DELETE', $deleted_word);
145 trigger_error($user->lang['WORD_REMOVED'] . adm_back_link($this->u_action));
147 else
149 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
150 'i' => $id,
151 'mode' => $mode,
152 'id' => $word_id,
153 'action' => 'delete',
154 )));
157 break;
161 $template->assign_vars(array(
162 'U_ACTION' => $this->u_action,
163 'S_HIDDEN_FIELDS' => $s_hidden_fields)
166 $sql = 'SELECT *
167 FROM ' . WORDS_TABLE . '
168 ORDER BY word';
169 $result = $db->sql_query($sql);
171 while ($row = $db->sql_fetchrow($result))
173 $template->assign_block_vars('words', array(
174 'WORD' => $row['word'],
175 'REPLACEMENT' => $row['replacement'],
176 'U_EDIT' => $this->u_action . '&amp;action=edit&amp;id=' . $row['word_id'],
177 'U_DELETE' => $this->u_action . '&amp;action=delete&amp;id=' . $row['word_id'])
180 $db->sql_freeresult($result);