<div class="row" data-form="edytuj_wniosek">
    <div class="col-xs-12">
        <div class="box box-danger">
            <?php echo $this->Form->create(null, ['templates' => ['submitContainer' => '{{content}}',], 'id' => 'pWniosek', 'name' => 'pWniosek', 'class' => 'form-horizontal', 'type' => 'file']); ?>
            <div class="box-body">
                <div class="form-group">
                    <label class="col-xs-12 col-md-2 control-label">Numer wniosku</label>
                    <div class="col-xs-12 col-md-10">
                        <label
                            class="control-label"><?php echo $this->request->getData('pWniosek')['dat:Numer']; ?></label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-md-2 control-label">Rodzaj wniosku</label>
                    <div class="col-xs-12 col-md-10">
                        <?php echo $this->Form->input('pWniosek.dat:Kod.dat2:NumerIGid', array('class' => 'form-control width-33', 'div' => false, 'id' => 'codeList', 'label' => false, 'type' => 'select', 'options' => $codes)); ?>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-md-2 control-label">Data Od</label>
                    <div class="col-xs-12 col-md-2 ">
                        <?php echo $this->Form->input('pWniosek.dat:DataOd', array('class' => 'form-control datepicker-from input-125', 'div' => false, 'label' => false, 'required' => 'required', 'autocomplete' => 'off')); ?>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-md-2 control-label">Data Do</label>
                    <div class="col-xs-12 col-md-2">
                        <?php echo $this->Form->input('pWniosek.dat:DataDo', array('class' => 'form-control datepicker-to input-125', 'div' => false, 'label' => false, 'required' => 'required', 'autocomplete' => 'off')); ?>
                    </div>
                </div>
                <div id="kng">
                    <div class="form-group">
                        <label class="col-xs-12 col-md-2 control-label">Godziny</label>
                        <div class="col-xs-12 col-md-2">
                            <?php echo $this->Form->input('pWniosek.dat:Godziny', array('class' => 'form-control timepicker input-125', 'div' => false, 'label' => false, 'required' => 'false', 'autocomplete' => 'off')); ?>
                        </div>
                        <div>
                            (dla nieobecności godzinowych)
                        </div>
                    </div>
                    <?php if ($wniosek['bWniosek']['bCzyWprowadzanieGodzinOdDoNieobecnosci'] == 'true') : ?>
                        <div class="form-group">
                            <label class="col-xs-12 col-md-2 control-label">Godzina Od</label>
                            <div class="col-xs-12 col-md-2 ">
                                <?php echo $this->Form->input('pWniosek.dat:GodzinaOd', array('class' => 'form-control timepicker input-125', 'div' => false, 'label' => false, 'required' => 'required', 'autocomplete' => 'off')); ?>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-md-2 control-label">Godzina Do</label>
                            <div class="col-xs-12 col-md-2">
                                <?php echo $this->Form->input('pWniosek.dat:GodzinaDo', array('class' => 'form-control timepicker input-125', 'div' => false, 'label' => false, 'required' => 'required', 'autocomplete' => 'off')); ?>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
                <?php echo $this->Form->input('pWniosek.dat:DataUtworzenia', array('type' => 'hidden')); ?>
                <?php echo $this->Form->input('pWniosek.dat:Gid', array('type' => 'hidden')); ?>

                <?php if (isset($saldo['bInformacjeOSaldach']['bInformacjaOSaldach']) && !empty($saldo['bInformacjeOSaldach']['bInformacjaOSaldach'])) : ?>
                    <?php
                    if (isset($saldo['bInformacjeOSaldach']['bInformacjaOSaldach']['bLimitOgolemDni'])) {
                        $tmp = $saldo['bInformacjeOSaldach']['bInformacjaOSaldach'];
                        $saldo['bInformacjeOSaldach']['bInformacjaOSaldach'] = array();
                        $saldo['bInformacjeOSaldach']['bInformacjaOSaldach'][] = $tmp;
                    }

                    $maksimum = $saldo['bInformacjeOSaldach']['bInformacjaOSaldach'][0]['bLimitOgolemDni'];
                    $pozostalo = $saldo['bInformacjeOSaldach']['bInformacjaOSaldach'][0]['bPozostaloOgolemDni'];
                    $percentage = $pozostalo * 100 / $maksimum;
                    $percentage = 100 - $percentage;
                    $deg = $percentage * 360 / 100;
                    ?>
                    <div id="CounterFreeDaysHolder" class="CounterFreeDaysHolder"  <?php if($wniosek['bWniosek']['bKod']['cCzyPracaZdalna'] === "true") { ?> style="display: none;" <?php } ?>>
                        <h4 class="">Do wykorzystania pozostało: <?= $pozostalo ?></h4>
                        <canvas id="pieChart" style="height: 180px; width: 350px;" height="180" width="350"></canvas>
                    </div>
                <?php endif; ?>

                <div class="form-group">
                    <label class="col-xs-12 col-md-2 control-label">Dodatkowy opis</label>
                    <div class="col-xs-12 col-md-10">
                        <?php echo $this->Form->input('dat:Opis', array('class' => 'form-control width-33', 'div' => false, 'label' => false)); ?>
                    </div>
                </div>
                <?php if (!empty($mozliwePowody)): ?>
                    <div class="form-group" id="wniosek_powod">
                        <label class="col-xs-12 col-md-2 control-label">Powód</label>
                        <div class="col-xs-12 col-md-10">
                            <?php echo $this->Form->input('pWniosek.dat:Powod', array('class' => 'form-control width-33', 'div' => false, 'id' => 'powodList', 'label' => false, 'type' => 'select', 'options' => $mozliwePowody)); ?>
                        </div>
                    </div>
                <?php endif; ?>
                <?php
                echo $this->Form->input('pWniosek.dat:Zastepca.dat1:Email', array('type' => 'hidden', 'id' => 'substitute-email'));
                echo $this->Form->input('pWniosek.dat:Zastepca.dat1:Gid', array('type' => 'hidden', 'id' => 'substitute-gid'));
                echo $this->Form->input('pWniosek.dat:Zastepca.dat1:Nazwa', array('type' => 'hidden', 'id' => 'substitute-name'));
                echo $this->Form->input('pWniosek.Code', array('type' => 'hidden', 'id' => 'wniosek-code'));
                ?>
                <?php if (isset($wniosek['bWniosek']['bCzyBezZastepcy']) && $wniosek['bWniosek']['bCzyBezZastepcy'] === "false") : ?>
                    <div class="form-group custom-error-holder" id="wniosekZastepca"  <?php if($wniosek['bWniosek']['bKod']['cCzyPracaZdalna'] === "true") { ?> style="display: none;" <?php } ?>>
                        <label class="col-xs-12 col-md-2 control-label">Zastępca</label>
                        <div class="col-xs-12 col-md-10" id="substitute-search-holder">
                            <div class="input-group">
                                <div class="input-group-addon ac-search-trigger" id="substitute-search-trigger"
                                     data-zmetody="wniosek"><i
                                        class="fa fa-search"></i></div>
                                <input type="text" class="form-control width-no-search" id="substitute-search"
                                       data-loader="#substitute-search-loader" placeholder="Wyszukaj zastępcę"/>
                            </div>
                        </div>
                        <?php /*
                    <div class="loader-holder" id="substitute-search-loader">
                        <div class="loader"></div>
                    </div>
                    */ ?>
                    </div>
                <?php endif; ?>
                <div class="form-group">
                    <label class="col-xs-12 col-md-2 control-label">Załącznik</label>
                    <div class="col-xs-12 col-md-10" data-file-multiple style="display: none;">
                        <label class="btn btn-primary" for="file-selector">
                            <input name="data[file][]" id="file-selector"
                                   onchange="fileInputMultiple(this, '#remove-attachments');" type="file"
                                   style="display:none;">
                            <span>Wybierz plik</span>
                        </label>
                        <a href="#" class="btn btn-danger" id="remove-attachments"
                           onclick="clearFileInputSingle('#file-selector', this)">
                            <i class="fa fa-trash"></i>
                        </a>
                    </div>
                </div>

                <div class="box-body" id="pola_dodatkowe">
                    <?php foreach ($extensionCode as $i => $code) { ?>
                        <div class="form-group" data-text="<?php echo $code['code']; ?>" style="display: none;">
                            <label class="col-xs-12 col-md-2 control-label" <?php if(empty($code['label'])) { ?> style="display: none;" <?php } ?>><?php echo $code['label']; ?></label>
                            <div class="col-xs-12 col-md-10" <?php if(empty($code['label'])) { ?> style="display: none;" <?php } ?>>
                                <?php echo $this->Form->input('pWniosek.dat:' . $code['inputName'] . '_' . $code['codeKey'], array('class' => 'form-control width-33', 'div' => false, 'id' => $code['inputName'], 'label' => false, 'type' => 'select', 'options' => $code['options'], 'value' => $wniosek['bWniosek']['b' . ucfirst($code['inputName'])])); ?>
                            </div>
                        </div>
                    <?php } ?>
                    <?php foreach ($extensionCode as $i => $code) { ?>
                        <div class="form-group" data-text="<?php echo $code['code']; ?>" style="display: none;">
                            <label class="col-xs-12 col-md-2 control-label" <?php if(empty($code['textLabel'])) { ?> style="display: none;" <?php } ?>><?php echo $code['textLabel']; ?></label>
                            <div class="col-xs-12 col-md-10" <?php if(empty($code['textLabel'])) { ?> style="display: none;" <?php } ?>>
                                <?php echo $this->Form->input('pWniosek.dat:' . $code['inputTextName'] . '_' . $code['codeKey'], array('class' => 'form-control width-33', 'div' => false, 'label' => false, 'value' => $wniosek['bWniosek']['b' . ucfirst($code['inputTextName'])])); ?>
                            </div>
                        </div>
                    <?php } ?>
                    <?php foreach ($extensionCode as $i => $code) { ?>
                        <div class="form-group" data-text="<?php echo $code['code']; ?>" style="display: none;">
                            <label class="col-xs-12 col-md-2 control-label" <?php if(empty($code['dateLabel'])) { ?> style="display: none;" <?php } ?>><?php echo $code['dateLabel']; ?></label>
                            <div class="col-xs-12 col-md-10" <?php if(empty($code['dateLabel'])) { ?> style="display: none;" <?php } ?>>
                                <?php
                                if (!empty($wniosek['bWniosek']['b' . ucfirst($code['inputDateName'])])) {
                                    $wniosekDataDodatkowa = date('Y-m-d', strtotime($wniosek['bWniosek']['b' . ucfirst($code['inputDateName'])]));
                                } else {
                                    $wniosekDataDodatkowa = '';
                                }
                                echo $this->Form->input('pWniosek.dat:' . $code['inputDateName'] . '_' . $code['codeKey'], array('class' => 'form-control width-33', 'div' => false, 'label' => false, 'value' => $wniosekDataDodatkowa)); ?>
                            </div>
                        </div>
                    <?php } ?>
                </div>

                <div class="box-body" id="wniosek_zdalna" <?php if($wniosek['bWniosek']['bKod']['cCzyPracaZdalna'] === "false") { ?> style="display: none;" <?php } ?>>
                    <div class="col-xs-12 col-md-10 col-md-offset-2">
                        <div class="form-group">
                            <h5><b>Praca zdalna</b></h5>
                            <h5 id="wniosek_zdalana_saldo" <?php if ($wniosek['bWniosek']['bKod']['cCzyPracaZdalnaSaldo'] === "false") { ?> style="display: none" <?php } ?>>
                                Pozostało: <?php echo (!empty($wniosek['bWniosek']['bZdalnaSaldo'])) ? $wniosek['bWniosek']['bZdalnaSaldo'] : '0'; ?> dni
                            </h5>
                            <hr>
                            <div class="col-xs-12 col-md-12" style="padding-left: 0;">
                                <?php echo (!empty($wniosek['bWniosek']['bZdalnaTekst'])) ? $wniosek['bWniosek']['bZdalnaTekst'] : ''; ?>
                            </div>
                        </div>
                        <div class="form-group" <?php if ($wniosek['bWniosek']['bZdalnaCzyAdres'] != 'true') { ?> style="display: none" <?php } ?>>
                            <label class="col-xs-12 col-md-12 control-label" style="text-align: left; padding-left: 0;">Praca świadczona
                                pod adresem</label>
                            <div class="col-xs-12 col-md-12" style="padding-left: 0;">
                                <?php echo $this->Form->input('pWniosek.dat:ZdalnaAdres', array('class' => 'form-control width-50', 'div' => false, 'label' => false, 'value' => $wniosek['bWniosek']['bZdalnaAdres'])); ?>
                            </div>
                        </div>

                        <div class="form-group">
                            <?php
                            echo $this->Form->input('pWniosek.dat:bZdalnaRodzaj', array('type' => 'hidden', 'id' => 'bZdalnaRodzaj', 'value' => $wniosek['bWniosek']['bZdalnaRodzaj']));
                            if (is_string($wniosek['bWniosek']['bZdalnaMozliweRodzaje']['cint'])) {
                                $bZdalnaMozliweRodzaje = [
                                    (string) $wniosek['bWniosek']['bZdalnaMozliweRodzaje']['cint'],
                                ];
                            } else {
                                $bZdalnaMozliweRodzaje = $wniosek['bWniosek']['bZdalnaMozliweRodzaje']['cint'];
                            }
                            ?>
                            <fieldset>
                                <div <?php if (!in_array('0', $bZdalnaMozliweRodzaje)) { ?> style="display: none" <?php } ?>>
                                    <input type="radio" id="dewey" name="ZdalnaMozliweRodzaje" value="dewey" <?php if($wniosek['bWniosek']['bZdalnaRodzaj'] == '0') { ?> checked <?php }?>>
                                    <label for="dewey">Wszystkie dni tygodnia</label>
                                </div>

                                <div <?php if (!in_array('1', $bZdalnaMozliweRodzaje)) { ?> style="display: none" <?php } ?>>
                                    <input type="radio" id="louie" name="ZdalnaMozliweRodzaje" value="louie" <?php if($wniosek['bWniosek']['bZdalnaRodzaj'] == '1') { ?> checked <?php }?>>
                                    <label for="louie">Wybrane dni tygodnia</label>
                                </div>

                                <div <?php if (!in_array('2', $bZdalnaMozliweRodzaje)) { ?> style="display: none" <?php } ?>>
                                    <input type="radio" id="douie" name="ZdalnaMozliweRodzaje" value="douie" <?php if($wniosek['bWniosek']['bZdalnaRodzaj'] == '2') { ?> checked <?php }?>>
                                    <label for="douie">Wybrane dni</label>
                                </div>
                            </fieldset>

                            <div class="form-group" id="weekDay" <?php if($wniosek['bWniosek']['bZdalnaRodzaj'] != '1') { ?>  style="display: none" <?php }?>>
                                <div class="row">
                                    <div class="col-xs-1 col-md-1 text-right">
                                        <?php
                                        $options = [
                                            'id' => 'bZdalnaPo'
                                        ];
                                        if ($wniosek['bWniosek']['bZdalnaPo'] == 'true') {
                                            $options['checked'] = 'checked';
                                        }
                                        echo $this->Form->checkbox('pWniosek.dat:bZdalnaPo', $options); ?>
                                    </div>
                                    <div class="col-xs-11 col-md-11">Poniedziałek</div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-1 col-md-1 text-right">
                                        <?php
                                        $options = [
                                            'id' => 'bZdalnaWt'
                                        ];
                                        if ($wniosek['bWniosek']['bZdalnaWt'] == 'true') {
                                            $options['checked'] = 'checked';
                                        }
                                        echo $this->Form->checkbox('pWniosek.dat:bZdalnaWt', $options); ?>
                                    </div>
                                    <div class="col-xs-11 col-md-11">Wtorek</div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-1 col-md-1 text-right">
                                        <?php
                                        $options = [
                                            'id' => 'bZdalnaSr'
                                        ];
                                        if ($wniosek['bWniosek']['bZdalnaSr'] == 'true') {
                                            $options['checked'] = 'checked';
                                        }
                                        echo $this->Form->checkbox('pWniosek.dat:bZdalnaSr', $options); ?>
                                    </div>
                                    <div class="col-xs-11 col-md-11">Środa</div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-1 col-md-1 text-right">
                                        <?php
                                        $options = [
                                            'id' => 'bZdalnaCz'
                                        ];
                                        if ($wniosek['bWniosek']['bZdalnaCz'] == 'true') {
                                            $options['checked'] = 'checked';
                                        }
                                        echo $this->Form->checkbox('pWniosek.dat:bZdalnaCz', $options); ?>
                                    </div>
                                    <div class="col-xs-11 col-md-11">Czwartek</div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-1 col-md-1 text-right">
                                        <?php
                                        $options = [
                                            'id' => 'bZdalnaPt'
                                        ];
                                        if ($wniosek['bWniosek']['bZdalnaPt'] == 'true') {
                                            $options['checked'] = 'checked';
                                        }
                                        echo $this->Form->checkbox('pWniosek.dat:bZdalnaPt', $options); ?>
                                    </div>
                                    <div class="col-xs-11 col-md-11">Piątek</div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-1 col-md-1 text-right">
                                        <?php
                                        $options = [
                                            'id' => 'bZdalnaSo'
                                        ];
                                        if ($wniosek['bWniosek']['bZdalnaSo'] == 'true') {
                                            $options['checked'] = 'checked';
                                        }
                                        echo $this->Form->checkbox('pWniosek.dat:bZdalnaSo', $options); ?>
                                    </div>
                                    <div class="col-xs-11 col-md-11">Sobota</div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-1 col-md-1 text-right">
                                        <?php
                                        $options = [
                                            'id' => 'bZdalnaNi'
                                        ];
                                        if ($wniosek['bWniosek']['bZdalnaNi'] == 'true') {
                                            $options['checked'] = 'checked';
                                        }
                                        echo $this->Form->checkbox('pWniosek.dat:bZdalnaNi', $options); ?>
                                    </div>
                                    <div class="col-xs-11 col-md-11">Niedziela</div>
                                </div>
                            </div>
                            <div class="form-group" id="calendarDay" <?php if($wniosek['bWniosek']['bZdalnaRodzaj'] != '2') { ?>  style="display: none" <?php }?>>
                                <div class="row">
                                    <div class="col-xs-11 col-xs-offset-1 col-md-11 col-md-offset-1">
                                        <?php
                                        echo $this->Form->input('pWniosek.dat:bZdalnaDni', array('type' => 'hidden', 'id' => 'bZdalnaDni', 'value' => $wniosek['bWniosek']['bZdalnaDni']));
                                        ?>
                                        <div id="datepicker"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-12 col-md-12" style="padding-left: 0;">
                                <?php echo (!empty($wniosek['bWniosek']['bZdalnaOswiadczenieBanerTekst'])) ? $wniosek['bWniosek']['bZdalnaOswiadczenieBanerTekst'] : ''; ?>
                            </div>
                        </div>
                        <div class="form-group"
                             <?php if (empty($wniosek['bWniosek']['bZdalnaOswiadczenie0Tekst'])) { ?>style="display: none" <?php } ?>>
                            <div class="col-xs-1 col-md-1 text-right">
                                <?php
                                $options = [
                                    'id' => 'bZdalnaOswiadczenie0'
                                ];
                                if ($wniosek['bWniosek']['bZdalnaOswiadczenie0'] == 'true') {
                                    $options['checked'] = 'checked';
                                } echo $this->Form->checkbox('pWniosek.dat:bZdalnaOswiadczenie0', $options); ?>
                            </div>
                            <div class="col-xs-11 col-md-11">
                                <?php echo $wniosek['bWniosek']['bZdalnaOswiadczenie0Tekst']; ?>
                            </div>
                        </div>
                        <div class="form-group"
                             <?php if (empty($wniosek['bWniosek']['bZdalnaOswiadczenie1Tekst'])) { ?>style="display: none" <?php } ?>>
                            <div class="col-xs-1 col-md-1 text-right">
                                <?php
                                $options = [
                                    'id' => 'bZdalnaOswiadczenie1'
                                ];
                                if ($wniosek['bWniosek']['bZdalnaOswiadczenie1'] == 'true') {
                                    $options['checked'] = 'checked';
                                } echo $this->Form->checkbox('pWniosek.dat:bZdalnaOswiadczenie1', $options); ?>
                            </div>
                            <div class="col-xs-11 col-md-11">
                                <?php echo $wniosek['bWniosek']['bZdalnaOswiadczenie1Tekst']; ?>
                            </div>
                        </div>
                        <div class="form-group"
                             <?php if (empty($wniosek['bWniosek']['bZdalnaOswiadczenie2Tekst'])) { ?>style="display: none" <?php } ?>>
                            <div class="col-xs-1 col-md-1 text-right">
                                <?php
                                $options = [
                                    'id' => 'bZdalnaOswiadczenie2'
                                ];
                                if ($wniosek['bWniosek']['bZdalnaOswiadczenie2'] == 'true') {
                                    $options['checked'] = 'checked';
                                } echo $this->Form->checkbox('pWniosek.dat:bZdalnaOswiadczenie2', $options); ?>
                            </div>
                            <div class="col-xs-11 col-md-11">
                                <?php echo $wniosek['bWniosek']['bZdalnaOswiadczenie2Tekst']; ?>
                            </div>
                        </div>
                        <div class="form-group"
                             <?php if (empty($wniosek['bWniosek']['bZdalnaOswiadczenie3Tekst'])) { ?>style="display: none" <?php } ?>>
                            <div class="col-xs-1 col-md-1 text-right">
                                <?php
                                $options = [
                                    'id' => 'bZdalnaOswiadczenie0'
                                ];
                                if ($wniosek['bWniosek']['bZdalnaOswiadczenie3'] == 'true') {
                                    $options['checked'] = 'checked';
                                } echo $this->Form->checkbox('pWniosek.dat:bZdalnaOswiadczenie3', $options); ?>
                            </div>
                            <div class="col-xs-11 col-md-11">
                                <?php echo $wniosek['bWniosek']['bZdalnaOswiadczenie3Tekst']; ?>
                            </div>
                        </div>
                        <div class="form-group"
                             <?php if (empty($wniosek['bWniosek']['bZdalnaOswiadczenie4Tekst'])) { ?>style="display: none" <?php } ?>>
                            <div class="col-xs-1 col-md-1 text-right">
                                <?php
                                $options = [
                                    'id' => 'bZdalnaOswiadczenie4'
                                ];
                                if ($wniosek['bWniosek']['bZdalnaOswiadczenie4'] == 'true') {
                                    $options['checked'] = 'checked';
                                } echo $this->Form->checkbox('pWniosek.dat:bZdalnaOswiadczenie4',$options); ?>
                            </div>
                            <div class="col-xs-11 col-md-11">
                                <?php echo $wniosek['bWniosek']['bZdalnaOswiadczenie4Tekst']; ?>
                            </div>
                        </div>
                        <div class="form-group"
                             <?php if (empty($wniosek['bWniosek']['bZdalnaOswiadczenie5Tekst'])) { ?>style="display: none" <?php } ?>>
                            <div class="col-xs-1 col-md-1 text-right">
                                <?php
                                $options = [
                                    'id' => 'bZdalnaOswiadczenie5'
                                ];
                                if ($wniosek['bWniosek']['bZdalnaOswiadczenie5'] == 'true') {
                                    $options['checked'] = 'checked';
                                } echo $this->Form->checkbox('pWniosek.dat:bZdalnaOswiadczenie5', $options); ?>
                            </div>
                            <div class="col-xs-11 col-md-11">
                                <?php echo $wniosek['bWniosek']['bZdalnaOswiadczenie5Tekst']; ?>
                            </div>
                        </div>
                        <div class="form-group">
                            <h5 <?php if (empty($wniosek['bWniosek']['bZdalnaOdrzucenieInfo'])) { ?> style="display: none" <?php } ?>>
                                <b>Informacja: </b><?php echo $wniosek['bWniosek']['bZdalnaOdrzucenieInfo'] ?>
                            </h5>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-md-2 control-label">&nbsp;</label>
                    <div class="col-xs-12 col-md-10">
                        <div id="SprawdzWniosekResponse" style="position: relative; top: -20px;">

                        </div>
                        <a href="wnioski" data-menu-action="wnioski" style="margin-right: 10px;"
                           class="btn btn-default btn-flat pull-left">Anuluj</a>
                        <a class="btn btn-primary btn-flat pull-left" id="SprawdzWniosek">Sprawdź wniosek</a>
                        <?php echo $this->Form->submit('Wyślij', array('class' => 'btn btn-success btn-flat pull-left hidden', 'disabled' => 'disabled')); ?>
                        <?php if ($uprawnienia['ModulRejestruCzasuPracyWspolpracownikow']['bCzyUruchamianie'] == 'true') : ?>
                            <a id="PokazWspolpracownikowBtn" class="btn btn-flat btn-primary pull-right"><i
                                    class="fa fa-users"></i> Czas pracy współpracowników</a>
                        <?php endif; ?>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <?php
                $freeDaysCurrent = (int)$saldo['bInformacjeOSaldach']['bInformacjaOSaldach']['bUrlopWykorzystanieDni'];
                $freeHoursCurrent = (int)$saldo['bInformacjeOSaldach']['bInformacjaOSaldach']['bUrlopWykorzystanieGodzin'];
                $freeDaysMax = (int)$saldo['bInformacjeOSaldach']['bInformacjaOSaldach']['bUrlopWypoczynkowySaldoDni'];
                $freeHoursMax = (int)$saldo['bInformacjeOSaldach']['bInformacjaOSaldach']['bUrlopWypoczynkowySaldoGodzin'];
                $previousFreeDays = (int)$saldo['bInformacjeOSaldach']['bInformacjaOSaldach']['bUrlopZalegly1goStyczniaDni'];
                $previousFreeHours = (int)$saldo['bInformacjeOSaldach']['bInformacjaOSaldach']['bUrlopZalegly1goStyczniaGodzin'];
                $freeHoursPercent = 0;
                if (0 !== $freeHoursMax) {
                    $freeHoursPercent = ($freeHoursCurrent / $freeHoursMax) * 100;
                }
                ?>
                <?php
                /**
                 * <div class="progress">
                 * <div class="progress-bar progress-bar-danger" role="progressbar"
                 * style="width: <?php echo $freeHoursPercent; ?>%">
                 * Wykorzystano
                 * </div>
                 * <div class="progress-bar progress-bar-success"
                 * style="width: <?php echo 100 - $freeHoursPercent; ?>%">
                 * Wymiar
                 * </div>
                 * </div>
                 * <div class="row">
                 * <div class="col-xs-12 col-md-9">
                 * <div class="progress-legend progress-legend-danger">
                 * <span>Wykorzystano <?php echo $freeDaysCurrent . ' dni (' . $freeHoursCurrent . ' godzin)'; ?></span>
                 * </div>
                 * <div class="progress-legend progress-legend-success">
                 * <span>Wymiar urlopu: <?php echo $freeDaysMax . ' dni (' . $freeHoursMax . ' godzin)'; ?>, w tym zaległy na 1-go stycznia: <?php echo $previousFreeDays . ' dni (' . $previousFreeDays . ' godzin)'; ?></span>
                 * </div>
                 * </div>
                 * <div class="col-xs-12 col-md-3 text-right">
                 * <a id="PokazWspolpracownikowBtn" class="btn btn-flat btn-primary"><i class="fa fa-users"></i> Pokaż współpracowników</a>
                 * </div>
                 * </div>
                 */
                ?>
            </div>
            <?php echo $this->Form->end(); ?>
        </div>
    </div>
