<?php include("parent/callMe.php"); ?>

<?php  include("sessioncheck.php"); ?>



<?php

date_default_timezone_set('Asia/Calcutta');



function findage($dob)

{

    $localtime = getdate();

    $today = $localtime['mday']."-".$localtime['mon']."-".$localtime['year'];

    $dob_a = explode("-", $dob);

    $today_a = explode("-", $today);

    $dob_d = $dob_a[0];$dob_m = $dob_a[1];$dob_y = $dob_a[2];

    $today_d = $today_a[0];$today_m = $today_a[1];$today_y = $today_a[2];

    $years = $today_y - $dob_y;

    $months = $today_m - $dob_m;

    if ($today_m.$today_d < $dob_m.$dob_d) 

    {

        $years--;

        $months = 12 + $today_m - $dob_m;

    }



    if ($today_d < $dob_d) 

    {

        $months--;

    }



    $firstMonths=array(1,3,5,7,8,10,12);

    $secondMonths=array(4,6,9,11);

    $thirdMonths=array(2);



    if($today_m - $dob_m == 1) 

    {

        if(in_array($dob_m, $firstMonths)) 

        {

            array_push($firstMonths, 0);

        }

        elseif(in_array($dob_m, $secondMonths)) 

        {

            array_push($secondMonths, 0);

        }elseif(in_array($dob_m, $thirdMonths)) 

        {

            array_push($thirdMonths, 0);

        }

    }

   // echo "<br><br> Age is $years years $months months.";

}





?>

<?php

 $branch=$_SESSION['branch'];

 $sql = " select * from  edu_student_details where status='0' and branch_id=".$_SESSION['branch']. " ";

 if($_REQUEST['gender']=="All"){
    } else {

     $sql .= " AND gender = '" .$_REQUEST['gender']. "' ";

    }

  //print_r($sql);

  $WorkAssignListings = $m->query($sql); 

     ?>





<!DOCTYPE html>

<html lang="en">

  <head>

    

    <title>Age Wise Reports | EduPortal</title>

    <?php include('RootMe/css_links.php');?>

   

  </head>

  









  <body class="nav-md">

    <div class="container body">

      <div class="main_container">

        <div class="col-md-3 left_col">

     

            <?php include('RootMe/sidebar.php');?>



              <?php include('RootMe/header.php');?>

     

        <!-- page content -->

          <div class="right_col" role="main">

          <div class="" style="background-color: white;">



      <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 

    

         <a href="students_reports_link.php">Students Reports </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 

              

          Age Wise Reports



          <br><br>



            

    <section class="add_sub_agent" id="table_sub_agent">

  <div class="container">



 <div class="" style="margin-top:10px;">

     

      <div class="clearfix"></div>

    </div>



<div style="overflow-x:auto;">

      



<form class="form-style-7" action="age_wise_students_report.php" method="get"  enctype="multipart/form-data">



  <input type="hidden" id="session"  name="session" value="<?php echo $_GET['session']; ?>" />
  <input type="hidden" id="date"  name="date" value="<?php echo $_GET['date']; ?>" />

      

        <div class="col-md-2 col-xs-12" style="padding: 8px;">

        <div class="form-group ">

        <label class="required">Gender</label>

        <select name="gender" class="form-control" style="height:40px;" >

        <option <?php if($_REQUEST['gender']=='All'){echo "selected";} ?> value="All">All</option>

        <option <?php if($_REQUEST['gender']=='male'){echo "selected";} ?> value="male">Male</option>

        <option <?php if($_REQUEST['gender']=='female'){echo "selected";} ?>value="female">Female</option>

        </select> 

        </div>

        </div>



        <div class="col-md-2 col-xs-12" style="padding: 8px;">

        <div class="form-group ">

        <label class="required">Choose Order</label>

        <select name="orderByAge" class="form-control" style="height:40px;" >

        <option <?php if($_REQUEST['orderByAge']=='exact') {echo "Selected";} ?> value="exact">Exact Age</option>

        <option <?php if($_REQUEST['orderByAge']=='above') {echo "Selected";} ?> value="above">Above Age</option>

        <option <?php if($_REQUEST['orderByAge']=='below'){echo "Selected";} ?> value="below">Below Age</option>

        </select> 

        </div>

        </div>





            <div class="col-md-2 col-xs-12" style="padding: 8px;">

            <div class="form-group ">

            <label class="required">Enter Age</label>                

            <input class="form-control" type="text" name="age"  id="age" style="height:40px;"  value="<?php echo $_GET['age'];?>" required>

            </div>

            </div>



            <div class="col-md-2 col-xs-12" style="padding: 8px;">

            <div class="form-group ">

            <label class="required">Order By</label>

            <select name="orderby" class="form-control" style="height:40px;" >

            <option <?php if($_GET['orderby']=="class"){echo 'selected';}?> value='class'>Class Wise</option>

            <option <?php if($_GET['orderby']=="adm"){echo 'selected';}?> value='adm'>Admission Wise</option>

            </select>

            </div>

            </div>

 



              <div class="col-md-2 " style="padding:2px;">

                <div class="form-group ">

                <button type="submit" class="btn btn-primary" style="margin-top: 34px;">Search</button>

                     <?php 

           if( $_REQUEST['age']!="") {  ?>

            <a target="_blank" title="Print Arrear Report" href="print_age_wise_students_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&orderByAge=<?php echo $_GET['orderByAge'];?>&age=<?php echo $_GET['age'];?>&gender=<?php echo $_GET['gender'];?>&orderby=<?php echo $_GET['orderby'];?>&8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1" class="fa fa-print btn btn-primary" style="margin-top: 34px;padding: 9px;">&nbsp;Print             

            </a>

          <?php }  ?>

                </div>



              </div>



     <?php  if(!isset($_REQUEST['age'])){?>



        <div class="col-md-12">



          

           <div id="check_std_msg" style="color:white;font-size:18px;" class="alert alert-danger alert-dismissible">

                    <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>

                     <strong>Warning!</strong> Please Enter age and search !!!

            </div>

    



        </div>



  <?php   }?>         





    <table id="listofstudents" data-page-length='100' class="table table-striped table-bordered" style="width:100%">

          

         <thead>

            <tr>

                <th width="3%" class=" center"> S.No</th>

                <th width="14%" class="center"> Name</th>

                <th width="14%" class="center"> F.Name</th>

                <th width="12%" class="center"> B.Form</th>

                <th width="10%" class=" center"> Roll No </th>  

                <th width="10%" class=" center"> Class</th>

                <th width="6%" class=" center"> Adm No </th>  

                <th width="6%" class=" center"> Gender </th> 

                <th width="8%" class=" center"> Date Of Birth </th>

                <th width="10%" class=" center" > Student Age </th>  

              

                

                

                 

            </tr>

        </thead>

        <tbody>

  <?php 

