<?php 
include ("kfunctions.php");
adminall("overadmin","priaccount","secaccount");
?>

<html>
<head>
<?php kheader(); ?>
</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 -->

            
                        

                    <?php
                    if( !empty($_GET["search"]) ){
$search = $_GET["search"];



$result_fs = $dbh->query("
select 

bravos.cid,
bravos.paid, 
bravos.balance,
bravos.payable,
bravos.fsid, 
children.cid, 
children.fname, 
children.sname,
children.schoolyear,
children.term,
scrap.item2



from bravos 
inner join children on children.cid=bravos.cid
inner join scrap on scrap.item=bravos.fsitemid

where bravos.balance >= 0 
and (children.fname like '%$search%' or children.sname like '%$search%')

");

$result_fs->bindValue(':search', $search, PDO::PARAM_STR);
$result_fs->execute();
$row_fs = $result_fs->fetchObject();
$count_fs = $result_fs->rowCount();
echo " 

<div class='panel panel-yellow' ><!--Initiative-->
<div class='panel-heading'><h3 class='panel-title'>Search result(s) : ".$search."</h3></div>
<div class='panel-body'>
<table class='table table-bordered table-hover table-striped sortable'>

 <thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Payment</th>
<th>Total</th>
<th>Paid</th>
<th>Balance</th>
</tr>
</thead>
<tbody>";

if($count_fs>0){ do{

  echo "<tr>
  <td>".$row_fs->cid."</td>
  <td>".$row_fs->fname." ".$row_fs->sname."</td>
  <td>".$row_fs->item2." [20".$row_fs->schoolyear." - T".$row_fs->term."]</td>
  <td><a href='addreceived.php?cid=".$row_fs->cid."&fsid=".$row_fs->fsid."&schoolyear=".$row_fs->schoolyear."&t=".$row_fs->term."'>".number_format($row_fs->payable)."</a></td>
  <td>".number_format($row_fs->paid)."</td>
  <td>".number_format($row_fs->balance)."</td>
  </tr>";




}while($row_fs = $result_fs->fetchObject());
}

                    }



//useractivity("searched about ".$search,"2");


?></table>
        </div></div>
  


        </div></div>


                    

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


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

        </div>
        <!-- /#page-wrapper -->

    </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 -->
<?php useractivity("on page","2"); ?>

</body>

</html>