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

<html>
<head>
<?php kheader(); ?>
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<link href="css/receipt_css.css" rel="stylesheet" media="screen">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">

<script src="js/sorttable.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
   <script src=
"https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js">
    </script>
<script src="js/printreceipt.js"></script>

<?php
if (isset($_POST['add_learner'])) {

$rel_id=$_GET['rel_id'];
$cid=$_POST["cid"];

$yy=date("Y");
$mm=date("m");
$dd=date("d");

$ourdate=$yy."-".$mm."-".$dd;

$insert_relationship=$dbh->query("INSERT into child_relatives (rel_id,cid,ouruser,ourdate) values('$rel_id','$cid','$rolenumber','$ourdate')"); 
if($insert_relationship){echo "<div class='alert alert-success'>Learner successfully Added to Relative!</div>";}
 } ?>

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

      <div class="row">
                    <div class="col-sm-12">

                        <h1 class="page-header">
                           Relative Details
                    
                         </h1>

                    </div>

                </div>

                <!-- /.row -->
<?php 
include ("connect.php");

$hi=date("H"); $mi=date("i");
$sa=date("sa"); $sa=date("s");
$ourtime=$hi."-".$mi;

$result_scrapaddress = $dbh->query("select * from scrap where item2='title1'");
$row_scrapaddress= $result_scrapaddress->fetchObject();
$count_scrapaddress = $result_scrapaddress->rowCount();

$headie=$row_scrapaddress->item;

$rel=$_GET['rel_id'];
 
$result_clo = $dbh->query("select * from relatives where rel_id='$rel' order by autoid desc");
$row_clo = $result_clo->fetchObject(); $count_clo = $result_clo->rowCount();

 ?>

<div id='myDiv'>
<div class="row">
        <div class="col-sm-10 col-sm-offset-1">
            <div class="widget-box">
                <div class="widget-header widget-header-large">
                    
                    <div class="widget-toolbar no-border invoice-info" style="float:left;">
                        <span class="invoice-info-label">                                               
                            <b style='font-size:17px;'>NEW JERUSALEM MIXED DAY & BOARDING SCHOOL</b>                           
                        </span><br>             
                        <span class="invoice-info-label"> 
                            Bulamu - Kasangati
                        </span>
                        
                    </div>

                    <div class="widget-toolbar no-border invoice-info">

                        <br>
                    </div>

                </div>
<div class="col-sm-12"></div>
                <div class="widget-body">
                    <div class="widget-main padding-24">
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="row">
                                    <div class="col-xs-11 label label-lg label-info arrowed-in arrowed-right">
                                        <b>Parent Info</b>
                                    </div>
                                </div>

                                <div>
                                    <ul class="list-unstyled spaced">
                                        <li>
                                            <i class="ace-icon fa fa-caret-right blue"></i> Name: <?php echo $row_clo->firstname." ".$row_clo->lastname; ?>
                                        </li>                               
                                    
                                        <li>
                                            <i class="ace-icon fa fa-caret-right blue"></i>
                                                Phone:
                                            <b class="green"> <?php echo $row_clo->phone1.", ".$row_clo->phone2; ?> </b>
                                        </li>

                                        <li>
                                            <i class="ace-icon fa fa-caret-right blue"></i>
                                                Email:
                                            <b class="green"><?php echo $row_clo->email; ?></b>
                                        </li>
                                        
                                        <li class="divider"></li>
                                        
                                    </ul>
                                </div>
                            </div><!-- /.col -->
                        </div>
                           <div class="row">
                            <div class="col-sm-3"></div>
                               <div class="col-sm-6">
                                    <div class='col-sm-8'>
                                    <form method='post'>
                                        <input type='text' class='form-control' name='search' placeholder='Search'>
                                    </div>
                                    <div>
                                        <input type='submit' style='margin-right;' class='btn btn-sm btn-success' value='Search' name='submit_search'>
                                    </div>
                                    </form>
                               </div>

                           </div> 
                                   <?php

// Isset for search of children. WHen clicked, brings results from children table.

