Browse Source

Another bit of ignore boards: the membergroups management page. A bit ugly, but that's the best I can think of. If I'm lucky I didn't break anything.

Signed-off-by: emanuele <[email protected]>
emanuele 12 years ago
parent
commit
bfdd853925

+ 1 - 1
Sources/ManageBoards.php

@@ -402,7 +402,7 @@ function EditBoard()
 		// Some things that need to be setup for a new board.
 		$curBoard = array(
 			'member_groups' => array(0, -1),
-			'deny_group' => array(),
+			'deny_groups' => array(),
 			'category' => (int) $_REQUEST['cat']
 		);
 		$context['board_order'] = array();

+ 84 - 58
Sources/ManageMembergroups.php

@@ -499,23 +499,30 @@ function AddMembergroup()
 		}
 
 		// Make sure all boards selected are stored in a proper array.
-		$_POST['boardaccess'] = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
-		foreach ($_POST['boardaccess'] as $key => $value)
-			$_POST['boardaccess'][$key] = (int) $value;
-
-		// Only do this if they have special access requirements.
-		if (!empty($_POST['boardaccess']))
-			$smcFunc['db_query']('', '
-				UPDATE {db_prefix}boards
-				SET member_groups = CASE WHEN member_groups = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT(member_groups, {string:comma_group}) END
-				WHERE id_board IN ({array_int:board_list})',
-				array(
-					'board_list' => $_POST['boardaccess'],
-					'blank_string' => '',
-					'group_id_string' => (string) $id_group,
-					'comma_group' => ',' . $id_group,
-				)
-			);
+		$accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
+		$changed_boards['allow'] = array();
+		$changed_boards['deny'] = array();
+		$changed_boards['ignore'] = array();
+		foreach ($accesses as $group_id => $action)
+			$changed_boards[$action][] = (int) $group_id;
+
+		foreach (array('allow', 'deny') as $board_action)
+		{
+			// Only do this if they have special access requirements.
+			if (!empty($changed_boards[$board_action]))
+				$smcFunc['db_query']('', '
+					UPDATE {db_prefix}boards
+					SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
+					WHERE id_board IN ({array_int:board_list})',
+					array(
+						'board_list' => $changed_boards[$board_action],
+						'blank_string' => '',
+						'group_id_string' => (string) $id_group,
+						'comma_group' => ',' . $id_group,
+						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
+					)
+				);
+		}
 
 		// If this is joinable then set it to show group membership in people's profiles.
 		if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1)
@@ -540,6 +547,9 @@ function AddMembergroup()
 	$context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
 	$context['allow_protected'] = allowedTo('admin_forum');
 
+	if (!empty($modSettings['deny_boards_access']))
+		loadLanguage('ManagePermissions');
+
 	$result = $smcFunc['db_query']('', '
 		SELECT id_group, group_name
 		FROM {db_prefix}membergroups
@@ -588,7 +598,8 @@ function AddMembergroup()
 			'id' => $row['id_board'],
 			'name' => $row['name'],
 			'child_level' => $row['child_level'],
-			'selected' => false
+			'allow' => false,
+			'deny' => false
 		);
 
 	}
@@ -648,6 +659,10 @@ function EditMembergroup()
 
 	$_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
 
