{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
{$hide_disabled_users = ConfigHelper::checkConfig('documents.hide_disabled_users')}
<!--// $Id$ //-->
<H1>{$layout.pagetitle}</H1>
<FORM method="POST" action="?m=documenttypeedit&id={$documenttype.id}" name="typeedit">
<INPUT type="submit" class="hiddenbtn">
<TABLE class="lmsbox">
	<COLGROUP>
		<COL style="width: 1%;">
		<COL style="width: 1%;">
		<COL style="width: 98%;">
	</COLGROUP>
	<THEAD>
	<TR>
		<TD colspan="3" class="bold">
			{icon name="document"}
			{trans("Name:")} {$documenttype.name}
		</TD>
	</TR>
	</THEAD>
	<TBODY>
	<TR>
		<TD>
			{icon name="permissions"}
		</TD>
		<TD class="bold nobr">
			{trans("Permissions:")}
		</TD>
		<TD>
			<table class="lmsbox lms-ui-background-cycle">
				<colgroup>
					<col style="width: {math x=100 y=count($_DOCRIGHTS) equation="x-y"}%;">
					{foreach $_DOCRIGHTS as $right}
						<col style="width: 1%;">
					{/foreach}
				</colgroup>
				<thead>
					<tr>
						<td>
							<strong>{trans("User")}</strong>
						</td>
						{foreach $_DOCRIGHTS as $right}
							<td class="text-center nobr">
								<strong>{$right}</strong>
							</td>
						{/foreach}
					</tr>
				</thead>
				<tbody>
					{foreach $documenttype.rights as $userid => $userrights}
						<tr class="highlight lms-ui-row-all-check{if empty($userrights.access)} blend{/if}"
							{if empty($userrights.access) && $hide_disabled_users} style="display: none;"{/if}>
							<td>
								<A href="?m=userinfo&id={$userid}">{$userrights.rname|escape} ({$userrights.login})</A>
							</td>
							{foreach $_DOCRIGHTS as $right => $label}
								<td class="text-center nobr">
									<input type="checkbox" name="rights[{$userid}][{$right}]" value="{$right}"{if ($userrights.rights & $right)} checked{/if}>
								</td>
							{/foreach}
						</tr>
						{if empty($userrights.access) && $hide_disabled_users}
							<tr style="display: none;">
								<td colspan="{count($_DOCRIGHTS) + 1}"></td>
							</tr>
						{/if}
					{/foreach}
					<tr class="highlight">
						<td class="nobr text-right">
							{trans("Check All")}
						</td>
						{foreach $_DOCRIGHTS as $right => $label}
							<td class="text-center">
								<input type="checkbox" name="allbox[{$right}]" data-value="{$right}">
							</td>
						{/foreach}
					</tr>
				</tbody>
			</table>
		</TD>
	</TR>
	<TR>
		<TD colspan="3" class="lms-ui-box-buttons">
			<div id="document-button-panel">
				<div>
					{button type="submit" icon="save" id="submit-button" label="Submit"}
					{button icon="cancel" label="Cancel" onclick="location.href = '?m=documenttypes';"}
				</div>
			</div>
		</TD>
	</TR>
	</TBODY>
</TABLE>
<script>

	$(function() {
		$('input:checkbox[name^="allbox"]').click(function () {
			$('input:checkbox[name^="rights"][value="' + $(this).attr('data-value') + '"]').prop('checked', this.checked);
		});
	});

</script>
{/block}
