<?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) {
           #grpname{
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="grprg.php">Group Of Accounts</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 Group</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">
                 
                        <input id="grpname" autocomplete="off"  type="text" placeholder="Enter Group of Account" style="padding: 2px; width: 500px; margin-bottom: 10px;"></input>
                   
                                     <br>

                      <select id="chrtid" class=" selectpicker"data-live-search="true"> 
                                         <?php
                    require 'connection.php'; 
         $qry = "SELECT * FROM chartacc";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
                                         <option value="<?php echo $row['chartid']; ?>"><?php echo $row['chartname']; ?></option>
                                     <?php } ?>
                                     </select>

                                       <select  id="grptype" class=" selectpicker"data-live-search="true"> 
                                    
                                         <option value="1">1st Group</option>
                                         <option value="2">2nd Group</option>
                                         <option value="3">Other Group</option>
                                   
                                     </select>
                                        <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 Groups</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>Group Name</th>
        <th>Type</th>
        <th>Head</th>
        <th>Actions</th> 
    </tr>
    </thead>
    <tbody>

                      <?php
                    require 'connection.php'; 
         $qry = "SELECT groupid,groupname,chartname,grouptype FROM groupreg inner join chartacc on groupreg.chartid=chartacc.chartid order by groupid ASC";
             $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
    while($row = mysqli_fetch_array($run)){
?>
                                     
           <tr>
        <td class="center"><?php echo $row['groupid']; ?></td>
        <td class="center"><?php echo $row['groupname']; ?></td>
        <td class="center">

            <?php 
            if ($row['grouptype']==1){
                echo "1st Group";
            } 
            if ($row['grouptype']==2){
                echo "2nd Group";
            } 
if ($row['grouptype']==3){
                echo "Other Group";
            } 
            ?>
            

        </td>
        <td class="center"><?php echo $row['chartname']; ?></td>

  
        <td class="center">
            <a class="btn btn-sm btn-info" href="#">
                <i class="glyphicon glyphicon-edit icon-white"></i>
                Edit
            </a>
        </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>
$(document).ready(function(){

    $("#svbtn").click(function(){

      var grpname = $('#grpname').val();
      var chrtid = $('#chrtid').val();
      var grptype = $('#grptype').val();
      $('#svbtn').hide();
      event.preventDefault();
 
            $.ajax({
        url: 'adgrp.php',
        method: 'POST',
       data: {grpname: grpname, chrtid: chrtid, grptype: grptype},
        success: function(data){
            // $('#prate').val(data);
            alert(data);
      $('#svbtn').show();

        }
      })

    });


});
</script>
<?php } ?>