]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/admin_words.php
Baseline
[www.vanrenterghem.biz.git] / phpBB2_old / admin / admin_words.php
1 <?php
2 /***************************************************************************
3  *                              admin_words.php
4  *                            -------------------
5  *   begin                : Thursday, Jul 12, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: admin_words.php,v 1.10.2.3 2004/03/25 15:57:20 acydburn Exp $
10  *
11  *
12  ***************************************************************************/
14 /***************************************************************************
15  *
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.
20  *
21  ***************************************************************************/
23 define('IN_PHPBB', 1);
25 if( !empty($setmodules) )
26 {
27         $file = basename(__FILE__);
28         $module['General']['Word_Censor'] = "$file";
29         return;
30 }
32 //
33 // Load default header
34 //
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']) )
40 {
41         $mode = ($HTTP_GET_VARS['mode']) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
42         $mode = htmlspecialchars($mode);
43 }
44 else 
45 {
46         //
47         // These could be entered via a form button
48         //
49         if( isset($HTTP_POST_VARS['add']) )
50         {
51                 $mode = "add";
52         }
53         else if( isset($HTTP_POST_VARS['save']) )
54         {
55                 $mode = "save";
56         }
57         else
58         {
59                 $mode = "";
60         }
61 }
63 if( $mode != "" )
64 {
65         if( $mode == "edit" || $mode == "add" )
66         {
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")
71                 );
73                 $s_hidden_fields = '';
75                 if( $mode == "edit" )
76                 {
77                         if( $word_id )
78                         {
79                                 $sql = "SELECT * 
80                                         FROM " . WORDS_TABLE . " 
81                                         WHERE word_id = $word_id";
82                                 if(!$result = $db->sql_query($sql))
83                                 {
84                                         message_die(GENERAL_ERROR, "Could not query words table", "Error", __LINE__, __FILE__, $sql);
85                                 }
87                                 $word_info = $db->sql_fetchrow($result);
88                                 $s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
89                         }
90                         else
91                         {
92                                 message_die(GENERAL_MESSAGE, $lang['No_word_selected']);
93                         }
94                 }
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)
109                 );
111                 $template->pparse("body");
113                 include('./page_footer_admin.'.$phpEx);
114         }
115         else if( $mode == "save" )
116         {
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 == "")
122                 {
123                         message_die(GENERAL_MESSAGE, $lang['Must_enter_word']);
124                 }
126                 if( $word_id )
127                 {
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'];
132                 }
133                 else
134                 {
135                         $sql = "INSERT INTO " . WORDS_TABLE . " (word, replacement) 
136                                 VALUES ('" . str_replace("\'", "''", $word) . "', '" . str_replace("\'", "''", $replacement) . "')";
137                         $message = $lang['Word_added'];
138                 }
140                 if(!$result = $db->sql_query($sql))
141                 {
142                         message_die(GENERAL_ERROR, "Could not insert data into words table", $lang['Error'], __LINE__, __FILE__, $sql);
143                 }
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);
148         }
149         else if( $mode == "delete" )
150         {
151                 if( isset($HTTP_POST_VARS['id']) ||  isset($HTTP_GET_VARS['id']) )
152                 {
153                         $word_id = ( isset($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
154                         $word_id = intval($word_id);
155                 }
156                 else
157                 {
158                         $word_id = 0;
159                 }
161                 if( $word_id )
162                 {
163                         $sql = "DELETE FROM " . WORDS_TABLE . " 
164                                 WHERE word_id = $word_id";
166                         if(!$result = $db->sql_query($sql))
167                         {
168                                 message_die(GENERAL_ERROR, "Could not remove data from words table", $lang['Error'], __LINE__, __FILE__, $sql);
169                         }
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);
174                 }
175                 else
176                 {
177                         message_die(GENERAL_MESSAGE, $lang['No_word_selected']);
178                 }
179         }
181 else
183         $template->set_filenames(array(
184                 "body" => "admin/words_list_body.tpl")
185         );
187         $sql = "SELECT * 
188                 FROM " . WORDS_TABLE . " 
189                 ORDER BY word";
190         if( !$result = $db->sql_query($sql) )
191         {
192                 message_die(GENERAL_ERROR, "Could not query words table", $lang['Error'], __LINE__, __FILE__, $sql);
193         }
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" => '')
210         );
212         for($i = 0; $i < $word_count; $i++)
213         {
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,
224                         "WORD" => $word,
225                         "REPLACEMENT" => $replacement,
227                         "U_WORD_EDIT" => append_sid("admin_words.$phpEx?mode=edit&amp;id=$word_id"),
228                         "U_WORD_DELETE" => append_sid("admin_words.$phpEx?mode=delete&amp;id=$word_id"))
229                 );
230         }
233 $template->pparse("body");
235 include('./page_footer_admin.'.$phpEx);
237 ?>