]> scripts.mit.edu Git - autoinstalls/phpBB.git/blob - admin/admin_forumauth.php
phpBB 2.0.19-scripts
[autoinstalls/phpBB.git] / admin / admin_forumauth.php
1 <?php
2 /***************************************************************************
3  *                            admin_forumauth.php
4  *                            -------------------
5  *   begin                : Saturday, Feb 13, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: admin_forumauth.php,v 1.23.2.5 2004/03/25 15:57:19 acydburn Exp $
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         $filename = basename(__FILE__);
28         $module['Forums']['Permissions']   = $filename;
29
30         return;
31 }
32
33 //
34 // Load default header
35 //
36 $no_page_header = TRUE;
37 $phpbb_root_path = './../';
38 require($phpbb_root_path . 'extension.inc');
39 require('./pagestart.' . $phpEx);
40
41 //
42 // Start program - define vars
43 //
44 //                View      Read      Post      Reply     Edit     Delete    Sticky   Announce    Vote      Poll
45 $simple_auth_ary = array(
46         0  => array(AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG),
47         1  => array(AUTH_ALL, AUTH_ALL, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG),
48         2  => array(AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_REG, AUTH_MOD, AUTH_MOD, AUTH_REG, AUTH_REG),
49         3  => array(AUTH_ALL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_ACL, AUTH_ACL),
50         4  => array(AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_ACL, AUTH_MOD, AUTH_ACL, AUTH_ACL),
51         5  => array(AUTH_ALL, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD),
52         6  => array(AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD, AUTH_MOD),
53 );
54
55 $simple_auth_types = array($lang['Public'], $lang['Registered'], $lang['Registered'] . ' [' . $lang['Hidden'] . ']', $lang['Private'], $lang['Private'] . ' [' . $lang['Hidden'] . ']', $lang['Moderators'], $lang['Moderators'] . ' [' . $lang['Hidden'] . ']');
56
57 $forum_auth_fields = array('auth_view', 'auth_read', 'auth_post', 'auth_reply', 'auth_edit', 'auth_delete', 'auth_sticky', 'auth_announce', 'auth_vote', 'auth_pollcreate');
58
59 $field_names = array(
60         'auth_view' => $lang['View'],
61         'auth_read' => $lang['Read'],
62         'auth_post' => $lang['Post'],
63         'auth_reply' => $lang['Reply'],
64         'auth_edit' => $lang['Edit'],
65         'auth_delete' => $lang['Delete'],
66         'auth_sticky' => $lang['Sticky'],
67         'auth_announce' => $lang['Announce'], 
68         'auth_vote' => $lang['Vote'], 
69         'auth_pollcreate' => $lang['Pollcreate']);
70
71 $forum_auth_levels = array('ALL', 'REG', 'PRIVATE', 'MOD', 'ADMIN');
72 $forum_auth_const = array(AUTH_ALL, AUTH_REG, AUTH_ACL, AUTH_MOD, AUTH_ADMIN);
73
74 if(isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]))
75 {
76         $forum_id = (isset($HTTP_POST_VARS[POST_FORUM_URL])) ? intval($HTTP_POST_VARS[POST_FORUM_URL]) : intval($HTTP_GET_VARS[POST_FORUM_URL]);
77         $forum_sql = "AND forum_id = $forum_id";
78 }
79 else
80 {
81         unset($forum_id);
82         $forum_sql = '';
83 }
84
85 if( isset($HTTP_GET_VARS['adv']) )
86 {
87         $adv = intval($HTTP_GET_VARS['adv']);
88 }
89 else
90 {
91         unset($adv);
92 }
93
94 //
95 // Start program proper
96 //
97 if( isset($HTTP_POST_VARS['submit']) )
98 {
99         $sql = '';
100
101         if(!empty($forum_id))
102         {
103                 if(isset($HTTP_POST_VARS['simpleauth']))
104                 {
105                         $simple_ary = $simple_auth_ary[intval($HTTP_POST_VARS['simpleauth'])];
106
107                         for($i = 0; $i < count($simple_ary); $i++)
108                         {
109                                 $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i];
110                         }
111
112                         if (is_array($simple_ary))
113                         {
114                                 $sql = "UPDATE " . FORUMS_TABLE . " SET $sql WHERE forum_id = $forum_id";
115                         }
116                 }
117                 else
118                 {
119                         for($i = 0; $i < count($forum_auth_fields); $i++)
120                         {
121                                 $value = intval($HTTP_POST_VARS[$forum_auth_fields[$i]]);
122
123                                 if ( $forum_auth_fields[$i] == 'auth_vote' )
124                                 {
125                                         if ( $HTTP_POST_VARS['auth_vote'] == AUTH_ALL )
126                                         {
127                                                 $value = AUTH_REG;
128                                         }
129                                 }
130
131                                 $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value;
132                         }
133
134                         $sql = "UPDATE " . FORUMS_TABLE . " SET $sql WHERE forum_id = $forum_id";
135                 }
136
137                 if ( $sql != '' )
138                 {
139                         if ( !$db->sql_query($sql) )
140                         {
141                                 message_die(GENERAL_ERROR, 'Could not update auth table', '', __LINE__, __FILE__, $sql);
142                         }
143                 }
144
145                 $forum_sql = '';
146                 $adv = 0;
147         }
148
149         $template->assign_vars(array(
150                 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("admin_forumauth.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">')
151         );
152         $message = $lang['Forum_auth_updated'] . '<br /><br />' . sprintf($lang['Click_return_forumauth'],  '<a href="' . append_sid("admin_forumauth.$phpEx") . '">', "</a>");
153         message_die(GENERAL_MESSAGE, $message);
154
155 } // End of submit
156
157 //
158 // Get required information, either all forums if
159 // no id was specified or just the requsted if it
160 // was
161 //
162 $sql = "SELECT f.*
163         FROM " . FORUMS_TABLE . " f, " . CATEGORIES_TABLE . " c
164         WHERE c.cat_id = f.cat_id
165         $forum_sql
166         ORDER BY c.cat_order ASC, f.forum_order ASC";
167 if ( !($result = $db->sql_query($sql)) )
168 {
169         message_die(GENERAL_ERROR, "Couldn't obtain forum list", "", __LINE__, __FILE__, $sql);
170 }
171
172 $forum_rows = $db->sql_fetchrowset($result);
173 $db->sql_freeresult($result);
174
175 if( empty($forum_id) )
176 {
177         //
178         // Output the selection table if no forum id was
179         // specified
180         //
181         $template->set_filenames(array(
182                 'body' => 'admin/auth_select_body.tpl')
183         );
184
185         $select_list = '<select name="' . POST_FORUM_URL . '">';
186         for($i = 0; $i < count($forum_rows); $i++)
187         {
188                 $select_list .= '<option value="' . $forum_rows[$i]['forum_id'] . '">' . $forum_rows[$i]['forum_name'] . '</option>';
189         }
190         $select_list .= '</select>';
191
192         $template->assign_vars(array(
193                 'L_AUTH_TITLE' => $lang['Auth_Control_Forum'],
194                 'L_AUTH_EXPLAIN' => $lang['Forum_auth_explain'],
195                 'L_AUTH_SELECT' => $lang['Select_a_Forum'],
196                 'L_LOOK_UP' => $lang['Look_up_Forum'],
197
198                 'S_AUTH_ACTION' => append_sid("admin_forumauth.$phpEx"),
199                 'S_AUTH_SELECT' => $select_list)
200         );
201
202 }
203 else
204 {
205         //
206         // Output the authorisation details if an id was
207         // specified
208         //
209         $template->set_filenames(array(
210                 'body' => 'admin/auth_forum_body.tpl')
211         );
212
213         $forum_name = $forum_rows[0]['forum_name'];
214
215         @reset($simple_auth_ary);
216         while( list($key, $auth_levels) = each($simple_auth_ary))
217         {
218                 $matched = 1;
219                 for($k = 0; $k < count($auth_levels); $k++)
220                 {
221                         $matched_type = $key;
222
223                         if ( $forum_rows[0][$forum_auth_fields[$k]] != $auth_levels[$k] )
224                         {
225                                 $matched = 0;
226                         }
227                 }
228
229                 if ( $matched )
230                 {
231                         break;
232                 }
233         }
234
235         //
236         // If we didn't get a match above then we
237         // automatically switch into 'advanced' mode
238         //
239         if ( !isset($adv) && !$matched )
240         {
241                 $adv = 1;
242         }
243
244         $s_column_span == 0;
245
246         if ( empty($adv) )
247         {
248                 $simple_auth = '<select name="simpleauth">';
249
250                 for($j = 0; $j < count($simple_auth_types); $j++)
251                 {
252                         $selected = ( $matched_type == $j ) ? ' selected="selected"' : '';
253                         $simple_auth .= '<option value="' . $j . '"' . $selected . '>' . $simple_auth_types[$j] . '</option>';
254                 }
255
256                 $simple_auth .= '</select>';
257
258                 $template->assign_block_vars('forum_auth_titles', array(
259                         'CELL_TITLE' => $lang['Simple_mode'])
260                 );
261                 $template->assign_block_vars('forum_auth_data', array(
262                         'S_AUTH_LEVELS_SELECT' => $simple_auth)
263                 );
264
265                 $s_column_span++;
266         }
267         else
268         {
269                 //
270                 // Output values of individual
271                 // fields
272                 //
273                 for($j = 0; $j < count($forum_auth_fields); $j++)
274                 {
275                         $custom_auth[$j] = '&nbsp;<select name="' . $forum_auth_fields[$j] . '">';
276
277                         for($k = 0; $k < count($forum_auth_levels); $k++)
278                         {
279                                 $selected = ( $forum_rows[0][$forum_auth_fields[$j]] == $forum_auth_const[$k] ) ? ' selected="selected"' : '';
280                                 $custom_auth[$j] .= '<option value="' . $forum_auth_const[$k] . '"' . $selected . '>' . $lang['Forum_' . $forum_auth_levels[$k]] . '</option>';
281                         }
282                         $custom_auth[$j] .= '</select>&nbsp;';
283
284                         $cell_title = $field_names[$forum_auth_fields[$j]];
285
286                         $template->assign_block_vars('forum_auth_titles', array(
287                                 'CELL_TITLE' => $cell_title)
288                         );
289                         $template->assign_block_vars('forum_auth_data', array(
290                                 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j])
291                         );
292
293                         $s_column_span++;
294                 }
295         }
296
297         $adv_mode = ( empty($adv) ) ? '1' : '0';
298         $switch_mode = append_sid("admin_forumauth.$phpEx?" . POST_FORUM_URL . "=" . $forum_id . "&adv=". $adv_mode);
299         $switch_mode_text = ( empty($adv) ) ? $lang['Advanced_mode'] : $lang['Simple_mode'];
300         $u_switch_mode = '<a href="' . $switch_mode . '">' . $switch_mode_text . '</a>';
301
302         $s_hidden_fields = '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '">';
303
304         $template->assign_vars(array(
305                 'FORUM_NAME' => $forum_name,
306
307                 'L_FORUM' => $lang['Forum'], 
308                 'L_AUTH_TITLE' => $lang['Auth_Control_Forum'],
309                 'L_AUTH_EXPLAIN' => $lang['Forum_auth_explain'],
310                 'L_SUBMIT' => $lang['Submit'],
311                 'L_RESET' => $lang['Reset'],
312
313                 'U_SWITCH_MODE' => $u_switch_mode,
314
315                 'S_FORUMAUTH_ACTION' => append_sid("admin_forumauth.$phpEx"),
316                 'S_COLUMN_SPAN' => $s_column_span,
317                 'S_HIDDEN_FIELDS' => $s_hidden_fields)
318         );
319
320 }
321
322 include('./page_header_admin.'.$phpEx);
323
324 $template->pparse('body');
325
326 include('./page_footer_admin.'.$phpEx);
327
328 ?>