<? 
$this->title->elem('a');
$this->title->cssClass('new_user');
$this->title->name($this->Language('Add user'));
$this->title->create($this->Language('Users')); 
?>

<form method="post" class="new_user_box hidden">
<table class="header">

<tr>
	<th><?=$this->Language('user name', true);?></th>
	<td><input type="text"    name="name"></td>
</tr>

<tr>
	<th><?=$this->Language('password', true);?></th>
	<td><input type="text"    name="password"></td>
</tr>

<tr>
	<th><?=$this->Language('first name', true);?></th>
	<td><input type="text"    name="first_name"></td>
</tr>

<tr>
	<th><?=$this->Language('last name', true);?></th>
	<td><input type="text"    name="last_name"></td>
</tr>

<tr>
	<th><?=$this->Language('roles', true);?></th>
	<td>
	<select name="role_id">
	<?
	while($row = $this->roles->Assoc()){

		$selected = '';
		if($_POST['role_id'] == $row['id']) $selected = 'selected="selected"';

		echo '<option value="'.$row['id'].'" '.$selected.'>'.$row['name'].'</option>';
	}
	?></select></td>
</tr>


<tr>
	<th><?=$this->Language('is_enabled', true);?></th>
	<td><input type="checkbox"    name="is_enabled" value="1"></td>
</tr>


<tr>
	<th><?=$this->Language('password_expires_at', true);?></th>
	<td><input type="text"    name="password_expires_at"></td>
</tr>


<tr>
	<th><?=$this->Language('account_expires_at', true);?></th>
	<td><input type="text"    name="account_expires_at"></td>
</tr>

<tr>
	<td></td>
	<td><input type="submit"    name="insert_user" value="<?=$this->Language('Insert');?>"></td>
</tr>
</table>
</form>

<form method="post" action="<?=$this->Link();?>">
<table class="content">
<tr>

	<th><?=$this->Language('user name', true);?></th>

	<th><?=$this->Language('company name', true);?></th>

	<th><?=$this->Language('password', true);?></th>

	<th><?=$this->Language('first name', true);?></th>

	<th><?=$this->Language('last name', true);?></th>

	<th><?=$this->Language('role', true);?></th>


	<th><?=$this->Language('is_enabled', true);?></th>


	<th><?=$this->Language('password_expires_at', true);?></th>


	<th><?=$this->Language('account_expires_at', true);?></th>
	<th></th>

</tr>
<?PHP
 while($row = $this->users->Assoc()){

	 $bg_color = $row['is_enabled'] == 0 ? '#ffe6e6' : '';
?>
<tr style="background:<?=$bg_color;?>;">

<? if($row['id'] == $_GET['id'] && $_GET['action'] == 'edit'){ ?>

	<td><input type="hidden"    name="id" value="<?=$row['id']?>"><input type="text"    name="name" value="<?=$row['name']?>"></td>

	<td></td>

	<td><input type="text"    name="password" value=""></td>

	<td><input type="text"    name="first_name" value="<?=$row['first_name']?>"></td>

	<td><input type="text"    name="last_name" value="<?=$row['last_name']?>"></td>

	<td><select name="role_id">
	<?
	while($row2 = $this->roles->Assoc()){

		$selected = '';
		if($row['role_id'] == $row2['id']) $selected = 'selected="selected"';

		echo '<option value="'.$row2['id'].'" '.$selected.'>'.$row2['name'].'</option>';
	}
	?></select></td>


	<td><input type="checkbox"    name="is_enabled" value="1" <?=($row['is_enabled'] == 1 ? 'checked' : '');?>></td>


	<td><input type="text"    name="password_expires_at" value="<?=$row['password_expires_at']?>" onclick="$(this).simpleDatepicker({dateFormat : 'dd.mm.yy'});"></td>


	<td><input type="text"    name="account_expires_at" value="<?=$row['account_expires_at']?>" onclick="$(this).simpleDatepicker({dateFormat : 'dd.mm.yy'});"></td>
	<td><input type="submit"    name="update_user" value="<?=$this->Language('Update');?>"></td>

<?
}
else{

?>
	<td><a href="<?=$this->appendLink('?action=edit&id='.$row['id'])?>"><?=$row['name']?></a></td>

	<td><?=$row['company']?></td>

	<td>******</td>

	<td><?=$row['first_name']?></td>

	<td><?=$row['last_name']?></td>

	<td><?=$row['type']?></td>


	<td><?=$row['is_enabled']?></td>


	<td><?=$row['password_expires_at']?></td>


	<td><?=$row['account_expires_at']?></td>

	<td><a href="<?=$this->appendLink('?action=delete_user&id='.$row['id'])?>" onclick="return $.confirm();"><?=$this->Language('delete');?></a></td>

<? } ?>

</tr>
<? } ?></table>
</form>


<script type="text/javascript">
$('.new_user').click(function(){

	$('.new_user_box').slideBox(500);
	return false;
});
</script>