<?php

$search=$_POST["name"];

$childtype1=$_POST["childtype1"];

$childtype2=$_POST["childtype2"];



if($childtype1=="Debtor" and $childtype2!="All"){

$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 $roler (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){

	do{

echo "

<tr>

<td>".$cid."</td>

<td>20".$row1->schoolyear."</td>";



$schoolclass = $row1->schoolclass;

include ("class.php");







$feesbal1=$row1->feesbalance;

$uniformbal1=$row1->uniformbal;

$contributionbal1=$row1->contributionbal;

$registrationbal1=$row1->registrationbal;

$holidaybal1=$row1->holidaybal;

$admissionbal1=$row1->admissionbal;

$transportbal1=$row1->transportbal;

$mockfabal1=$row1->mockfabal;

$other1bal1=$row1->other1bal;

$other2bal1=$row1->other2bal;

$other3bal1=$row1->other3bal;





$schoolyear=$row1->schoolyear;

$allpay=$row1->ownfee+$row1->contribution;



//totalbalance minus except holiday

$allbal1=$feesbal1+$uniformbal1+$contributionbal1+$registrationbal1+$admissionbal1+$transportbal1+$mockfabal1+$other1bal1+$other2bal1+$other3bal1;



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($allpay)."</td>

<td><a href='addreceived.php?cid=".$cid."&tid=1&schoolyear=".$schoolyear."&t=1'>".number_format($allbal1)."</a></td>

<td>".number_format($row1->feesbalance)."</td>

<td>".number_format($row1->reqsbalance)."</td>

<td>Term 1</td>

<td>".$row1->comment."</td>

</tr>";

}while($row1 = $result1->fetchObject());

}







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

$row2 = $result2->fetchObject();

$count2 = $result2->rowCount();



if($count2>0){

do{

echo "

<tr>

<td>".$row2->cid."</td>

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



$schoolclass = $row2->schoolclass;

include ("class.php");



$feesbal2=$row2->feesbalance;

$uniformbal2=$row2->uniformbal;

$contributionbal2=$row2->contributionbal;

$registrationbal2=$row2->registrationbal;

$holidaybal2=$row2->holidaybal;

$admissionbal2=$row2->admissionbal;

$transportbal2=$row2->transportbal;

$mockfabal2=$row2->mockfabal;

$other1bal2=$row2->other1bal;

$other2bal2=$row2->other2bal;

$other3bal2=$row2->other3bal;





$schoolyear=$row2->schoolyear;

$allpay2=$row2->ownfee+$row2->contribution;



//totalbalance minus except holiday

$allbal2=$feesbal2+$uniformbal2+$contributionbal2+$registrationbal2+$admissionbal2+$transportbal2+$mockfabal2+$other1bal2+$other2bal2+$other3bal2;









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($allpay2)."</td>

<td><a href='addreceived.php?cid=".$cid."&tid=2&schoolyear=".$schoolyear."&t=2'>".number_format($allbal2)."</a></td>

<td>".number_format($row2->feesbalance)."</td>

<td>".number_format($row2->reqsbalance)."</td>

<td>Term 2</td>

<td>".$row2->comment."</td>

</tr>

";

}while($row2 = $result2->fetchObject());

}



$result3 = $dbh->query("select * from t3 where (feesbalance >'0' or reqsbalance >'0') and cid='$cid' ");

$row3 = $result3->fetchObject();

$count3 = $result3->rowCount();



if($count3>0){

do{

echo "

<tr>

<td>".$row3->cid."</td>

<td>20".$row3->schoolyear."</td>";



$schoolclass = $row3->schoolclass;

include ("class.php");



$feesbal3=$row3->feesbalance;

$uniformbal3=$row3->uniformbal;

$contributionbal3=$row3->contributionbal;

$registrationbal3=$row3->registrationbal;

$holidaybal3=$row3->holidaybal;

$admissionbal3=$row3->admissionbal;

$transportbal3=$row3->transportbal;

$mockfabal3=$row3->mockfabal;

$other1bal3=$row3->other1bal;

$other2bal3=$row3->other2bal;

$other3bal3=$row3->other3bal;





$schoolyear=$row3->schoolyear;

$allpay2=$row3->ownfee+$row3->contribution;



//totalbalance minus except holiday

$allbal3=$feesbal3+$uniformbal3+$contributionbal3+$registrationbal3+$admissionbal3+$transportbal3+$mockfabal3+$other1bal3+$other2bal3+$other3bal3;









echo "

<td>".$daclass."</td>";

$role = $_SESSION["role"];

if($role=="overadmin"){

echo "<td><a href='studentedit.php?cid=".$cid."&t=t3'>".$row10->fname." ".$row10->sname."</td>";

}else{

echo "<td>".$row10->fname." ".$row10->sname."</td>";

}

echo "

<td>".number_format($allpay2)."</td>

<td><a href='addreceived.php?cid=".$cid."&tid=2&schoolyear=".$schoolyear."&t=2'>".number_format($allbal3)."</a></td>

<td>".number_format($row3->feesbalance)."</td>

<td>".number_format($row3->reqsbalance)."</td>

<td>Term 3</td>

<td>".$row3->comment."</td>

</tr>";

}while($row3 = $result3->fetchObject());

}





}

while($row10 = $result10->fetchObject());



}

