~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/php/phpBB3/includes/acp/acp_ranks.php

  • Committer: dcoles
  • Date: 2008-02-13 04:10:55 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:443
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
*
 
4
* @package acp
 
5
* @version $Id: acp_ranks.php,v 1.18 2007/10/14 10:07:52 kellanved Exp $
 
6
* @copyright (c) 2005 phpBB Group
 
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
 
8
*
 
9
*/
 
10
 
 
11
/**
 
12
* @ignore
 
13
*/
 
14
if (!defined('IN_PHPBB'))
 
15
{
 
16
        exit;
 
17
}
 
18
 
 
19
/**
 
20
* @package acp
 
21
*/
 
22
class acp_ranks
 
23
{
 
24
        var $u_action;
 
25
 
 
26
        function main($id, $mode)
 
27
        {
 
28
                global $db, $user, $auth, $template, $cache;
 
29
                global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
 
30
 
 
31
                $user->add_lang('acp/posting');
 
32
 
 
33
                // Set up general vars
 
34
                $action = request_var('action', '');
 
35
                $action = (isset($_POST['add'])) ? 'add' : $action;
 
36
                $action = (isset($_POST['save'])) ? 'save' : $action;
 
37
                $rank_id = request_var('id', 0);
 
38
 
 
39
                $this->tpl_name = 'acp_ranks';
 
40
                $this->page_title = 'ACP_MANAGE_RANKS';
 
41
 
 
42
                $form_name = 'acp_prune';
 
43
                add_form_key($form_name);
 
44
 
 
45
                switch ($action)
 
46
                {
 
47
                        case 'save':
 
48
 
 
49
                                if (!check_form_key($form_name))
 
50
                                {
 
51
                                        trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
 
52
                                }
 
53
                                $rank_title = utf8_normalize_nfc(request_var('title', '', true));
 
54
                                $special_rank = request_var('special_rank', 0);
 
55
                                $min_posts = ($special_rank) ? 0 : request_var('min_posts', 0);
 
56
                                $rank_image = request_var('rank_image', '');
 
57
 
 
58
                                // The rank image has to be a jpg, gif or png
 
59
                                if ($rank_image != '' && !preg_match('#(\.gif|\.png|\.jpg|\.jpeg)$#i', $rank_image))
 
60
                                {
 
61
                                        $rank_image = '';
 
62
                                }
 
63
 
 
64
                                if (!$rank_title)
 
65
                                {
 
66
                                        trigger_error($user->lang['NO_RANK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING);
 
67
                                }
 
68
 
 
69
                                $sql_ary = array(
 
70
                                        'rank_title'            => $rank_title,
 
71
                                        'rank_special'          => $special_rank,
 
72
                                        'rank_min'                      => $min_posts,
 
73
                                        'rank_image'            => htmlspecialchars_decode($rank_image)
 
74
                                );
 
75
                                
 
76
                                if ($rank_id)
 
77
                                {
 
78
                                        $sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = $rank_id";
 
79
                                        $message = $user->lang['RANK_UPDATED'];
 
80
 
 
81
                                        add_log('admin', 'LOG_RANK_UPDATED', $rank_title);
 
82
                                }
 
83
                                else
 
84
                                {
 
85
                                        $sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 
86
                                        $message = $user->lang['RANK_ADDED'];
 
87
 
 
88
                                        add_log('admin', 'LOG_RANK_ADDED', $rank_title);
 
89
                                }
 
90
                                $db->sql_query($sql);
 
91
 
 
92
                                $cache->destroy('_ranks');
 
93
 
 
94
                                trigger_error($message . adm_back_link($this->u_action));
 
95
 
 
96
                        break;
 
97
 
 
98
                        case 'delete':
 
99
 
 
100
                                if (!$rank_id)
 
101
                                {
 
102
                                        trigger_error($user->lang['MUST_SELECT_RANK'] . adm_back_link($this->u_action), E_USER_WARNING);
 
103
                                }
 
104
 
 
105
                                if (confirm_box(true))
 
106
                                {
 
107
                                        $sql = 'SELECT rank_title
 
108
                                                FROM ' . RANKS_TABLE . '
 
109
                                                WHERE rank_id = ' . $rank_id;
 
110
                                        $result = $db->sql_query($sql);
 
111
                                        $rank_title = (string) $db->sql_fetchfield('rank_title');
 
112
                                        $db->sql_freeresult($result);
 
113
 
 
114
                                        $sql = 'DELETE FROM ' . RANKS_TABLE . "
 
115
                                                WHERE rank_id = $rank_id";
 
116
                                        $db->sql_query($sql);
 
117
 
 
118
                                        $sql = 'UPDATE ' . USERS_TABLE . "
 
119
                                                SET user_rank = 0
 
120
                                                WHERE user_rank = $rank_id";
 
121
                                        $db->sql_query($sql);
 
122
 
 
123
                                        $cache->destroy('_ranks');
 
124
 
 
125
                                        add_log('admin', 'LOG_RANK_REMOVED', $rank_title);
 
126
                                }
 
127
                                else
 
128
                                {
 
129
                                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 
130
                                                'i'                     => $id,
 
131
                                                'mode'          => $mode,
 
132
                                                'rank_id'       => $rank_id,
 
133
                                                'action'        => 'delete',
 
134
                                        )));
 
135
                                }
 
136
 
 
137
                        break;
 
138
 
 
139
                        case 'edit':
 
140
                        case 'add':
 
141
 
 
142
                                $data = $ranks = $existing_imgs = array();
 
143
                                
 
144
                                $sql = 'SELECT *
 
145
                                        FROM ' . RANKS_TABLE . '
 
146
                                        ORDER BY rank_min ASC, rank_special ASC';
 
147
                                $result = $db->sql_query($sql);
 
148
 
 
149
                                while ($row = $db->sql_fetchrow($result))
 
150
                                {
 
151
                                        $existing_imgs[] = $row['rank_image'];
 
152
 
 
153
                                        if ($action == 'edit' && $rank_id == $row['rank_id'])
 
154
                                        {
 
155
                                                $ranks = $row;
 
156
                                        }
 
157
                                }
 
158
                                $db->sql_freeresult($result);
 
159
 
 
160
                                $imglist = filelist($phpbb_root_path . $config['ranks_path'], '');
 
161
                                $edit_img = $filename_list = '';
 
162
 
 
163
                                foreach ($imglist as $path => $img_ary)
 
164
                                {
 
165
                                        sort($img_ary);
 
166
 
 
167
                                        foreach ($img_ary as $img)
 
168
                                        {
 
169
                                                $img = $path . $img;
 
170
 
 
171
                                                if (!in_array($img, $existing_imgs) || $action == 'edit')
 
172
                                                {
 
173
                                                        if ($ranks && $img == $ranks['rank_image'])
 
174
                                                        {
 
175
                                                                $selected = ' selected="selected"';
 
176
                                                                $edit_img = $img;
 
177
                                                        }
 
178
                                                        else
 
179
                                                        {
 
180
                                                                $selected = '';
 
181
                                                        }
 
182
 
 
183
                                                        if (strlen($img) > 255)
 
184
                                                        {
 
185
                                                                continue;
 
186
                                                        }
 
187
 
 
188
                                                        $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>';
 
189
                                                }
 
190
                                        }
 
191
                                }
 
192
 
 
193
                                $filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list;
 
194
                                unset($existing_imgs, $imglist);
 
195
 
 
196
                                $template->assign_vars(array(
 
197
                                        'S_EDIT'                        => true,
 
198
                                        'U_BACK'                        => $this->u_action,
 
199
                                        'RANKS_PATH'            => $phpbb_root_path . $config['ranks_path'],
 
200
                                        'U_ACTION'                      => $this->u_action . '&amp;id=' . $rank_id,
 
201
 
 
202
                                        'RANK_TITLE'            => (isset($ranks['rank_title'])) ? $ranks['rank_title'] : '',
 
203
                                        'S_FILENAME_LIST'       => $filename_list,
 
204
                                        'RANK_IMAGE'            => ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : $phpbb_admin_path . 'images/spacer.gif',
 
205
                                        'S_SPECIAL_RANK'        => (!isset($ranks['rank_special']) || $ranks['rank_special']) ? true : false,
 
206
                                        'MIN_POSTS'                     => (isset($ranks['rank_min']) && !$ranks['rank_special']) ? $ranks['rank_min'] : 0)
 
207
                                );
 
208
                                                
 
209
 
 
210
                                return;
 
211
 
 
212
                        break;
 
213
                }
 
214
        
 
215
                $template->assign_vars(array(
 
216
                        'U_ACTION'              => $this->u_action)
 
217
                );
 
218
 
 
219
                $sql = 'SELECT *
 
220
                        FROM ' . RANKS_TABLE . '
 
221
                        ORDER BY rank_special DESC, rank_min ASC, rank_title ASC';
 
222
                $result = $db->sql_query($sql);
 
223
 
 
224
                while ($row = $db->sql_fetchrow($result))
 
225
                {
 
226
                        $template->assign_block_vars('ranks', array(
 
227
                                'S_RANK_IMAGE'          => ($row['rank_image']) ? true : false,
 
228
                                'S_SPECIAL_RANK'        => ($row['rank_special']) ? true : false,
 
229
 
 
230
                                'RANK_IMAGE'            => $phpbb_root_path . $config['ranks_path'] . '/' . $row['rank_image'],
 
231
                                'RANK_TITLE'            => $row['rank_title'],
 
232
                                'MIN_POSTS'                     => $row['rank_min'],
 
233
 
 
234
                                'U_EDIT'                        => $this->u_action . '&amp;action=edit&amp;id=' . $row['rank_id'],
 
235
                                'U_DELETE'                      => $this->u_action . '&amp;action=delete&amp;id=' . $row['rank_id'])
 
236
                        );      
 
237
                }
 
238
                $db->sql_freeresult($result);
 
239
 
 
240
        }
 
241
}
 
242
 
 
243
?>
 
 
b'\\ No newline at end of file'