phpBB
Statistics
| Revision:

root / tags / release_2_0_2 / phpBB / admin / admin_words.php

History | View | Annotate | Download (6.4 kB)

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 2570 2002-05-12 15:57:47Z psotfx $
10
 *
11
 *
12
 ***************************************************************************/
13
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
 ***************************************************************************/
22
23
define('IN_PHPBB', 1);
24
25
if( !empty($setmodules) )
26
{
27
        $file = basename(__FILE__);
28
        $module['General']['Word_Censor'] = "$file";
29
        return;
30
}
31
32
//
33
// Load default header
34
//
35
$phpbb_root_path = "./../";
36
require($phpbb_root_path . 'extension.inc');
37
require('./pagestart.' . $phpEx);
38
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
}
43
else 
44
{
45
        //
46
        // These could be entered via a form button
47
        //
48
        if( isset($HTTP_POST_VARS['add']) )
49
        {
50
                $mode = "add";
51
        }
52
        else if( isset($HTTP_POST_VARS['save']) )
53
        {
54
                $mode = "save";
55
        }
56
        else
57
        {
58
                $mode = "";
59
        }
60
}
61
62
if( $mode != "" )
63
{
64
        if( $mode == "edit" || $mode == "add" )
65
        {
66
                $word_id = ( isset($HTTP_GET_VARS['id']) ) ? $HTTP_GET_VARS['id'] : 0;
67
68
                $template->set_filenames(array(
69
                        "body" => "admin/words_edit_body.tpl")
70
                );
71
72
                $s_hidden_fields = '';
73
74
                if( $mode == "edit" )
75
                {
76
                        if( $word_id )
77
                        {
78
                                $sql = "SELECT * 
79
                                        FROM " . WORDS_TABLE . " 
80
                                        WHERE word_id = $word_id";
81
                                if(!$result = $db->sql_query($sql))
82
                                {
83
                                        message_die(GENERAL_ERROR, "Could not query words table", "Error", __LINE__, __FILE__, $sql);
84
                                }
85
86
                                $word_info = $db->sql_fetchrow($result);
87
                                $s_hidden_fields .= '<input type="hidden" name="id" value="' . $word_id . '" />';
88
                        }
89
                        else
90
                        {
91
                                message_die(GENERAL_MESSAGE, $lang['No_word_selected']);
92
                        }
93
                }
94
95
                $template->assign_vars(array(
96
                        "WORD" => $word_info['word'],
97
                        "REPLACEMENT" => $word_info['replacement'],
98
99
                        "L_WORDS_TITLE" => $lang['Words_title'],
100
                        "L_WORDS_TEXT" => $lang['Words_explain'],
101
                        "L_WORD_CENSOR" => $lang['Edit_word_censor'],
102
                        "L_WORD" => $lang['Word'],
103
                        "L_REPLACEMENT" => $lang['Replacement'],
104
                        "L_SUBMIT" => $lang['Submit'],
105
106
                        "S_WORDS_ACTION" => append_sid("admin_words.$phpEx"),
107
                        "S_HIDDEN_FIELDS" => $s_hidden_fields)
108
                );
109
110
                $template->pparse("body");
111
112
                include('./page_footer_admin.'.$phpEx);
113
        }
114
        else if( $mode == "save" )
115
        {
116
                $word_id = ( isset($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : 0;
117
                $word = ( isset($HTTP_POST_VARS['word']) ) ? trim($HTTP_POST_VARS['word']) : "";
118
                $replacement = ( isset($HTTP_POST_VARS['replacement']) ) ? trim($HTTP_POST_VARS['replacement']) : "";
119
120
                if($word == "" || $replacement == "")
121
                {
122
                        message_die(GENERAL_MESSAGE, $lang['Must_enter_word']);
123
                }
124
125
                if( $word_id )
126
                {
127
                        $sql = "UPDATE " . WORDS_TABLE . " 
128
                                SET word = '" . str_replace("\'", "''", $word) . "', replacement = '" . str_replace("\'", "''", $replacement) . "' 
129
                                WHERE word_id = $word_id";
130
                        $message = $lang['Word_updated'];
131
                }
132
                else
133
                {
134
                        $sql = "INSERT INTO " . WORDS_TABLE . " (word, replacement) 
135
                                VALUES ('" . str_replace("\'", "''", $word) . "', '" . str_replace("\'", "''", $replacement) . "')";
136
                        $message = $lang['Word_added'];
137
                }
138
139
                if(!$result = $db->sql_query($sql))
140
                {
141
                        message_die(GENERAL_ERROR, "Could not insert data into words table", $lang['Error'], __LINE__, __FILE__, $sql);
142
                }
143
144
                $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>");
145
146
                message_die(GENERAL_MESSAGE, $message);
147
        }
148
        else if( $mode == "delete" )
149
        {
150
                if( isset($HTTP_POST_VARS['id']) ||  isset($HTTP_GET_VARS['id']) )
151
                {
152
                        $word_id = ( isset($HTTP_POST_VARS['id']) ) ? $HTTP_POST_VARS['id'] : $HTTP_GET_VARS['id'];
153
                }
154
                else
155
                {
156
                        $word_id = 0;
157
                }
158
159
                if( $word_id )
160
                {
161
                        $sql = "DELETE FROM " . WORDS_TABLE . " 
162
                                WHERE word_id = $word_id";
163
164
                        if(!$result = $db->sql_query($sql))
165
                        {
166
                                message_die(GENERAL_ERROR, "Could not remove data from words table", $lang['Error'], __LINE__, __FILE__, $sql);
167
                        }
168
169
                        $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>");
170
171
                        message_die(GENERAL_MESSAGE, $message);
172
                }
173
                else
174
                {
175
                        message_die(GENERAL_MESSAGE, $lang['No_word_selected']);
176
                }
177
        }
178
}
179
else
180
{
181
        $template->set_filenames(array(
182
                "body" => "admin/words_list_body.tpl")
183
        );
184
185
        $sql = "SELECT * 
186
                FROM " . WORDS_TABLE . " 
187
                ORDER BY word";
188
        if( !$result = $db->sql_query($sql) )
189
        {
190
                message_die(GENERAL_ERROR, "Could not query words table", $lang['Error'], __LINE__, __FILE__, $sql);
191
        }
192
193
        $word_rows = $db->sql_fetchrowset($result);
194
        $word_count = count($word_rows);
195
196
        $template->assign_vars(array(
197
                "L_WORDS_TITLE" => $lang['Words_title'],
198
                "L_WORDS_TEXT" => $lang['Words_explain'],
199
                "L_WORD" => $lang['Word'],
200
                "L_REPLACEMENT" => $lang['Replacement'],
201
                "L_EDIT" => $lang['Edit'],
202
                "L_DELETE" => $lang['Delete'],
203
                "L_ADD_WORD" => $lang['Add_new_word'],
204
                "L_ACTION" => $lang['Action'],
205
206
                "S_WORDS_ACTION" => append_sid("admin_words.$phpEx"),
207
                "S_HIDDEN_FIELDS" => '')
208
        );
209
210
        for($i = 0; $i < $word_count; $i++)
211
        {
212
                $word = $word_rows[$i]['word'];
213
                $replacement = $word_rows[$i]['replacement'];
214
                $word_id = $word_rows[$i]['word_id'];
215
216
                $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
217
                $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
218
219
                $template->assign_block_vars("words", array(
220
                        "ROW_COLOR" => "#" . $row_color,
221
                        "ROW_CLASS" => $row_class,
222
                        "WORD" => $word,
223
                        "REPLACEMENT" => $replacement,
224
225
                        "U_WORD_EDIT" => append_sid("admin_words.$phpEx?mode=edit&amp;id=$word_id"),
226
                        "U_WORD_DELETE" => append_sid("admin_words.$phpEx?mode=delete&amp;id=$word_id"))
227
                );
228
        }
229
}
230
231
$template->pparse("body");
232
233
include('./page_footer_admin.'.$phpEx);
234
235
?>