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

$this->headTitle($this->projectName);
$this->placeholder('title')->set($this->t('dokumenty-f'));
?>
<h1 class="page_title"><?=$this->t('dokumenty-f')?></h1>
        <h1 class="group_title"><?=($this->edit) ? $this->t('editovat-zaznam-f') : $this->t('pridat-zaznam-f')?></h1>
            <div class="main_inner2">
    			<div class="main_inner">
    			
    				 <div class="left_column">
    	                <div class="left_column_item">
    	                    <?=$this->action('documents-menu', 'layout', 'default', array('leftmenu' => $this->leftmenu)); ?>
    	                </div>
    	            </div>
    	            
    				<div class="main_text_right">
    				    
                        <h2 class="section_heading"><?=($this->edit) ? $this->t('dokument-f') . ': ' . $this->val($this->form, 'doc_name') : $this->t('dokumenty-f') . ' ' . $this->t('novy-dokument')?></h2>
                        
                        <div class="button_line">
                            <a href="<?=$this->baseUrl()?>/documents/index/section/<?=$this->val($this->form, 'id_category')?>"><?=$this->t('zpet-AF')?></a>
                            <?php if ($this->isLoggedAdmin && $this->edit) : ?>
                            <a href="<?=$this->baseUrl()?>/documents/all-users/id/<?=$this->val($this->form, 'id_document')?>"><?=$this->t('seznam-uzivatelu-tohoto-dokumentu-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>
                        
                        <?php if (!$this->edit || (isset($this->docRights['edit']) && $this->docRights['edit'])) : ?>
                        <form action="<?=$this->baseUrl()?>/documents/<?=($this->edit) ? 'detail' : 'add'?>" method="post" enctype="multipart/form-data">
                        <?php endif; ?>
	                        <label><?=$this->t('nazev-dokumentu-f')?>:</label>
	                        <?php if (isset($this->docRights['edit']) && !$this->docRights['edit']) : ?> 
	                        	<div class="document_name"><?=$this->val($this->form, 'doc_name')?></div>
	                        <?php else : ?>
			                	<input class="short" type="text" name="doc_name" value="<?=$this->val($this->form, 'doc_name')?>" />
			        		<?php endif; ?>
			                <br />
			                
			                <label><?=$this->t('kategorie-f')?>:</label>
			                <?php if (isset($this->docRights['edit']) && !$this->docRights['edit']) : ?>
			                	<?php $multi = $this->form->getElement('id_category')->getMultiOptions(); ?>
			                	<div class="document_category"><?=$multi[$this->val($this->form, 'id_category')]?></div>
			                <?php else : ?>
			                <select class="short" name="id_category">
			                	<?=$this->selVal($this->form, 'id_category', array('rights' => $this->rights))?>
			                </select>
			        		<?php endif; ?>
			                <br />
			                
			                
			                <?php if (isset($this->docRights['edit']) && !$this->docRights['edit']) : ?>
			                	<?php if ($this->val($this->form, 'doc_note')) : ?>
			                	<label><?=$this->t('poznamka-f')?>:</label>
			                	<div class="small"><?=$this->val($this->form, 'doc_note')?></div>
			                	<?php endif; ?>
			                <?php else : ?>
			                	<label><?=$this->t('poznamka-f')?>:</label>
			                	<textarea class="medium"  rows="3" name="doc_note"><?=$this->val($this->form, 'doc_note')?></textarea>
			        		<?php endif; ?>
			                <br />
			                
			                
			                <?php if (!$this->edit) : ?>
			                <label><?=$this->t('soubor-f')?>:</label>
							<input type="file" name="doc_file" />		                
			                <br />
			                <br />
			                <?php endif; ?>
			                
							
			                <?php if ($this->edit) : ?>
			                	<input type="hidden" name="id_document" value="<?=$this->val($this->form, 'id_document')?>" />
			                <?php endif; ?>
			                <div class="submit_line">
			                	<?php if (!$this->edit || (isset($this->docRights['edit']) && $this->docRights['edit'])) : ?>
		                  		<button type="submit" class="inline_button"><?=$this->t('ulozit-f')?></button>
		                  		<?php endif; ?>
	                        	
		                  		<?php if ($this->edit) : ?>
		                  			<?php if (isset($this->docRights['del']) && $this->docRights['del']) : ?>
		                        	<a class="grey" id="delete_button" href="<?=$this->baseUrl()?>/documents/delete/id/<?=$this->val($this->form, 'id_document')?>"><?=$this->t('smazat-AF')?></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')?>"))
												{
													return true;	
												} else {
													return false;
												}
										   });
										 });
									 </script>
									<?php endif; ?>
	                        	<?php endif; ?>
                        	</div>
                        <?php if (!$this->edit || (isset($this->docRights['edit']) && $this->docRights['edit'])) : ?>
                        </form>
                        <?php endif; ?>
                        
                        
			            <?php if ($this->edit) : ?>
			            
                        <h2 class="section_heading" id="versrefs"><?=$this->t('prehled-verzi-a-revizi-dokumentu-f')?></h2>
                        <?php if (isset($this->docRights['edit']) && $this->docRights['edit']) : ?>
						<div class="button_line">
						    <a href="<?=$this->baseUrl()?>/documents/add-version/id/<?=$this->val($this->form, 'id_document')?>"><?=$this->t('pridat-verzi-AF')?></a>
						    <a href="<?=$this->baseUrl()?>/documents/add-revision/id/<?=$this->val($this->form, 'id_document')?>"><?=$this->t('pridat-revizi-AF')?></a>
						</div>
						<?php endif; ?>
						
						<?php if (count($this->versions)) : ?>
						 <table>
                        	<tr class="header">
                        		<td><?=$this->t('verze-a-revize-f')?></td>
                        		<td><?=$this->t('pridano-f')?></td>
                        		<td><?=$this->t('pridal-f')?></td>
                        		<td><?=$this->t('poznamka-f')?></td>
                        		<td class="right"><?=$this->t('moznosti-f')?></td>
                        	</tr>
                        	<?php foreach ($this->versions as $i) : ?>
                        	
                        	<tr>
                        		<td><a href="<?=$this->baseUrl()?>/documents/document/id/<?=$this->val($this->form, 'id_document')?>/ver/<?=$i['ver']->id_version?>"><?=number_format($i['ver']->ver_number, 1, '.', '')?></a></td>
                        		<td style="cursor: help" title="<?=$this->date($i['ver']->ver_added)?> <?=$this->time($i['ver']->ver_added)?>"><?=$this->date($i['ver']->ver_added)?></td>
                        		<td><?=$this->escape($i['ver']->surname . ' ' . $i['ver']->firstname)?></td>
                        		<td style="cursor: help" title="<?=$this->escape($i['ver']->ver_note)?>"><?=$this->truncate($this->escape($i['ver']->ver_note))?></td>
                        		<td class="actions">
                        		<?php if ($this->isLoggedAdmin) : ?>
		                        <a class="action_read" href="<?=$this->baseUrl()?>/documents/version-confirm-summary/id/<?=$i['ver']->id_version?>"><?=$this->t('prehled-potvrzeni-AF')?></a>                     		
		                        <?php endif; ?>
                        		<?php if (isset($this->docRights['edit']) && $this->docRights['edit']) : ?>
   								<a class="action_read" href="<?=$this->baseUrl()?>/documents/note-version/id/<?=$i['ver']->id_version?>"><?=$this->t('editovat-poznamku-AF')?></a>                     		
                        		<?php endif ; ?>
                        		<?php if (isset($this->docRights['del']) && $this->docRights['del']) : ?>
                        		<a id="del_ver_<?=$i['ver']->id_version?>" href="<?=$this->baseUrl()?>/documents/delete-version/id/<?=$i['ver']->id_version?>"><?=$this->t('smazat-AF')?></a></td>
                        		<script type="text/javascript">
			                        	$(document).ready(function(){
			                        		$('#del_ver_<?=$i['ver']->id_version?>').attr('href', $('#del_ver_<?=$i['ver']->id_version?>').attr('href') + '/thru/1');
										   	$('#del_ver_<?=$i['ver']->id_version?>').click(function(){
										   		if (confirm("<?=$this->t('delete_confirm')?>"))
												{
													return true;	
												} else {
													return false;
												}
										   });
										 });
									 </script>
									 
								<?php endif; ?>
                        	
                        	</tr>
                        	
                        		<?php foreach ($i['revs'] as $j) : ?>
                        			<tr>
		                        		<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?=$this->baseUrl()?>/documents/document/id/<?=$this->val($this->form, 'id_document')?>/rev/<?=$j->id_revision?>"><?=$i['ver']->ver_number . '.' . $j->rev_number?><a/></td>
		                        		<td style="cursor: help" title="<?=$this->date($j->rev_added)?> <?=$this->time($j->rev_added)?>"><?=$this->date($j->rev_added)?></td>
		                        		<td><?=$this->escape($j->surname . ' ' . $j->firstname)?></td>
		                        		<td style="cursor: help" title="<?=$this->escape($j->rev_note)?>"><?=$this->truncate($this->escape($j->rev_note))?></td>
		                        		<td class="actions">
		                        		<?php if ($this->isLoggedAdmin) : ?>
		                        		<a class="action_read" href="<?=$this->baseUrl()?>/documents/revision-confirm-summary/id/<?=$j->id_revision?>"><?=$this->t('prehled-potvrzeni-AF')?></a>                     		
		                        		<?php endif; ?>
		                        		<?php if (isset($this->docRights['edit']) && $this->docRights['edit']) : ?>
		   								<a class="action_read" href="<?=$this->baseUrl()?>/documents/note-revision/id/<?=$j->id_revision?>"><?=$this->t('editovat-poznamku-AF')?></a>                     		
		                        		<?php endif ; ?>
		                        		<?php if (isset($this->docRights['del']) && $this->docRights['del']) : ?>
		                        		<a id="rev_ver_<?=$j->id_revision?>" href="<?=$this->baseUrl()?>/documents/delete-revision/id/<?=$j->id_revision?>"><?=$this->t('smazat-AF')?></a></td>
		                        		<script type="text/javascript">
			                        	$(document).ready(function(){
			                        		$('#rev_ver_<?=$j->id_revision?>').attr('href', $('#rev_ver_<?=$j->id_revision?>').attr('href') + '/thru/1');
										   	$('#rev_ver_<?=$j->id_revision?>').click(function(){
										   		if (confirm("<?=$this->t('delete_confirm')?>"))
												{
													return true;	
												} else {
													return false;
												}
										   });
										 });
									 </script>
									 <?php endif; ?>
		                        	</tr>	
                        		<?php endforeach; ?>
                           
                            <?php endforeach; ?>
                        </table>
                        
                        <?php else : ?>
                        <div class="error_box"><?=$this->t('dokument-nema-zadne-verze-f')?>!</div>
                        <?php endif; ?>
			            
			            <?php endif; ?>
			            
			             <div class="button_line">
                            <a href="<?=$this->baseUrl()?>/documents/index/section/<?=$this->id_category?>"><?=$this->t('zpet-AF')?></a>
                        </div>
                        
                    </div>
    			
    			</div>
			</div>