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

$ins = array();

$allduplicate = Duplicate:: showduplicate();

//  foreach ($allduplicate as $dup){
//     $data = Duplicate::allApp($dup->matricno);
//  }
   
   //print_r($allduplicate);
   $data = Duplicate::allDup();
    
    //print_r($data);
    $count=0;
    foreach ($allduplicate as $dt){
        
         echo "<br>".$dt->names ." ". $dt->formno." ".$dt->matricno." ".$dt->department."<br>";
          Duplicate::insertD($dt->names, $dt->formno,$dt->matricno,$dt->department);
         //echo $dt->matricno;
           //$stu = Duplicate::selC($dt->matricno);
          
         //  $stu = Duplicate::selUpdate($dt->matricno);
         
        //  if ($dt->ToUse!=1){
        //      $count++;
           
        //   echo "Full Name: ". $dt->fullname."<br>";
        //   Duplicate::revokemat($dt->formno);
           
        //  }
           //Duplicate::updateToUse($stu->id);
           
           //echo "Frm: ".$dt->formno;
           
         // $updateDupMat = Duplicate::getNewMat($dt->formno);
           
          //echo "Mat: ". $updateDupMat->matricno;
           
           
        //   if (isset($updateDupMat->matricno)){
               
        //       Duplicate::updateNewMat($updateDupMat->matricno, $dt->formno);
           
        //   }
           
           
        //   print_r($stu);
          
        //   foreach($stu as $dat)
        //   {
              
        //       //echo "Student: ". $dat->matricno."<br>";
              
        //      // echo $dat->std_process_id."<br>";
         
        //  if (isset($dat->std_process_id) AND ($dat->std_process_id==800)){
         
        //   echo  " ID: ".$dat->id.' ------ Process ID  '. $dat->std_process_id.'  '. $dat->matricno . " --------------->    "."Shared Matric, try to update<br><br>";
           
        //   // Duplicate::updateId($dat->id);
          
        //   Duplicate::deleteId($dat->id);
        //  }else{
            
        //       echo  " ID: ".$dat->id.' ------ Process ID  '. $dat->std_process_id.' '. $dat->matricno . " --------------->    "."Real matric no update<br><br>";
           
        //      //echo $dat->matricno . " --------------->    "."No need to update<br>"; 
        //  }
          }
          
        
    //}
     
//}

foreach ($ins as $data){
    
    //echo $data->names ." ". $data->formno." ".$data->matricno." ".$data->department."<br>";
    //Duplicate::insertD($data->names, $data->formno,$data->matricno,$data->department);
}
//print_r($ins);
echo "Insertion completed successfully:  count-> ".$count;

// $allsession = ONLINEPAY:: showsession();
// College Martic Number Format : year|programmecode|departmentcode|Levelcode|4digit'e.g 0001'

if (isset($_POST['btnsearch']))
{
    
  
}

?>

<html>
 <head>
  <title>Admin-GenerateMatric</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" />
        <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>
        <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">
   <h2 align="center">MATRICULATION LIST</h2>
   <h3 align="center">DEPARTMENT OF </h3>
   <h3 align="center"></h3>
   <br />
   <form method="post" action="" role="form" enctype="multipart/form-data">                        	
    	<div class="form-group input-group" align="center">
    	<table class="table table-bordered table-hover">
        	<tr>
        	    <td>
                    <select name = "depart" id="depart" class="form-control action" style="width:120px" required>
                        <option value="">Select Department...</option>
                        <?php foreach($alldept as $dept){?>
                        <option value="<?php echo $dept->department;?>"><?php 
                        $dprepare= strtolower($dept->department);
                        echo ucwords($dprepare);?></option> <?php }?>
                    </select>
                </td>
                <td>
                	<select name="level" id="level" class="form-control action" style="width:120px" required>
						<option value="">Select Level</option>
						<option value="ND I">ND</option>
	                    <option value="HND I">HND</option>		
					</select>
                </td>
                <td>
    				<select name="programme" id="programme" class="form-control action" style="width:120px" required>
    					<option value="">Select Programme</option>
    					<option value="DP18">Daily-PartTime</option>
                        <option value="FT18">Full-Time(HND)</option>
                        <option value="PU18">Full-Time(ND)</option>
    				</select>
    			</td>
    			
    			<!--<td>-->
    			<!--	<select name="session" id="session" class="form-control action" style="width:120px" required>-->
    			<!--		<option value="">Select Session</option>-->
    			<!--		<option value="18">2018/2019</option>-->
       <!--                 <option value="19">2019/2020</option>-->
                      
    			<!--	</select>-->
    			<!--</td>-->
            	<td>
                    <span class="input-group-btn">
                        <input type="submit" class="btn btn-danger" name="btnsearch" value="Search" id="btnsearch" title="Search Student">
                    </span>
                </td>
         	</tr>
        </table>
        </div>
    </form></br>
    
   <? //$n = 0;  //$matno = ("%04d", $n);
   // $format = $yr.$progcode.$dptcode->deptcode.$levcode; ?>
    
    <div class="panel panel-primary chat-panel">
        <div class="panel-heading ">
            <? echo $msg;?>
        </div><br/>
   <div class="table-responsive">
    <table id="applicant_table" class="table table-bordered table-striped">
     <thead>
      <tr>
        <th width="5%">S/N</th>  
        <th width="10%">FORM NO</th>  
        <th width="20%">MATRIC NO</th>  
        <th width="30%">FULL NAMES</th>  
        <th width="45%">DEPARTMENT</th>
      
      </tr>
     </thead>
     <?php
        try
            { 
                // if(empty($get_prog)){throw new Exception ();}
                // else{
                foreach ($allduplicate as $rows)
                {
                    // $matno = str_pad($start_matno+1, 4, 0, STR_PAD_LEFT);
                    // ++$start_matno;
                    // $mat = $format.$matno;
                   echo  '<tr>'
                            .'<td>'.++$count.'</td>'
        					.'<td>'.$rows->formno.'</td>'
        					.'<td>'.strtoupper($rows->matricno).'</td>'
        					.'<td>'.strtoupper($rows->names).'</td>'
        					.'<td>'.$rows->department.'</td>'
        					
    					.'</tr>';
    					
    				 	//$update = ONLINEPAY::update_matricno('student_activity_level',$mat,$rows->formno,$rows->email);
                }
                
                // }
            }catch (exception $e){ }
        
     
     
     ?>
    </table>
   </div>
   </div>
  </div>
  <br />
  <br />
 </body>
</html>


<script type="text/javascript" language="javascript" >
 $(document).ready(function(){
     $('#applicant_table').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    });
});
 
</script>