<div class="buttons">

    <a href="/admin/balance_list" class="addbutton big">Név szerinti rendezés</a>
    <a href="/admin/balance_list/1" class="addbutton big">Egyenleg szerinti rendezés</a>
    <a href="/admin/balance_list/2" class="addbutton big">Tartozások</a>
    <a href="/admin/money_update{$url_postfix}" class="addbutton add-big">Egyenleg frissítése</a>

</div>
<br>
{if $page_id == 2 || $page_id == 3 || $page_id == 4 || $page_id == 5}
    <div class="buttons">
        <a href="/admin/balance_list/3" class="addbutton big">Legnagyobb tartozás előre</a>
        <a href="/admin/balance_list/4" class="addbutton big">Legkisebb tartozás előre</a>
        <a href="/admin/balance_list/5" class="addbutton big">Kiküldés szerint rendezés</a>
    </div>
{/if}

<div class="list half_width">
    {foreach $user_kids as $user}
    <a href="#" id="kid_{$user->get_uk_id()}">
        <div class="list_item">
            <img src="/_image/shuttlecock.png">
            {$user->get_uk_name()}
            {if $user->get_uk_last_notification() && $page_id >= 2}
                <span style="font-size: 14px; font-weight: normal; font-style: italic;">({$user->get_uk_last_notification()})</span>
            {/if}
            {if $user->get_uk_balance() < 0 && $page_id >= 2}
                <span class="float_right notification-text" id="{$user->get_uk_id()}">Értesítő e-mail</span>
            {/if}
            <span class="float_right">{$user->get_uk_balance()|number_format:0:'':' '} Ft</span>
        </div>
    </a>
    {/foreach}
</div>
<script type="text/javascript">
    var clickFunction = function(event) {
        event.preventDefault();
        $(event.target).off('click', clickFunction)
        $(event.target).addClass('in-progress');
        $(event.target).html('Küldés folyamatban...');

        $.post("/_ajax/send_notify.php",
        {
            uk_id: event.target.id,
        },
        function(data, status){
            var pdata = JSON.parse(data);

            if (null == pdata) {
                //error
                $(event.target).removeClass('in-progress');
                $(event.target).addClass('fail');
                $(event.target).html('Küldés sikertelen');
            }
            else if ('missing-data' == pdata) {
                $(event.target).removeClass('in-progress');
                $(event.target).addClass('fail');
                $(event.target).html('Hiányzó adatok!');
            }
            else {
                $(event.target).removeClass('in-progress');
                $(event.target).addClass('success');
                $(event.target).html('Kiküldve');
            }
        });

    };

    $(document).ready(function() {
        $('.notification-text').on('click', clickFunction);
    });
</script>
