<?php 
include ("kfunctions.php");
adminall("overadmin","secadmin","priadmin");
?>

<html>
<head>
<?php kheader(); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="js/input.js"></script>
</head>
<body>

    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <?php kleftbar(); ?>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid" style='margin-top:10px;'>


      

                <!-- /.row -->
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                           Fee Structure
                        
                        </h1>
                    </div>
                </div>   
                
                <div class='col-lg-4'>                         
<div class='panel panel-primary'>
      <div class='panel-heading'>
        <h4 class='panel-title'>
          <a data-toggle='collapse' data-parent='#accordion' href='#cord3' aria-expanded='false' class='collapsed'>Add New Item</a>
        </h4>
      </div>
      <div id='cord3' class='panel-collapse collapse' aria-expanded='false' style='height: 0px;'>
        <div class='panel-body'>
        <?php
                              if(isset($_POST["submit_item"])){
                                $itemname=$_POST["itemname"];

                                
                                  $yy=date("Y"); $fyy=substr($yy,2,2); $mm=date("m"); 
                                  $dd=date("d"); $hi=date("h"); $mi=date("i");
                                  $sa=date("sa"); $sa=date("s");
                                  
                                  
                                  $fsitemid="it".$fyy.$mm.$dd.$hi.$mi;
                                $insert_scrap=$dbh->query("insert into scrap (item,item2,type) values('$fsitemid','$itemname','fsitem')");
                                if($insert_scrap){echo "<div class='alert alert-success'>Success: Item has been added.</div>";}
                              }

                              ?>
        <form method='post'>
  <div class='col-lg-9'>                           
  <input type='text' class='form-control' name='itemname' placeholder='Enter Item' required>  
</div>                          
<div class='col-lg-2'>                           
  <input type='submit' name='submit_item' class='btn btn-sm btn-primary' value='Submit'>  
</div>                          

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


                <div class='col-lg-12'>                         
<div class='panel panel-primary'>
      <div class='panel-heading'>
        <h4 class='panel-title'>
          <a data-toggle='collapse' data-parent='#accordion' href='#cord4' aria-expanded='false' class='collapsed'>New Fees</a>
        </h4>
      </div>
      <div id='cord4' class='panel-collapse collapse' aria-expanded='false' style='height: 0px;'>
        <div class='panel-body'>
        <?php
                              if(isset($_POST["submit"])){
                                $count_class=$_POST["count_class"];
                                for($x=1; $x<=$count_class; $x++){
                                  if(isset($_POST["clas".$x.""])){
                                    $clas=$_POST["clas".$x.""];
                                    $requirement=$_POST["requirement".$x.""];
                                    $gender=$_POST["gender".$x.""];
                                    $category=$_POST["category".$x.""];
                                    $applicable=$_POST["applicable".$x.""];
                                    $amount=$_POST["amount".$x.""];

                                    $yy=date("Y"); $fyy=substr($yy,2,2); $mm=date("m"); 
                                    $dd=date("d"); $hi=date("h"); $mi=date("i");
                                    $sa=date("sa"); $sa=date("s");
                                   
                                    $fsid="fs".$fyy.$mm.$dd.$hi.$mi.$x;

                                    /*$result_fsitems=$dbh->query("select * from fsitems where schoolclass='$clas' and fsitemid='$requirement' and category='$category'");
                                    $row_fsitems=$result_fsitems->fetchObject(); $count_fsitems=$result_fsitems->rowCount();
                                    

                                    if($count_fsitems == 0){*/
                                      $insert_fsitems=$dbh->query("insert into fsitems (ouruser,fsid,schoolclass,fsitemid,gender,category,applicable,amount,lastupdate,status) values('$rolenumber','$fsid','$clas','$requirement','$gender','$category','$applicable','$amount','$rolenumber','2')");
                                    /*} else {
                                      $update_fsitems=$dbh->query("update fsitems set fsitemid='$requirement', gender='$gender', category='$category', applicable='$applicable', amount='$amount', lastupdate='$rolenumber' where schoolclass='$clas'");                                    
                                    }*/

                                  }
                                }
                              }

                              ?>
                              <form method='post'>
                              <input type='submit' name='submit' style="float:right;" class='btn btn-md btn-primary' value='Submit'>
                              <table class='table table-hover table-bordered'>
                                <tr>
                                  <th>Classes</th>
                                  <th>Fees Item</th>
                                  <th>Gender</th>
                                  <th>Category</th>
                                  <th>Applicable To</th>
                                  <th>Amount</th>
  </tr>
  <?php
$result_scrap=$dbh->query("select * from scrap where type='priclas'");
$row_scrap=$result_scrap->fetchObject(); $count_scrap=$result_scrap->rowCount();

