<?php require_once(APPPATH.'/views/header.php'); ?>
<body>
    <div id="wrapper">
    <?php require_once(APPPATH.'/views/menu_user.php'); ?>
        <div id="page-wrapper">
            <div class="container-fluid">
                <fieldset class="admin-border">
                <fieldset class="scheduler-border">
                <legend class="scheduler-border"><?php echo $title;?> <a href="<?=base_url();?>adm/client/add" class="btn btn-primary"><i class="fa fa-plus"></i></a></legend>
                
                <div class="row">
                    <div>
                        <table class="table table-condensed" id="list"></table>
                        <div id="gridpager"></div> 
                        <div id="filterToolbar"></div>   
                                
                    </div>
                </div>
                <br/>
            </fieldset>
            </fieldset>
            </div>
        </div>
        <!-- /#page-wrapper -->
    </div>
    <div id="gif" class="modal fade loading-gif">
        <div class="modal-dialog">
            <div>
                <img src="<?=base_url()?>img/loading.gif">
            </div>
        </div>
    </div>
    <!-- /#wrapper -->
<?php require_once(APPPATH.'/views/footer.php'); ?> 
<script>
        $(document).ready(function(){

                jQuery("#list").jqGrid({
                  url:'<?=base_url()."adm/client/loadData"?>',      //another controller function for generating data
                  mtype : "post",             //Ajax request type. It also could be GET
                  datatype: "json",            //supported formats XML, JSON or Arrray
                  colNames:<?=(isset($colNames) && $colNames)? $colNames : '';?>,       //Grid column headings
                  colModel:<?=(isset($colModel) && $colModel)? $colModel : '';?>,
                  rowNum:30,
                  width: null,
                  shrinkToFit: true,
                  autowidth: true,
                  height: null,
                  rowList:[5,10,20,30],
                  pager: '#gridpager',
                  sortname: 'id_client',
                  viewrecords: true,
                  sortorder: 'DESC',
                  rownumbers: true,
                  gridview: true
              }).navGrid('#gridpager',{edit:false,add:false,del:false,excel:true})
              .navButtonAdd('#gridpager',{
                caption:"",
                title:"Search", 
                buttonicon:"ui-icon-search", 
                onClickButton: function(){ 
                    jQuery("#list").jqGrid('searchGrid', 
                        {sopt:['cn','eq','ne'],
                        multipleSearch:true}
                    );
                }, 
                
                position:"center"
             });

             jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn"});  
             $("#search_list").css('display','none');
    
        });
            function chg(id,st)
            {
                        var yes = confirm('Doriti sa schimbati starea acestui client?');
                        
                        if(yes)
                        {
                            var c_data  =   {ajax:'1', id:id, stare:st};
                            $.ajax({
                                url : "<?php echo base_url();?>adm/client/change",
                                type:"POST",
                                data: c_data,
                                success: function(data, textStatus, jqXHR)
                                {
                                    jQuery("#list").setGridParam({url:'<?=base_url()."adm/client/loadData"?>'});
                                    jQuery("#list").trigger("reloadGrid");
                                    my_type = 'success';
                                    my_msg  = 'Actualizare cu success!';
                                    Lobibox.notify(my_type, {
                                        title:'Informare',
                                        msg: my_msg,
                                        icon: 'fa fa-check',
                                        position: "top right"
                                    });
                                },
                                error: function (jqXHR, textStatus, errorThrown)
                                {  
                                }
                            });
                        }
            } 

            function deleteClient(id)
            {
                var yes = confirm('Doriti sa eliminati acest client?');
                        
                        if(yes)
                        {
                            var c_data  =   {ajax:'1', id:id};
                            $.ajax({
                                url : "<?php echo base_url();?>adm/client/delete",
                                type:"POST",
                                data: c_data,
                                success: function(data, textStatus, jqXHR)
                                {
                                    jQuery("#list").setGridParam({url:'<?=base_url()."adm/client/loadData"?>'});
                                    jQuery("#list").trigger("reloadGrid");
                                    my_type = 'success';
                                    my_msg  = 'Stergere cu success!';
                                    Lobibox.notify(my_type, {
                                        title:'Informare',
                                        msg: my_msg,
                                        icon: 'fa fa-check',
                                        position: "top right"
                                    });
                                },
                                error: function (jqXHR, textStatus, errorThrown)
                                {  
                                }
                            });
                        }
            }
</script>      
</body>
</html>