$count=1;

      foreach($WorkAssignListings as $WorkAssignListVal)

      { 



      if ($WorkAssignListVal['dob']==NULL || $WorkAssignListVal['dob']=='') {

        continue;

      }



       // findage($WorkAssignListVal['dob']); //put date in the dd-mm-yyyy format



        $m->where("section_id", $WorkAssignListVal['section_id']);

        $section=$m->get("edu_adm_section_detail");

         

        $m->where("class_id", $WorkAssignListVal['class_id']);

        $class=$m->get("edu_class_config");







  //date in mm/dd/yyyy format; or it can be in other formats as well

  $birthDate = date("m-d-Y",strtotime($WorkAssignListVal['dob']));

  //explode the date to get month, day and year

  $birthDate = explode("-", $birthDate);

  //get age from date or birthdate

  $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md")

    ? ((date("Y") - $birthDate[2]) - 1)

    : (date("Y") - $birthDate[2]));

 // echo "Age is:" . $age;





      if ($_REQUEST['orderByAge']=='above') {

        

        if ($age<$_REQUEST['age']) {



         continue;

       }



      } elseif ($_REQUEST['orderByAge']=='below'){



      if ($age>$_REQUEST['age']) {



       continue;

     }



      } elseif ($_REQUEST['orderByAge']=='exact'){





        if ($age==$_REQUEST['age']) {



       

     } else {



        continue;

     }



      }



     ?>

<tr> 

<td class="center"> <?php echo $count; $count++;?> </td>

<td style="padding-left:1%;"><?php echo $WorkAssignListVal['first_name'];  ?></td>

<td style="padding-left:1%;"><?php echo $WorkAssignListVal['last_name'];  ?></td>

<td style="padding-left:1%;"><?php echo $WorkAssignListVal['formBNo'];  ?></td>

<td class="center">  <?php echo $WorkAssignListVal['candidate_roll_no'];?></td>

<td style="padding-left:1%;"><?php echo  $class[0]['Class_Name'];  ?></td>

<td class="center">  <?php echo $WorkAssignListVal['ref_no'];?>  </td> 

<td class="center">  <?php echo $WorkAssignListVal['gender'];?>  </td>   

<td class="center">  <?php echo date("d-M-Y",strtotime($WorkAssignListVal['dob']));?>  </td>               

<td class="center" >  <?php echo $age." Years Old";?> </td>



</tr>



<?php } ?>



       

           

            

           

        </tbody>

        

    </table>



</form>

</div>



    <br><br>





  </div>

  <div class="clearfix"></div>

</section>



           

          </div>

        </div>



            </div>

          </div>

        </div>

        <!-- /page content -->

  



    

  <?php include('RootMe/js_linksscript.php');?>



  <script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>

    <script>

        $(document).ready(function() {

        $('#listofstudents').DataTable();

        } 

        );

    </script>



  <script src="js/FileSaver.min.js" type="text/javascript"></script>

  <script src="js/tableexport.min.js" type="text/javascript"></script>



  <script type="text/javascript">

    $('#listofstudents').tableExport();

  </script>

  </body>

</html>

