<?php
/**
 * @author Lukas Havlicek
 * @version 1.0
 */

$this->headTitle($this->projectName);
$this->placeholder('title')->set($this->t('uzivatele-f'));
?>

<h1 class="page_title"><?=$this->t('uzivatele-f')?></h1>
        <h1 class="group_title"><?=($this->edit) ? $this->t('editovat-f') : $this->t('pridat-f')?> <?$this->t('zaznam')?></h1>
            <div class="main_inner2">
    			<div class="main_inner">
    			
    				 <div class="left_column">
    	                <div class="left_column_item">
    	                    <?=$this->action('left-menu', 'layout', 'admin', array('leftmenu' => $this->leftmenu)); ?>
    	                </div>
    	            </div>
    	            
    				<div class="main_text_right">
    				    
                        <h2 class="section_heading"><?=$this->t('uzivatele-f')?> - <?=($this->edit) ? $this->val($this->form, 'user_surname') . ' ' . $this->val($this->form, 'user_firstname') : $this->t('pridat-f')?> <?$this->t('zaznam')?></h2>
                        
                        <div class="button_line">
                            <a href="<?=$this->baseUrl()?>/admin/users"><?=$this->t('zpet-AF')?></a>
                            <?php if ($this->edit) : ?>
                            <a href="#groups"><?=$this->t('clenstvi-ve-skupinach-AF')?></a>
                            <a href="<?=$this->baseUrl()?>/admin/users/all-docs/id/<?=$this->val($this->form, 'id_user')?>"><?=$this->t('seznam-dokumentu-tohoto-uzivatele-AF')?></a>
                            <?php endif; ?>
                        </div>
                        
                        <div class="form_errors">
                        	<?php if (isset($this->errors)) : ?>
                        		<?php foreach ($this->errors as $k => $v) : ?>
                        		 		<?=$this->t('polozka-f')?> "<?=$this->t($k)?>": <?=$this->t($v)?>.<br />
                        		<?php endforeach; ?>
                        	<?php endif; ?>
                        </div>
                        
                        <form action="<?=$this->baseUrl()?>/admin/users/<?=($this->edit) ? 'edit' : 'add'?>" method="post">
                        
	                        <label><?=$this->t('prihlasovaci-jmeno-f')?>:</label>
			                <input class="short" type="text" name="login" value="<?=$this->val($this->form, 'login')?>" />
			                <br />
			                
			                <label><?=$this->t('jmeno-f')?>:</label>
			                <input class="short" type="text" name="user_firstname" value="<?=$this->val($this->form, 'user_firstname')?>" />
			                <br />
			                
			                <label><?=$this->t('prijmeni-f')?>:</label>
			                <input class="short" type="text" name="user_surname" value="<?=$this->val($this->form, 'user_surname')?>" />
			                <br />
			                
			                <label><?=$this->t('e-mail-f')?>:</label>
			                <input class="short" type="text" name="email" value="<?=$this->val($this->form, 'email')?>" />
			                <br />
			                
			                <label><?=$this->t('typ-uzivatele-f')?>:</label>
			                <select class="short" name="super_admin">
			                	<?=$this->selVal($this->form, 'super_admin')?>
			                </select>
			                <br />
			                <br />
			                
			                <?php if ($this->edit) : ?>
			                	<input type="hidden" name="id_user" value="<?=$this->val($this->form, 'id_user')?>" />
			                <?php endif; ?>
			                <div class="submit_line">
		                  		<button class="inline_button"><?=$this->t('ulozit-f')?></button>
	                        	
		                  		<?php if ($this->edit) : ?>
		                        	<a class="grey" id="delete_button" href="<?=$this->baseUrl()?>/admin/users/delete/id/<?=$this->val($this->form, 'id_user')?>">SMAZAT</a>
		                        	<script type="text/javascript">
			                        	$(document).ready(function(){
			                        		$('#delete_button').attr('href', $('#delete_button').attr('href') + '/thru/1');
										   	$('#delete_button').click(function(){
										   		if (confirm("<?=$this->t('delete_confirm')?>"))
												{
													
												} else {
												return false;
												}
										   });
										 });
									 </script>
	                        	<?php endif; ?>
                        	</div>
                        </form>
                        
                        <?php if ($this->edit) : ?>
                        <h2 class="section_heading" id="groups"><?=$this->t('clenstvi-ve-skupinach-f')?></h2>
                        <div class="button_line">
                            <a href="<?=$this->baseUrl()?>/admin/groups/add-members/id/<?=$this->val($this->form, 'id_user')?>"><?=$this->t('pridat-skupinu-AF')?></a>
                        </div>
                        
                        <?php if ($this->data->count()) : ?>
	                        <table>
                        	<tr class="header">
                        		<td><?=$this->t('nazev-skupiny-f')?></td>
                        		<td><?=$this->t('aktivni-ve-skupine-f')?></td>
                        		<td class="right"><?=$this->t('moznosti-f')?></td>
                        	</tr>
                        	<?php foreach ($this->data as $i) : ?>
	                            <tr class="<?=$this->evod('odd', 'even');?>">
	                                <td><?=$this->escape($i->group_name)?></td>
	                                <td class="<?=($i->active) ? 'active' : 'inactive';?>">
	                                	<?php if ($i->active) : ?>
	                                		<a href="<?=$this->baseUrl()?>/admin/users/deactivate-member/id/<?=$i->id_group?>/user/<?=$this->val($this->form, 'id_user')?>"><?=$this->t('aktivni-AF')?></a>
	                                	<?php else : ?>
	                                		<a href="<?=$this->baseUrl()?>/admin/users/activate-member/id/<?=$i->id_group?>/user/<?=$this->val($this->form, 'id_user')?>"><?=$this->t('neaktivni-AF')?></a>
	                                	<?php endif; ?>    
	                                </td>
	                                <td class="actions">
	                                    <a class="action_delete" id="item_del_<?=$i->id_group?>"href="<?=$this->baseUrl()?>/admin/groups/delete-member/user/<?=$i->id_group?>/id/<?=$this->val($this->form, 'id_user')?>"><?=$this->t('vyradit-AF')?></a> 
	                                </td>
	                            </tr>
	                            <script type="text/javascript">
			                        	$(document).ready(function(){
			                        		$('#item_del_<?=$i->id_group?>').attr('href', $('#item_del_<?=$i->id_group?>').attr('href') + '/thru/1');
										   	$('#item_del_<?=$i->id_group?>').click(function(){
										   		if (confirm("<?=$this->t('delete_confirm')?>"))
												{
													return true;
												} else {
													return false;
												}
										   });
										 });
									 </script>
	                        <?php endforeach; ?>
	                        </table>
                        <?php else : ?>
                        
                        <?php endif; ?>
                        <div class="button_line">
                            <a href="<?=$this->baseUrl()?>/admin/users"><?=$this->t('zpet-AF')?></a>
                        </div>
                        <?php endif; ?>
                    </div>
    			
    			</div>
			</div>