<?php
$formatter = function ($str) {

	if (is_array($str)) {
		return '';
	}

	return $str;
};
?>
<div class="row">
    <div class="col-xs-12">
        <div class="box box-danger mb0">
            <div class="row">
                <div class="col-xs-12">
                    <div class="pull-right">
                        <a class="btn btn-success btn-flat" data-menu-action="dodaj_urlop" href="/dodaj_urlop">
                            <span style="margin-right: 10px;"><i class="fa fa-plus"></i> Dodaj</span>
                            <label class="switch"></label>
                        </a>
                    </div>
                </div>
            </div>
            <div class="box-body table-responsive table-fixed-height">
                <table id="PlanUrlopuTable" class="table hover-rows custom-table FullTable" data-start-sort="1" data-start-sort-direction="desc" data-start-height="50vh">
                    <thead>
                    <tr class="text-uppercase">
                        <th>Urlop</th>
                        <th>W okresie od</th>
                        <th>W okresie do</th>
                        <th>Dni</th>
                        <th>Godziny</th>
						<?php if($this->request->getSession()->read('licencja') == 'UMC'): ?>
						<th>Status</th>
						<?php endif; ?>
                        <th class="text-right no-sortable"></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($free_days['bPlanyUrlopu']['bPlanUrlopu'] as $k => $fd): ?>
                        <tr
                            <?php if (!empty($fd['bInformacjeDodatkowe'])): ?>
                                class="more-info-append" data-append-to="#more-info-container"
                                data-more-info="<?php echo $fd['bInformacjeDodatkowe']; ?>"
                            <?php endif; ?>
                        >
                            <td class="info-addon"><?php echo $fd['bKod']['cOpis']; ?></td>
                            <td><span class="span-date"><?php echo $fd['bDataOd']; ?></span></td>
                            <td><span class="span-date"><?php echo $fd['bDataDo']; ?></span></td>
                            <td><span class="span-date"><?php echo $fd['bDni']; ?></span></td>
                            <td><span class="span-date"><?php echo $fd['bGodziny']; ?></span></td>
							<?php if($this->request->getSession()->read('licencja') == 'UMC'): ?>
							<td><span class="span-date"><?php echo $formatter($fd['bOpisAktualnegoStatusu']); ?></span></td>
							<?php endif; ?>
                            <td class="text-right">
								<?php if($fd['bCzyAktualnyUserMozeEdytowac'] == 'true'):?>
                                <a data-menu-action="edytuj_plan_urlopu/<?php echo $fd['bGid']; ?>" class="btn btn-primary" href="edytuj_wniosek/<?php echo $fd['bGid']; ?>">
                                    <i class="fa fa-pencil"></i>
                                </a>
								<?php endif; ?>
								<?php if($fd['bCzyAktualnyUserMozeUsunac'] == 'true'):?>
                                <a class="btn btn-danger" data-remove-entry data-gid="<?php echo $fd['bGid']; ?>" data-url="usun_plan_urlopu" data-title="Na pewno usunąć?"><i class="fa fa-trash"></i></a>
                            	<?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="row more-info-container">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h2 class="box-title">Informacje dodatkowe</h2>
            </div>
            <div class="box-body" id="more-info-container">

            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.page-name:first-of-type').html('<?php echo $pageName; ?>');
    })

    $(function(){
        const elemsData = document.querySelectorAll('[data-menu-action]');
        elemsData.forEach(elem => elem.onclick = testFun);
    });

    function testFun(e) {
        e.preventDefault();

        $(this).parents('.sidebar').find('li.active:not(.treeview)').removeClass('active');
        $(this).parents('li').addClass('active');

        var url = $(this).data('menu-action');
        localStorage.setItem('menu_action', url);

        loadAjaxView(url);
    }
</script>

<?php echo $this->element('alert_close'); ?>