+	if (!empty($modSettings['deny_boards_access']))
+		loadLanguage('ManagePermissions');
+
+
 	// Make sure this group is editable.
 	if (!empty($_REQUEST['group']))
 	{
@@ -744,48 +759,57 @@ function EditMembergroup()
 		// Time to update the boards this membergroup has access to.
 		if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3)
 		{
-			$_POST['boardaccess'] = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
-			foreach ($_POST['boardaccess'] as $key => $value)
-				$_POST['boardaccess'][$key] = (int) $value;
-
-			// Find all board this group is in, but shouldn't be in.
-			$request = $smcFunc['db_query']('', '
-				SELECT id_board, member_groups
-				FROM {db_prefix}boards
-				WHERE FIND_IN_SET({string:current_group}, member_groups) != 0' . (empty($_POST['boardaccess']) ? '' : '
-					AND id_board NOT IN ({array_int:board_access_list})'),
-				array(
-					'current_group' => (int) $_REQUEST['group'],
-					'board_access_list' => $_POST['boardaccess'],
-				)
-			);
-			while ($row = $smcFunc['db_fetch_assoc']($request))
-				$smcFunc['db_query']('', '
-					UPDATE {db_prefix}boards
-					SET member_groups = {string:member_group_access}
-					WHERE id_board = {int:current_board}',
-					array(
-						'current_board' => $row['id_board'],
-						'member_group_access' => implode(',', array_diff(explode(',', $row['member_groups']), array($_REQUEST['group']))),
-					)
-				);
-			$smcFunc['db_free_result']($request);
-
-			// Add the membergroup to all boards that hadn't been set yet.
-			if (!empty($_POST['boardaccess']))
-				$smcFunc['db_query']('', '
-					UPDATE {db_prefix}boards
-					SET member_groups = CASE WHEN member_groups = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT(member_groups, {string:comma_group}) END
-					WHERE id_board IN ({array_int:board_list})
-						AND FIND_IN_SET({int:current_group}, member_groups) = 0',
+			$accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
+			$changed_boards['allow'] = array();
+			$changed_boards['deny'] = array();
+			$changed_boards['ignore'] = array();
+			foreach ($accesses as $group_id => $action)
+				$changed_boards[$action][] = (int) $group_id;
+
+			foreach (array('allow', 'deny') as $board_action)
+			{
+				// Find all board this group is in, but shouldn't be in.
+				$request = $smcFunc['db_query']('', '
+					SELECT id_board, {raw:column}
+					FROM {db_prefix}boards
+					WHERE FIND_IN_SET({string:current_group}, {raw:column}) != 0' . (empty($changed_boards[$board_action]) ? '' : '
+						AND id_board NOT IN ({array_int:board_access_list})'),
 					array(
-						'board_list' => $_POST['boardaccess'],
-						'blank_string' => '',
 						'current_group' => (int) $_REQUEST['group'],
-						'group_id_string' => (string) (int) $_REQUEST['group'],
-						'comma_group' => ',' . $_REQUEST['group'],
+						'board_access_list' => $changed_boards[$board_action],
+						'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
 					)
 				);
+				while ($row = $smcFunc['db_fetch_assoc']($request))
+					$smcFunc['db_query']('', '
+						UPDATE {db_prefix}boards
+						SET {raw:column} = {string:member_group_access}
+						WHERE id_board = {int:current_board}',
+						array(
+							'current_board' => $row['id_board'],
+							'member_group_access' => implode(',', array_diff(explode(',', $row['member_groups']), array($_REQUEST['group']))),
+							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
+						)
+					);
+				$smcFunc['db_free_result']($request);
+
+				// Add the membergroup to all boards that hadn't been set yet.
+				if (!empty($changed_boards[$board_action]))
+					$smcFunc['db_query']('', '
+						UPDATE {db_prefix}boards
+						SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
+						WHERE id_board IN ({array_int:board_list})
+							AND FIND_IN_SET({int:current_group}, {raw:column}) = 0',
+						array(
+							'board_list' => $changed_boards[$board_action],
+							'blank_string' => '',
+							'current_group' => (int) $_REQUEST['group'],
+							'group_id_string' => (string) (int) $_REQUEST['group'],
+							'comma_group' => ',' . $_REQUEST['group'],
+							'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
+						)
+					);
+			}
 		}
 
 		// Remove everyone from this group!
@@ -1032,7 +1056,8 @@ function EditMembergroup()
 	if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3)
 	{
 		$request = $smcFunc['db_query']('', '
-			SELECT b.id_cat, c.name as cat_name, b.id_board, b.name, b.child_level, FIND_IN_SET({string:current_group}, b.member_groups) != 0 AS can_access
+			SELECT b.id_cat, c.name as cat_name, b.id_board, b.name, b.child_level,
+			FIND_IN_SET({string:current_group}, b.member_groups) != 0 AS can_access, FIND_IN_SET({string:current_group}, b.deny_member_groups) != 0 AS cannot_access
 			FROM {db_prefix}boards AS b
 				LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
 			ORDER BY board_order',
@@ -1056,7 +1081,8 @@ function EditMembergroup()
 				'id' => $row['id_board'],
 				'name' => $row['name'],
 				'child_level' => $row['child_level'],
-				'selected' => !(empty($row['can_access']) || $row['can_access'] == 'f'),
+				'allow' => !(empty($row['can_access']) || $row['can_access'] == 'f'),
+				'deny' => !(empty($row['cannot_access']) || $row['cannot_access'] == 'f'),
 			);
 		}
 		$smcFunc['db_free_result']($request);

