<?php

    /*
     * Acest fisier contine informatiile din Home Page.
     */

    $ci = &get_instance();
    
?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title><?php echo "Admin";?></title>

    <!-- Bootstrap Core CSS -->
    <link href="<?php echo base_url();?>css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="<?php echo base_url();?>css/sb-admin.css" rel="stylesheet">
    <link type="text/css" href="<?php echo base_url()?>js/plugins/jqgrid/css/ui.jqgrid.css" rel="stylesheet" />
    <link type="text/css" href="<?php echo base_url()?>js/plugins/jqgrid/plugins/searchFilter.css" rel="stylesheet" />
    <link type="text/css" href="<?php echo base_url()?>js/plugins/jqgrid/css/ui.jqgrid-bootstrap.css" rel="stylesheet" />

    <!-- Custom Fonts -->
    <link href="<?php echo base_url();?>font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- jQuery Version 1.11.0 -->
    <script src="<?php echo base_url();?>js/jquery-1.11.0.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="<?php echo base_url();?>js/bootstrap.min.js"></script>
    
    <script src="<?php echo base_url();?>js/jquery.floatThead.min.js"></script>
    <script type="text/javascript" charset="utf8" src="<?php echo base_url();?>js/jquery-ui.js"></script>


    <!--jQgrid-->
    <script type="text/javascript" src="<?php echo base_url(); ?>js/plugins/jqgrid/js/i18n/grid.locale-en.js"></script>

    <script type="text/javascript" src="<?php echo base_url(); ?>js/plugins/jqgrid/js/jquery.jqGrid.min.js"></script>

    <link href="<?php echo base_url();?>css/jquery-ui.css" rel="stylesheet">
    <style>

    .showActive
        {
            margin-bottom: 5px;
            float: right;
        }
        
        input[type="text"].form-control,select.form-control{
            float : left;
            margin-left: 0px;
            margin-bottom: 2px;
        }

        #search_reset,#search_submit{
            float : left;
            margin-left: 5px;
            margin-bottom:10px;
        }
        .ui-widget-header {
            background: #74b2e2 !important;
        }
        .ui-state-default {
            background: #ffffff !important;
        }
        #list{
            border: none !important;  
        }
        .ui-jqdialog {
            display: none;
            /*width: 300px;*/
            position: absolute;
            padding: .2em;
            font-size: 11px;
            overflow: visible;
        }
        .ui-jqdialog-titlebar-close{
            padding: 0px !important;
        }
        table{
            font-size: 16px;
            font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
        }
        .ui-jqgrid tr.jqgrow td {font-size:14px}

    .chgCol{
        color: #68A3C6;
    }
    
    .chgCol:hover,.chgText:hover{
        cursor: pointer;
    }
    
    .unreadM{
        font-weight: bold;
    }
    
    .envelopeRead{
        width: 15px;
        height: 15px;
        margin-bottom: 5px;
    }
    
    .envelopeUnread{
        color: black;
    }
    .tooltip-inner {
        color: #000000;
        background: #FFFFFF;
        border: solid 1px #000000;
        font-size: 14px !important;
      }
      pre {
          height: auto !important;
      }
      div.ui-datepicker{
        font-size:10px;
     } 
    </style>
    
</head>

