<?php 
//require_once("includes/initialize.php");





global $database;
$alldept = ONLINEPAY:: showdept();
$allsession = ONLINEPAY:: showsession();
session_start();

if (isset($_POST['search']))
{
//   $department = $_POST['department'];
//   $level = $_POST['level'];
   $session = $_POST['session'];
   
   $table = $_POST['ptype'];
//   $formno = $_POST['formno'];
//   $prog = $_POST['programme'];
   $start_date = date('Y-m-d', strtotime($_POST['start_date']));
  $end_date = date('Y-m-d', strtotime($_POST['end_date']));
  
   //echo $table.' '.$session.' '.$start_date.' '.$end_date;
    if (($start_date !='') AND ($end_date !='') AND ($session!='2020/2021')){
 
 $result= ONLINEPAY::searchbydatebackend($table,$session, $start_date, $end_date);
 $msg='Between '.$start_date .' AND '.$end_date;
 }else if (($start_date !='') AND ($end_date !='') AND ($session=='2020/2021')){
     
     $result= ONLINEPAY::searchbydatebackends($table,$session,'ND I', $start_date, $end_date);
 $msg='Between '.$start_date .' AND '.$end_date;
 
 }
    
    echo "<h3> Number of students that paid: ".sizeof($result)."</h3><br>";
    echo "<h4> Date: ".$start_date."  AND  ".$end_date."</h4>";
    // $_SESSION['level'] =  $lev;
    // $_SESSION['programme'] =  $prog;
    // $_SESSION['gender'] = $gend;
    // if( $prog != "" && $department!="" && $session!="")
    // {
        
        // $query = "SELECT * FROM `admission_list` WHERE `formno` LIKE '%$prog%' AND `department` = '$department' AND session = '$session'";
        
        // if ((($level=='ND') or ($level=='HND')) and ($department!='')){
            
        //     //echo $level.$department."t";
        
        
        //   $result= ONLINEPAY::getStudent($level, $prog, $department);
        
        // }else if ((($level=='ND I') or ($level=='HND I')) and ($department!='')){
            
        //     //echo $level.$department."r";
            
        //     $result= ONLINEPAY::getStudentI($level, $prog, $department);
        
      
        // }
        
        
    //     else if ((($level=='ND') or ($level=='HND')) and ($department=='')){
        
    //     //echo $level.$department."u";
        
    //      $result= ONLINEPAY::getStudentII($level, $prog, $department);
    //   $query = "";
       
    //     } else if ((($level=='ND I') or ($level=='HND I')) and ($department=='')){
            
            //echo $level.$department."y";
            
            // $result= ONLINEPAY::getStudentIII($level, $prog);
            
             //$query = "";
            
        // }
         //$result = mysql_query($query) or die(mysql_error());
   // }
    
    // if($department =="" && $level !="" && $session !="")
    // {
    //     $quy = "SELECT COUNT(admission_list.formno), admission_list.department FROM admission_list JOIN admitted_student_details_2019 
    //                 ON admitted_student_details_2019.formno = admission_list.formno WHERE admission_list.formno LIKE '%$prog%'
    //                 AND admitted_student_details_2019.level LIKE '{$level}' 
    //                 AND admission_list.session LIKE '{$session}' GROUP BY department";
        
    //     $rest = mysql_query($quy) or die(mysql_error());
    // }
    
    // if ($level == 'ND' && $prog == 'PU')
    // {
    //     $msg = 'ND I On Full-Time Programme ';
    // }
    // elseif ($level == 'ND' && $prog == 'DP')
    // {
    //     $msg = 'ND I On Daily Part-Time Programme ';
    // }elseif ($level == 'HND' && $prog == 'FT')
    // {
    //     $msg = 'HND I On Full-Time Programme ';
    // }elseif ($level == 'HND' && $prog == 'DP')
    // {
    //     $msg = 'HND I On Daily Part-Time Programme';
        
    // }elseif ($level == 'ND I' && $prog == 'PU')
    // {
    //     $msg = 'ND II On Full-Time Programme ';
    // }
    // elseif ($level == 'ND I' && $prog == 'DP')
    // {
    //     $msg = 'ND II On Daily Part-Time Programme ';
    // }elseif ($level == 'HND I' && $prog == 'FT')
    // {
    //     $msg = 'HND II On Full-Time Programme ';
    // }elseif ($level == 'HND I' && $prog == 'DP')
    // {
    //     $msg = 'HND II On Daily Part-Time Programme';
    // }

    
}
$count = 0;