echo "</table>";



}elseif($childtype2=="All" and $childtype1!="Debtor"){



$role = $_SESSION["role"];



if($role=="priaccount"){

$roler = "cid<=49999 and";



}elseif($role=="secaccount"){

  $roler = "cid>=50000 and";



}elseif($role=="overadmin" || $role=="hmp"){

  $roler = "cid>=10000 and";

}





$result10 = $dbh->query("select * from children  where $roler (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 cid='$cid' ");

$row1 = $result1->fetchObject();

$count1 = $result1->rowCount();





if($count1>0){

	do{

echo "

<tr>

<td>".$cid."</td>

<td>20".$row1->schoolyear."</td>";



$schoolclass = $row1->schoolclass;

include ("class.php");





$schoolyear=$row1->schoolyear;

$allpay=$row1->ownfee+$row1->contribution;





$feesbal1=$row1->feesbalance;

$uniformbal1=$row1->uniformbal;

$contributionbal1=$row1->contributionbal;

$registrationbal1=$row1->registrationbal;

$holidaybal1=$row1->holidaybal;

$admissionbal1=$row1->admissionbal;

$transportbal1=$row1->transportbal;

$mockfabal1=$row1->mockfabal;

$other1bal1=$row1->other1bal;

$other2bal1=$row1->other2bal;

$other3bal1=$row1->other3bal;





//totalbalance minus except holiday

$allbal1=$feesbal1+$uniformbal1+$contributionbal1+$registrationbal1+$admissionbal1+$transportbal1+$mockfabal1+$other1bal1+$other2bal1+$other3bal1;





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($allpay)."</td>

<td><a href='addreceived.php?cid=".$cid."&tid=1&schoolyear=".$schoolyear."&t=1'>".number_format($allbal1)."</a></td>

<td>".number_format($row1->feesbalance)."</td>

<td>".number_format($row1->reqsbalance)."</td>

<td>Term 1</td>

<td>".$row1->comment."</td>

</tr>";

}while($row1 = $result1->fetchObject());

}





//term 2

$result2 = $dbh->query("select * from t2 where cid='$cid' ");

$row2 = $result2->fetchObject();

$count2 = $result2->rowCount();



if($count2>0){

do{

echo "

<tr>

<td>".$row2->cid."</td>

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

$schoolclass = $row2->schoolclass;

include ("class.php");



$feesbal2=$row2->feesbalance;

$uniformbal2=$row2->uniformbal;

$contributionbal2=$row2->contributionbal;

$registrationbal2=$row2->registrationbal;

$holidaybal2=$row2->holidaybal;

$admissionbal2=$row2->admissionbal;

$transportbal2=$row2->transportbal;

$mockfabal2=$row2->mockfabal;

$other1bal2=$row2->other1bal;

$other2bal2=$row2->other2bal;

$other3bal2=$row2->other3bal;





$schoolyear=$row2->schoolyear;

$allpay2=$row2->ownfee+$row2->contribution;

//totalbalance minus except holiday

$allbal2=$feesbal2+$uniformbal2+$contributionbal2+$registrationbal2+$admissionbal2+$transportbal2+$mockfabal2+$other1bal2+$other2bal2+$other3bal2;





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($allpay2)."</td>

<td><a href='addreceived.php?cid=".$cid."&tid=2&schoolyear=".$schoolyear."&t=2'>".number_format($allbal2)."</a></td>

<td>".number_format($row2->feesbalance)."</td>

<td>".number_format($row2->reqsbalance)."</td>

<td>Term 2</td>

<td>".$row2->comment."</td>

</tr>";

}while($row2 = $result2->fetchObject());

}



//term 3

$result3 = $dbh->query("select * from t3 where cid='$cid' ");

$row3 = $result3->fetchObject();

$count3 = $result3->rowCount();



if($count3>0){

do{

echo "

<tr>

<td>".$row3->cid."</td>

<td>20".$row3->schoolyear."</td>";



$schoolclass = $row3->schoolclass;

include ("class.php");



$feesbal3=$row3->feesbalance;

$uniformbal3=$row3->uniformbal;

$contributionbal3=$row3->contributionbal;

$registrationbal3=$row3->registrationbal;

$holidaybal3=$row3->holidaybal;

$admissionbal3=$row3->admissionbal;

$transportbal3=$row3->transportbal;

$mockfabal3=$row3->mockfabal;

$other1bal3=$row3->other1bal;

$other2bal3=$row3->other2bal;

$other3bal3=$row3->other3bal;





$schoolyear=$row3->schoolyear;

$allpay3=$row3->ownfee+$row3->contribution;



//totalbalance minus except holiday

$allbal3=$feesbal3+$uniformbal3+$contributionbal3+$registrationbal3+$admissionbal3+$transportbal3+$mockfabal3+$other1bal3+$other2bal3+$other3bal3;





echo "

<td>".$daclass."</td>";

$role = $_SESSION["role"];

if($role=="overadmin"){

echo "<td><a href='studentedit.php?cid=".$cid."&t=t3'>".$row10->fname." ".$row10->sname."</td>";

}else{

echo "<td>".$row10->fname." ".$row10->sname."</td>";

}

echo "

<td>".number_format($allpay3)."</td>

<td><a href='addreceived.php?cid=".$cid."&tid=3&schoolyear=".$schoolyear."&t=3'>".number_format($allbal3)."</a></td>

<td>".number_format($row3->feesbalance)."</td>

<td>".number_format($row3->reqsbalance)."</td>

<td>Term 3</td>

<td>".$row3->comment."</td>

</tr>";

}while($row3 = $result3->fetchObject());

}







}

while($row10 = $result10->fetchObject());

}



echo "</table>";

}else{  

echo "

<table width='100%'>

<tr>

<td align='center'><i>Please check <b>EITHER</b> Debtor <b>OR</b> All But <b>NOT BOTH</b></i></td>

</tr>

</table>

";

}

	





?>