<?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">

      

                <!-- /.row -->

                <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-body">
                           

     <form method="post">               
<div class="col-lg-12">
  <div class="panel panel-green">
                <div class="panel-heading">
                                <h3 class="panel-title">Fees Search</h3>
                            </div>
                            <div class="panel-body">


                  <div class='col-lg-4'>
                    <input type="text" name="trid" class="form-control" placeholder="Transaction ID">
                  </div>


<div class='col-lg-3'> 
<input type="submit" name='searcher' class='btn btn-sm btn-success' value="Search">
</form>
</div>


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


                                
                            </div>


                    <?php
                    if((isset($_POST["searcher"])) and ($_POST["search"]!='') ){
$search = $_POST["search"];

$role = $_SESSION["role"];

if($role=="priaccount"){
$roler = "cid<=49999 and";

}elseif($role=="secaccount"){
  $roler = "cid>=50000 and";

}elseif($role=="overadmin"){
  $roler = "cid>=10000 and";
}


$result10 = $dbh->query("select * from children  where sname like '%$search%' or fname like '%$search%' or sname like '$search%' or sname like '$search%' or cid='$search'");
$row10 = $result10->fetchObject();
$count10 = $result10->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>Year</th>
<th>Class</th>
<th>Names</th>
<th>Total fees</th>
<th>Total bal</th>
<th>Bal.fees</th>
<th>Bal.rqmts</th>
<th>Term</th>
<th>Comment</th>
</tr>
</thead>
<tbody>";

if($count10>0){

do {
$cid = $row10->cid;
$result1 = $dbh->query("select * from t1  where (feesbalance >'0' or reqsbalance >'0') and cid='$cid' ");
$row1 = $result1->fetchObject();
$count1 = $result1->rowCount();


if($count1>0){
echo "
<tr>
<td>".$cid."</td>
<td>20".$row1->schoolyear."</td>";

$schoolclass = $row1->schoolclass;
include ("class.php");


$schoolyear=$row1->schoolyear;
$allbal=$row1->feesbalance+$row1->reqsbalance;

echo "
<td>".$daclass."</td>";
$role = $_SESSION["role"];
if($role=="overadmin"){
echo "<td><a href='studentedit.php?cid=".$cid."&t=t1'>".$row10->fname." ".$row10->sname."</td>";
}else{
echo "<td>".$row10->fname." ".$row10->sname."</td>";
}
echo "
<td>".number_format($row1->ownfee)."</td>
<td><a href='addreceived.php?cid=".$cid."&tid=1&schoolyear=".$schoolyear."&t=1'>".number_format($allbal)."</a></td>
<td>".number_format($row1->feesbalance)."</td>
<td>".number_format($row1->reqsbalance)."</td>
<td>Term 1</td>
<td>".$row1->comment."</td>
</tr>
";
}



$result2 = $dbh->query("select * from t2 where (feesbalance >'0' or reqsbalance >'0') and cid='$cid' ");
$row2 = $result2->fetchObject();
$count2 = $result2->rowCount();

if($count2>0){

echo "
<tr>
<td>".$row2->cid."</td>
<td>20".$row2->schoolyear."</td>";

$schoolclass = $row2->schoolclass;
include ("class.php");

$cid=$row2->cid;
$schoolyear=$row2->schoolyear;
$allbal=$row2->feesbalance+$row2->reqsbalance;


echo "
<td>".$daclass."</td>";
$role = $_SESSION["role"];
if($role=="overadmin"){
echo "<td><a href='studentedit.php?cid=".$cid."&t=t2'>".$row10->fname." ".$row10->sname."</td>";
}else{
echo "<td>".$row10->fname." ".$row10->sname."</td>";
}
echo "
<td>".number_format($row2->ownfee)."</td>
<td><a href='addreceived.php?cid=".$cid."&tid=2&schoolyear=".$schoolyear."&t=2'>".number_format($allbal)."</a></td>
<td>".number_format($row2->feesbalance)."</td>
<td>".number_format($row2->reqsbalance)."</td>
<td>Term 2</td>
<td>".$row2->comment."</td>
</tr>
";
}
}
while($row10 = $result10->fetchObject());

}

}else{  
$search = "";

}

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


?></table>
        </div></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>