+ 85 - 67
Themes/default/ManageMembergroups.template.php

@@ -114,44 +114,17 @@ function template_new_group()
 							</fieldset>
 						</dd>';
 	}
+
 	echo '
 						<dt>
 							<strong>', $txt['membergroups_new_board'], ':</strong>', $context['post_group'] ? '<br />
 							<span class="smalltext" style="font-weight: normal">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
 						</dt>
-						<dd>
-							<fieldset id="visible_boards">
-								<legend>', $txt['membergroups_new_board_desc'], '</legend>
-								<ul class="ignoreboards floatleft">';
-
-	foreach ($context['categories'] as $category)
-	{
-		echo '
-									<li class="category">
-										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'new_group\'); return false;">', $category['name'], '</a>
-									<ul>';
-
-		foreach ($category['boards'] as $board)
-		{
-			echo '
-										<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
-											<input type="checkbox" name="boardaccess[]" id="brd', $board['id'], '" value="', $board['id'], '" ', $board['selected'] ? ' checked="checked" disabled="disabled"' : '', ' class="input_check" /> <label for="brd', $board['id'], '">', $board['name'], '</label>
-										</li>';
-		}
-
-		echo '
-									</ul>
-								</li>';
-	}
+						<dd>';
 
-	echo '
-							</ul>
-							<br class="clear" />';
+	template_add_edit_group_boards_list(false);
 
 	echo '
-								<br />
-								<input type="checkbox" id="checkall_check" class="input_check" onclick="invertAll(this, this.form, \'boardaccess\');" /> <label for="checkall_check"><em>', $txt['check_all'], '</em></label>
-							</fieldset>
 						</dd>
 					</dl>
 					<hr class="hrcolor" />
@@ -327,44 +300,9 @@ function template_edit_group()
 							<strong>', $txt['membergroups_new_board'], ':</strong>', $context['group']['is_post_group'] ? '<br />
 							<span class="smalltext">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
 						</dt>
-						<dd>
-							<fieldset id="visible_boards" style="width: 95%;">
-								<legend><a href="javascript:void(0);" onclick="document.getElementById(\'visible_boards\').style.display = \'none\';document.getElementById(\'visible_boards_link\').style.display = \'block\'; return false;">', $txt['membergroups_new_board_desc'], '</a></legend>
-								<ul class="ignoreboards floatleft">';
-
-		foreach ($context['categories'] as $category)
-		{
-			echo '
-									<li class="category">
-										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'groupForm\'); return false;">', $category['name'], '</a>
-										<ul>';
-
-			foreach ($category['boards'] as $board)
-			{
-				echo '
-											<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
-												<input type="checkbox" name="boardaccess[]" id="brd', $board['id'], '" value="', $board['id'], '" ', $board['selected'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="brd', $board['id'], '">', $board['name'], '</label>
-											</li>';
-			}
-
-			echo '
-										</ul>
-									</li>';
-		}
-
+						<dd>';
+		template_add_edit_group_boards_list();
 		echo '
