<?php 
include ("kfunctions.php");

adminall("overadmin","priaccount","priaccount");
?>

<html>
<head>
<?php kheader(); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!--<script src="js/thousandseparator.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">
                <div class="panel-body"></div>
 
               <?php
 $role = $_SESSION["role"];
  if($role=="overadmin"){

              } else{

         include ("connect.php");
         if ($role=="priadmin"){$cidcheck='where cid<=49999';}
         elseif ($role=="secadmin"){$cidcheck='where cid>=50000';}
        
             
              $result=$dbh->query("select * from children $cidcheck order by cid desc");
                $row=$result->fetchObject();
}
                         
 if(isset($_POST["addstudent"])){
$role = $_SESSION["role"];

$pfname=$_POST["pfname"];
$plname=$_POST["plname"];
$pphone1=$_POST["pphone1"];
$pphone2=$_POST["pphone2"];
$pdetails=$_POST["pdetails"];
$pgender=$_POST["pgender"];

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

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

$rel_id="$yy$mm$dd-$hi$mi$sa";

include("connect.php");
 
 $insert_relatives=$dbh->prepare("INSERT into relatives (rel_id,firstname,lastname,phone1,phone2,other_details,gender) values('$rel_id','$pfname','$plname','$pphone1','$pphone2','$pdetails','$pgender')");
$insert_relatives->execute();

echo "<div class='alert alert-success'>Parent Details for ".$pfname." ".$plname." - ID: ".$rel_id." have been submitted. </div>";

//echo "<script>window.location='last20students.php'</script>";
}

?>

<form method="post">

<div class="col-lg-12">
  <div class="panel panel-info">
                <div class="panel-heading">
                                <h3 class="panel-title">Parent details</h3>
                            </div>
                            <div class="panel-body">
                  
                  <div class='col-lg-3'>
<input type="text" name="pfname" class="form-control" placeholder="Firstname" required>
                  </div>

                  <div class='col-lg-3'>
<input type="text" name="plname" class="form-control" placeholder="Lastname"  required>
                  </div>

                  <div class='col-lg-2'>
<input type="text" name="pphone1" class="form-control" placeholder="Phone 1"  required>
                  </div>

                  <div class='col-lg-2'>
<input type="text" name="pphone2" class="form-control" placeholder="Phone 2"  >
                  </div>

                  <div class='col-lg-2'>
<input type="text" name="pdetails" class="form-control" placeholder="Other Contact Details"  required>
                  &nbsp </div>

<div class="col-lg-2">
<select class="form-control" name="pgender">
<option value="">Select the gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>

<div style='float:right;margin-right:15px;'> 
<input type='submit' class='btn btn-sm btn-primary' name='addstudent' value='Submit Form'>
</div>

</div>
</div>

                    </div>
                                     
</form>


<div class="col-lg-12">
  <div class="panel panel-success">

                <div class="panel-heading">

                                <h3 class="panel-title">List of Parents</h3>
                            </div>
                            <div class="panel-body">

<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 >Name</th>
    <th >Gender</th>
    <th >Telephone</th>
    <th >Other details</th>
    <th width="10%">No. of Learners</th> 
    <th width="8%">Action</th> </tr></thead> 

     <tbody></tr>

<?php 

$result_parents=$dbh->query("SELECT * from relatives order by autoid desc");
$row_parents=$result_parents->fetchObject();
$count_parents=$result_parents->rowCount();

if($count_parents>0){ 

$r=1;

do {

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

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

    <td>".$row_parents->firstname." ".$row_parents->lastname."</td>
    <td>".$row_parents->gender."</td>
    <td >".$row_parents->phone1.", ".$row_parents->phone2."</td>
    <td >".$row_parents->other_details."</td>
    <td >".$count_children."</td>
    <td ><center><a href='relatives_details.php?rel_id=".$row_parents->rel_id."' class='btn btn-sm btn-success' role='button'><i class='fa fa-eye'></i></a></center></td></tr>";

} while ($row_parents=$result_parents->fetchObject()); } 

?>
</div>
</td></tr>

                            </tbody>
                            </table>


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

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

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