<?php
//	error_reporting(0);
	define('INCLUDE_CHECK',true);
	session_start();
	require ('classes/config2.php');
	require_once('classes/session.php');
	
	
?>
<title>OSCOTECH, ESA-OKE :: Admin-Dashboard > DPT Admitted List</title>


        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Matriculation Generated Engine</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                	<div class="well" style="background:#FFF">
                    	<form method="post" action="" role="form" enctype="multipart/form-data">                        	
                        	<div class="form-group input-group">
                        	<table class="table table-bordered table-hover">
                            	<tr>
                                	<td>
                                        <select name="courses" id="courses"  class="form-control">
                                          <option value="">-- Select Department -- </option>
                                             <?php 
                                                    $getdept = ("SELECT department FROM department_mat where faculty!='dpt_FO'");
                                                     $result = $conn1->query($getdept);
                                                     while($row = $result->fetch_assoc()) {
                                                ?>
                                                    <option value="<?php echo $row['department'] ?>"><?php echo $row['department']?></option>
                                                <?php
                                                    }
                                            ?>
                                            ?>
                                        </select>
                                	</td>
                                    <td>
                                    	<select name="programme" class="form-control" id="programme">
                                            <option value="">--Select Programme--</option>
                                           
                                           <?php 
                                           
                                                    $getsetup = ("SELECT ptypename, faculty, code FROM fo_setup");
                                                     $res = $conn1->query($getsetup);
                                                     while($row = $res->fetch_assoc()) {
                                                ?>
                                                    <option value="<?php echo $row['ptypename'] ?>"><?php echo $row['faculty']?></option>
                                                <?php
                                                    }
                                            ?>
                                            ?>
                                        </select>
                                    </td>
                                    <td>
                                    	<select name="session" class="form-control" id="session">
                                            <option value="">--Select Session--</option>
                                            <option value="2019/2020">2019/2020</option>
                                            <option value="2020/2021">2020/2021</option>
                                        <option value="2021/2022">2021/2022</option>
                                        <option value="2022/2023">2022/2023</option>
                                         <option value="2023/2024">2023/2024</option>
                                        </select>
                                    </td>
                                    <td>
				                       <input type="text" class="form-control" placeholder="From: yyyy-mm-dd"name="fromdate" title="Uploading Date " autocomplete="on">
                                    </td>
                                    <td>
				                       <input type="text" class="form-control" placeholder="To: yyyy-mm-dd"name="todate" title="Uploading Date " autocomplete="on">
                                    </td>
                                	<td>
                                        <span class="input-group-btn">
                                            <input type="submit" class="btn btn-danger" name="btnsearch" value="Search" id="button-search" title="Search Student">
                                        </span>
                                    </td>
                             	</tr>
                            </table>
                            </div>
                        </form>
                    </div>
                    <form action="" method="post" enctype="multipart/form-data">
                    <div class="panel panel-primary chat-panel">
                        <div class="panel-heading ">
                            Student Admitted Table
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                        <tr height="20">
                                            <th>S/N</th>
                                            <th>FORM NO</th>
                                            <th>SURNAME</th>
                                            <th>OTHER NAMES</th>
                                            <th>DEPARTMENT</th>
                                            <th>SEX</th>
                                            <th>MATRIC NO</th>
                                        </tr>
                                    </thead>
					<?php
							$_SESSION['sek']= $_POST['session'];
							$_SESSION['programme']= $_POST['programme'];
							$_SESSION['fromdate']= $_POST['fromdate'];
							$_SESSION['todate']= $_POST['todate'];
							$courses=$_POST['courses'];
							$_SESSION['courses'] = $courses;
						    $progtype=$_SESSION['programme'];
                        
                         $sqldept=("select deptcode,matListCode from department_mat where department='$courses' ");
						$resdept = $conn1->query($sqldept);
						while($row = $resdept->fetch_assoc()) {
						$code=$row['deptcode'];
						$cmcode=$row['matListCode'];
						}
						
						$b='0';
						
						if ($code <=9) {
						   // $mcode=$b.$code;
						   $mcode= $code;
						    
						}
						else	if ($code >9) {
						    $mcode= $code;
						    
						}
						
						if ($progtype=='%PU230%' AND $cmcode==0) {
                                $ptype=1;
                                $lv=1;
                                $classlv='Full Time ND';
                            }
                            elseif ($progtype=='%PT230%' AND $cmcode==0) {
                                $ptype=2;
                                $lv=1;
                                $classlv='Part Time ND';
                            }
                            elseif ($progtype=='%FT230%' AND $cmcode==0) {
                                $ptype=1;
                                $lv=2;
                                $classlv='Full Time HND';
                            }
                            
                             
                            elseif ($progtype=='%FT230%' AND $cmcode==2) {
                                $ptype=1;
                                $lv=2;
                                $classlv='Full Time HND';
                            }
                            elseif ($progtype=='%FT230%' AND $cmcode==3) {
                                $ptype=1;
                                $lv=3;
                                $classlv='Full Time HND';
                            }
                            elseif ($progtype=='%FT230%' AND $cmcode==4) {
                                $ptype=1;
                                $lv=4;
                                $classlv='Full Time HND';
                            }
                            elseif ($progtype=='%FT230%' AND $cmcode==5) {
                                $ptype=1;
                                $lv=5;
                                $classlv='Full Time HND';
                            }
                            elseif ($progtype=='%FT230%' AND $cmcode==6) {
                                $ptype=1;
                                $lv=6;
                                $classlv='Full Time HND';
                            }
                             elseif ($progtype=='%FT230%' AND $cmcode==7) {
                                $ptype=1;
                                $lv=7;
                                $classlv='Full Time HND';
                            }
                             elseif ($progtype=='%FT230%' AND $cmcode==8) {
                                $ptype=1;
                                $lv=8;
                                $classlv='Full Time HND';
                            }
                          //  echo $cmcode; 
                            $yr=23;
                            $l='%';
                            $g='%';
                            $yrcode=$yr.$ptype.$mcode.$lv;
                            $csel=$l.$yrcode.$g;
                          //  echo $csel;
                         //  echo $yr,$ptype,$mcode,$lv;
						
				 $sqlcnt = ("SELECT  COUNT(distinct matricno)  FROM student_activity_level WHERE matricno LIKE '$csel'");
                $row = mysqli_fetch_assoc(mysqli_query($conn1, $sqlcnt));
                $crow = $row['COUNT(distinct matricno)'];
               $dd= $crow;
						
						
						
							echo $courses,$progtype,$classlv,$_POST[session];
							
                        	if($_POST[fromdate]=="" || $_POST[todate]=="")
                        	                                    {
							$sql = ("SELECT DISTINCT schoolfees_tranzact_remita.formno,student_activity_level.formno,student_activity_level.matricno, schoolfees_tranzact_remita.session, schoolfees_tranzact_remita.surname,schoolfees_tranzact_remita.othernames,schoolfees_tranzact_remita.faculty,schoolfees_tranzact_remita.department, schoolfees_tranzact_remita.level, schoolfees_tranzact_remita.statusMessage FROM schoolfees_tranzact_remita,student_activity_level WHERE schoolfees_tranzact_remita.formno=student_activity_level.formno AND schoolfees_tranzact_remita.formno LIKE '$progtype' AND student_activity_level.matricno=0 AND schoolfees_tranzact_remita.department='$courses' AND schoolfees_tranzact_remita.statusMessage='Successful' AND student_activity_level.start_session='$_SESSION[sek]' ");
							// ORDER BY schoolfees_tranzact_remita.surname
                        	}
                        	$result = $conn1->query($sql);
                        
                            $k='000';
                            $k1='00';
                            $k2='0';
                            
                            
                            
                        $i=$dd;
                        echo $i;
                         while($row = $result->fetch_assoc()) {
                             
                             
                     //   while($row=mysql_fetch_array($sql)){
                        $i++;
                        
                        $color=($i%2==0)?"lightblue":"white";
                         if ($i<=9){
                                            $mat=($yrcode.$k.$i);
                                            
                                            }
                                            elseif ($i<=99) {
                                                $mat= $yrcode.$k1.$i;
                                            }
                                            elseif ($i<=999) {
                                                $mat= $yrcode.$k2.$i;
                                            }
                                            elseif ($i>999) {
                                                $mat=$yrcode.$i;
                                            }
                    ?>
                    
                   	
                                    <tbody>
                                        <tr >
                                        	<td><?php echo $i;?></td>
                                            <td><?php echo $row['formno'];?></td>
                                            <td><?php echo $row['surname'];?></td>
                                            <td><?php echo $row['othernames'];?></td>
                                            <td><?php echo $row['department'];?></td>
                                            <td><?php echo $row['faculty'];?></td>
                                            <td><?php 
                                                 echo $mat;
                                                 
                                                 
                                           	 	
											?></td>
                                        </tr>
                                    </tbody>
                                    <?php
                                    
                $sqlupdate=("UPDATE student_activity_level SET matricno='$mat' WHERE formno='$row[formno]'");
                $resupdate = $conn1->query($sqlupdate);
                        ?>
                          <?php	
							}
							?>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                          
                        </div>
                        <!-- /.panel-body --> 
                    </div> 
                    <!-- /.panel -->
                    	<center>
                       		 <a href="printout_admitted_student_spreadsheet_con.php" target="_new" class="btn btn-warning">Download Matriculation List</a> 
                             <a href="printout_matric_list.php" target="_new" class="btn btn-success">Print Matriculation List</a>
                            <p>&nbsp;</p>
                        </center>
                    </form>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->

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

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