-								</ul>
-								<br class="clear" />';
-
-		echo '
-								<br />
-								<input type="checkbox" id="checkall_check" class="input_check" onclick="invertAll(this, this.form, \'boardaccess\');" /> <label for="checkall_check"><em>', $txt['check_all'], '</em></label>
-							</fieldset>
-							<a href="javascript:void(0);" onclick="document.getElementById(\'visible_boards\').style.display = \'block\'; document.getElementById(\'visible_boards_link\').style.display = \'none\'; return false;" id="visible_boards_link" style="display: none;">[ ', $txt['membergroups_select_visible_boards'], ' ]</a>
-							<script type="text/javascript"><!-- // --><![CDATA[
-								document.getElementById("visible_boards_link").style.display = "";
-								document.getElementById("visible_boards").style.display = "none";
-							// ]]></script>
 						</dd>';
 	}
 	echo '
@@ -431,6 +369,86 @@ function template_edit_group()
 		// ]]></script>';
 }
 
+function template_add_edit_group_boards_list($collapse = true)
+{
+	global $context, $txt, $modSettings;
+	echo '
+							<fieldset id="visible_boards">
+								<legend>', $txt['membergroups_new_board_desc'], '</legend>
+								<ul class="ignoreboards floatleft">';
+
+	foreach ($context['categories'] as $category)
+	{
+		if (empty($modSettings['deny_boards_access']))
+			echo '
+									<li class="category">
+										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), '], \'new_group\'); return false;"><strong>', $category['name'], '</strong></a>
+									<ul style="width:100%">';
+		else
+			echo '
+									<li class="category">
+										<strong>', $category['name'], '</strong>
+										<em style="margin-left:5em;">', $txt['all_boards_in_cat'], ': </em>
+										<select onchange="select_in_category(', $category['id'], ', this, [', implode(',', array_keys($category['boards'])), ']);">
+											<option>---</option>
+											<option value="allow">', $txt['board_perms_allow'], '</option>
+											<option value="ignore">', $txt['board_perms_ignore'], '</option>
+											<option value="deny">', $txt['board_perms_deny'], '</option>
+										</select>
+									</td>
+									<ul style="width:100%" id="boards_list_', $category['id'], '">';
+
+		foreach ($category['boards'] as $board)
+		{
+			if (empty($modSettings['deny_boards_access']))
+				echo '
+										<li class="board" style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">
+											<input type="checkbox" name="boardaccess[', $board['id'], ']" id="brd', $board['id'], '" value="\'allow\'" ', $board['allow'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="brd', $board['id'], '">', $board['name'], '</label>
+										</li>';
+			else
+				echo '
+										<li class="board" style="width:100%">
+											<span style="margin-', $context['right_to_left'] ? 'right' : 'left', ': ', $board['child_level'], 'em;">', $board['name'], ': </span>
+											<span style="width:50%;float:right">
+												<input type="radio" name="boardaccess[', $board['id'], ']" id="allow_brd', $board['id'], '" value="allow" ', $board['allow'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="allow_brd', $board['id'], '">', $txt['permissions_option_on'], '</label>
+												<input type="radio" name="boardaccess[', $board['id'], ']" id="ignore_brd', $board['id'], '" value="ignore" ', !$board['allow'] && !$board['deny'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="ignore_brd', $board['id'], '">', $txt['permissions_option_off'], '</label>
+												<input type="radio" name="boardaccess[', $board['id'], ']" id="deny_brd', $board['id'], '" value="deny" ', $board['deny'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="deny_brd', $board['id'], '">', $txt['permissions_option_deny'], '</label>
+											</span>
+										</li>';
+		}
+
+		echo '
+									</ul>
+								</li>';
+	}
+
+	echo '
+							</ul>
+							<br class="clear" />';
+
+	if (empty($modSettings['deny_boards_access']))
+		echo '
+								<br />
+								<input type="checkbox" id="checkall_check" class="input_check" onclick="invertAll(this, this.form, \'boardaccess\');" /> <label for="checkall_check"><em>', $txt['check_all'], '</em></label>
+							</fieldset>';
+	else
+		echo '
+								<br />
+								<em>', $txt['all'], ': </em>
+								<input type="radio" name="select_all" id="allow_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'allow\');" /> <label for="allow_all">', $txt['board_perms_allow'], '</label>
+								<input type="radio" name="select_all" id="ignore_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'ignore\');" /> <label for="ignore_all">', $txt['board_perms_ignore'], '</label>
+								<input type="radio" name="select_all" id="deny_all" class="input_radio" onclick="selectAllRadio(this, this.form, \'boardaccess\', \'deny\');" /> <label for="deny_all">', $txt['board_perms_deny'], '</label>
+							</fieldset>';
+
+	if ($collapse)
+		echo '
+							<a href="javascript:void(0);" onclick="document.getElementById(\'visible_boards\').style.display = \'block\'; document.getElementById(\'visible_boards_link\').style.display = \'none\'; return false;" id="visible_boards_link" style="display: none;">[ ', $txt['membergroups_select_visible_boards'], ' ]</a>
+							<script type="text/javascript"><!-- // --><![CDATA[
+								document.getElementById("visible_boards_link").style.display = "";
+								document.getElementById("visible_boards").style.display = "none";
+							// ]]></script>';
+}
+
 // Templating for viewing the members of a group.
 function template_group_members()
 {

+ 1 - 1
Themes/default/css/index.css

@@ -2770,7 +2770,7 @@ img.centericon {
 .ignoreboards {
 	margin: 0 2%;
 	padding: 0;
-	width: 45%;
+	width: 90%;
 }
 .ignoreboards a {
 	font-weight: bold;

+ 1 - 1
Themes/default/index.template.php

@@ -636,4 +636,4 @@ function template_css()
 	<link rel="stylesheet" type="text/css" href="', $filename, '" />';
 }
 
-?>
+?>

+ 5 - 0
Themes/default/languages/Admin.english.php

@@ -659,4 +659,9 @@ $txt['hooks_disable_legend_disabled'] = 'the hook exists but has been disabled';
 $txt['hooks_disable_legend_missing'] = 'the hook has not been found';
 $txt['hooks_reset_filter'] = 'Reset filter';
 
+$txt['board_perms_allow'] = 'Allow';
+$txt['board_perms_ignore'] = 'Ignore';
+$txt['board_perms_deny'] = 'Deny';
+$txt['all_boards_in_cat'] = 'All boards in this category';
+
 ?>

+ 0 - 2
Themes/default/languages/Reports.english.php

@@ -21,8 +21,6 @@ $txt['results'] = 'Results';
 
 // Board permissions
 $txt['board_perms_permission'] = 'Permission';
-$txt['board_perms_allow'] = 'Allow';
-$txt['board_perms_deny'] = 'Deny';
 $txt['board_perms_name_announce_topic'] = 'Announce topic';
 $txt['board_perms_name_approve_posts'] = 'Approve posts';
 $txt['board_perms_name_delete_any'] = 'Delete any posts';

+ 8 - 0
Themes/default/scripts/admin.js

@@ -599,4 +599,12 @@ function repeatString(sString, iTime)
 		return '';
 	else
 		return sString + repeatString(sString, iTime - 1);
+}
+
+function select_in_category(cat_id, elem, brd_list)
+{
+	for (var brd in brd_list)
+	{
+		document.getElementById(elem.value + '_brd' + brd_list[brd]).checked = true;
+	}
 }

+ 1 - 1
Themes/default/scripts/script.js

@@ -533,7 +533,7 @@ function selectRadioByName(oRadioGroup, sName)
 function selectAllRadio(oInvertCheckbox, oForm, sMask, sValue)
 {
 	for (var i = 0; i < oForm.length; i++)
-		if (oForm[i].name.substr(0, sMask.length) == sMask && oForm[i].value == sValue)
+		if (oForm[i].name != undefined && oForm[i].name.substr(0, sMask.length) == sMask && oForm[i].value == sValue)
 			oForm[i].checked = true;
 }
 

+ 1 - 1
Themes/penguin/css/index.css

@@ -2671,7 +2671,7 @@ img.centericon {
 .ignoreboards {
 	margin: 0 2%;
 	padding: 0;
-	width: 45%;
+	width: 90%;
 }
 .ignoreboards a {
 	font-weight: bold;