<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 "Utilizatori";?></legend>
                
                <a class="btn btn-primary" id="add">Adauga utilizator</a>
                Coduri:  {nume}, {prenume}, {email}, {telefon}, {compania}, {adresa}, {cui}, {nr_registru}, {banca}, {cont}
                <div class="clearfix"></div><br/>
                <div class="row">
                            <div>
                                <table class="table table-condensed" id="list"></table>
                                <div id="gridpager"></div> 
                                <div id="filterToolbar"></div>   
                                
                            </div>
                </div>
                <br/>
                <!-- <a id="export_csv" class="btn btn-primary" >Export Excel</a> -->
            </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 -->
    <div id="add_modal" class="modal fade">
       <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                   <h4 class="modal-title"><?='Adauga Utilizator';?></h4>
               </div>
               <div class="modal-body">                                        
                   <div style="background-color: white;" class="form-group">  
                       <label>Nume* </label><br />
                       <input class="form-control" type="text" id="nume"  name="nume" placeholder="Nume..." />    
                   </div> 

                   <div style="background-color: white;" class="form-group">  
                       <label>Prenume* </label><br />
                       <input class="form-control" type="text" id="prenume"  name="prenume" placeholder="Prenume..." />    
                   </div> 

                   <div style="background-color: white;" class="form-group">  
                       <label>Email* </label><br />
                       <input class="form-control" type="text" id="email"  name="email" placeholder="Email..."  />    
                   </div> 

                   <div style="background-color: white;" class="form-group">  
                       <label>Utilizator* </label><br />
                       <input class="form-control" type="text" id="utilizator"  name="utilizator" placeholder="Utilizator..." />    
                       <span class="text-danger" id="utl_status"></span>
                   </div> 

                   <div style="background-color: white;" class="form-group">  
                       <label>Parola* </label><br />
                       <input class="form-control" type="text" id="parola"  name="parola" placeholder="Parola..." />    
                   </div> 
                   
                   <span id="alert_mod" style=" color: red;"></span>
               </div>
               <div class="modal-footer">
                   <button type="button" class="btn btn-default" data-dismiss="modal"><?='Inchide';?></button>
                   <a id="add_btn" class="btn btn-primary">Adauga</a>
               </div>
            </div>
        </div>
    </div>
    <div id="edit_modal" class="modal fade">
       <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                   <h4 class="modal-title"><?='Modifica utilizator';?></h4>
               </div>
               <div class="modal-body">   
                   <input type="hidden" id="edit_id" />                                     
                   <div style="background-color: white;" class="form-group">  
                       <label>Nume* </label><br />
                       <input class="form-control" type="text" id="nume_edit"  name="nume_edit" placeholder="Nume..." />    
                   </div> 

                   <div style="background-color: white;" class="form-group">  
                       <label>Prenume* </label><br />
                       <input class="form-control" type="text" id="prenume_edit"  name="prenume_edit" placeholder="Prenume..." />    
                   </div> 

                   <div style="background-color: white;" class="form-group">  
                       <label>Email* </label><br />
                       <input class="form-control" type="text" id="email_edit"  name="email_edit" placeholder="Email..."  />    
                   </div> 
                   <span id="ed_alert_mod" style=" color: red;"></span>
               </div>
               <div class="modal-footer">
                   <button type="button" class="btn btn-default" data-dismiss="modal"><?='Inchide';?></button>
                   <a id="save_btn" class="btn btn-primary">Salveaza</a>
               </div>
            </div>
        </div>
    </div>

    <div id="pass_modal" class="modal fade">
       <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                   <h4 class="modal-title"><?='Parola utilizator';?></h4>
               </div>
               <div class="modal-body">   
                   <input type="hidden" id="pass_id" />                                     
                   <div style="background-color: white;" class="form-group">  
                      <h3 id="utilizator_pass" ></h3>
                          
                   </div> 

                   <div style="background-color: white;" class="form-group">  
                       <label>Parola* </label><br />
                       <input class="form-control" type="text" id="parola_pass"  name="parola_pass" placeholder="Parola..." />    
                   </div> 

                   <span id="pass_alert_mod" style=" color: red;"></span>
               </div>
               <div class="modal-footer">
                   <button type="button" class="btn btn-default" data-dismiss="modal"><?='Inchide';?></button>
                   <a id="save_btn_pass" class="btn btn-primary">Salveaza</a>
               </div>
            </div>
        </div>
    </div>

    <div id="drept_modal" class="modal fade">
       <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                   <h4 class="modal-title"><?='Drepturi utilizator';?></h4>
               </div>
               <div class="modal-body">   
                   <input type="hidden" id="drept_id" />                                     
                   <div style="background-color: white;" class="form-group">  
                    <h3 id="utilizator_drept" ></h3>
                           
                   </div> 

                   <div style="background-color: white;" class="form-group" id="drepturi_content">  
 
                   </div> 

                   <span id="drept_alert_mod" style=" color: red;"></span>
               </div>
               <div class="modal-footer">
                   <button type="button" class="btn btn-default" data-dismiss="modal"><?='Inchide';?></button>
                   <a id="save_btn_drept" class="btn btn-primary">Salveaza</a>
               </div>
            </div>
        </div>
    </div>

