Browse Source

Added categories in membergroups management pages [mod 3120] + removed duplicate js function selectBoards (defined in script.js) from Profile.template.php

emanuele 13 năm trước cách đây
mục cha
commit
c8fcacd9b0

+ 1 - 1
Sources/Display.php

@@ -1232,7 +1232,7 @@ function Download()
 		isAllowedTo('view_attachments');
 
 		// Make sure this attachment is on this board.
-		// NOTE: We must verify that $topic is the attachment's topic, or else the permission check above is broken.
+		// @todo: We must verify that $topic is the attachment's topic, or else the permission check above is broken.
 		$request = $smcFunc['db_query']('', '
 			SELECT a.id_folder, a.filename, a.file_hash, a.fileext, a.id_attach, a.attachment_type, a.mime_type, a.approved, m.id_member
 			FROM {db_prefix}attachments AS a

+ 74 - 14
Sources/ManageMembergroups.php

@@ -562,22 +562,51 @@ function AddMembergroup()
 		);
 	$smcFunc['db_free_result']($result);
 
-	$result = $smcFunc['db_query']('', '
-		SELECT id_board, name, child_level
-		FROM {db_prefix}boards
+	$request = $smcFunc['db_query']('', '
+		SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level
+		FROM {db_prefix}boards AS b
+			LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
 		ORDER BY board_order',
 		array(
 		)
 	);
-	$context['boards'] = array();
-	while ($row = $smcFunc['db_fetch_assoc']($result))
-		$context['boards'][] = array(
+	$context['num_boards'] = $smcFunc['db_num_rows']($request);
+
+	$context['categories'] = array();
+	while ($row = $smcFunc['db_fetch_assoc']($request))
+	{
+		// This category hasn't been set up yet..
+		if (!isset($context['categories'][$row['id_cat']]))
+			$context['categories'][$row['id_cat']] = array(
+				'id' => $row['id_cat'],
+				'name' => $row['cat_name'],
+				'boards' => array()
+			);
+
+		// Set this board up, and let the template know when it's a child.  (indent them..)
+		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
 			'id' => $row['id_board'],
 			'name' => $row['name'],
 			'child_level' => $row['child_level'],
 			'selected' => false
 		);
-	$smcFunc['db_free_result']($result);
+
+	}
+	$smcFunc['db_free_result']($request);
+
+	// Now, let's sort the list of categories into the boards for templates that like that.
+	$temp_boards = array();
+	foreach ($context['categories'] as $category)
+	{
+		$temp_boards[] = array(
+			'name' => $category['name'],
+			'child_ids' => array_keys($category['boards'])
+		);
+		$temp_boards = array_merge($temp_boards, array_values($category['boards']));
+
+		// Include a list of boards per category for easy toggling.
+		$context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
+	}
 
 	createToken('admin-mmg');
 }
@@ -1004,22 +1033,53 @@ function EditMembergroup()
 	$context['boards'] = array();
 	if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3)
 	{
-		$result = $smcFunc['db_query']('', '
-			SELECT id_board, name, child_level, FIND_IN_SET({string:current_group}, member_groups) != 0 AS can_access
-			FROM {db_prefix}boards
+		$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
+			FROM {db_prefix}boards AS b
+				LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
 			ORDER BY board_order',
 			array(
 				'current_group' => (int) $_REQUEST['group'],
 			)
 		);
-		while ($row = $smcFunc['db_fetch_assoc']($result))
-			$context['boards'][] = array(
+		$context['categories'] = array();
+		while ($row = $smcFunc['db_fetch_assoc']($request))
+		{
+			// This category hasn't been set up yet..
+			if (!isset($context['categories'][$row['id_cat']]))
+				$context['categories'][$row['id_cat']] = array(
+					'id' => $row['id_cat'],
+					'name' => $row['cat_name'],
+					'boards' => array()
+				);
+
+			// Set this board up, and let the template know when it's a child.  (indent them..)
+			$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
 				'id' => $row['id_board'],
 				'name' => $row['name'],
 				'child_level' => $row['child_level'],
-				'selected' => !(empty($row['can_access']) || $row['can_access'] == 'f'),
+				'selected' => !empty($row['can_access']),
 			);
-		$smcFunc['db_free_result']($result);
+		}
+		$smcFunc['db_free_result']($request);
+
+		// Now, let's sort the list of categories into the boards for templates that like that.
+		$temp_boards = array();
+		foreach ($context['categories'] as $category)
+		{
+			$temp_boards[] = array(
+				'name' => $category['name'],
+				'child_ids' => array_keys($category['boards'])
+			);
+			$temp_boards = array_merge($temp_boards, array_values($category['boards']));
+
+			// Include a list of boards per category for easy toggling.
+			$context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
+		}
+
+		$max_boards = ceil(count($temp_boards) / 2);
+		if ($max_boards == 1)
+			$max_boards = 2;
 	}
 
 	// Finally, get all the groups this could be inherited off.

