<?php 
$response = $this->response;
$user = $response["user"];
?>
<h1>Editace uživatele <?php echo $user->username; ?></h1>
<form action="/user/put/<?php echo $user->username; ?>.html" method="post">
	<p>
		Uživatelské jméno: <strong><?php echo $user->username; ?></strong>
	</p>
	<p>
		<?php echo $this->formLabel("user[email]", "E-Mailová adresa"); ?>
		<?php echo $this->formText("user[email]", $user->email); ?>
	</p>
	<p>
		<?php echo $this->formLabel("user[password_old]", "Staré heslo"); ?>
		<?php echo $this->formPassword("user[password_old]", ""); ?>
	</p>
	<p>
		<?php echo $this->formLabel("user[password]", "Nové heslo"); ?>
		<?php echo $this->formPassword("user[password]", ""); ?>
	</p>
	<p>
		<?php echo $this->formLabel("user[password_check]", "Kontrola hesla"); ?>
		<?php echo $this->formPassword("user[password_check]", ""); ?>
	</p>
	<p>
		Domovský adresář: <strong><a href="/directory/get/<?php echo $user->root_directory_id; ?>.html"># <?php echo $user->root_directory_id; ?></a></strong>
	</p>
	<h2>Role uživatele</h2>
	<p>
		<ul>
			<?php 
			//nacteni vsech moznych roli
			$tableRoles = new Application_Model_UsersRoles();
			$roleList = $tableRoles->fetchAll(null, "role_name");
			
			//prevedeni seznamu uzivatelovych roli do pole
			$userRoles = array();
			
			foreach ($response["roles"] as $role) {
				$userRoles[] = $role->role_name;
			}
			
			//vyhodnoceni jestli uzivatel smi upravovat role
			$disableRoles = !in_array("USER_MANAGER", $userRoles) && ($this->thisUser->id != 1);
			
			$parameters = array(
				"checked" => false
			);
			
			if ($disableRoles) {
				//editace roli ma byt vypnuta
				$parameters["disabled"] = true;
			}
			
			foreach ($roleList as $role) {
				$parameters["checked"] = in_array($role->role_name, $userRoles);
				?>
				<li>
					<?php echo $this->formCheckbox("user[role][$role->id]", 1, $parameters); ?>
					<?php echo $role->role_name; ?>
				</li>
				<?php 
			}
			?>
		</ul>
	</p>
	<h2>Sklupiny uživatele</h2>
	<p>
		<ul>
			<?php 
			//nacteni seznamu skupin
			$tableGroups = new Application_Model_UsersGroups();
			$groupList = $tableGroups->fetchAll(null, "group_name");
			
			//prevedeni uzivatelovych skupin do pole
			$userGroups = array();
			
			foreach ($response["groups"] as $group) {
				$userGroups[] = $group->id;
			}
			
			//inicializace pole parametru
			$parameters = array(
				"checked" => false
			);
			
			//kontorla jeslti se maji zneaktivnit policka skupin
			if (!in_array("USER_MANAGER", $userRoles) && ($this->thisUser->id != 1)) {
				//policka maji byt disablnuta
				$parameters["disabled"] = true;
			}
			
			foreach ($groupList as $group) {
				//vyhodnoceni zaskrtnitu
				$parameters["checked"] = in_array($group->id, $userGroups);
				?>
				<li>
					<?php echo $this->formCheckbox("user[group][$group->id]", 1, $parameters) ?>
					<a href="/group/get/<?php echo $group->id . "_" . $group->group_name; ?>.html"><?php echo $group->group_name; ?></a>
				</li>
				<?php 
			}
			?>
		</ul>
	</p>
	<p>
		<?php echo $this->formSubmit("user[submit]", "Zapsat změny"); ?>
	</p>
</form>