<script>
            
        $(document).ready(function(){

            $('#utilizator').keyup(function() {
                var utl = $(this).val();
                if(utl != ''){
                    var info    = {ajax:'1',utl:utl};
                            $.ajax({
                               url : "<?php echo base_url();?>admin/utilizator/existaUtilizator",
                               type:"POST",
                               data: info,
                                   success: function(data, textStatus, jqXHR)
                                   {
                                      $('#utl_status').text(data);
                                   },
                                   error: function (jqXHR, textStatus, errorThrown)
                                   {   
                                   }
                    }); 
                } else {
                    $('#utl_status').text('');
                }
            });


            $("#add").click(function(){
                $("#add_modal").modal('show');
            });


            $("#add_btn").click(function(){
                        var nu = $("#nume").val();
                        var pre = $("#prenume").val();
                        var em = $("#email").val();
                        var ut = $("#utilizator").val();
                        var pa = $("#parola").val();

                        if(nu && pre && em && ut && pa)
                        {
                            $("#add_btn").attr('disabled', true);
                            $('#gif').modal('show');
                            var info    = {ajax:'1',nu:nu, pre:pre, em:em, ut:ut, pa:pa};
                            $.ajax({
                               url : "<?php echo base_url();?>admin/utilizator/add",
                               type:"POST",
                               data: info,
                                   success: function(data, textStatus, jqXHR)
                                   {
                                      window.location.href=window.location.href;
                                   },
                                   error: function (jqXHR, textStatus, errorThrown)
                                   {   
                                   }
                           }); 
                       }
                       else
                       {
                        $("#alert_mod").text("Atentie! Completati campurile obligatorii!");
                       }

            });  

            $("#save_btn").click(function(){
                        var id = $("#edit_id").val();
                        var nu = $("#nume_edit").val();
                        var pre = $("#prenume_edit").val();
                        var em = $("#email_edit").val();

                        if(nu && pre && em)
                        {
                            $("#save_btn").attr('disabled', true);
                            $('#gif').modal('show');
                            var info    = {ajax:'1',id:id, nu:nu, pre:pre, em:em};
                            $.ajax({
                               url : "<?php echo base_url();?>admin/utilizator/save",
                               type:"POST",
                               data: info,
                                   success: function(data, textStatus, jqXHR)
                                   {
                                       window.location.href=window.location.href;
                                   },
                                   error: function (jqXHR, textStatus, errorThrown)
                                   {   
                                   }
                           }); 
                       }
                       else
                       {
                        $("#ed_alert_mod").text("Atentie! Completati campurile obligatorii!");
                       }

            }); 

            $("#save_btn_pass").click(function(){
                        var id = $("#pass_id").val();
                        var pa = $("#parola_pass").val();

                        if(id && pa)
                        {
                            $("#save_btn_pass").attr('disabled', true);
                            $('#gif').modal('show');
                            var info    = {ajax:'1',id:id, pa:pa};
                            $.ajax({
                               url : "<?php echo base_url();?>admin/utilizator/parola",
                               type:"POST",
                               data: info,
                                   success: function(data, textStatus, jqXHR)
                                   {
                                       window.location.href=window.location.href;
                                   },
                                   error: function (jqXHR, textStatus, errorThrown)
                                   {   
                                   }
                           }); 
                       }
                       else
                       {
                        $("#pass_alert_mod").text("Atentie! Completati campurile obligatorii!");
                       }

            }); 

            $("#save_btn_drept").click(function(){
                        var id = $("#drept_id").val();
                        var drepturi = $(".rightUser").serialize();
                        if(id)
                        {
                            $("#save_btn_pass").attr('disabled', true);
                            $('#gif').modal('show');
                            var info    = {ajax:'1',id:id, drepturi:drepturi};
                            $.ajax({
                               url : "<?php echo base_url();?>admin/utilizator/saveDrepturi",
                               type:"POST",
                               data: info,
                                   success: function(data, textStatus, jqXHR)
                                   {
                                       window.location.href=window.location.href;
                                   },
                                   error: function (jqXHR, textStatus, errorThrown)
                                   {   
                                   }
                           }); 
                       }
                       else
                       {
                        $("#pass_alert_mod").text("Atentie! Completati campurile obligatorii!");
                       }

            }); 

            jQuery("#list").jqGrid({
                  url:'<?=base_url()."admin/utilizator/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_utilizator',
                  viewrecords: true,
                  sortorder: 'DESC',
                  rownumbers: true,
                  onCellSelect: function(rowid, icol, cellcontent, e) {if(icol > 0 && icol < 9)
                    { myCellSelect(rowid, icol,e); } }, 
                  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 edit(id)
        {
                            var info    = {ajax:'1',id:id};
                            $.ajax({
                               url : "<?php echo base_url();?>admin/utilizator/info",
                               type:"POST",
                               data: info,
                                   success: function(data, textStatus, jqXHR)
                                   {

                                        var info = jQuery.parseJSON(data); 
                                        $('#nume_edit').val(info[0].nume);
                                        $('#prenume_edit').val(info[0].prenume);
                                        $('#email_edit').val(info[0].email);
                                        $('#edit_id').val(id);

                                        $('#edit_modal').modal('show');
                                   },
                                   error: function (jqXHR, textStatus, errorThrown)
                                   {   
                                   }
                           }); 
        }

        function changePass(id)
        {
                    var ut = $("#utl"+id).val();
                    var dialog = $("#confirmare").dialog({
                    height:200,closeOnEscape: false,width: "30%",modal: true,
                    show: {effect: "blind"},
                    position: {my: 'top', at: 'top+100'},
                    open: function(event, ui) {var markup = "Doresti sa schimbi parola la acest utilizator?";
                    $(".ui-dialog-titlebar-close").hide();
                    $(this).html(markup);},
                    buttons: {"Da": function() { 
                        $("#confirmare").dialog( "close" );
                        $('#utilizator_pass').html(ut);
                        $('#pass_id').val(id);
                        $('#pass_modal').modal('show');
                    },
                    "Nu": function() {$("#confirmare").dialog( "close" );}}
                    }).prev(".ui-dialog-titlebar").css("border","none").css("background","white");       
        }

        function del(id)
        {
                    var dialog = $("#confirmare").dialog({
                    height:200,closeOnEscape: false,width: "30%",modal: true,
                    show: {effect: "blind"},
                    position: {my: 'top', at: 'top+100'},
                    open: function(event, ui) {var markup = "Doresti sa stergeti acest utilizator?";
                    $(".ui-dialog-titlebar-close").hide();
                    $(this).html(markup);},
                    buttons: {"Da": function() { 
                        
                        var info    = {ajax:'1',id:id};
                        $.ajax({
                               url : "<?php echo base_url();?>admin/utilizator/delete",
                               type:"POST",
                               data: info,
                                   success: function(data, textStatus, jqXHR)
                                   {
                                      window.location.href=window.location.href;
                                      $("#confirmare").dialog( "close" );
                                   },
                                   error: function (jqXHR, textStatus, errorThrown)
                                   {   
                                   }
                        }); 
                        
                    },
                    "Nu": function() {$("#confirmare").dialog( "close" );}}
                    }).prev(".ui-dialog-titlebar").css("border","none").css("background","white");       
        }

        function drepturi(id)
        {
                    var dialog = $("#confirmare").dialog({
                    height:200,closeOnEscape: false,width: "30%",modal: true,
                    show: {effect: "blind"},
                    position: {my: 'top', at: 'top+100'},
                    open: function(event, ui) {var markup = "Doresti sa modifici drepturile pentru acest utilizator?";
                    $(".ui-dialog-titlebar-close").hide();
                    $(this).html(markup);},
                    buttons: {"Da": function() { 
                        var ut = $("#utl"+id).val();   
                        var info    = {ajax:'1',id:id};
                        $.ajax({
                               url : "<?php echo base_url();?>admin/utilizator/drepturi",
                               type:"POST",
                               data: info,
                                   success: function(data, textStatus, jqXHR)
                                   {
                                      $("#confirmare").dialog( "close" );
                                      $('#utilizator_drept').html(ut);
                                      $('#drepturi_content').html(data);

                                      $('#drept_id').val(id);
                                      $('#drept_modal').modal('show');
                                   },
                                   error: function (jqXHR, textStatus, errorThrown)
                                   {   
                                   }
                        }); 
                        
                    },
                    "Nu": function() {$("#confirmare").dialog( "close" );}}
                    }).prev(".ui-dialog-titlebar").css("border","none").css("background","white");       
        }


</script>      
</body>

</html>
