<commit_before><?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines
 * @copyright 2013 Simple Machines and individual contributors
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 Alpha 1
 */

function template_main()
{
	global $context, $settings, $options, $scripturl, $txt;

	template_show_list('regular_membergroups_list');
	echo '<br /><br />';
	template_show_list('post_count_membergroups_list');

}

function template_new_group()
{
	global $context, $settings, $options, $scripturl, $txt, $modSettings;

	echo '
	<div id="admincenter">
		<form id="new_group" action="', $scripturl, '?action=admin;area=membergroups;sa=add" method="post" accept-charset="', $context['character_set'], '">
			<div class="cat_bar">
				<h3 class="catbg">', $txt['membergroups_new_group'], '</h3>
			</div>
			<div class="windowbg">
				<div class="content">
					<dl class="settings">
						<dt>
							<label for="group_name_input"><strong>', $txt['membergroups_group_name'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="group_name" id="group_name_input" size="30" class="input_text" />
						</dd>';
	if ($context['undefined_group'])
	{
		echo '
						<dt>
							<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], '</strong>:</label>
						</dt>
						<dd>
							<fieldset id="group_type">
								<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
								<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" checked="checked" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_private'], '</label><br />';

		if ($context['allow_protected'])
			echo '
								<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_protected'], '</label><br />';

		echo '
								<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_request'], '</label><br />
								<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_free'], '</label><br />
								<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" class="input_radio" onclick="swapPostGroup(1);" />', $txt['membergroups_group_type_post'], '</label><br />
							</fieldset>
						</dd>';
	}

	if ($context['post_group'] || $context['undefined_group'])
		echo '
						<dt id="min_posts_text">
							<strong>', $txt['membergroups_min_posts'], ':</strong>
						</dt>
						<dd>
							<input type="text" name="min_posts" id="min_posts_input" size="5" class="input_text" />
						</dd>';
	if (!$context['post_group'] || !empty($modSettings['permission_enable_postgroups']))
	{
		echo '
						<dt>
							<label for="permission_base"><strong>', $txt['membergroups_permissions'], ':</strong></label><br />
							<span class="smalltext">', $txt['membergroups_can_edit_later'], '</span>
						</dt>
						<dd>
							<fieldset id="permission_base">
								<legend>', $txt['membergroups_select_permission_type'], '</legend>
								<input type="radio" name="perm_type" id="perm_type_inherit" value="inherit" checked="checked" class="input_radio" />
								<label for="perm_type_inherit">', $txt['membergroups_new_as_inherit'], ':</label>
								<select name="inheritperm" id="inheritperm_select" onclick="document.getElementById(\'perm_type_inherit\').checked = true;">
									<option value="-1">', $txt['membergroups_guests'], '</option>
									<option value="0" selected="selected">', $txt['membergroups_members'], '</option>';
		foreach ($context['groups'] as $group)
			echo '
									<option value="', $group['id'], '">', $group['name'], '</option>';
		echo '
								</select>
								<br />
								<input type="radio" name="perm_type" id="perm_type_copy" value="copy" class="input_radio" />
								<label for="perm_type_copy">', $txt['membergroups_new_as_copy'], ':</label>
								<select name="copyperm" id="copyperm_select" onclick="document.getElementById(\'perm_type_copy\').checked = true;">
									<option value="-1">', $txt['membergroups_guests'], '</option>
									<option value="0" selected="selected">', $txt['membergroups_members'], '</option>';
		foreach ($context['groups'] as $group)
			echo '
									<option value="', $group['id'], '">', $group['name'], '</option>';
		echo '
								</select>
								<br />
								<input type="radio" name="perm_type" id="perm_type_predefined" value="predefined" class="input_radio" />
								<label for="perm_type_predefined">', $txt['membergroups_new_as_type'], ':</label>
								<select name="level" id="level_select" onclick="document.getElementById(\'perm_type_predefined\').checked = true;">
									<option value="restrict">', $txt['permitgroups_restrict'], '</option>
									<option value="standard" selected="selected">', $txt['permitgroups_standard'], '</option>
									<option value="moderator">', $txt['permitgroups_moderator'], '</option>
									<option value="maintenance">', $txt['permitgroups_maintenance'], '</option>
								</select>
							</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>';

	template_add_edit_group_boards_list(false);

	echo '
						</dd>
					</dl>
					<input type="submit" value="', $txt['membergroups_add_group'], '" class="button_submit" />
				</div>
			</div>';
	if ($context['undefined_group'])
	{
		echo '
			<script type="text/javascript"><!-- // --><![CDATA[
				function swapPostGroup(isChecked)
				{
					var min_posts_text = document.getElementById(\'min_posts_text\');
					document.getElementById(\'min_posts_input\').disabled = !isChecked;
					min_posts_text.style.color = isChecked ? "" : "#888888";
				}
				swapPostGroup(', $context['post_group'] ? 'true' : 'false', ');
			// ]]></script>';
	}
	echo '
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '" />
		</form>
	</div>';
}

function template_edit_group()
{
	global $context, $settings, $options, $scripturl, $txt;

	echo '
	<div id="admincenter">
		<form action="', $scripturl, '?action=admin;area=membergroups;sa=edit;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '" name="groupForm" id="groupForm">
			<div class="cat_bar">
				<h3 class="catbg">', $txt['membergroups_edit_group'], ' - ', $context['group']['name'], '
				</h3>
			</div>
			<div class="windowbg2">
				<div class="content">
					<dl class="settings">
						<dt>
							<label for="group_name_input"><strong>', $txt['membergroups_edit_name'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="group_name" id="group_name_input" value="', $context['group']['editable_name'], '" size="30" class="input_text" />
						</dd>';

	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
		echo '

						<dt id="group_desc_text">
							<label for="group_desc_input"><strong>', $txt['membergroups_edit_desc'], ':</strong></label>
						</dt>
						<dd>
							<textarea name="group_desc" id="group_desc_input" rows="4" cols="40">', $context['group']['description'], '</textarea>
						</dd>';

	// Group type...
	if ($context['group']['allow_post_group'])
	{
		echo '
						<dt>
							<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], ':</strong></label>
						</dt>
						<dd>
							<fieldset id="group_type">
								<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
								<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" ', !$context['group']['is_post_group'] && $context['group']['type'] == 0 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_private'], '</label><br />';

		if ($context['group']['allow_protected'])
			echo '
								<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" ', $context['group']['type'] == 1 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_protected'], '</label><br />';

		echo '
								<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" ', $context['group']['type'] == 2 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_request'], '</label><br />
								<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" ', $context['group']['type'] == 3 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_free'], '</label><br />
								<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" ', $context['group']['is_post_group'] ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(1);" />', $txt['membergroups_group_type_post'], '</label><br />
							</fieldset>
						</dd>';
	}

	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
		echo '
						<dt id="group_moderators_text">
							<label for="group_moderators"><strong>', $txt['moderators'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="group_moderators" id="group_moderators" value="', $context['group']['moderator_list'], '" size="30" class="input_text" />
							<div id="moderator_container"></div>
						</dd>
						<dt id="group_hidden_text">
							<label for="group_hidden_input"><strong>', $txt['membergroups_edit_hidden'], ':</strong></label>
						</dt>
						<dd>
							<select name="group_hidden" id="group_hidden_input" onchange="if (this.value == 2 &amp;&amp; !confirm(\'', $txt['membergroups_edit_hidden_warning'], '\')) this.value = 0;">
								<option value="0" ', $context['group']['hidden'] ? '' : 'selected="selected"', '>', $txt['membergroups_edit_hidden_no'], '</option>
								<option value="1" ', $context['group']['hidden'] == 1 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_hidden_boardindex'], '</option>
								<option value="2" ', $context['group']['hidden'] == 2 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_hidden_all'], '</option>
							</select>
						</dd>';

	// Can they inherit permissions?
	if ($context['group']['id'] > 1 && $context['group']['id'] != 3)
	{
		echo '
						<dt id="group_inherit_text">
							<label for="group_inherit_input"><strong>', $txt['membergroups_edit_inherit_permissions'], '</strong></label>:<br />
							<span class="smalltext">', $txt['membergroups_edit_inherit_permissions_desc'], '</span>
						</dt>
						<dd>
							<select name="group_inherit" id="group_inherit_input">
								<option value="-2">', $txt['membergroups_edit_inherit_permissions_no'], '</option>
								<option value="-1" ', $context['group']['inherited_from'] == -1 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_guests'], '</option>
								<option value="0" ', $context['group']['inherited_from'] == 0 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_members'], '</option>';

		// For all the inheritable groups show an option.
		foreach ($context['inheritable_groups'] as $id => $group)
			echo '
								<option value="', $id, '" ', $context['group']['inherited_from'] == $id ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $group, '</option>';

		echo '
							</select>
							<input type="hidden" name="old_inherit" value="', $context['group']['inherited_from'], '" />
						</dd>';
	}

	if ($context['group']['allow_post_group'])
		echo '

						<dt id="min_posts_text">
							<label for="min_posts_input"><strong>', $txt['membergroups_min_posts'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="min_posts" id="min_posts_input"', $context['group']['is_post_group'] ? ' value="' . $context['group']['min_posts'] . '"' : '', ' size="6" class="input_text" />
						</dd>';
	echo '
						<dt>
							<label for="online_color_input"><strong>', $txt['membergroups_online_color'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="online_color" id="online_color_input" value="', $context['group']['color'], '" size="20" class="input_text" />
						</dd>
						<dt>
							<label for="icon_count_input"><strong>', $txt['membergroups_icon_count'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4" class="input_text" />
						</dd>';
        
        // Do we have any possible icons to select from?
       	if (!empty($context['possible_icons']))
       	{
       		echo '
						<dt>
							<label for="icon_image_input"><strong>', $txt['membergroups_icon_image'], ':</strong></label><br />
							<span class="smalltext">', $txt['membergroups_icon_image_note'], '</span>
						</dt>
						<dd>
							', $txt['membergroups_images_url'], '
							<select name="icon_image" id="icon_image_input">';

		// For every possible icon, create an option.
		foreach ($context['possible_icons'] as $icon)
		{
			echo '
								<option value="', $icon, '"', $context['group']['icon_image'] == $icon ? ' selected="selected"' : '', '>', $icon, '</option>';
		}
	
		echo '
							</select>
							<img id="icon_preview" src="" alt="*" />
						</dd>';
	}
	
	// No? Hide the entire control.
	else
		echo '
						<input type="hidden" name="icon_image" value="" />';
						
	echo '
						<dt>
							<label for="max_messages_input"><strong>', $txt['membergroups_max_messages'], ':</strong></label><br />
							<span class="smalltext">', $txt['membergroups_max_messages_note'], '</span>
						</dt>
						<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['categories']))
	{
		echo '
						<dt>
							<strong>', $txt['membergroups_new_board'], ':</strong>', $context['group']['is_post_group'] ? '<br />
							<span class="smalltext">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
						</dt>
						<dd>';
		template_add_edit_group_boards_list();
		echo '
						</dd>';
	}
	echo '
					</dl>
					<input type="submit" name="save" value="', $txt['membergroups_edit_save'], '" class="button_submit" />', $context['group']['allow_delete'] ? '
					<input type="submit" name="delete" value="' . $txt['membergroups_delete'] . '" onclick="return confirm(\'' . ($context['is_moderator_group'] ? $txt['membergroups_confirm_delete_mod'] : $txt['membergroups_confirm_delete']) . '\');" class="button_submit" />' : '', '
				</div>
			</div>
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '" />
		</form>
	</div>
		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
		<script type="text/javascript"><!-- // --><![CDATA[
			var oModeratorSuggest = new smc_AutoSuggest({
				sSelf: \'oModeratorSuggest\',
				sSessionId: smf_session_id,
				sSessionVar: smf_session_var,
				sSuggestId: \'group_moderators\',
				sControlId: \'group_moderators\',
				sSearchType: \'member\',
				bItemList: true,
				sPostName: \'moderator_list\',
				sURLMask: \'action=profile;u=%item_id%\',
				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
				sItemListContainerId: \'moderator_container\',
				aListItems: [';

			foreach ($context['group']['moderators'] as $id_member => $member_name)
				echo '
							{
								sItemId: ', JavaScriptEscape($id_member), ',
								sItemName: ', JavaScriptEscape($member_name), '
							}', $id_member == $context['group']['last_moderator_id'] ? '' : ',';

			echo '
				]
			});
		// ]]></script>';

	if ($context['group']['allow_post_group'])
		echo '
		<script type="text/javascript"><!-- // --><![CDATA[
			function swapPostGroup(isChecked)
			{
				var is_moderator_group = ', $context['is_moderator_group'], ';
				var group_type = ', $context['group']['type'], ';
				var min_posts_text = document.getElementById(\'min_posts_text\');
				var group_desc_text = document.getElementById(\'group_desc_text\');
				var group_hidden_text = document.getElementById(\'group_hidden_text\');
				var group_moderators_text = document.getElementById(\'group_moderators_text\');
				
				// If it\'s a moderator group, warn of possible problems... and remember the group type
				if (isChecked && is_moderator_group && !confirm(\'', $txt['membergroups_swap_mod'], '\'))
				{
					isChecked = false;

					switch(group_type)
					{
						case 0:
							document.getElementById(\'group_type_private\').checked = true;
							break;
						case 1:
							document.getElementById(\'group_type_protected\').checked = true;
							break;
						case 2:
							document.getElementById(\'group_type_request\').checked = true;
							break;
						case 3:
							document.getElementById(\'group_type_free\').checked = true;
							break;
						default:
							document.getElementById(\'group_type_private\').checked = true;
							break;
					}
				}
				
				document.forms.groupForm.min_posts.disabled = !isChecked;
				min_posts_text.style.color = isChecked ? "" : "#888888";
				document.forms.groupForm.group_desc_input.disabled = isChecked;
				group_desc_text.style.color = !isChecked ? "" : "#888888";
				document.forms.groupForm.group_hidden_input.disabled = isChecked;
				group_hidden_text.style.color = !isChecked ? "" : "#888888";
				document.forms.groupForm.group_moderators.disabled = isChecked;
				group_moderators_text.style.color = !isChecked ? "" : "#888888";
			}';
			
			echo '				
			swapPostGroup(', $context['group']['is_post_group'] ? 'true' : 'false', ');
		// ]]></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<commit_msg>I should learn to clean up after myself...<commit_after><?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines
 * @copyright 2013 Simple Machines and individual contributors
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 Alpha 1
 */

function template_main()
{
	global $context, $settings, $options, $scripturl, $txt;

	template_show_list('regular_membergroups_list');
	echo '<br /><br />';
	template_show_list('post_count_membergroups_list');

}

function template_new_group()
{
	global $context, $settings, $options, $scripturl, $txt, $modSettings;

	echo '
	<div id="admincenter">
		<form id="new_group" action="', $scripturl, '?action=admin;area=membergroups;sa=add" method="post" accept-charset="', $context['character_set'], '">
			<div class="cat_bar">
				<h3 class="catbg">', $txt['membergroups_new_group'], '</h3>
			</div>
			<div class="windowbg">
				<div class="content">
					<dl class="settings">
						<dt>
							<label for="group_name_input"><strong>', $txt['membergroups_group_name'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="group_name" id="group_name_input" size="30" class="input_text" />
						</dd>';
	if ($context['undefined_group'])
	{
		echo '
						<dt>
							<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], '</strong>:</label>
						</dt>
						<dd>
							<fieldset id="group_type">
								<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
								<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" checked="checked" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_private'], '</label><br />';

		if ($context['allow_protected'])
			echo '
								<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_protected'], '</label><br />';

		echo '
								<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_request'], '</label><br />
								<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_free'], '</label><br />
								<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" class="input_radio" onclick="swapPostGroup(1);" />', $txt['membergroups_group_type_post'], '</label><br />
							</fieldset>
						</dd>';
	}

	if ($context['post_group'] || $context['undefined_group'])
		echo '
						<dt id="min_posts_text">
							<strong>', $txt['membergroups_min_posts'], ':</strong>
						</dt>
						<dd>
							<input type="text" name="min_posts" id="min_posts_input" size="5" class="input_text" />
						</dd>';
	if (!$context['post_group'] || !empty($modSettings['permission_enable_postgroups']))
	{
		echo '
						<dt>
							<label for="permission_base"><strong>', $txt['membergroups_permissions'], ':</strong></label><br />
							<span class="smalltext">', $txt['membergroups_can_edit_later'], '</span>
						</dt>
						<dd>
							<fieldset id="permission_base">
								<legend>', $txt['membergroups_select_permission_type'], '</legend>
								<input type="radio" name="perm_type" id="perm_type_inherit" value="inherit" checked="checked" class="input_radio" />
								<label for="perm_type_inherit">', $txt['membergroups_new_as_inherit'], ':</label>
								<select name="inheritperm" id="inheritperm_select" onclick="document.getElementById(\'perm_type_inherit\').checked = true;">
									<option value="-1">', $txt['membergroups_guests'], '</option>
									<option value="0" selected="selected">', $txt['membergroups_members'], '</option>';
		foreach ($context['groups'] as $group)
			echo '
									<option value="', $group['id'], '">', $group['name'], '</option>';
		echo '
								</select>
								<br />
								<input type="radio" name="perm_type" id="perm_type_copy" value="copy" class="input_radio" />
								<label for="perm_type_copy">', $txt['membergroups_new_as_copy'], ':</label>
								<select name="copyperm" id="copyperm_select" onclick="document.getElementById(\'perm_type_copy\').checked = true;">
									<option value="-1">', $txt['membergroups_guests'], '</option>
									<option value="0" selected="selected">', $txt['membergroups_members'], '</option>';
		foreach ($context['groups'] as $group)
			echo '
									<option value="', $group['id'], '">', $group['name'], '</option>';
		echo '
								</select>
								<br />
								<input type="radio" name="perm_type" id="perm_type_predefined" value="predefined" class="input_radio" />
								<label for="perm_type_predefined">', $txt['membergroups_new_as_type'], ':</label>
								<select name="level" id="level_select" onclick="document.getElementById(\'perm_type_predefined\').checked = true;">
									<option value="restrict">', $txt['permitgroups_restrict'], '</option>
									<option value="standard" selected="selected">', $txt['permitgroups_standard'], '</option>
									<option value="moderator">', $txt['permitgroups_moderator'], '</option>
									<option value="maintenance">', $txt['permitgroups_maintenance'], '</option>
								</select>
							</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>';

	template_add_edit_group_boards_list(false);

	echo '
						</dd>
					</dl>
					<input type="submit" value="', $txt['membergroups_add_group'], '" class="button_submit" />
				</div>
			</div>';
	if ($context['undefined_group'])
	{
		echo '
			<script type="text/javascript"><!-- // --><![CDATA[
				function swapPostGroup(isChecked)
				{
					var min_posts_text = document.getElementById(\'min_posts_text\');
					document.getElementById(\'min_posts_input\').disabled = !isChecked;
					min_posts_text.style.color = isChecked ? "" : "#888888";
				}
				swapPostGroup(', $context['post_group'] ? 'true' : 'false', ');
			// ]]></script>';
	}
	echo '
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '" />
		</form>
	</div>';
}

function template_edit_group()
{
	global $context, $settings, $options, $scripturl, $txt;

	echo '
	<div id="admincenter">
		<form action="', $scripturl, '?action=admin;area=membergroups;sa=edit;group=', $context['group']['id'], '" method="post" accept-charset="', $context['character_set'], '" name="groupForm" id="groupForm">
			<div class="cat_bar">
				<h3 class="catbg">', $txt['membergroups_edit_group'], ' - ', $context['group']['name'], '
				</h3>
			</div>
			<div class="windowbg2">
				<div class="content">
					<dl class="settings">
						<dt>
							<label for="group_name_input"><strong>', $txt['membergroups_edit_name'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="group_name" id="group_name_input" value="', $context['group']['editable_name'], '" size="30" class="input_text" />
						</dd>';

	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
		echo '

						<dt id="group_desc_text">
							<label for="group_desc_input"><strong>', $txt['membergroups_edit_desc'], ':</strong></label>
						</dt>
						<dd>
							<textarea name="group_desc" id="group_desc_input" rows="4" cols="40">', $context['group']['description'], '</textarea>
						</dd>';

	// Group type...
	if ($context['group']['allow_post_group'])
	{
		echo '
						<dt>
							<label for="group_type"><strong>', $txt['membergroups_edit_group_type'], ':</strong></label>
						</dt>
						<dd>
							<fieldset id="group_type">
								<legend>', $txt['membergroups_edit_select_group_type'], '</legend>
								<label for="group_type_private"><input type="radio" name="group_type" id="group_type_private" value="0" ', !$context['group']['is_post_group'] && $context['group']['type'] == 0 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_private'], '</label><br />';

		if ($context['group']['allow_protected'])
			echo '
								<label for="group_type_protected"><input type="radio" name="group_type" id="group_type_protected" value="1" ', $context['group']['type'] == 1 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_protected'], '</label><br />';

		echo '
								<label for="group_type_request"><input type="radio" name="group_type" id="group_type_request" value="2" ', $context['group']['type'] == 2 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_request'], '</label><br />
								<label for="group_type_free"><input type="radio" name="group_type" id="group_type_free" value="3" ', $context['group']['type'] == 3 ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(0);" />', $txt['membergroups_group_type_free'], '</label><br />
								<label for="group_type_post"><input type="radio" name="group_type" id="group_type_post" value="-1" ', $context['group']['is_post_group'] ? 'checked="checked"' : '', ' class="input_radio" onclick="swapPostGroup(1);" />', $txt['membergroups_group_type_post'], '</label><br />
							</fieldset>
						</dd>';
	}

	if ($context['group']['id'] != 3 && $context['group']['id'] != 4)
		echo '
						<dt id="group_moderators_text">
							<label for="group_moderators"><strong>', $txt['moderators'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="group_moderators" id="group_moderators" value="', $context['group']['moderator_list'], '" size="30" class="input_text" />
							<div id="moderator_container"></div>
						</dd>
						<dt id="group_hidden_text">
							<label for="group_hidden_input"><strong>', $txt['membergroups_edit_hidden'], ':</strong></label>
						</dt>
						<dd>
							<select name="group_hidden" id="group_hidden_input" onchange="if (this.value == 2 &amp;&amp; !confirm(\'', $txt['membergroups_edit_hidden_warning'], '\')) this.value = 0;">
								<option value="0" ', $context['group']['hidden'] ? '' : 'selected="selected"', '>', $txt['membergroups_edit_hidden_no'], '</option>
								<option value="1" ', $context['group']['hidden'] == 1 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_hidden_boardindex'], '</option>
								<option value="2" ', $context['group']['hidden'] == 2 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_hidden_all'], '</option>
							</select>
						</dd>';

	// Can they inherit permissions?
	if ($context['group']['id'] > 1 && $context['group']['id'] != 3)
	{
		echo '
						<dt id="group_inherit_text">
							<label for="group_inherit_input"><strong>', $txt['membergroups_edit_inherit_permissions'], '</strong></label>:<br />
							<span class="smalltext">', $txt['membergroups_edit_inherit_permissions_desc'], '</span>
						</dt>
						<dd>
							<select name="group_inherit" id="group_inherit_input">
								<option value="-2">', $txt['membergroups_edit_inherit_permissions_no'], '</option>
								<option value="-1" ', $context['group']['inherited_from'] == -1 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_guests'], '</option>
								<option value="0" ', $context['group']['inherited_from'] == 0 ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $txt['membergroups_members'], '</option>';

		// For all the inheritable groups show an option.
		foreach ($context['inheritable_groups'] as $id => $group)
			echo '
								<option value="', $id, '" ', $context['group']['inherited_from'] == $id ? 'selected="selected"' : '', '>', $txt['membergroups_edit_inherit_permissions_from'], ': ', $group, '</option>';

		echo '
							</select>
							<input type="hidden" name="old_inherit" value="', $context['group']['inherited_from'], '" />
						</dd>';
	}

	if ($context['group']['allow_post_group'])
		echo '

						<dt id="min_posts_text">
							<label for="min_posts_input"><strong>', $txt['membergroups_min_posts'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="min_posts" id="min_posts_input"', $context['group']['is_post_group'] ? ' value="' . $context['group']['min_posts'] . '"' : '', ' size="6" class="input_text" />
						</dd>';
	echo '
						<dt>
							<label for="online_color_input"><strong>', $txt['membergroups_online_color'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="online_color" id="online_color_input" value="', $context['group']['color'], '" size="20" class="input_text" />
						</dd>
						<dt>
							<label for="icon_count_input"><strong>', $txt['membergroups_icon_count'], ':</strong></label>
						</dt>
						<dd>
							<input type="text" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4" class="input_text" />
						</dd>';
        
        // Do we have any possible icons to select from?
       	if (!empty($context['possible_icons']))
       	{
       		echo '
						<dt>
							<label for="icon_image_input"><strong>', $txt['membergroups_icon_image'], ':</strong></label><br />
							<span class="smalltext">', $txt['membergroups_icon_image_note'], '</span>
						</dt>
						<dd>
							', $txt['membergroups_images_url'], '
							<select name="icon_image" id="icon_image_input">';

		// For every possible icon, create an option.
		foreach ($context['possible_icons'] as $icon)
		{
			echo '
								<option value="', $icon, '"', $context['group']['icon_image'] == $icon ? ' selected="selected"' : '', '>', $icon, '</option>';
		}
	
		echo '
							</select>
							<img id="icon_preview" src="" alt="*" />
						</dd>';
	}
	
	// No? Hide the entire control.
	else
		echo '
						<input type="hidden" name="icon_image" value="" />';
						
	echo '
						<dt>
							<label for="max_messages_input"><strong>', $txt['membergroups_max_messages'], ':</strong></label><br />
							<span class="smalltext">', $txt['membergroups_max_messages_note'], '</span>
						</dt>
						<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['categories']))
	{
		echo '
						<dt>
							<strong>', $txt['membergroups_new_board'], ':</strong>', $context['group']['is_post_group'] ? '<br />
							<span class="smalltext">' . $txt['membergroups_new_board_post_groups'] . '</span>' : '', '
						</dt>
						<dd>';
		template_add_edit_group_boards_list();
		echo '
						</dd>';
	}
	echo '
					</dl>
					<input type="submit" name="save" value="', $txt['membergroups_edit_save'], '" class="button_submit" />', $context['group']['allow_delete'] ? '
					<input type="submit" name="delete" value="' . $txt['membergroups_delete'] . '" onclick="return confirm(\'' . ($context['is_moderator_group'] ? $txt['membergroups_confirm_delete_mod'] : $txt['membergroups_confirm_delete']) . '\');" class="button_submit" />' : '', '
				</div>
			</div>
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
			<input type="hidden" name="', $context['admin-mmg_token_var'], '" value="', $context['admin-mmg_token'], '" />
		</form>
	</div>
		<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/suggest.js?alp21"></script>
		<script type="text/javascript"><!-- // --><![CDATA[
			var oModeratorSuggest = new smc_AutoSuggest({
				sSelf: \'oModeratorSuggest\',
				sSessionId: smf_session_id,
				sSessionVar: smf_session_var,
				sSuggestId: \'group_moderators\',
				sControlId: \'group_moderators\',
				sSearchType: \'member\',
				bItemList: true,
				sPostName: \'moderator_list\',
				sURLMask: \'action=profile;u=%item_id%\',
				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
				sItemListContainerId: \'moderator_container\',
				aListItems: [';

			foreach ($context['group']['moderators'] as $id_member => $member_name)
				echo '
							{
								sItemId: ', JavaScriptEscape($id_member), ',
								sItemName: ', JavaScriptEscape($member_name), '
							}', $id_member == $context['group']['last_moderator_id'] ? '' : ',';

			echo '
				]
			});
		// ]]></script>';

	if ($context['group']['allow_post_group'])
		echo '
		<script type="text/javascript"><!-- // --><![CDATA[
			function swapPostGroup(isChecked)
			{
				var is_moderator_group = ', $context['is_moderator_group'], ';
				var group_type = ', $context['group']['type'], ';
				var min_posts_text = document.getElementById(\'min_posts_text\');
				var group_desc_text = document.getElementById(\'group_desc_text\');
				var group_hidden_text = document.getElementById(\'group_hidden_text\');
				var group_moderators_text = document.getElementById(\'group_moderators_text\');
				
				// If it\'s a moderator group, warn of possible problems... and remember the group type
				if (isChecked && is_moderator_group && !confirm(\'', $txt['membergroups_swap_mod'], '\'))
				{
					isChecked = false;

					switch(group_type)
					{
						case 0:
							document.getElementById(\'group_type_private\').checked = true;
							break;
						case 1:
							document.getElementById(\'group_type_protected\').checked = true;
							break;
						case 2:
							document.getElementById(\'group_type_request\').checked = true;
							break;
						case 3:
							document.getElementById(\'group_type_free\').checked = true;
							break;
						default:
							document.getElementById(\'group_type_private\').checked = true;
							break;
					}
				}
				
				document.forms.groupForm.min_posts.disabled = !isChecked;
				min_posts_text.style.color = isChecked ? "" : "#888888";
				document.forms.groupForm.group_desc_input.disabled = isChecked;
				group_desc_text.style.color = !isChecked ? "" : "#888888";
				document.forms.groupForm.group_hidden_input.disabled = isChecked;
				group_hidden_text.style.color = !isChecked ? "" : "#888888";
				document.forms.groupForm.group_moderators.disabled = isChecked;
				group_moderators_text.style.color = !isChecked ? "" : "#888888";
			}
				
			swapPostGroup(', $context['group']['is_post_group'] ? 'true' : 'false', ');
		// ]]></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
{'fraction_non_alphanumeric': 0.21352349681920788, 'fraction_numerical': 0.005951159450030782, 'mean_word_length': 4.274658368285753, 'pattern_counts': {'":': 0, '<': 675, '<?xml version=': 0, '>': 679, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3861860', 'n_tokens_mistral': 15531, 'n_tokens_neox': 12498, 'n_words': 2113}