+ 2 - 2
Sources/ManageSmileys.php

@@ -439,7 +439,7 @@ function EditSmileySets()
 		'additional_rows' => array(
 			array(
 				'position' => 'below_table_data',
-				'value' => '<input type="submit" name="delete" value="' . $txt['smiley_sets_delete'] . '" onclick="return confirm(\'' . $txt['smiley_sets_confirm'] . '\');" style="float: right;" class="button_submit" /> [<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifyset' . '">' . $txt['smiley_sets_add'] . '</a>]',
+				'value' => '[<a href="' . $scripturl . '?action=admin;area=smileys;sa=modifyset' . '">' . $txt['smiley_sets_add'] . '</a>] <input type="submit" name="delete" value="' . $txt['smiley_sets_delete'] . '" onclick="return confirm(\'' . $txt['smiley_sets_confirm'] . '\');" class="button_submit" />',
 			),
 		),
 	);
@@ -1731,7 +1731,7 @@ function EditMessageIcons()
 		'additional_rows' => array(
 			array(
 				'position' => 'below_table_data',
-				'value' => '<input type="submit" name="delete" value="' . $txt['quickmod_delete_selected'] . '" style="float: right" class="button_submit" />[<a href="' . $scripturl . '?action=admin;area=smileys;sa=editicon">' . $txt['icons_add_new'] . '</a>]',
+				'value' => '[<a href="' . $scripturl . '?action=admin;area=smileys;sa=editicon">' . $txt['icons_add_new'] . '</a>] <input type="submit" name="delete" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit" />',
 			),
 		),
 	);

+ 51 - 7
Themes/default/ManageMembergroups.template.php

@@ -121,10 +121,32 @@ function template_new_group()
 						</dt>
 						<dd>
 							<fieldset id="visible_boards">
-								<legend>', $txt['membergroups_new_board_desc'], '</legend>';
-	foreach ($context['boards'] as $board)
+								<legend>', $txt['membergroups_new_board_desc'], '</legend>
+								<ul class="ignoreboards floatleft">';
+
+	foreach ($context['categories'] as $category)
+	{
 		echo '
-								<div style="margin-left: ', $board['child_level'], 'em;"><input type="checkbox" name="boardaccess[]" id="boardaccess_', $board['id'], '" value="', $board['id'], '" ', $board['selected'] ? ' checked="checked" disabled="disabled"' : '', ' class="input_check" /> <label for="boardaccess_', $board['id'], '">', $board['name'], '</label></div>';
+									<li class="category">
+										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), ']); 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>';
+	}
+
+	echo '
+							</ul>
+							<br class="clear" />';
 
 	echo '
 								<br />
@@ -298,7 +320,7 @@ function template_edit_group()
 						<dd>
 							<input type="text" name="max_messages" id="max_messages_input" value="', $context['group']['id'] == 1 ? 0 : $context['group']['max_messages'], '" size="6"', $context['group']['id'] == 1 ? ' disabled="disabled"' : '', ' class="input_text" />
 						</dd>';
-	if (!empty($context['boards']))
+	if (!empty($context['categories']))
 	{
 		echo '
 						<dt>
@@ -307,10 +329,32 @@ function template_edit_group()
 						</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>';
-		foreach ($context['boards'] as $board)
+								<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 '
-								<div style="margin-left: ', $board['child_level'], 'em;"><input type="checkbox" name="boardaccess[]" id="boardaccess_', $board['id'], '" value="', $board['id'], '" ', $board['selected'] ? ' checked="checked"' : '', ' class="input_check" /> <label for="boardaccess_', $board['id'], '">', $board['name'], '</label></div>';
+									<li class="category">
+										<a href="javascript:void(0);" onclick="selectBoards([', implode(', ', $category['child_ids']), ']); 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>';
+		}
+
+		echo '
+								</ul>
+								<br class="clear" />';
 
 		echo '
 								<br />

+ 0 - 13
Themes/default/Profile.template.php

@@ -1856,19 +1856,6 @@ function template_ignoreboards()
 	global $context, $txt, $settings, $scripturl;
 	// The main containing header.
 	echo '
-	<script type="text/javascript"><!-- // --><![CDATA[
-		function selectBoards(ids)
-		{
-			var toggle = true;
-
-			for (i = 0; i < ids.length; i++)
-				toggle = toggle & document.forms.creator["ignore_brd" + ids[i]].checked;
-
-			for (i = 0; i < ids.length; i++)
-				document.forms.creator["ignore_brd" + ids[i]].checked = !toggle;
-		}
-	// ]]></script>
-
 	<form action="', $scripturl, '?action=profile;area=ignoreboards;save" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator">
 		<div class="cat_bar">
 			<h3 class="catbg">