2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: admin_forumauth.php,v 1.23.2.5 2004/03/25 15:57:19 acydburn 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 define('IN_PHPBB', 1);
25 if( !empty($setmodules) )
27 $filename = basename(__FILE__);
28 $module['Forums']['Permissions'] = $filename;
34 // Load default header
36 $no_page_header = TRUE;
37 $phpbb_root_path = './../';
38 require($phpbb_root_path . 'extension.inc');
39 require('./pagestart.' . $phpEx);
42 // Start program - define vars
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),
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'] . ']');
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');
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']);
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);
74 if(isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]))
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";
85 if( isset($HTTP_GET_VARS['adv']) )
87 $adv = intval($HTTP_GET_VARS['adv']);
95 // Start program proper
97 if( isset($HTTP_POST_VARS['submit']) )
101 if(!empty($forum_id))
103 if(isset($HTTP_POST_VARS['simpleauth']))
105 $simple_ary = $simple_auth_ary[intval($HTTP_POST_VARS['simpleauth'])];
107 for($i = 0; $i < count($simple_ary); $i++)
109 $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i];
112 if (is_array($simple_ary))
114 $sql = "UPDATE " . FORUMS_TABLE . " SET $sql WHERE forum_id = $forum_id";
119 for($i = 0; $i < count($forum_auth_fields); $i++)
121 $value = intval($HTTP_POST_VARS[$forum_auth_fields[$i]]);
123 if ( $forum_auth_fields[$i] == 'auth_vote' )
125 if ( $HTTP_POST_VARS['auth_vote'] == AUTH_ALL )
131 $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value;
134 $sql = "UPDATE " . FORUMS_TABLE . " SET $sql WHERE forum_id = $forum_id";
139 if ( !$db->sql_query($sql) )
141 message_die(GENERAL_ERROR, 'Could not update auth table', '', __LINE__, __FILE__, $sql);
149 $template->assign_vars(array(
150 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("admin_forumauth.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">')
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);
158 // Get required information, either all forums if
159 // no id was specified or just the requsted if it
163 FROM " . FORUMS_TABLE . " f, " . CATEGORIES_TABLE . " c
164 WHERE c.cat_id = f.cat_id
166 ORDER BY c.cat_order ASC, f.forum_order ASC";
167 if ( !($result = $db->sql_query($sql)) )
169 message_die(GENERAL_ERROR, "Couldn't obtain forum list", "", __LINE__, __FILE__, $sql);
172 $forum_rows = $db->sql_fetchrowset($result);
173 $db->sql_freeresult($result);
175 if( empty($forum_id) )
178 // Output the selection table if no forum id was
181 $template->set_filenames(array(
182 'body' => 'admin/auth_select_body.tpl')
185 $select_list = '<select name="' . POST_FORUM_URL . '">';
186 for($i = 0; $i < count($forum_rows); $i++)
188 $select_list .= '<option value="' . $forum_rows[$i]['forum_id'] . '">' . $forum_rows[$i]['forum_name'] . '</option>';
190 $select_list .= '</select>';
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'],
198 'S_AUTH_ACTION' => append_sid("admin_forumauth.$phpEx"),
199 'S_AUTH_SELECT' => $select_list)
206 // Output the authorisation details if an id was
209 $template->set_filenames(array(
210 'body' => 'admin/auth_forum_body.tpl')
213 $forum_name = $forum_rows[0]['forum_name'];
215 @reset($simple_auth_ary);
216 while( list($key, $auth_levels) = each($simple_auth_ary))
219 for($k = 0; $k < count($auth_levels); $k++)
221 $matched_type = $key;
223 if ( $forum_rows[0][$forum_auth_fields[$k]] != $auth_levels[$k] )
236 // If we didn't get a match above then we
237 // automatically switch into 'advanced' mode
239 if ( !isset($adv) && !$matched )
248 $simple_auth = '<select name="simpleauth">';
250 for($j = 0; $j < count($simple_auth_types); $j++)
252 $selected = ( $matched_type == $j ) ? ' selected="selected"' : '';
253 $simple_auth .= '<option value="' . $j . '"' . $selected . '>' . $simple_auth_types[$j] . '</option>';
256 $simple_auth .= '</select>';
258 $template->assign_block_vars('forum_auth_titles', array(
259 'CELL_TITLE' => $lang['Simple_mode'])
261 $template->assign_block_vars('forum_auth_data', array(
262 'S_AUTH_LEVELS_SELECT' => $simple_auth)
270 // Output values of individual
273 for($j = 0; $j < count($forum_auth_fields); $j++)
275 $custom_auth[$j] = ' <select name="' . $forum_auth_fields[$j] . '">';
277 for($k = 0; $k < count($forum_auth_levels); $k++)
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>';
282 $custom_auth[$j] .= '</select> ';
284 $cell_title = $field_names[$forum_auth_fields[$j]];
286 $template->assign_block_vars('forum_auth_titles', array(
287 'CELL_TITLE' => $cell_title)
289 $template->assign_block_vars('forum_auth_data', array(
290 'S_AUTH_LEVELS_SELECT' => $custom_auth[$j])
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>';
302 $s_hidden_fields = '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '">';
304 $template->assign_vars(array(
305 'FORUM_NAME' => $forum_name,
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'],
313 'U_SWITCH_MODE' => $u_switch_mode,
315 'S_FORUMAUTH_ACTION' => append_sid("admin_forumauth.$phpEx"),
316 'S_COLUMN_SPAN' => $s_column_span,
317 'S_HIDDEN_FIELDS' => $s_hidden_fields)
322 include('./page_header_admin.'.$phpEx);
324 $template->pparse('body');
326 include('./page_footer_admin.'.$phpEx);