<style>
    .item-btn-special {
        background-color: #00AEEF;
        color: #FFFFFF;
        height: 55px!important;
    }
</style>
<div style="display:none">
    <div id="SpecialPopup" class="popupouter">
        <form id="specialFormCustom">
            <div class="custom-modify-block">
                <div class="form-group">
                    <?php echo form_label('Custom', 'customSpecial', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-capitalize')); ?>
                    <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                        <input type="text" name="quantity" class="form-control">
                    </div>
                    <input type="hidden" name="order_id" value="<?php isset($order_id) ? print $order_id : print $this->Orders_Model->get_current_orderid() ?>">
                    <input type="hidden" class="specialLine_custom" name="line" value="">
                    <input type="hidden" name="action" value="special">
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-8 col-sm-offset-4"><a class="btn btn-sm btn-block btn-danger round" onclick="submitSpecial('specialFormCustom', 'custom')">Add</a></label>
                </div>
            </div>
        </form>
        <?php $specials = get_specials(); ?>
        <?php if (!empty($specials)): ?>
            <?php foreach ($specials as $aspecial): ?>
                <a class="inline item-btn item-btn-special col-lg-4 col-md-4 col-sm-4 col-xs-4 menu-item text-center" onclick="submitSpecial('specialForm_<?php echo $aspecial->id ?>', '<?php echo $aspecial->id ?>')"><?php echo ucwords(strtolower($aspecial->title)) ?></a>
                <form id="specialForm_<?php echo $aspecial->id ?>">
                    <input name="quantity" type="hidden" value="<?php echo $aspecial->title ?>">
                    <input type="hidden" name="order_id" value="<?php isset($order_id) ? print $order_id : print $this->Orders_Model->get_current_orderid() ?>">
                    <input type="hidden" class="specialLine_<?php echo $aspecial->id ?>" name="line" value="">
                    <input type="hidden" name="action" value="special">
                </form>
            <?php endforeach; ?>
        <?php else: ?>
            <p style="color: #ffffff">No Specials/modify record found. Please list them first</p>
        <?php endif; ?>

    </div>
    <script>
        function addSpecial(order_id) {
            
            var line = $('#selectedRow').val();
            var CurrentOrderTotal = $('#CurrentOrderTotal').val();
            ALERT_TITLE = "<?php echo $this->lang->line('gkpos_alert_title_warning') ?>";
            if (!order_id) {
                alert("<?php echo $this->lang->line('gkpos_make_order_sure') ?>");
            } else {
                if (CurrentOrderTotal <= 0) {
                    alert("<?php echo $this->lang->line('gkpos_put_item_on_cart') ?>");
                } else if (!line) {
                    alert("<?php echo $this->lang->line('gkpos_select_item_row_to_change_quantity') ?>");
                } else {
                    var element = '<a href="javascript:void(0)" onclick="addSpecial(\'' + order_id + '\')">' + 'Add Special/Modify' + '</a>';
                    $('#menuBreadcurmb').html(element);
                    $('#selectrionBreadcurmb').html('');
                    var SpecialPopup = $("#SpecialPopup").html();
                    $('#menuListArea').html(SpecialPopup);
                    return false;
                }
            }

        }
        function submitSpecial(specialItemForm, specialItemId) {
            var line = $('#selectedRow').val();
            $('#' + specialItemForm + ' .specialLine_' + specialItemId).val(line);
            var myform = document.getElementById(specialItemForm);
            var formdata = new FormData(myform);
            $.ajax({
                url: '<?php echo site_url('gkpos/orders/updatecart') ?>',
                data: formdata,
                cache: false,
                processData: false,
                contentType: false,
                type: 'POST',
                dataType: 'json',
                success: function (output) {
                    if (typeof output.line !== 'undefined') {
                        loadCart(output.order_id, output.line);
                    } else {
                        loadCart(output.order_id, false);
                    }
                }
            });
        }
    </script>
</div>