<link rel="stylesheet" href="/resources/css/checktree.css" type="text/css" media="screen" />
<script type="text/javascript" src="/resources/jquery/jquery.checkboxtree.js"></script>
<script type="text/javascript" src="/resources/javascript/checktree.js"></script>
<script type="text/javascript" src="/resources/javascript/comercializacao/relacionausuario.js"></script>

<form class="formAjax" id="formToRel" method="POST" style="background:#FFFFFF;" action="/comercializacao/usuario/saverelacionamentousuario">
	<input type="hidden" name="id" value="<?=$this->id?>" />

	<div class="padding-10">	
		<? if (is_array($this->usuarios)):?>
			<ul class="unorderedlisttree">
				<? foreach ($this->usuarios as $usuario): ?>
					<? $check = (in_array($usuario['id_usuario'], $this->relacionados)) ? 'checked="checked"' : '';?>
					
					<li>
						<input type="checkbox" value="<?=$usuario['id_usuario']?>" name="usuarios[]" <?=$check?>/>
						<label><?=$usuario['ds_nome_fantasia']?></label>
						<? if (isset($usuario['prepostos']) && !empty($usuario['prepostos'])): ?>
						<ul>
							<? foreach($usuario['prepostos'] as $preposto): ?>
								<? $check = (in_array($preposto['id_usuario'], $this->relacionados)) ? 'checked="checked"' : '';?>
								<li>
									<input type="checkbox" value="<?=$preposto['id_usuario']?>" name="usuarios[]" <?=$check?>/>
									<label><?=$preposto['ds_nome_preposto']?></label>
								</li>
							<? endforeach; ?>
						</ul>
					<? endif; ?>		
				<? endforeach; ?>
			</ul>
		<? endif; ?>
	</div>
</form>