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.6 2006/04/13 09:56:48 grahamje 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 if( !empty($setmodules) )
25 $file = basename(__FILE__);
26 $module['General']['Word_Censor'] = $file;
30 define('IN_PHPBB', 1);
33 // Load default header
35 $phpbb_root_path = "./../";
36 require($phpbb_root_path . 'extension.inc');
38 $cancel = ( isset($HTTP_POST_VARS['cancel']) ) ? true : false;
39 $no_page_header = $cancel;
41 require('./pagestart.' . $phpEx);
45 redirect('admin/' . append_sid("admin_words.$phpEx", true));
48 if( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
50 $mode = (isset($HTTP_GET_VARS['mode'])) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
51 $mode = htmlspecialchars($mode);
56 // These could be entered via a form button
58 if( isset($HTTP_POST_VARS['add']) )
62 else if( isset($HTTP_POST_VARS['save']) )
72 // Restrict mode input to valid options
73 $mode = ( in_array($mode, array('add', 'edit', 'save', 'delete')) ) ? $mode : '';
77 if( $mode == "edit" || $mode == "add" )
79 $word_id = ( isset($HTTP_GET_VARS['id']) ) ? intval($HTTP_GET_VARS['id']) : 0;
81 $template->set_filenames(array(
82 "body" => "admin/words_edit_body.tpl")
85 $word_info = array('word' => '', 'replacement' => '');
86 $s_hidden_fields = '';
93 FROM " . WORDS_TABLE . "
94 WHERE word_id = $word_id";
95 if(!$result = $db->sql_query($sql))
97 message_die(GENERAL_ERROR, "Could not query words table", "Error", __LINE__, __FILE__, $sql);
100 $word_info = $db->sql_fetchrow($result);
101 $s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
105 message_die(GENERAL_MESSAGE, $lang['No_word_selected']);
109 $template->assign_vars(array(
110 "WORD" => $word_info['word'],
111 "REPLACEMENT" => $word_info['replacement'],
113 "L_WORDS_TITLE" => $lang['Words_title'],
114 "L_WORDS_TEXT" => $lang['Words_explain'],
115 "L_WORD_CENSOR" => $lang['Edit_word_censor'],
116 "L_WORD" => $lang['Word'],
117 "L_REPLACEMENT" => $lang['Replacement'],
118 "L_SUBMIT" => $lang['Submit'],
120 "S_WORDS_ACTION" => append_sid("admin_words.$phpEx"),
121 "S_HIDDEN_FIELDS" => $s_hidden_fields)
124 $template->pparse("body");
126 include('./page_footer_admin.'.$phpEx);
128 else if( $mode == "save" )
130 $word_id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) : 0;
131 $word = ( isset($HTTP_POST_VARS['word']) ) ? trim($HTTP_POST_VARS['word']) : "";
132 $replacement = ( isset($HTTP_POST_VARS['replacement']) ) ? trim($HTTP_POST_VARS['replacement']) : "";
134 if($word == "" || $replacement == "")
136 message_die(GENERAL_MESSAGE, $lang['Must_enter_word']);
141 $sql = "UPDATE " . WORDS_TABLE . "
142 SET word = '" . str_replace("\'", "''", $word) . "', replacement = '" . str_replace("\'", "''", $replacement) . "'
143 WHERE word_id = $word_id";
144 $message = $lang['Word_updated'];
148 $sql = "INSERT INTO " . WORDS_TABLE . " (word, replacement)
149 VALUES ('" . str_replace("\'", "''", $word) . "', '" . str_replace("\'", "''", $replacement) . "')";
150 $message = $lang['Word_added'];
153 if(!$result = $db->sql_query($sql))
155 message_die(GENERAL_ERROR, "Could not insert data into words table", $lang['Error'], __LINE__, __FILE__, $sql);
158 $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>");
160 message_die(GENERAL_MESSAGE, $message);
162 else if( $mode == "delete" )
164 if( isset($HTTP_POST_VARS['id']) || isset($HTTP_GET_VARS['id']) )
166 $word_id = ( isset($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
167 $word_id = intval($word_id);
174 $confirm = isset($HTTP_POST_VARS['confirm']);
176 if( $word_id && $confirm )
178 $sql = "DELETE FROM " . WORDS_TABLE . "
179 WHERE word_id = $word_id";
181 if(!$result = $db->sql_query($sql))
183 message_die(GENERAL_ERROR, "Could not remove data from words table", $lang['Error'], __LINE__, __FILE__, $sql);
186 $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>");
188 message_die(GENERAL_MESSAGE, $message);
190 elseif( $word_id && !$confirm)
192 // Present the confirmation screen to the user
193 $template->set_filenames(array(
194 'body' => 'admin/confirm_body.tpl')
197 $hidden_fields = '<input type="hidden" name="mode" value="delete" /><input type="hidden" name="id" value="' . $word_id . '" />';
199 $template->assign_vars(array(
200 'MESSAGE_TITLE' => $lang['Confirm'],
201 'MESSAGE_TEXT' => $lang['Confirm_delete_word'],
203 'L_YES' => $lang['Yes'],
204 'L_NO' => $lang['No'],
206 'S_CONFIRM_ACTION' => append_sid("admin_words.$phpEx"),
207 'S_HIDDEN_FIELDS' => $hidden_fields)
212 message_die(GENERAL_MESSAGE, $lang['No_word_selected']);
218 $template->set_filenames(array(
219 "body" => "admin/words_list_body.tpl")
223 FROM " . WORDS_TABLE . "
225 if( !$result = $db->sql_query($sql) )
227 message_die(GENERAL_ERROR, "Could not query words table", $lang['Error'], __LINE__, __FILE__, $sql);
230 $word_rows = $db->sql_fetchrowset($result);
231 $db->sql_freeresult($result);
232 $word_count = count($word_rows);
234 $template->assign_vars(array(
235 "L_WORDS_TITLE" => $lang['Words_title'],
236 "L_WORDS_TEXT" => $lang['Words_explain'],
237 "L_WORD" => $lang['Word'],
238 "L_REPLACEMENT" => $lang['Replacement'],
239 "L_EDIT" => $lang['Edit'],
240 "L_DELETE" => $lang['Delete'],
241 "L_ADD_WORD" => $lang['Add_new_word'],
242 "L_ACTION" => $lang['Action'],
244 "S_WORDS_ACTION" => append_sid("admin_words.$phpEx"),
245 "S_HIDDEN_FIELDS" => '')
248 for($i = 0; $i < $word_count; $i++)
250 $word = $word_rows[$i]['word'];
251 $replacement = $word_rows[$i]['replacement'];
252 $word_id = $word_rows[$i]['word_id'];
254 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
255 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
257 $template->assign_block_vars("words", array(
258 "ROW_COLOR" => "#" . $row_color,
259 "ROW_CLASS" => $row_class,
261 "REPLACEMENT" => $replacement,
263 "U_WORD_EDIT" => append_sid("admin_words.$phpEx?mode=edit&id=$word_id"),
264 "U_WORD_DELETE" => append_sid("admin_words.$phpEx?mode=delete&id=$word_id"))
269 $template->pparse("body");
271 include('./page_footer_admin.'.$phpEx);