2 /***************************************************************************
5 * begin : Thursday, Jul 12, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: admin_words.php,v 1.10.2.3 2004/03/25 15:57:20 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 ***************************************************************************/
23 define('IN_PHPBB', 1);
25 if( !empty($setmodules) )
27 $file = basename(__FILE__);
28 $module['General']['Word_Censor'] = "$file";
33 // Load default header
35 $phpbb_root_path = "./../";
36 require($phpbb_root_path . 'extension.inc');
37 require('./pagestart.' . $phpEx);
39 if( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
41 $mode = ($HTTP_GET_VARS['mode']) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
42 $mode = htmlspecialchars($mode);
47 // These could be entered via a form button
49 if( isset($HTTP_POST_VARS['add']) )
53 else if( isset($HTTP_POST_VARS['save']) )
65 if( $mode == "edit" || $mode == "add" )
67 $word_id = ( isset($HTTP_GET_VARS['id']) ) ? intval($HTTP_GET_VARS['id']) : 0;
69 $template->set_filenames(array(
70 "body" => "admin/words_edit_body.tpl")
73 $s_hidden_fields = '';
80 FROM " . WORDS_TABLE . "
81 WHERE word_id = $word_id";
82 if(!$result = $db->sql_query($sql))
84 message_die(GENERAL_ERROR, "Could not query words table", "Error", __LINE__, __FILE__, $sql);
87 $word_info = $db->sql_fetchrow($result);
88 $s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
92 message_die(GENERAL_MESSAGE, $lang['No_word_selected']);
96 $template->assign_vars(array(
97 "WORD" => $word_info['word'],
98 "REPLACEMENT" => $word_info['replacement'],
100 "L_WORDS_TITLE" => $lang['Words_title'],
101 "L_WORDS_TEXT" => $lang['Words_explain'],
102 "L_WORD_CENSOR" => $lang['Edit_word_censor'],
103 "L_WORD" => $lang['Word'],
104 "L_REPLACEMENT" => $lang['Replacement'],
105 "L_SUBMIT" => $lang['Submit'],
107 "S_WORDS_ACTION" => append_sid("admin_words.$phpEx"),
108 "S_HIDDEN_FIELDS" => $s_hidden_fields)
111 $template->pparse("body");
113 include('./page_footer_admin.'.$phpEx);
115 else if( $mode == "save" )
117 $word_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : 0;
118 $word = ( isset($HTTP_POST_VARS['word']) ) ? trim($HTTP_POST_VARS['word']) : "";
119 $replacement = ( isset($HTTP_POST_VARS['replacement']) ) ? trim($HTTP_POST_VARS['replacement']) : "";
121 if($word == "" || $replacement == "")
123 message_die(GENERAL_MESSAGE, $lang['Must_enter_word']);
128 $sql = "UPDATE " . WORDS_TABLE . "
129 SET word = '" . str_replace("\'", "''", $word) . "', replacement = '" . str_replace("\'", "''", $replacement) . "'
130 WHERE word_id = $word_id";
131 $message = $lang['Word_updated'];
135 $sql = "INSERT INTO " . WORDS_TABLE . " (word, replacement)
136 VALUES ('" . str_replace("\'", "''", $word) . "', '" . str_replace("\'", "''", $replacement) . "')";
137 $message = $lang['Word_added'];
140 if(!$result = $db->sql_query($sql))
142 message_die(GENERAL_ERROR, "Could not insert data into words table", $lang['Error'], __LINE__, __FILE__, $sql);
145 $message .= "<br /><br />" . sprintf($lang['Click_return_wordadmin'], "<a href=\"" . append_sid("admin_words.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
147 message_die(GENERAL_MESSAGE, $message);
149 else if( $mode == "delete" )
151 if( isset($HTTP_POST_VARS['id']) || isset($HTTP_GET_VARS['id']) )
153 $word_id = ( isset($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
154 $word_id = intval($word_id);
163 $sql = "DELETE FROM " . WORDS_TABLE . "
164 WHERE word_id = $word_id";
166 if(!$result = $db->sql_query($sql))
168 message_die(GENERAL_ERROR, "Could not remove data from words table", $lang['Error'], __LINE__, __FILE__, $sql);
171 $message = $lang['Word_removed'] . "<br /><br />" . sprintf($lang['Click_return_wordadmin'], "<a href=\"" . append_sid("admin_words.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
173 message_die(GENERAL_MESSAGE, $message);
177 message_die(GENERAL_MESSAGE, $lang['No_word_selected']);
183 $template->set_filenames(array(
184 "body" => "admin/words_list_body.tpl")
188 FROM " . WORDS_TABLE . "
190 if( !$result = $db->sql_query($sql) )
192 message_die(GENERAL_ERROR, "Could not query words table", $lang['Error'], __LINE__, __FILE__, $sql);
195 $word_rows = $db->sql_fetchrowset($result);
196 $word_count = count($word_rows);
198 $template->assign_vars(array(
199 "L_WORDS_TITLE" => $lang['Words_title'],
200 "L_WORDS_TEXT" => $lang['Words_explain'],
201 "L_WORD" => $lang['Word'],
202 "L_REPLACEMENT" => $lang['Replacement'],
203 "L_EDIT" => $lang['Edit'],
204 "L_DELETE" => $lang['Delete'],
205 "L_ADD_WORD" => $lang['Add_new_word'],
206 "L_ACTION" => $lang['Action'],
208 "S_WORDS_ACTION" => append_sid("admin_words.$phpEx"),
209 "S_HIDDEN_FIELDS" => '')
212 for($i = 0; $i < $word_count; $i++)
214 $word = $word_rows[$i]['word'];
215 $replacement = $word_rows[$i]['replacement'];
216 $word_id = $word_rows[$i]['word_id'];
218 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
219 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
221 $template->assign_block_vars("words", array(
222 "ROW_COLOR" => "#" . $row_color,
223 "ROW_CLASS" => $row_class,
225 "REPLACEMENT" => $replacement,
227 "U_WORD_EDIT" => append_sid("admin_words.$phpEx?mode=edit&id=$word_id"),
228 "U_WORD_DELETE" => append_sid("admin_words.$phpEx?mode=delete&id=$word_id"))
233 $template->pparse("body");
235 include('./page_footer_admin.'.$phpEx);