</div>

<div id="saldoWniosku" <?php if($wniosek['bWniosek']['bKod']['cCzyPracaZdalna'] === "true") { ?> style="display: none;" <?php } ?>>
    <?php echo $this->element('saldo', array('saldo' => $saldo, 'showBack' => false, 'showHeader' => true)); ?>
</div>

<?php echo $this->element('wniosek_historia', array('wniosek' => $wniosek)); ?>

<script>
    $(document).ready(function () {
        let dateOd = new Date();
        let dateDo = new Date();
        if ($('[name="pWniosek[dat:DataOd]"]').val().length != 0) {
            dateOd = new Date($('[name="pWniosek[dat:DataOd]"]').val());
        }
        const newDateOd = dateOd.getDate() + '.' + (dateOd.getMonth() + 1) + '.' + dateOd.getFullYear();
        if ($('[name="pWniosek[dat:DataDo]"]').val().length != 0) {
            dateDo = new Date($('[name="pWniosek[dat:DataDo]"]').val());
        }
        const newDateDo = dateDo.getDate() + '.' + (dateDo.getMonth() + 1) + '.' + dateDo.getFullYear();
        $('#datepicker').multiDatesPicker('destroy');
        $('#datepicker').multiDatesPicker({
            minDate: newDateOd,
            maxDate: newDateDo
        });

        <?php
        if(!is_array($wniosek['bWniosek']['bZdalnaDni'])) {
        $arrayDate = explode(',', $wniosek['bWniosek']['bZdalnaDni']);

        foreach ($arrayDate as $date) { ?>
            $('#datepicker').multiDatesPicker({
                addDates: ['<?php echo trim($date); ?>']
            });
        <?php }}?>

        $('#datepicker').on('blur', function () {
            $('#bZdalnaDni').val($('#datepicker').multiDatesPicker('value'));
        });

        <?php if(isset($this->request->getData()['pWniosek']['dat:Zastepca']['dat1:Nazwa']) && !empty($this->request->getData()['pWniosek']['dat:Zastepca']['dat1:Nazwa'])) : ?>
        $('#substitute-search').val("<?php echo $this->request->getData()['pWniosek']['dat:Zastepca']['dat1:NazwaWyswietlana']; ?>");
        <?php endif; ?>
    });
