<?php
	error_reporting(0);
	define('INCLUDE_CHECK',true);
	session_start();
	require ('classes/config1.php');
	require_once('classes/session.php');
	
 
	if(isset($_POST['adm'])) { 
	    
			$checkbox1=$_POST['sadmitted'];  
			$chk="";  
			foreach($checkbox1 as $chk1) {  
			  	$chk = $chk1;  
		   	    $chk_form = substr($chk,0,9);
				$chk_type = substr($chk,9,12);
			//	$chk_email=$email;
	           //  echo $chk_email;
	           
	           
	   $sql2=("Select student_account.id,student_account.email,student_account.surname,student_account.othernames,student_account.department, form_data21.acc_id, form_data21.formno
	                            FROM student_account, form_data21
                                WHERE form_data21.acc_id=student_account.id
                                 AND form_data21.formno='$chk_form'");
            $result = $conn->query($sql2);  
            
            //  while($row=mysql_fetch_array($sql2)){  
            while($row = $result->fetch_assoc()) {
                 $email=$row['email']; 
                 $names=$row['surname'] . "  " . $row['othernames'];
                 $department= $row['department'];
                 
                 if ($department=='Microbiology (Option)'){
                     
                     $department='Applied Science (Microbiology Option)';
                 }
                     
                else if ($department=='Chemistry (Option)'){
                     
                     $department='Applied Science (Chemistry Option)';
                     
                } else if ($department=='Physics with Electronics (Option)'){
                     
                     $department='Applied Science (Physics with Electronics Option)';
                     
                }else if ($department=='Bio-chemistry'){
                     
                     $department='Applied Science (Biochemistry Option)';
                     
                }else if ($department=='Environmental Biology'){
                     
                     $department='Applied Science (Environmental Biology Option)';
                     
                }
                 
              }        
	
	
	    	require ('classes/config2.php');
	       require_once('classes/session.php');
		$sql = ("INSERT INTO admission_list(formno,names,department,status,session,admitted_date) values ('$chk_form','$names','$department','$chk_type','{$_SESSION['sek']}',NOW())"); 
		 $res = $conn1->query($sql); 
		
		
		$sql1 = ("INSERT INTO student_activity_level(formno,matricno,batch,email,std_process_id,adm_date,status,start_session) values ('$chk_form','0','0','$email','1',NOW(),'open','{$_SESSION['sek']}')"); 
		$res = $conn1->query($sql); 	
		
		$sql = ("INSERT INTO admission_list(formno,names,department,status,session,admitted_date) values ('$chk_form','$names','$department','$chk_type','{$_SESSION['sek']}',NOW())"); 
		 $res = $conn->query($sql); 	
		
		
		
			require ('classes/config1.php');
         	require_once('classes/session.php');
	
	
	
		$sqlupdate=("UPDATE form_data21 SET status ='admitted' WHERE formno='$chk_form'")or die ('An error occured ' . mysql_error()); } 
	      $res1 = $conn->query($sqlupdate); 
			if($sql==1){  
			  echo'<script>alert("Admitted Successfully")</script>';  
		   	}else{  
			  echo'<script>alert("Failed To Admitted")</script>';
		   	} 
		}   
?>
<title>OSCOTECH, ESA-OKE :: Admin-Dashboard > Admission Operation Student List</title>


        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Admission List By Programme and Department</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">                        	
                        	<div class="form-group input-group">
                        	<table class="table table-bordered table-hover">
                            	<tr>
                                	<td>
                                        <select name="department" id="department"  class="form-control">
                                          <option value="">-- Select Department -- </option>
                                            <?php 
                                                    $getdept = ("SELECT dept FROM department ");
                                                    $res = mysqli_query($conn, $getdept);
                                                    //while($row = mysql_fetch_array($res)){
                                                while($row = mysqli_fetch_assoc($res)) {
                                                ?>
                                                    <option value="<?php echo $row['dept'] ?>"><?php echo $row['dept']?></option>
                                                <?php
                                                    }
                                            ?>
                                        </select>
                                	</td>
                                    <td>
                                    	<select name="progtype" class="form-control" id="progtype">
                                            <option value="">--Select Programme--</option>
                                            <option value="NDPT">National Diploma (PART TIME)</option>
                                            <option value="HND">Higher National Diploma (FULL TIME)</option>
                                            <option value="HNDPT">Higher National Diploma (PART TIME)</option>
                                          <!--   <option value="CAPND">Weekend Part Time(National Diploma) </option>
                                              <option value="CAPHND">Weekend Part Time(Higher National Diploma) </option> -->
                                        </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">
                    <div class="panel panel-primary chat-panel">
                        <div class="panel-heading ">
                            Student Details 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>EMAIL</th>
                                            <th>PROGRAMME</th>
                                          <!--  <th>COURSES</th> -->
                                            <th>PROV</th>
                                            <th>CONC</th>
                                        </tr>
                                    </thead>
					<?php
							$_SESSION['sek']= $_POST['session'];
							$_SESSION['department']= $_POST['department'];
							$_SESSION['progtype']= $_POST['progtype'];
							$_SESSION['fromdate']= $_POST['fromdate'];
							$_SESSION['todate']= $_POST['todate'];
							$department=$_POST['department'];
							$progtype=$_POST['progtype'];
						//	$key="FT";
							echo $department,$progtype,$_POST[session];
							
                        	if($_POST['progtype']=="NDPT" )
                        	  {
                        	$sqlnew=("SElECT student_account.id,student_account.surname, student_account.othernames,
                        	     student_account.email, student_account.progtype,student_account.level,student_account.department 
                        	     
                             	  FROM  student_account
                                  
                             	 ");
                             //	 echo $progtype;
                        	 	$result = mysqli_query($conn, $sqlnew); 
                        	  }
                         
                           elseif($_POST[fromdate]=="" || $_POST[todate]=="" ||$_POST['progtype']=="HND" )
                        	  {
                        		$sql=("SElECT student_account.id,student_account.surname, student_account.othernames,student_account.email, student_account.progtype,student_account.level,student_account.department,
							   form_data22.acc_id,form_data22.formno
                             	FROM  student_account
                             	JOIN form_data22
                                ON student_account.id=form_data22.acc_id
                               
                                AND student_account.department='$department'
                                AND student_account.progtype='$progtype'
                                AND form_data22.status=''
                          order by form_data22.formno
                                ");
                            	$result = $conn->query($sql);    
                        	  }
                        	  
                        elseif($_POST[fromdate]=="" || $_POST[todate]=="" ||$_POST['progtype']=="HNDPT" )
                        	  {
                        		$sql=("SElECT student_account.id,student_account.surname, student_account.othernames,student_account.email, student_account.progtype,student_account.level,student_account.department,
							   form_data22.acc_id,form_data22.formno
                             	FROM  student_account
                             	JOIN form_data22
                                ON student_account.id=form_data22.acc_id
                               
                                AND student_account.department='$department'
                                AND student_account.progtype='$progtype'
                                AND form_data22.status=''
                          order by form_data22.formno
                                ");
                                	$result = $conn->query($sql);
                        	  }
                        
                        	elseif($_POST[fromdate]=="" || $_POST[todate]=="" ||$_POST['progtype']=="NDPU" )
                        	  {
                        		$sql=("SElECT student_account.id,student_account.surname, student_account.othernames,student_account.email, student_account.progtype,student_account.level,student_account.department,
							   admission_card_pin.acc_id,admission_card_pin.formno
                             	FROM  student_account
                             	JOIN admission_card_pin
                                ON student_account.id=admission_card_pin.acc_id
                                AND admission_card_pin.adm_status='not-admitted'
                                AND student_account.department='$department'
                                AND student_account.progtype='$progtype'
                                ");
                                	$result = $conn->query($sql);
                        	  }
                        	
                        	
							//	$sql = mysql_query("SELECT * FROM admission_2017_students_details
							//			WHERE courses='$courses' AND programme='$_POST[programme]' 
							//			AND formno  like '%$key%' AND session='$_POST[session]' 
							//			AND status='not-admitted'");
										
						//	elseif($_POST[courses]=="" || $_POST[programme]=="" || $_POST[session]=="" || $_POST[fromdate]=="" || $_POST[todate]=="")								
							//	$sql = mysql_query("SElECT * FROM admission_students_details");
							else							
								
								$sql=("SElECT student_account.id,student_account.surname, student_account.othernames,student_account.email, student_account.progtype,student_account.level,student_account.department,
							     admission_card_pin.acc_id,admission_card_pin.formno
                             	FROM  student_account
                             	JOIN admission_card_pin
                                ON student_account.id=admission_card_pin.acc_id
                                AND admission_card_pin.adm_status='not-admitted'
                                AND student_account.department='$department'
                                ");
									$result = $conn->query($sql);
								
							//	$sql = mysql_query("SELECT * FROM admission_2017_students_details
							//			WHERE courses='$courses' AND programme='$_POST[programme]' 
							//			AND formno  like '%$key%'
							//			AND reg_date Between '$_POST[fromdate]' AND '$_POST[todate]'
							//			AND session='$_POST[session]' AND status='not-admitted'");
                           
                        $i=0;
                       // while($row=mysql_fetch_array($sql)){
                       while($row = $result->fetch_assoc()) {
                        $i++;
                        $color=($i%2==0)?"lightblue":"white";
                        
                    ?>
                                    <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['email'];?></td>
                                            <td><?php echo $row['progtype'];?></td>
                                          <!--  <td><?php //echo $row['department'];?></td>  -->
                                            <td><input type="checkbox" name="sadmitted[]" value="<?php echo $row['formno']."PRO";?>" /></td>
                                            <td><input type="checkbox" name="sadmitted[]" value="<?php echo $row['formno']."CON";?>" /></td>
                                        </tr>
                                    </tbody>
                          <?php	
							}
						//	if ($_SESSION['programme']=='HND'){ ($_SESSION['pass'] ="HND") AND ($_SESSION['entry'] ="Higher National Diploma, Daily Part Time-2years");}
														
							?>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                          
                        </div>
                        <!-- /.panel-body --> 
                    </div> 
                    <!-- /.panel -->
                    	<center>
                       		<!-- <a href="#" target="_new" class="btn btn-success">ADMITTED</a> -->
                            <input type="submit" class="btn btn-success" value="ADMITTED" name="adm" />
                            <p>&nbsp;</p>
                        </center>
                    </form>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->

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

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