if($count_scrap>0){ $y=1; echo "<input type='hidden' name='count_class' value='".$count_scrap."'>"; do{
$r=$y++;
  echo "<tr>
<td><input type='checkbox' name='clas".$r."' value='".$row_scrap->item."'>  ".$row_scrap->item2."</td>
<td>
<select class='form-control' name='requirement".$r."'>
<option value=''>Fees Items</option>";
$result_scrapreq=$dbh->query("select * from scrap where type='fsitem'");
$row_scrapreq=$result_scrapreq->fetchObject(); $count_scrapreq=$result_scrapreq->rowCount();

if($count_scrapreq>0){
  do{
    echo "<option value='".$row_scrapreq->item."'>".$row_scrapreq->item2."</option>";

  }while($row_scrapreq=$result_scrapreq->fetchObject());
}

echo "</select>
</td>
<td>
<select class='form-control' name='gender".$r."'>
<option value=''>Gender</option>
<option value='Male'>Male</option>
<option value='Female'>Female</option>
<option value='All'>All</option>
  </select>
</td>
<td>
<select class='form-control' name='category".$r."'>
<option value=''>Fees Items</option>";
$result_scrapreq=$dbh->query("select * from scrap where type='category'");
$row_scrapreq=$result_scrapreq->fetchObject(); $count_scrapreq=$result_scrapreq->rowCount();

if($count_scrapreq>0){
  do{
    echo "<option value='".$row_scrapreq->item."'>".$row_scrapreq->item2."</option>";

  }while($row_scrapreq=$result_scrapreq->fetchObject());
}

echo "</select>

</td>
<td>
<select class='form-control' name='applicable".$r."'>
<option value=''>Applicable To</option>
<option value='New'>New</option>
<option value='Old'>Old</option>
<option value='All'>All</option>
  </select>
</td>
<td>
<input type='number' class='form-control' name='amount".$r."' placeholder='Amount'>
</td>

</tr>"; 
 }while($row_scrap=$result_scrap->fetchObject());}
?>


  </table>
</form>

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

<div class="col-lg-12">
  <div class="panel panel-primary">
                <div class="panel-heading">
                                <h3 class="panel-title">Fee Structures</h3>
                            </div>
                            <div class="panel-body">
                            <table class='table table-hover table-bordered'>
                                <tr>
                                <th>No</th>
                                  <th>Classes</th>
                                  <th>Fees Item</th>
                                  <th>Gender</th>
                                  <th>Category</th>
                                  <th>Applicable To</th>
                                  <th>Amount</th>
  </tr>
  <?php
$result_fsitems=$dbh->query("select * from fsitems where newitemname='' order by schoolclass asc");
$row_fsitems=$result_fsitems->fetchObject(); $count_fsitems=$result_fsitems->rowCount();

if($count_fsitems>0){ $y=1;  do{
  $result_clas=$dbh->query("select * from scrap where item='$row_fsitems->schoolclass' and type='priclas'");
  $row_clas=$result_clas->fetchObject(); $count_clas=$result_clas->rowCount();

  $result_fsitem=$dbh->query("select * from scrap where item='$row_fsitems->fsitemid'");
  $row_fsitem=$result_fsitem->fetchObject(); $count_fsitem=$result_fsitem->rowCount();

  $result_cat=$dbh->query("select * from scrap where item='$row_fsitems->category'");
  $row_cat=$result_cat->fetchObject(); $count_cat=$result_cat->rowCount();

  echo "<tr>
<td>".$y++."</td>
<td>"; if($count_clas>0){echo $row_clas->item2;} echo "</td>
<td>"; if($count_fsitem>0){ echo $row_fsitem->item2;} echo "</td>
<td>".$row_fsitems->gender."</td>
<td>"; if($count_cat>0){ echo $row_cat->item2;} echo "</td>
<td>".$row_fsitems->applicable."</td>
<td>".number_format($row_fsitems->amount)."</td>
</tr>"; 
 }while($row_fsitems=$result_fsitems->fetchObject());}
?>


  </table>
                              
                             
                                



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

 
              
<!----row---->

                     


                             
                                </div>
                                
                            </div>
                        </div>
                    </div>
                  </div>
                <!-- /.row -->
</form>




                  </div>
                <!-- /.row -->

            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->
        <script>
function sender(){
var selectedusers = document.getElementById("selectedusers");
var values = [];

<?php
$result_scrap=$dbh->query("select * from scrap where type='priclas' or type='secclas'");
$row_scrap=$result_scrap->fetchObject(); $count_scrap=$result_scrap->rowCount();
if($count_scrap>0){
    do{
?>
if(document.getElementById("chkout<?php echo $row_scrap->item; ?>").checked==true) {
 var user = document.getElementById("chkout<?php echo $row_scrap->item; ?>").value;
  values.push(user);
}
<?php
}while($row_scrap=$result_scrap->fetchObject());
}
?>

selectedusers.value = values.join(",");

}
</script> 
<?php useractivity("on page","2"); ?>
    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Morris Charts JavaScript -->

</body>

</html>