</script>

<div class="modal fade" id="receivers-list-modal" data-single="1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Wybierz zastępcę</h4>
            </div>
            <div class="modal-body" id="receivers-list-body">
                <div class="row">
                    <div class="loader-holder" id="receivers-list-loader">
                        <div class="loader"></div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
                <button type="button" class="btn btn-success" id="receivers-list-submit" data-module="appliactions">
                    Wybierz
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<?php echo $this->Html->script('appliactions'); ?>

<script>
    jQuery.validator.addMethod("datefrom", function (value, element) {
        if ($('[name="data[pWniosek][dat:DataDo]"]').val() == undefined || $('[name="data[pWniosek][dat:DataDo]"]').val().length == 0) {
            return true;
        } else {
            return ($('[name="data[pWniosek][dat:DataOd]"]').val() > $('[name="data[pWniosek][dat:DataDo]"]').val()) ? false : true;
        }
    }, "'Data od' nie może być większa od 'Data do'");

    jQuery.validator.addMethod("selectpeople", function (value, element) {
        var s_text = $('#substitute-search').val();
        var s_email = $('#substitute-email').val();
        var s_gid = $('#substitute-gid').val();
        var s_name = $('#substitute-name').val();
        if (s_text.length > 0) {
            if (s_email.length > 0 && s_gid.length > 0 && s_name.length > 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }, "Proszę wybrać poprawną wartość w polu 'Zastępca'");

    $(document).ready(function () {
        <?php
        $codeList = [];
        foreach ($extensionCode as $item) {
            $codeList[] = $item['code'];
        }
        ?>

        wniosek_dodatkowe($.inArray($('#codeList option:selected').val(), <?php echo json_encode($codeList); ?>) !== -1);
        createCalendar();
        $('#datepicker').multiDatesPicker('value', $('#bZdalnaDni').val());

        $('#dewey').click(function () {
            $('#bZdalnaRodzaj').val(0);
            $('#weekDay').hide();
            $('#calendarDay').hide();
        })

        $('#louie').click(function () {
            $('#bZdalnaRodzaj').val(1);
            $('#weekDay').show();
            $('#calendarDay').hide();
        })

        $('#douie').click(function () {
            $('#bZdalnaRodzaj').val(2);
            $('#weekDay').hide();
            $('#calendarDay').show();
            createCalendar();
        })

        datepickerFromToInit();
        initEditor();
        initMultipleFiles();
        $("#pWniosek").validate({
            rules: {
                'data[pWniosek][dat:DataOd]': {
                    datefrom: true
                },
                'substitute-search': {
                    selectpeople: true
                }
            },
            submitHandler: function (form) {
                $('#bZdalnaDni').val($('#datepicker').multiDatesPicker('value'));

                $('#table-loading2[data-main-loader]').css('visibility', 'visible');
                $('#table-loading2[data-main-loader]').css('opacity', '1');
                $('#table-loading2[data-main-loader]').css('display', 'block');

                $('[data-file-multiple] input[type="file"]').each(function () {
                    if ($(this).val().length == 0 || $(this).val().length == null || $(this).val().length == undefined) {
                        $(this).parents('[data-file-multiple]').remove();
                    }
                });
                $('[data-file-multiple]:hidden').remove();

                var formData = $(form).serializeArray();
                var formAction = $(form).attr('action');

                $('#pWniosek').ajaxSubmit({
                    success: function (response) {
                        response = JSON.parse(response);

                        $('#table-loading2[data-main-loader]').css('visibility', 'hidden');
                        $('#table-loading2[data-main-loader]').css('opacity', '0');
                        $('#table-loading2[data-main-loader]').css('display', 'none');

                        if (response['error'] != undefined) {
                            showError(response['error']);
                        } else {
                            hideMessages();
                            showSuccess(response['message']);
                            loadAjaxView('/wnioski');
                        }
                    },
                    complete: function (xhr) {
                        console.log(xhr);
                    }
                });
            }
        });
    });
</script>

<script>
    $(document).ready(function () {
        var licznikZalacznikow = 0;

        function przygotujZalacznik(bGid, bGidRodzica, bNazwa, bPlik, bStronaKodowa, bTresc) {
            var html = '<div class="col-xs-12 col-md-10 col-md-offset-2 mb10" data-file-multiple="" style="">' +
                '<label class="btn btn-primary">' +
                '<input type="hidden" name="bZalacznik[' + licznikZalacznikow + '][bGid]" value="' + bGid + '" />' +
                '<input type="hidden" name="bZalacznik[' + licznikZalacznikow + '][bGidRodzica]" value="' + bGidRodzica + '" />' +
                '<input type="hidden" name="bZalacznik[' + licznikZalacznikow + '][bNazwa]" value="' + bNazwa + '" />' +
                '<input type="hidden" name="bZalacznik[' + licznikZalacznikow + '][bPlik]" value="' + bPlik + '" />' +
                '<input type="hidden" name="bZalacznik[' + licznikZalacznikow + '][bStronaKodowa]" value="' + bStronaKodowa + '" />' +
                '<input type="hidden" name="bZalacznik[' + licznikZalacznikow + '][bTresc]" value="' + bTresc + '" />' +
                '<span>' + bPlik + '</span>' +
                '</label>' +
                '<a href="#" class="btn btn-danger ml3" style="" data-usun-zalacznik id="remove-attachments">' +
                '<i class="fa fa-trash"></i>' +
                '</a>' +
                '</div>';
            $('[data-file-multiple]:last-of-type').before(html);
            licznikZalacznikow++;
        }

        setTimeout(function () {
            <?php if(isset($zalaczniki['cGid']) && !empty($zalaczniki['cGid'])) : ?>
            <?php $z = $zalaczniki; ?>
            przygotujZalacznik("<?php echo $z['cGid']; ?>", "<?php echo $z['cGidRodzica']; ?>", "<?php echo $z['cNazwa']; ?>", "<?php echo $z['cPlik']; ?>", "<?php echo $z['cStronaKodowa']; ?>", "<?php echo $z['cTresc']; ?>");
            <?php else : ?>
            <?php foreach ($zalaczniki as $z) : ?>
            przygotujZalacznik("<?php echo $z['cGid']; ?>", "<?php echo $z['cGidRodzica']; ?>", "<?php echo $z['cNazwa']; ?>", "<?php echo $z['cPlik']; ?>", "<?php echo $z['cStronaKodowa']; ?>", "<?php echo $z['cTresc']; ?>");
            <?php endforeach; ?>
            <?php endif; ?>
        });
    });
</script>

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

<script>
    var pieChartCanvas = $('#pieChart').get(0).getContext('2d');
    var pieChart = new Chart(pieChartCanvas);
    var PieData = [
        {
            value: <?php echo round($maksimum - $pozostalo, 0) ?>,
            color: '#f56954',
            highlight: '#f56954',
            label: 'Wykorzystane'
        },
        {
            value: <?php echo $pozostalo ?>,
            color: '#00c0ef',
            highlight: '#00c0ef',
            label: 'Pozostało'
        },
    ];
    var pieOptions = {};
    pieChart.Doughnut(PieData, pieOptions);
</script>

<script>
    $(function () {
        localStorage.setItem('typ_wniosku_return', localStorage.getItem('typ_wniosku'));
        localStorage.setItem('typ_wniosku_filter_return', localStorage.getItem('typ_wniosku_filter'));

        $('[name="pWniosek[dat:DataOd]"], [name="pWniosek[dat:DataDo]"]').on('blur', function () {
            checkFormAgain();
            createCalendar();
        });

        $('[name="pWniosek[dat:Kod][dat2:NumerIGid]"], [name="pWniosek[dat:Wnioskujacy][dat1:Gid]"]').change(function () {
            $('#SprawdzWniosekResponse').html('');
        });

        $('[name="pWniosek[dat:Kod][dat2:NumerIGid]"], [name="pWniosek[dat:Wnioskujacy][dat1:Gid]"]').change(function () {
            checkFormAgain();
        });

        $('#datepicker .ui-datepicker-calendar a').on('blur', function () {
            checkFormAgain();
        });

        $('#datepicker .ui-datepicker-calendar tbody td').on('blur', function () {
            checkFormAgain();
        });

        $('[name="ZdalnaMozliweRodzaje"], [name="pWniosek[dat:ZdalnaAdres]"]').on('change', function () {
            checkFormAgain();
        });

        $('#bZdalnaPo, #bZdalnaWt, #bZdalnaSr, #bZdalnaCz, #bZdalnaPt, #bZdalnaSo, #bZdalnaNi').on('change', function () {
            checkFormAgain();
        });

        $('#bZdalnaOswiadczenie0, #bZdalnaOswiadczenie1, #bZdalnaOswiadczenie2, #bZdalnaOswiadczenie3, #bZdalnaOswiadczenie4, #bZdalnaOswiadczenie5').on('change', function () {
            checkFormAgain();
        });

        var knG = <?php echo json_encode($knG) ?>;
        var valCodeList = $('#codeList option:selected').val();
        var parent = $("#kng");
        hasKnG(knG, valCodeList, parent);
        $('#codeList').change(function () {
            hasKnG(knG, this.value, parent);
            wniosek_dodatkowe($.inArray(this.value, <?php echo json_encode($codeList); ?>) !== -1);
            wniosek_zdalna($.inArray(this.value, <?php echo json_encode($pracaZdalna); ?>) !== -1);
            wniosek_zdalna_saldo($.inArray(this.value, <?php echo json_encode($pracaZdalnaSaldo); ?>) !== -1);
        });

        $('#SprawdzWniosek').click(function () {
            $('#bZdalnaDni').val($('#datepicker').multiDatesPicker('value'));
            $('[name="data[pWniosek][dat:DataOd]"], [name="data[pWniosek][dat:DataDo]"]').on('blur', function () {
                $('#SprawdzWniosek').removeClass('hidden');
                $('form input[type="submit"]').attr("disabled", "disabled").addClass('hidden');
            });
            $('[name="data[pWniosek][dat:Kod][dat2:NumerIGid]"]').on('change', function () {
                $('#SprawdzWniosek').removeClass('hidden');
                $('form input[type="submit"]').attr("disabled", "disabled").addClass('hidden');
            });
            $('#SprawdzWniosekResponse').html('<b>Proszę czekać...</b>');
            $('#table-loading2[data-main-loader]').css('visibility', 'visible');
            $('#table-loading2[data-main-loader]').css('opacity', '1');
            $('#table-loading2[data-main-loader]').css('display', 'block');
            $.ajax({
                method: 'POST',
                data: $('#pWniosek').serializeArray(),
                url: local_url + 'ajax/api/sprawdz_wniosek_edycja'
            }).done(function (response) {
                var response = JSON.parse(response);
                var r = response['bKomunikaty']['bKomunikat'];
                $('#table-loading2[data-main-loader]').css('visibility', 'hidden');
                $('#table-loading2[data-main-loader]').css('opacity', '0');
                $('#table-loading2[data-main-loader]').css('display', 'none');
                if (r['bGid'] !== undefined) {
                    var content = '<div style="margin-bottom: 10px;">';
                    content += '<div class="pull-left"><svg style="margin-right: 10px; position: relative; top: 3px;" width="16px" height="16px"><g transform="scale(0.5)"><path fill="' + r['bKolorWypelnieniaObrazkaHTML'] + '" d="' + r['bObrazekSVG'] + '" /></g></svg></div>';
                    content += '<div class="pull-left"><b>' + r['bTytul'] + '</b><br />' + r['bOpis'] + '</div>';
                    content += '<div class="clearfix"></div>';
                    content += '</div>';
                    $('#SprawdzWniosekResponse').html(content);
                    if (r['bStatus'] > 0) {
                        $('#SprawdzWniosek').addClass('hidden');
                        $('form input[type="submit"][disabled="disabled"]').removeAttr('disabled').removeClass('hidden');
                    }
                } else {
                    var content = '';
                    for (var rr in r) {
                        var _r = r[rr];
                        content += '<div style="margin-bottom: 10px;">';
                        content += '<div class="pull-left"><svg style="margin-right: 10px; position: relative; top: 3px;" width="16px" height="16px"><g transform="scale(0.5)"><path fill="' + _r['bKolorWypelnieniaObrazkaHTML'] + '" d="' + _r['bObrazekSVG'] + '" /></g></svg></div>';
                        content += '<div class="pull-left"><b>' + _r['bTytul'] + '</b><br />' + _r['bOpis'] + '</div>';
                        content += '<div class="clearfix"></div>';
                        content += '</div>';
                    }
                    $('#SprawdzWniosekResponse').html(content);
                    if (r[0]['bStatus'] > 0) {
                        $('#SprawdzWniosek').addClass('hidden');
                        $('form input[type="submit"][disabled="disabled"]').removeAttr('disabled').removeClass('hidden');
                    }
                }
            });
        });
    })
</script>

<script>
    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'); ?>
