<div class="row">
    <div class="col-xs-12">
        <div class="box box-danger mb0">
            <div class="box-body table-responsive table-fixed-height">
                <table id="WyksztalceniaTable" 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>Uczelnia</th>
                        <th>Od</th>
                        <th>Do</th>
                        <th class="text-center lmd-1">Suma<br/>L/M/D</th>
                        <th>Kod wykształcenia</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $sumL = 0;
                    $sumM = 0;
                    $sumD = 0; ?>
                    <?php foreach ($educations['bWyksztalcenia']['bWyksztalcenie'] as $k => $education): ?>
                        <?php
                        $sumL += (int)$education['bLat'];
                        $sumM += (int)$education['bMiesiecy'];
                        $sumD += (int)$education['bDni'];
                        ?>
                        <tr
                            <?php if (!empty($education['bInformacjeDodatkowe'])): ?>
                                class="more-info-append" data-append-to="#more-info-container"
                                data-more-info="<?php echo $education['bInformacjeDodatkowe']; ?>"
                            <?php endif; ?>
                        >
                            <td class="info-addon"><?php echo $education['bNazwaUczelni']; ?></td>
                            <td><span class="span-date"><?php echo $education['bDataOd']; ?></span></td>
                            <td><span class="span-date"><?php echo $education['bDataDo']; ?></span></td>
                            <td class="text-center lmd-1"><?php echo $education['bLat'] . '/' . $education['bMiesiecy'] . '/' . $education['bDni']; ?></td>
                            <td><?php echo $education['bWyksztalcenieOpisKodu']; ?></td>
                        </tr>
                    <?php endforeach; ?>

                    <?php
                    if($sumD >= 30) {
                        $sumM += floor($sumD / 30);
                        $sumD = $sumD % 30;
                    }
                    if($sumM >= 12) {
                        $sumL += floor($sumM / 12);
                        $sumM = $sumM % 12;
                    }
                    ?>

                    </tbody>
                    <tfoot>
                    <tr>
                        <th>PODSUMOWANIE:</th>
                        <th></th>
                        <th></th>
                        <th class="text-center" data-lmd="1"><?php echo $sumL . '/' . $sumM . '/' . $sumD; ?></th>
                        <th></th>
                    </tr>
                    </tfoot>
                </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 () {
        $(document).on('change keyup blur', '[aria-controls="WyksztalceniaTable"]', function () {
            var sumD = 0;
            var sumM = 0;
            var sumL = 0;
            var counter = 0;
            $('table').find('.lmd-1').each(function () {
                counter++;
                if(counter > 2) {
                    var s = $(this).html().split('/');
                    sumD += parseInt(s[2]);
                    sumM += parseInt(s[1]);
                    sumL += parseInt(s[0]);
                }
            });
            if(sumD >= 30) {
                sumM += Math.floor(sumD / 30);
                sumD = sumD % 30;
            }
            if(sumM >= 12) {
                sumL += Math.floor(sumM / 12);
                sumM = sumM % 12;
            }

            $('.dataTables_scrollFoot [data-lmd="1"]').html(sumL+"/"+sumM+"/"+sumD);
        });
    });
</script>

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

        initiateDataTable();
    })
</script>

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