<!-- Main Content -->

<div class="page-wrapper">

    <div class="container-fluid pt-25">

        <div class="row">

            <div class="col-md-12">

                <div class="alert alert-success alert-dismissible" role="alert" <?php if($this->session->flashdata('message')==''){ ?> style="display:none" <?php } ?> >

                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>

                    <?php echo $this->session->flashdata('message'); ?>

                </div>

            </div>

        </div>

        <!-- Row -->

        <div class="row">

            <div class="col-sm-12">

                <div class="panel panel-default card-view">

                    <div class="panel-heading">

                        <div class="pull-left">

                            <h6 class="panel-title txt-dark">Pincode List</h6>

                        </div>

                        <div class="clearfix"></div>

                    </div>

                    <div class="panel-wrapper collapse in">

                        <div class="panel-body">

                            <div class="table-wrap">

                                <div class="table-responsive">

                                    <table id="datable_1-1" class="table table-bordered table-striped">
                                        <thead align="center">
                                            <tr>
                                                <td colspan="6"><?php echo (isset($h1)?$h1:""); ?></td>
                                                <td colspan="7">
                                                    <div class="col-md-8">&nbsp;</div>
                                                    <div class="col-md-4">
                                                        <select id="admin_length" class="pull-right form-control">
                                                            <option value="10" <?php echo ($this->perPage==10)?'selected':""; ?>>10</option>
                                                            <option value="20" <?php echo ($this->perPage==20)?'selected':""; ?>>20</option>
                                                            <option value="50" <?php echo ($this->perPage==50)?'selected':""; ?>>50</option>
                                                            <option value="100" <?php echo ($this->perPage==100)?'selected':""; ?>>100</option>
                                                            <option value="250" <?php echo ($this->perPage==250)?'selected':""; ?>>250</option>
                                                            <option value="500" <?php echo ($this->perPage==500)?'selected':""; ?>>500</option>
                                                        </select>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr><td colspan="6" style="color: red;"><?php echo (isset($h2)?$h2:""); ?></td>
                                                <td colspan="7">
                                                    <!-- <div class="text-center" id="links"><?php echo (isset($links))?$links:""; ?></div> -->
                                                </td>
                                            </tr>
                                        </thead>
                                        <thead>
                                            <tr>
                                                <th>Sr. No.</th>
                                                <th>Pincode</th>
                                                <th>City</th>
                                                <th>State</th>
                                                <th>State Code</th>
                                                <th>Prepaid</th>
                                                <th>Reverse Pikup</th>
                                                <th>REPL</th>
                                                <th>Cod</th>
                                                <th>Dispatch Center</th>
                                                <th>sort code</th>
                                                <th>value capping</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php if($pincode){ foreach ($pincode as $key => $value) : ?>
                                                <tr id="<?php echo "pincode_".$value['id']; ?>">
                                                    <td><?php echo ($k++); ?></td>
                                                    <td><?php echo $value['pincode']; ?></td>
                                                    <td><?php echo $value['city']; ?></td>
                                                    <td><?php echo $value['state']; ?></td>
                                                    <td><?php echo $value['state_code']; ?></td>
                                                    <td><?php echo $value['prepaid']; ?></td>
                                                    <td><?php echo $value['reverse_pikup']; ?></td>
                                                    <td><?php echo $value['repl']; ?></td>
                                                    <td><?php echo $value['cod']; ?></td>
                                                    <td><?php echo $value['dispatch_center']; ?></td>
                                                    <td><?php echo $value['sort_code']; ?></td>
                                                    <td><?php echo $value['value_capping']; ?></td>
                                                    <th><a href="javascript:void(0)" class="ajax_delete" data-table="pincode" data-value="<?php echo "id_".$value['id']; ?>"> <i class="fa fa-trash-o fa-lg"></i></a></th>
                                                </tr>
                                            <?php endforeach; } ?>
                                        </tbody>
                                    </table>

                                </div>

                            </div>

                        </div>
                        <div class="panel-footer clearfix">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="text-center"><?php echo (isset($links))?$links:""; ?></div>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>  

            </div>

        </div>

        <!-- /Row -->

    </div>

<script type="text/javascript">

    var site_url = "<?php echo base_url(); ?>";
    var urlLink = "<?php echo A; ?>";

    $(".ajax_delete").on("click",function(){

        var id = $(this).attr("data-value");

        var split = id.split("_");

        //alert(split[0]);

        var table = $(this).attr("data-table");

        var image = ($(this).attr("data-image")=="undefined")?"":$(this).attr("data-image");

        var result = confirm("Really want to delete?");

        if(result) {

            $.ajax({

                url: site_url+urlLink+"/ajaxDelete",

                type: "POST",

                data: split[0]+"="+split[1]+"&table="+table+"&image="+image,

                success: function(result){

                    if(result==1)

                    {

                        $("#"+table+"_"+split[1]).remove();

                    }

                }

            });

        }

    });
</script>
<script type="text/javascript">
    var path = "<?php echo base_url(A); ?>";
    $("#admin_length").on("change",function(){
        var length = $(this).val();
        $.ajax({
            url: path+"/AdminSearchLength",
            type:"POST",
            data:"length="+length,
            success: function(result){
                if(result==1){
                    window.location.reload();
                }
            }
        });
    });
</script>