?>



<html>
 <head>
  <title>Gender-Generate</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css"/>
 </head>
 <body>
  <div class="container box" style="width:100%; background-color:white" >
   <h2 align="center">
       <?php
       
       ?> </h2>
   <h3 align="center"></h3>
   <br />
   <form method="POST" action="">                        	
    	<!--<div class="form-group input-group" align="center" style="width:100%; background-color:red" >-->
    
    
    <div class="table-responsive">
       <table id="mytable" class="table table-bordered table-striped"  >
        	<tr>
        	    
    
    			
    			<td>
					<select name="ptype" id="ptype" class="form-control action" style="width:120px">
						<option value="">Select Payment</option>
						
						<option value="acceptance_tranzact">Acceptance</option> 
						<option value="schoolfees_tranzact">School Fees</option> 
					
					</select>
				</td>
    			
    			<td>
					<select name="session" id="session" class="form-control action" style="width:120px">
						<option value="">Select Session</option>
						<?php foreach($allsession as $session){?>
						<option value="<?php echo $session->session;?>"><?php 
						echo $session->session?></option><?php }?>
					</select>
				</td>
				
				<td>
<!--<div class="input-daterange">-->

                <div><label  style="margin-left:10px" >Start Date</label></div>
                <div class="col-md-12">
                <input type="text"  autocomplete="off" name="start_date" id="start_date" style="width:100%" placeholder="StartDate"/>
                </div>
                </td>


                <td>
                    <div><label  style="margin-left:10px" >End Date</label></div>
                            <div class="col-md-12">
                    <input type="text" autocomplete="off" name="end_date" id="end_date" style="width:100%"   placeholder="EndDate"/>
                    
                    </div>
                </td>
            	<td>
                    <span class="input-group-btn">
                        <input type="submit" class="btn btn-danger" name="search" value="Search" id="search">
                    </span>
                </td>
                <!--<td>-->
                <!--    <div>-->
                <!--        <input type="submit" name="Print_pdf" id ="Print_pdf" class="btn btn-danger" value="Print PDF" />-->
                <!--    </div>-->
                <!--</td>-->
         	</tr>
        </table>
        </div>
    </br>
    
    <div class="panel panel-primary chat-panel" width="50px" >
        <div class="panel-heading ">
            <? echo $msg;?>
        </div><br/>
   <div class="table-responsive">
       <table id="mytable" class="table table-bordered table-striped"  >
     <thead>
      <tr height ="40">
        <th>S/N</th>  
        <th>FORMNO</th>
        <th>DEPARTMENT</th>
        <th>NUMBER OF STUDENTS</th>
        <th>LEVEL</th>
        <th>PAYMENT DATE</th>
       
      </tr>
     </thead>
    <?
     
    // print_r($result);
    if (sizeof($result)>0)
    {
        foreach($result as $row){
        echo    '<tr>'
                    .'<td>'.++$count.'</td>'
                    .'<td>'.$row->formno.'</td>'
                    .'<td>'.$row->department.'</td>'
                    
                    .'<td>'.($row->surname.''.$row->othernames).'</td>'
                    .'<td>'.$row->level.'</td>'
                    .'<td>'.$row->datetime.'</td>'
                    
                   
				.'</tr>';
         }
                   
        
    }
    if ($rest){
        echo '<table id="summary" class="table table-striped table-bordered" >
                <tr>
                    <td width="50px">Total number of students:</td>
                    <td width="100px"> Department </td>';
                    while($row = mysql_fetch_array($rest)){
                        echo    '<tr>'
                                .'<td>'.$row['admission_list.formno'].'</td>'
                                .'<td>'.$row['department'].'</td>'
    						.'</tr>';
                     }
                   
                '</tr>';
            '</table>';
        
        }
    ?>
    </table>
   </div>
   </div>
  </div>
  <br />
  </form><br />
 </body>
</html>



    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
        <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
        <script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
        <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
        <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
        <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>
    
<script type="text/javascript" language="javascript" >
  {
    $('#mytable').DataTable( {
    dom: 'Bfrtip',
    buttons: [
        'copy', 'csv', 'excel', 'pdf', 'print'
        // extend:'print',
            // autoPrint: true,
            //     title: '2019/2020 ADIMISSION LIST',
    ]
});

  }
  
  
</script>

<script>
     $( function() {
      $( "#start_date" ).datepicker();
      $( "#end_date" ).datepicker();
     
  } );

</script>