if (isset($_POST["submit_search"]) and !empty($_POST['search'])){

$rel_id=$_GET['rel_id'];
$search_results="where fname LIKE '%".addslashes($_POST["search"])."%' OR sname LIKE '%".addslashes($_POST["search"])."%'";
$searchwords=" - Showing search results for &quot".$_POST["search"]."&quot";

$result_child=$dbh->query("SELECT * from children  $search_results order by autoid desc");
$row_child=$result_child->fetchObject();
$count_child=$result_child->rowCount();

echo "<table border='0' style='margin-top:20px;width:100%;' class='table table-bordered table-hover table-striped sortable'>
                            <thead>
                            <tr>
    <th width='2%'>No</th>

    <th >Child Name</th>
    <th >Class</th>
    <th width='5%'>Action</th>
    
    </tr>";

    if($count_child>0){ 

$r=1;

do {

echo "
    <tr>
    <td>".$r++."</td>

    <td>".$row_child->fname." ".$row_child->sname."</td>
    <td> </td> <td>";

$result_children=$dbh->query("SELECT * from child_relatives where rel_id='$rel_id' and cid='$row_child->cid' order by autoid asc");
$row_children=$result_children->fetchObject();
$count_children=$result_children->rowCount();

    if($count_children<='0'){

   echo "<form method='post' onsubmit='return delete_checker('Trend','Not be Viewed In The')'>

      <input type='hidden' name='cid' value=".$row_child->cid.">
      <input type='hidden' name='rel_id' value=".$rel_id.">

    <button type='submit' name='add_learner' class='btn btn-md btn-success'>Attach Learner to current relative</button>";
} else{ echo "Already Added";}

    echo "</td></form></tr>";
}while ($row_child=$result_child->fetchObject()); }

else{$search_results=""; $searchwords="";} 

}

?>
<!-- End of Isset for search feature. Includes preview inside it! -->

                        <div class="space"></div>
                                            <center>
                                                <h4>
                                                <b>Attached Learners</b>
                                                </h4>
                                            </center>

                        <div>

<?php
$rel_id=$_GET['rel_id'];

?>

                        <table border='0' style='margin-top:20px;width:100%;' class='table table-bordered table-hover table-striped sortable'>
                            <thead>
                            <tr>
    <th width='2%'>No</th>

    <th >Child Name</th>
    <th >Class</th>
    <th >Gender</th>
    
    </tr>

<?php 

$result_homelands=$dbh->query("SELECT * from child_relatives where rel_id='$rel_id' order by autoid desc");
$row_homelands=$result_homelands->fetchObject();
$count_homelands=$result_homelands->rowCount();

if($count_homelands>0){ 

$r=1;

do {

$result_childs=$dbh->query("SELECT * from children where cid='$row_homelands->cid'");
$row_childs=$result_childs->fetchObject();
$count_childs=$result_childs->rowCount();

$result_scrapp=$dbh->query("select * from scrap where type='priclas' and item='$row_childs->schoolclass'");
$row_scrapp=$result_scrapp->fetchObject();
$count_scrapp=$result_scrapp->rowCount();

echo "
    <tr>
    <td>".$r++."</td>

    <td>".$row_childs->fname." ".$row_childs->sname."</td>

    <td >".$row_scrapp->item2."</td>

    <td >".$row_childs->gender."</td></tr>";

} while ($row_homelands=$result_homelands->fetchObject()); } 

else{}

?>

</td></tr>

                            </tbody>
                            </table>

                        </table>
                        </div>

                        <div class="hr hr8 hr-double hr-dotted"></div>

                        <div class="row">
                            <div class="col-sm-5 pull-right">
                                <h4 class="pull-right">
                                    .
                                </h4>
                            </div>
                            <div class="col-sm-7 pull-left"> <?php echo "<div class='col-lg-12'>Prepared by : ".$_SESSION["firstname"]." ".$_SESSION["lastname"].", ".$ourtime."</div>"; ?> </div>
                        </div>

                        <div class="space-6"></div>
                        <div class="well" style="text-transform:uppercase; text-align:center;">
                            Thank you for choosing NEW JERUSALEM MIXED DAY & BOARDING SCHOOL.
We believe you will be satisfied by our services.
                        </div>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div id="output"></div>

                <!-- /.row -->

    <!-- /#wrapper -->

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

    <!-- Bootstrap Core JavaScript -->
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript">
    $('.form_datetime').datetimepicker({
        //language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1
    });
    $('.form_date').datetimepicker({
        language:  'en',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
    $('.form_time').datetimepicker({
        language:  'en',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 1,
        minView: 0,
        maxView: 1,
        forceParse: 0
    });
</script>

    <!-- Bootstrap Core JavaScript -->

    

</body>

</html>