<?php
 echo @$_GET['msg'];
  session_start();
  if(isset($_SESSION['userId'])){ 
include 'template/header.php';

?>


<div class="ch-container">
    <div class="row">
        
<!-- SIDEBAR HERE-->
<?php

include 'template/sidebar.php';

?>
       <style type="text/css">
@media only screen and (max-width: 600px) {
           .inp-box{
max-width: 100%;
           }
       }



       </style>



        <div id="content" class="col-lg-10 col-sm-10">
            <!-- content starts -->
            <div>
    <ul class="breadcrumb">
        
        <li>
            <a href="dashboard.php">Dashboard</a>
        </li>
         <li>
            <a href="accrg.php">User Detail</a>
        </li>
    </ul>
</div>

<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well">
                <h2><i class="glyphicon glyphicon-info-sign"></i> Add / Update User</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content row">
                <div class="col-lg-12 col-md-12">
                 
                                     <p>Select User</p>
                        
                      <select id="userid" class="form-control selectpicker"data-live-search="true"> 
                                         <?php
                    require 'connection.php'; 
         $qry = "SELECT * FROM userreg";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
                                         <option value="<?php echo $row['userid']; ?>"><?php echo $row['username']; ?></option>
                                     <?php } ?>
                                     </select>
<br>
<input class="inp-box" id="usrname" autocomplete="off"  type="text" placeholder="New UserName" style="padding: 2px; width: 500px; margin-bottom: 10px; margin-top: 10px;"></input>
<br>
<input class="inp-box" id="olpas" autocomplete="off"  type="Password" placeholder="Old Password" style="padding: 2px; width: 500px; margin-bottom: 10px; margin-top: 10px;"></input>
<br>

<input class="inp-box" id="newpas" autocomplete="off"  type="Password" placeholder="New Password" style="padding: 2px; width: 500px; margin-bottom: 10px; margin-top: 10px;"></input>
<br>

<input class="inp-box" id="conpas" autocomplete="off"  type="Password" placeholder="Confirm Password" style="padding: 2px; width: 500px; margin-bottom: 10px; margin-top: 10px;"></input>


                   
                                     <br>
                                
                                        <br>
                                     <button id="svbtn" class="btn btn-sm btn-primary">Save Record</button>

                </div>
            </div>
        </div>
    </div>
</div>


<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well">
                <h2><i class="glyphicon glyphicon-info-sign"></i> List of Accounts</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content row">
                <div class="col-lg-12 col-md-12">
                  <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
    <thead>
    <tr>
        <th>ID</th>
        <th>User Name</th>
      
    </tr>
    </thead>
    <tbody>

                      <?php
                    require 'connection.php'; 
         $qry = "SELECT userid, username FROM userreg  order by userid ASC";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
                                     
           <tr>
        <td class="center"><?php echo $row['userid']; ?></td>
        <td class="center"><?php echo $row['username']; ?></td>
      
    </tr>

                                     <?php } ?>


         </tbody>
    </table>
                       



                </div>
            </div>
        </div>
    </div>
</div>


    <!-- content ends -->
    </div><!--/#content.col-md-0-->
</div><!--/fluid-row-->


    <hr>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">

        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">×</button>
                    <h3>Settings</h3>
                </div>
                <div class="modal-body">
                    <p>Here settings can be configured...</p>
                </div>
                <div class="modal-footer">
                    <a href="#" class="btn btn-default" data-dismiss="modal">Close</a>
                    <a href="#" class="btn btn-primary" data-dismiss="modal">Save changes</a>
                </div>
            </div>
        </div>
    </div>

<?php
include 'template/footer.php';
?>

<script>
    $("#svbtn").click(function(){

      var userid = $('#userid').val();
      var usrname = $('#usrname').val();
      var olpas = $('#olpas').val();
      var newpas = $('#newpas').val();
      var conpas = $('#conpas').val();

      $('#svbtn').hide();
      event.preventDefault();
 
            $.ajax({
        url: 'aduserrg.php',
        method: 'POST',
       data: {userid: userid, usrname: usrname, olpas: olpas, newpas: newpas, conpas: conpas},
        success: function(data){
            // $('#prate').val(data);
            alert(data);
      $('#svbtn').show();

        }
      })

    });

</script>

     <script type="text/javascript">
  $('.table tbody').on('click','.edtbtn',function(){
    var currow = $(this).closest('tr');
    var acid = currow.find('td:eq(0)').text();
    var acname = currow.find('td:eq(1)').text();
    var addrs = currow.find('td:eq(3)').text();
    var contct = currow.find('td:eq(2)').text();
    $("#accidlbl").html(acid);  
    $("#edtaccname").val(acname);
    $("#edtaddrs").val(addrs);
    $("#mobno").val(contct);

  $('#myModal').modal('toggle');

  });
</script>

     <script type="text/javascript">
    $("#btnupdt").click(function(){

      var accid = $('#accidlbl').html();
      var grpid = $('#selgrp').val();
      var accnam = $('#edtaccname').val();
      var adrsbox = $('#edtaddrs').val();
      var contbox = $('#mobno').val();

      event.preventDefault();
 
            $.ajax({
        url: 'adaccrg.php',
        method: 'POST',
       data: {accid: accid, grpid: grpid, grpid: grpid, accnam: accnam, adrsbox: adrsbox, contbox: contbox},
        success: function(data){
            // $('#prate').val(data);
            alert(data);
            location.reload();


        }
      })

    });

</script>

     <script type="text/javascript">
    $("#btndlt").click(function(){

      var acciddlt = $('#accidlbl').html();


      event.preventDefault();
 
            $.ajax({
        url: 'adaccrg.php',
        method: 'POST',
       data: {acciddlt: acciddlt},
        success: function(data){
            // $('#prate').val(data);
            alert(data);
            location.reload();


        }
      })

    });

</script>

<?php } ?>