<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
    <div class="page-header">
        <div class="container-fluid">

            <h1><?php echo $heading_title; ?></h1>
            <ul class="breadcrumb">
                <?php foreach ($breadcrumbs as $breadcrumb) { ?>
                <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
                <?php } ?>
            </ul>
        </div>
    </div>
    <div class="container-fluid">
        <?php if ($error_warning) { ?>
        <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
            <button type="button" class="close" data-dismiss="alert">&times;</button>
        </div>
        <?php } ?>
        <?php if ($success) { ?>
        <div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
            <button type="button" class="close" data-dismiss="alert">&times;</button>
        </div>
        <?php } ?>
        <div class="row">
            <!--<div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
            <div class="col-sm-6 text-right"><?php echo $results; ?></div>-->
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-list"></i> <?php echo $text_list; ?></h3>
            </div>
            <div class="panel-body">
                <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
                    Arama Filtresini Göster / Gizle
                </a>
                <div class="well collapse" id="collapseExample">
                    <div class="row">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="input-order-id"><?php echo $entry_order_id; ?></label>
                                <input type="text" name="filter_order_id" value="<?php echo $filter_order_id; ?>" placeholder="<?php echo $entry_order_id; ?>" id="input-order-id" class="form-control" />
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="input-email">Mail</label>
                                <input type="text" name="filter_email" value="<?php echo $filter_email; ?>" placeholder="Mail" id="input-email" class="form-control" />
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="input-filter_telephone">Telefon</label>
                                <input type="text" name="filter_telephone" value="<?php echo $filter_telephone; ?>" placeholder="Telefon" id="input-filter_telephone" class="form-control" />
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="input-customer"><?php echo $entry_customer; ?></label>
                                <input type="text" name="filter_customer" value="<?php echo $filter_customer; ?>" placeholder="<?php echo $entry_customer; ?>" id="input-customer" class="form-control" />
                            </div>
                        </div>

                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="input-order-status"><?php echo $entry_order_status; ?></label>
                                <select name="filter_order_status" id="input-order-status" class="form-control">
                                    <option value="*"></option>
                                    <?php if ($filter_order_status == '0') { ?>
                                    <option value="0" selected="selected"><?php echo $text_missing; ?></option>
                                    <?php } else { ?>
                                    <option value="0"><?php echo $text_missing; ?></option>
                                    <?php } ?>
                                    <?php foreach ($order_statuses as $order_status) { ?>
                                    <?php if ($order_status['order_status_id'] == $filter_order_status) { ?>
                                    <option value="<?php echo $order_status['order_status_id']; ?>" selected="selected"><?php echo $order_status['name']; ?></option>
                                    <?php } else { ?>
                                    <option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
                                    <?php } ?>
                                    <?php } ?>
                                </select>
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="input-order-zone">Şehir</label>
                                <select name="filter_order_zone" id="input-order-zone" class="form-control">
                                    <option value="*"></option>
                                    <?php foreach ($zones as $zone) { ?>
                                    <?php if ($zone['zone_id'] == $filter_order_zone) { ?>
                                    <option value="<?php echo $zone['zone_id']; ?>" selected="selected"><?php echo $zone['name']; ?></option>
                                    <?php } else { ?>
                                    <option value="<?php echo $zone['zone_id']; ?>"><?php echo $zone['name']; ?></option>
                                    <?php } ?>
                                    <?php } ?>
                                </select>
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="input-order-payment">Ödeme Yöntemi</label>
                                <select name="filter_order_payment" id="input-order-payment" class="form-control">
                                    <option value="*"></option>
                                    <?php foreach ($paymnet_methods as $paymnet_method) { ?>
                                    <?php if ($paymnet_method['payment_code'] == $filter_order_payment) { ?>
                                    <option value="<?php echo $paymnet_method['payment_code']; ?>" selected="selected"><?php echo $paymnet_method['payment_method']; ?></option>
                                    <?php } else { ?>
                                    <option value="<?php echo $paymnet_method['payment_code']; ?>"><?php echo $paymnet_method['payment_method']; ?></option>
                                    <?php } ?>
                                    <?php } ?>
                                </select>
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="input-total"><?php echo $entry_total; ?></label>
                                <input type="text" name="filter_total" value="<?php echo $filter_total; ?>" placeholder="<?php echo $entry_total; ?>" id="input-total" class="form-control" />
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="input-date-added"><?php echo $entry_date_added; ?></label>
                                <div class="input-group date">
                                    <input type="text" name="filter_date_added" value="<?php echo $filter_date_added; ?>" placeholder="<?php echo $entry_date_added; ?>" data-date-format="YYYY-MM-DD" id="input-date-added" class="form-control" />
                                    <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span></div>
                            </div>
                            <div class="form-group">
                                <label class="control-label" for="input-date-modified"><?php echo $entry_date_modified; ?></label>
                                <div class="input-group date">
                                    <input type="text" name="filter_date_modified" value="<?php echo $filter_date_modified; ?>" placeholder="<?php echo $entry_date_modified; ?>" data-date-format="YYYY-MM-DD" id="input-date-modified" class="form-control" />
                                    <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span></div>
                            </div>
                            <div class="form-group">
                                <label class="control-label" for="input-date-added"><?php echo $entry_tranfer_order_status; ?></label><br>
                                <select id="filter_tranfer_order_status" class="form-control" name="filter_tranfer_order_status" style="width: 100%; float: left; margin-right: 10px">
                                    <option value="*"></option>
                                    <option value="1" <?=($filter_tranfer_order_status=='1'?'selected':'')?>><?php echo $text_tranferred_to_excel; ?></option>
                                    <option value="0" <?=($filter_tranfer_order_status=='0'?'selected':'')?>><?php echo $text_not_tranferred_to_excel; ?></option>

                                </select>
                            </div>
                            <br><br>
                            <button type="button" id="button-filter" class="btn btn-primary pull-right"><i class="fa fa-filter"></i> <?php echo $button_filter; ?></button>
                        </div>
                    </div>
                </div>
                <div class="well">
                    <div class="row">
                        <div class="col-sm-2">
                            <label class="label-control">Sipariş Durumu</label><br>
                            <select id="scf_order_status_id" class="form-control" name="order_status_id" style="width: 208px; float: left; margin-right: 10px">
                                <?php foreach ($order_statuses as $order_status) { ?>
                                <option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="col-sm-1" style="margin-left:30px;">
                            <label class="label-control">Bilgilendir</label><br>
                            <input type="checkbox" name="override" value="1" id="scf_notify" data-toggle="tooltip" title="<?php echo $add_notify; ?>" style="margin-top:5px;"/>&nbsp;&nbsp;
                        </div>
                        <div class="col-sm-2">
                            <label class="label-control">Yorum</label>
                            <div class="extra-comment comment-box">
                                <label class="add-comment btn btn-info" data-toggle="tooltip" title="<?php echo $add_comment; ?>"><i class="fa fa-comment add-comment" aria-hidden="true"> </i> Yorum</label>
                                <div class="comment-description">
                                    <div class="comment-icon"></div>
                                    <textarea name="comment" rows="8" id="scf_comment" class="form-control"></textarea>
                                </div>    &nbsp;&nbsp;&nbsp;

                            </div>
                        </div>
                        <div class="col-sm-3"><br><button id="btn-update-status" data-toggle="tooltip" title="<?php echo $button_update_status; ?>" class="btn btn-info btn-update-status" style="margin-top:5px;"><i class="fa fa-refresh"></i> Sipariş Durumlarını Güncelle</button></div>
                    </div>
                    <div class="row">
                        <div class="notification col-sm-7"></div>
                    </div>
                </div>
                <form method="post" action="" enctype="multipart/form-data" id="form-order">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                                <td class="text-right"><?php if ($sort == 'o.order_id') { ?>
                                    <a href="<?php echo $sort_order; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_order_id; ?></a>
                                    <?php } else { ?>
                                    <a href="<?php echo $sort_order; ?>"><?php echo $column_order_id; ?></a>
                                    <?php } ?></td>
                                <td class="text-left"><?php echo $column_coupon_name; ?></td>
                                <td class="text-left"><?php if ($sort == 'customer') { ?>
                                    <a href="<?php echo $sort_customer; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_customer; ?></a>
                                    <?php } else { ?>
                                    <a href="<?php echo $sort_customer; ?>"><?php echo $column_customer; ?></a>
                                    <?php } ?></td>


                                <td class="text-left">

                                    <a >Kaç Kere Sipariş Verdi ?</a>
                                </td>


                                <td class="text-left"><?php if ($sort == 'order_status') { ?>
                                    <a href="<?php echo $sort_status; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_status; ?></a>
                                    <?php } else { ?>
                                    <a href="<?php echo $sort_status; ?>"><?php echo $column_status; ?></a>
                                    <?php } ?></td>
                                <td class="text-right"><?php if ($sort == 'o.total') { ?>
                                    <a href="<?php echo $sort_total; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_total; ?></a>
                                    <?php } else { ?>
                                    <a href="<?php echo $sort_total; ?>"><?php echo $column_total; ?></a>
                                    <?php } ?></td>
                                <td class="text-left"><?php if ($sort == 'o.date_added') { ?>
                                    <a href="<?php echo $sort_date_added; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_date_added; ?></a>
                                    <?php } else { ?>
                                    <a href="<?php echo $sort_date_added; ?>"><?php echo $column_date_added; ?></a>
                                    <?php } ?></td>
                                <?php if(isset($netgsm_status) && $netgsm_status== 1 ){ ?>
                                <td style="display:none">Telefon</td>
                                <?php } ?>
                                <td class="text-left"><?php if ($sort == 'o.date_modified') { ?>
                                    <a href="<?php echo $sort_date_modified; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_date_modified; ?></a>
                                    <?php } else { ?>
                                    <a href="<?php echo $sort_date_modified; ?>"><?php echo $column_date_modified; ?></a>
                                    <?php } ?></td>

                            </tr>
                            </thead>
                            <tbody>
                            <?php if ($orders) { ?>
                            <?php foreach ($orders as $order) { ?>
                            <tr style="background-color: <?= $order['row_color_code']; ?>;" class="row-item-<?php echo $order['order_id']; ?>">
                                <td class="text-center"><?php if (in_array($order['order_id'], $selected)) { ?>
                                    <input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" checked="checked" />
                                    <?php } else { ?>
                                    <input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" />
                                    <?php } ?>
                                    <input type="hidden" name="shipping_code[]" value="<?php echo $order['shipping_code']; ?>" /></td>
                                <td class="text-right"><?php echo $order['order_id']; ?></td>
                                <td class="text-right"><?php echo $order['coupon_name']; ?></td>
                                <td class="text-left"><?php echo $order['customer']; ?>
                                </td>
                                <td class="text-left"> <?php if (isset($order['total_customer_orders'])) { ?>
                                    <?php if ($order['total_customer_orders'] == '0') { ?>
                                    Müşteri Üye Değil
                                    <?php } else { ?>
                                    <?php echo $order['total_customer_orders']; ?>
                                    <?php } ?>
                                    <?php } ?></td>
                                <td class="text-left">
                                    <? if ($order ['order_status'] == "İptal Edildi"): ?>
                                    <span class="label label-danger" style="font-size: 13px;"><?= $order['order_status']; ?></span>
                                    <? else: ?>
                                    <?= $order['order_status']; ?>
                                    <? endif; ?>
                                </td>
                                <td class="text-right"><?php echo $order['total']; ?></td>
                                <td class="text-left"><?php echo $order['date_added']; ?></td>
                                <?php if (isset($netgsm_status) && $netgsm_status== 1){ ?>
                                <td style="display:none" id="td[<?php echo $order['order_id']?>]"><?php echo $order['telephone'] ?></td>
                                <?php } ?>
                                <td class="text-left"><?php echo $order['date_modified']; ?></td>

                            </tr>
                            <?php } ?>
                            <?php } else { ?>
                            <tr>
                                <td class="text-center" colspan="8"><?php echo $text_no_results; ?></td>
                            </tr>
                            <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </form>
                <div class="row">
                    <!--<div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
                    <div class="col-sm-6 text-right"><?php echo $results; ?></div>-->
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript"><!--
        $('#button-filter').on('click', function() {
            url = 'index.php?route=sale/coupon_uludaguni_order&token=<?php echo $token; ?>';

            var filter_order_id = $('input[name=\'filter_order_id\']').val();

            if (filter_order_id) {
                url += '&filter_order_id=' + encodeURIComponent(filter_order_id);
            }

            var filter_email = $('input[name=\'filter_email\']').val();

            if (filter_email) {
                url += '&filter_email=' + encodeURIComponent(filter_email);
            }

            var filter_telephone = $('input[name=\'filter_telephone\']').val();

            if (filter_telephone) {
                url += '&filter_telephone=' + encodeURIComponent(filter_telephone);
            }

            var filter_customer = $('input[name=\'filter_customer\']').val();

            if (filter_customer) {
                url += '&filter_customer=' + encodeURIComponent(filter_customer);
            }

            var filter_order_status = $('select[name=\'filter_order_status\']').val();

            if (filter_order_status != '*') {
                url += '&filter_order_status=' + encodeURIComponent(filter_order_status);
            }

            var filter_order_zone = $('select[name=\'filter_order_zone\']').val();

            if (filter_order_zone != '*') {
                url += '&filter_order_zone=' + encodeURIComponent(filter_order_zone);
            }

            var filter_order_payment = $('select[name=\'filter_order_payment\']').val();

            if (filter_order_payment != '*') {
                url += '&filter_order_payment=' + encodeURIComponent(filter_order_payment);
            }

            var filter_total = $('input[name=\'filter_total\']').val();

            if (filter_total) {
                url += '&filter_total=' + encodeURIComponent(filter_total);
            }

            var filter_date_added = $('input[name=\'filter_date_added\']').val();

            if (filter_date_added) {
                url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
            }

            var filter_date_modified = $('input[name=\'filter_date_modified\']').val();

            if (filter_date_modified) {
                url += '&filter_date_modified=' + encodeURIComponent(filter_date_modified);
            }

            var filter_tranfer_order_status = $('select[name=\'filter_tranfer_order_status\']').val();

            if (filter_tranfer_order_status != '*') {
                url += '&filter_tranfer_order_status=' + encodeURIComponent(filter_tranfer_order_status);
            }
            location = url;
        });
        //--></script>
    <script type="text/javascript"><!--
        $('input[name=\'filter_customer\']').autocomplete({
            'source': function(request, response) {
                $.ajax({
                    url: 'index.php?route=customer/customer/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request),
                    dataType: 'json',
                    success: function(json) {
                        response($.map(json, function(item) {
                            return {
                                label: item['name'],
                                value: item['customer_id']
                            }
                        }));
                    }
                });
            },
            'select': function(item) {
                $('input[name=\'filter_customer\']').val(item['label']);
            }
        });
        //--></script>
    <script type="text/javascript"><!--
        $('input[name^=\'selected\']').on('change', function() {
            $('#button-shipping, #button-invoice').prop('disabled', true);

            var selected = $('input[name^=\'selected\']:checked');

            if (selected.length) {
                $('#button-invoice').prop('disabled', false);
            }

            for (i = 0; i < selected.length; i++) {
                if ($(selected[i]).parent().find('input[name^=\'shipping_code\']').val()) {
                    $('#button-shipping').prop('disabled', false);

                    break;
                }
            }
        });

        $('#button-shipping, #button-invoice').prop('disabled', true);

        $('input[name^=\'selected\']:first').trigger('change');

        // IE and Edge fix!
        $('#button-shipping, #button-invoice').on('click', function(e) {
            $('#form-order').attr('action', this.getAttribute('formAction'));
        });

        $('#button-excel-download').on('click', function(e) {
            $('#form-order').attr('action', this.getAttribute('formAction'));

            if (confirm('Excel dosyasını onaylıyor musunuz?')) {

                $('input[name^=\'selected\']:checked').each(function (item, index) {
                    $('.row-item-' + $(this).val()).css("background-color", "#ABFF72");
                });

                $('#form-order').submit();
            } else {
                return false;
            }
        });

        $('#button-delete').on('click', function(e) {
            $('#form-order').attr('action', this.getAttribute('formAction'));

            if (confirm('<?php echo $text_confirm; ?>')) {
                $('#form-order').submit();
            } else {
                return false;
            }
        });
        //--></script>
    <script src="view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
    <link href="view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet" media="screen" />
    <script type="text/javascript"><!--
        $('.date').datetimepicker({
            pickTime: false
        });
        //--></script></div>


<!-- HARUN EDIT -->
<style type="text/css">
    .comment-icon:after, .comment-icon:before {
        bottom: 100%; left: 50%; border: solid transparent; content: " "; height: 0; width: 0; position: absolute; pointer-events: none; }
    .comment-icon:after { border-color: rgba(213, 130, 100, 0); border-bottom-color: #ffffff; border-width: 12px; margin-left: -12px;}
    .comment-icon:before { border-color: rgba(0, 0, 0, 0); border-bottom-color: #dedede;
        border-width: 12px; margin-left: -12px; }
    .comment-description{ background: #ffffff; display: none; left: -131px;position: absolute; top: 45px;
        width: 300px; z-index: 99999999; padding:15px; border:1px solid #dedede;}
    .comment-box{ position:relative; height: 45px;}
    .table-responsive{ overflow-x: unset;}
    .extra-comment:hover .comment-description{ display:block; }
</style>

<script type="text/javascript"><!--
    var token = '';

    // Login to the API
    $.ajax({
        url: '<?php echo $catalog; ?>index.php?route=api/login',
        type: 'post',
        dataType: 'json',
        data: 'key=<?php echo $api_key; ?>',
        crossDomain: true,
        success: function(json) {
            $('.alert').remove();

            if (json['error']) {
                if (json['error']['key']) {
                    $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error']['key'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                }

                if (json['error']['ip']) {
                    $('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error']['ip'] + ' <button type="button" id="button-ip-add" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-danger btn-xs pull-right"><i class="fa fa-plus"></i> <?php echo $button_ip_add; ?></button></div>');
                }
            }

            if (json['token']) {
                token = json['token'];
            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
    });

    //Add Order history
    $("#btn-update-status").on('click', function(e){
        e.preventDefault();
        var order_status_id  = $('#scf_order_status_id option:selected').val();
        var notify  = $('#scf_notify:checked').val();
        var comment  = $('#scf_comment').val();
        var selected = $('.table input[type=checkbox]:checked');

        if(!selected.length) {
            alert('Error: Order selection required to update');
            return;
        }
        notify = (notify == 1) ? 1 : 0;
        $(selected).each(function(){
            var order_id = $(this).val(); //alert(order_id);
            $.ajax({
                url: '<?php echo $catalog; ?>index.php?route=api/order/history&token=' + token + '&order_id=' + order_id,
                type: 'post',
                data:  '&order_status_id=' + encodeURIComponent(order_status_id) + '&notify=' + encodeURIComponent(notify ) + '&comment=' + encodeURIComponent(comment) + '&override=1',
                dataType: 'json',
                crossDomain: true,
                beforeSend: function() {
                    $('#btn-update-status').button('loading');
                },
                complete: function() {
                    $('#btn-update-status').button('reset');
                },
                success: function(json){
                    if(json['success']){
                        $(".notification").html('<div class="alert" style="background:#8fbb6c;color:#ffffff;"><i class="fa fa-check-circle"></i>&nbsp;&nbsp;'+ json['success'] +' <button type="button" class="close" data-dismiss="alert">×</button></div>');
                        //location.reload();
                    }

                    if(json['error']){
                        //alert(json['error']);
                        $(".notification").html('<div class="alert" style="background:#a94442;color:#ffffff;"><i class="fa fa fa-exclamation-circle"></i>&nbsp;&nbsp;'+ json['error'] +' <button type="button" class="close" data-dismiss="alert">×</button></div>');
                    }
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });
        });
    });
    //--></script>
<!-- END HARUN EDIT -->

<script>
    $('#input-order-id,#input-email,#input-filter_telephone,#input-customer').keyup(function(e){
        if(e.keyCode == 13)
            $('#button-filter').trigger("click");
    });
</script>



<?php echo $footer; ?>