<?php session_start() ?>
<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SCHOOL PORTAL </title>

<meta name="description" content="" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">






<script src="excellentexport.js"></script>
  
</head>
<head>
<style>
table {

    border-collapse: collapse;
    font: normal 75% arial, sans-serif;
}
th.rotate {
  /* Something you can count on */
  height: 140px;

  white-space: nowrap;
}

th.rotate > div {
  transform: 
    /* Magic Numbers */
    translate(10px, 51px)
    /* 45 is really 360 - 45 */
    rotate(270deg);
  width: 40px;

}
th.rotate > div > span {
  border-bottom: 1px solid #ccc;
  padding: 5px 10px;
}

.csstransforms & th.rotate {
  height: 140px;
  
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 3px;

}
td.rotate {
  /* Something you can count on */
  height: 140px;


}

td.rotate > div {
  transform: 
    /* Magic Numbers */
    translate(10px, 51px)
    /* 45 is really 360 - 45 */
    rotate(270deg);
  width: 40px;
height: 40px;
}
td.rotate > div > span {
  border-bottom: 1px solid #ccc;
  padding: 5px 10px;
}

.csstransforms & tr.rotate {
  height: 140px;
  white-space: nowrap;
}


tr:nth-child(even) {
    background-color: #dddddd;
}
</style>
</head>
<body>
<script>
function cons()

{

window.print();


}

function funagree(){
        document.lodge.action="set1083.php";
}

</script>
<?php
    function do_alert($msg) 
    {
        echo '<script type="text/javascript">alert("' . $msg . '") 
           parent.location="set1083.php";

</script>';
       
    }
?>
<body bgcolor="#fff" class="common-home">

<header>

  <div class="container">
    <div class="row">
      <div class="col-sm-12">

	
	
        <div id="logo">
 
                  </div>
      </div>

      
     
</div>
    </div>
  </div>
<?php
$dte= date("d/m/y", time());

$tme= date(" h:i:s a", time());


?>
<?php
$pee=$_POST['term'];
$peea=$_POST['session'];


$ddd=$_SESSION['clay'];
$ddd=strtolower($ddd);
$cll=$_SESSION['class'];
$aarm=$_SESSION['arm'];

$class=$_SESSION['class'];
$arm=$_SESSION['arm'];
$ddd=$_SESSION['clay'];
$clasx=strtoupper($class);

$sx=strtoupper($arm); 

$cll=$class;
$aarm=$arm;

$cvb="$pee$peea";

$asz="leotftqa_patt";
$ddd=strtolower($ddd);
$dcv="$cvb$asz";
if ($pee=="1stterm")
{
$bbl=$asz;
}else 
{
$bbl=$dcv;
}

$bbl="leotftqa_patt";
$_SESSION['bbl']=$bbl;





?>
<?php

$servername = "localhost";
$username = "leotftqa";
$password = "7OOjblml0I90";
$dbname = "leotftqa_patt";
$dbname = $bbl;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}



$sql =

"select 
* from `beva1` where password ='$ddd' order by regno ";
$data=(mysqli_query($conn,$sql)); 

$rows4 = mysqli_num_rows($data);
$rows4y = mysqli_num_rows($data);

?>



<?php

 
$sql =" create table `#crd$ddd` 

as

select 
* from `beva1` where password ='$ddd' order by regno ";
$data=(mysqli_query($conn,$sql));  


$sql =" create table `cleand$ddd` 

as

select 
regno,name from `beva1` where password ='$ddd' order by regno ";
$data=(mysqli_query($conn,$sql));  

 
?>


<?php

 
$sql =" delete from `#crd$ddd` where regno=0";
$data=(mysqli_query($conn,$sql)); 

 
?>

 

<?php
 
$sql ="ALTER TABLE `#crd$ddd` ADD ibv INT AUTO_INCREMENT NOT NULL PRIMARY KEY";


(mysqli_query($conn,$sql)); 

?>


<?php

 

for ($i = 1; $i <= $rows4; $i++){


$sql = "select regno from `#crd$ddd` where ibv = '$i'";

$data=(mysqli_query($conn,$sql)); 
while($row= mysqli_fetch_array($data))
{

$svc=  $row['regno'];
 
}

$sql =

" create table `#ss$svc` as select 
REGNO,name,sex,term,Subjects from `$ddd` where REGNO ='$svc'    order by subjects  ";
$data=(mysqli_query($conn,$sql)); 


$sql ="ALTER TABLE `#ss$svc` ADD ibv INT AUTO_INCREMENT NOT NULL PRIMARY KEY";



(mysqli_query($conn,$sql)); 



$sql =

"select 
* from `$ddd` where REGNO ='$svc'  ";
$data=(mysqli_query($conn,$sql)); 
while($row= mysqli_fetch_array($data))
{

$svc=  $row['REGNO'];
$sv1=  $row['Name'];


 
}



$sql = "


INSERT INTO `cleand$ddd` values (0,'NAME')";
          
$data=(mysqli_query($conn,$sql)); 

$sql = "


update `cleand$ddd` set name='$sv1' where regno='$svc'";
          
$data=(mysqli_query($conn,$sql)); 


$sql =" 
select 
* from `#ss$svc` ";
$data=(mysqli_query($conn,$sql)); 
$rows4c = mysqli_num_rows($data);





for ($r = 1; $r <= $rows4c; $r++){


$sql = "select * from `#ss$svc` where ibv = '$r' ";

$data=(mysqli_query($conn,$sql));  
while($row= mysqli_fetch_array($data))
{

$s11=  $row['Subjects'];


}

$sql = "select * from `$ddd` where Subjects = '$s11' and REGNO=$svc";

$data=(mysqli_query($conn,$sql)); 
while($row= mysqli_fetch_array($data))
{

$s1=  $row['Subjects'];

$s2=  $row['tot']; 

}

$sql = "SELECT MAX(tot) AS maxidi FROM `$ddd` where Subjects = '$s11'  ";
          
         
$result = (mysqli_query($conn,$sql)); 
    $result1 = mysqli_fetch_assoc($result);

         

$paii=  $result1['maxidi'];

$sql = " select *  FROM `$ddd` where Subjects = '$s11' and tot != 0 ";
          
         
$result = (mysqli_query($conn,$sql)); 
$rows4c0 = mysqli_num_rows($result);


$sql = "SELECT SUM(tot) AS sume FROM `$ddd` where Subjects = '$s11'  ";
          
         
$result = (mysqli_query($conn,$sql)); 
    $result1 = mysqli_fetch_assoc($result);

         

$saii=  $result1['sume'];


$svgg= round(($saii/$rows4 ),2);




$sql = "create table rtey as select *  FROM `$ddd` where Subjects = '$s11' and tot != 0 ";
          
         
$result = (mysqli_query($conn,$sql)); 

$sql = "SELECT MIN(tot) AS mixidi FROM `rtey` where Subjects = '$s11'  ";
          
         
$result = (mysqli_query($conn,$sql)); 
    $result1 = mysqli_fetch_assoc($result);

         

$pami=  $result1['mixidi'];

$rann=$paii-$pami;


$sql ="create TABLE `stat$ddd` as select * from metroc     ";
(mysqli_query($conn,$sql)); 

$sql ="ALTER TABLE `stat$ddd` ADD `$s1` varchar(30)      ";
(mysqli_query($conn,$sql)); 



$sql ="update `stat$ddd` set `$s1`='$svgg' where regno='1'";
          
$data=(mysqli_query($conn,$sql)); 

$sql ="update `stat$ddd` set `$s1`='$paii' where regno='2'";
          
$data=(mysqli_query($conn,$sql)); 

$sql ="update `stat$ddd` set `$s1`='$pami' where regno='3'";
          
$data=(mysqli_query($conn,$sql)); 

$sql ="update `stat$ddd` set `$s1`='$rann' where regno='4'";
          
$data=(mysqli_query($conn,$sql)); 



$sql = "drop table rtey  ";
          
         
$result = (mysqli_query($conn,$sql)); 





























$sql ="ALTER TABLE `cleand$ddd` ADD `$s1` varchar(30)      ";
(mysqli_query($conn,$sql)); 




$sql ="update `cleand$ddd` set `$s1`='$s2' where regno='$svc'";
          
$data=(mysqli_query($conn,$sql)); 



$sql ="update `cleand$ddd` set `$s1`='$s1' where regno=0 ";
          
$data=(mysqli_query($conn,$sql)); 


}



$sql ="
drop table  `#ss$svc` ";
$data2=(mysqli_query($conn,$sql)); 


}


$sql ="ALTER TABLE `cleand$ddd` ADD GRANDTOTAL DECIMAL( 60, 2 ) NULL DEFAULT NULL      ";


(mysqli_query($conn,$sql)); 


$sql ="ALTER TABLE `cleand$ddd` ADD AVERAGE DECIMAL( 60, 2 )        ";


(mysqli_query($conn,$sql)); 

$sql ="ALTER TABLE `cleand$ddd` ADD TAKE varchar(130)          ";


(mysqli_query($conn,$sql)); 


$sql ="ALTER TABLE `cleand$ddd` ADD POSITION varchar(130)       ";



(mysqli_query($conn,$sql)); 



for ($i = 1; $i <= $rows4; $i++){



$sql = "select regno from `#crd$ddd` where ibv = '$i'";

$data=(mysqli_query($conn,$sql));  
while($row= mysqli_fetch_array($data))
{

$svc=  $row['regno'];
 
}


$sql =" 
select 
* from `$ddd` where tot=0 and REGNO=$svc";
$data=(mysqli_query($conn,$sql));  
$rows4c1 = mysqli_num_rows($data);

$sql = "SELECT SUM(tot) AS maxid FROM `$ddd` where tot !='0' and REGNO='$svc' ";
          
         
$result = (mysqli_query($conn,$sql)); 
    $result1 = mysqli_fetch_assoc($result);

       
$se=($rows4c-$rows4c1) ;
 
$pa=  $result1['maxid'];

$pe= round(($pa ),2);


$avgg= round(($pe/$se ),2);




$sql ="update `cleand$ddd` set `GRANDTOTAL`='$pe' where regno='$svc'";
          
$data=(mysqli_query($conn,$sql));  

$sql ="update `cleand$ddd` set `AVERAGE`='$avgg' where regno='$svc'";
          
$data=(mysqli_query($conn,$sql));  




}


$sql ="delete from  `cleand$ddd` where `GRANDTOTAL`=0";
          
$data=(mysqli_query($conn,$sql));  



///
?>





<?php



 
$sql ="create  TABLE `clean$ddd` as select * from `cleand$ddd` order by `AVERAGE` DESC";
$data=(mysqli_query($conn,$sql)); 
?>
<?php


 
$sql ="ALTER TABLE `clean$ddd` ADD ibv INT AUTO_INCREMENT NOT NULL PRIMARY KEY";
$data=(mysqli_query($conn,$sql)); 


$sql ="update `clean$ddd` set `POSITION`='POSITION' where regno='0'";
          
$data=(mysqli_query($conn,$sql)); 

$sql ="ALTER TABLE `clean$ddd` CHANGE `GRANDTOTAL` `GRANDTOTAL` VARCHAR( 130 ) NULL DEFAULT NULL ";
$data=(mysqli_query($conn,$sql)); 


$sql ="update `clean$ddd` set `AVERAGE`='AVERAGE' where regno='0'";
          
$data=(mysqli_query($conn,$sql)); 


$sql ="update `clean$ddd` set `TAKE`='TAKE' where regno='0'";
          
$data=(mysqli_query($conn,$sql)); 

$sql ="update `clean$ddd` set `GRANDTOTAL`='GRANDTOTAL' where regno='0'";
          
$data=(mysqli_query($conn,$sql)); 

$sql ="ALTER TABLE `clean$ddd` ADD GRADE DECIMAL( 60, 2 )        ";


(mysqli_query($conn,$sql)); 
 
?>
<?php



 


for ($i =1; $i <=$rows4; $i++){



$sql = "select regno from `clean$ddd` where ibv= '$i'";

$data=(mysqli_query($conn,$sql)); 
while($row= mysqli_fetch_array($data))
{

$svc=  $row['regno'];


}
 $b= "1st";
$c= $i-1;

if ($c==0){

$a=0;

}else {
$sql ="select 
`AVERAGE` from `clean$ddd` where ibv =  '$c'  ";
$data1=(mysqli_query($conn,$sql)); 
$rows1 = mysqli_num_rows($data1);



while($row= mysqli_fetch_array($data1))
{

$a=  $row['AVERAGE'];



}
}

$sql =" 
select 
AVERAGE from `clean$ddd` where `ibv` =  '$i' ";
$data1=(mysqli_query($conn,$sql)); 
$rows22 = mysqli_num_rows($data1);





while($row= mysqli_fetch_array($data1))
{

$aa=  $row['AVERAGE'];


}



if($a == $aa){
$sql =" 
select 
* from `clean$ddd` where `AVERAGE` =  '$a'  ";
$data1=(mysqli_query($conn,$sql));  
$rows1 = mysqli_num_rows($data1);

 
while($row= mysqli_fetch_array($data1))
{

$df=  $row['POSITION'];

 
}
}
else {
$d=$i;
}if ($d==1){
$df="1st";
}else if ($d==2){
$df="2nd";
}else if ($d==3){
$df="3rd";
}else if ($d==4){
$df="4th";
}else if ($d==5){
$df="5th";
}else if ($d==6){
$df="6th";
}else if ($d==7){
$df="7th";
}else if ($d==8){
$df="8th";
}else if ($d==9){
$df="9th";
}else if ($d==10){
$df="10th";
}else if ($d==11){
$df="11th";
}else if ($d==12){
$df="12th";
}else if ($d==13){
$df="13th";
}else if ($d==14){
$df="14th";
}else if ($d==15){
$df="15th";
}else if ($d==16){
$df="16th";
}else if ($d==17){
$df="17th";
}else if ($d==18){
$df="18th";
}else if ($d==19){
$df="19th";
}else if ($d==20){
$df="20th";
}else if ($d==21){
$df="21st";
}else if ($d==22){
$df="22nd";
}else if ($d==23){
$df="23rd";
}else if ($d==24){
$df="24th";
}else if ($d==25){
$df="25th";
}else if ($d==26){
$df="26th";
}else if ($d==27){
$df="27th";
}else if ($d==28){
$df="28th";
}else if ($d==29){
$df="29th";
}else if ($d==30){
$df="30th";
}else if ($d==31){
$df="31st";
}else if ($d==32){
$df="32nd";
}else if ($d==33){
$df="33rd";
}else if ($d==34){
$df="34th";
}else if ($d==35){
$df="35th";
}else if ($d==36){
$df="36th";
}else if ($d==37){
$df="37th";
}else if ($d==38){
$df="38th";
}else if ($d==39){
$df="39th";
}else if ($d==40){
$df="40th";
}else if ($d==41){
$df="41st";
}else if ($d==42){
$df="42nd";
}else if ($d==43){
$df="43rd";
}else if ($d==44){
$df="44th";
}else if ($d==45){
$df="45th";
}else if ($d==46){
$df="46th";
}else if ($d==47){
$df="47th";
}else if ($d==48){
$df="48th";
}else if ($d==49){
$df="49th";
}else if ($d==50){
$df="50th";
}else if ($d==51){
$df="51st";
}else if ($d==52){
$df="52nd";
}else if ($d==53){
$df="53rd";
}else if ($d==54){
$df="54th";
}else if ($d==55){
$df="55th";
}else if ($d==56){
$df="56th";
}else if ($d==57){
$df="57th";
}else if ($d==58){
$df="58th";
}else if ($d==59){
$df="59th";
}else if ($d==60){
$df="60th";
}else if ($d==61){
$df="61st";
}else if ($d==62){
$df="62nd";
}else if ($d==63){
$df="63rd";
}else if ($d==64){
$df="64th";
}else if ($d==65){
$df="65th";
}
 $sql =" 
update `clean$ddd` set `POSITION`= '$df' where `ibv`='$i'"; 

$data2=(mysqli_query($conn,$sql)); 

$sql =" 
select 
tot from `$ddd` where `Subjects` ='MATHEMATICS' and regno='$svc' ";
$data1=(mysqli_query($conn,$sql));  
$rows1 = mysqli_num_rows($data1);




while($row= mysqli_fetch_array($data1))
{

$mat=  $row['tot'];
$mgt=round($mat,2);
}

$sql =" 
select 
tot from `$ddd` where `Subjects` ='ENGLISH LANGUAGE' or Subjects='ENGLISH STUDIES' and regno='$svc' ";
$data1=(mysqli_query($conn,$sql)); 
$rows1 = mysqli_num_rows($data1);




while($row= mysqli_fetch_array($data1))
{

$eng=  $row['tot'];
  
$egt=round($eng,2);


}


$sql = "SELECT SUM(tot) AS maxid FROM `$ddd` where  REGNO='$svc' ";
          
         
$result = (mysqli_query($conn,$sql)); 
    $result1 = mysqli_fetch_assoc($result);

          
$se=($rows4c- $rows4c1) ;

$pa=  $result1['maxid'];

$pe= round(($pa ),2);


$fgt= round(($pe/$se ),2);

$meng=$mat + $eng + $pe;

if ($mgt >=80.00 ){
$mm=1;
}else if($mgt >=70.00 ){
$mm=0.75;
}else if($mgt >=60.00 ){
$mm=0.3;
}else if($mgt <60.00){
$mm="0";
}


if ($egt >=80.00){
$ee="1";
}else if($egt >=70.00 ){
$ee="0.75";
}else if($egt >=60.00){
$ee="0.3";
}else if($egt <60.00 ){
$ee="0";
}


if ($fgt >=80.00){
$px="1";
}else if($fgt >=70.00 ){
$px="0.75";
}else if($fgt >=60.00){
$px="0.3";
}else if($fgt <60.00){
$px="0";
}

$dfry = $mm + $ee + $px;


$sql = "update  `clean$ddd` set TAKE= 'BRONZE' WHERE (`MATHEMATICS` < 6.00) OR (`ENGLISH LANGUAGE` < 6.00) OR (`AVERAGE` < 6.00 ) ";
          
         
$result = (mysqli_query($conn,$sql)); 


$sql = "update  `clean$ddd` set GRADE= '$dfry' where  regno='$svc'";
          
         
$result = (mysqli_query($conn,$sql)); 




$sql = "update  `clean$ddd` set TAKE= 'DIAMOND' where regno='$svc' and GRADE=3 ";
          
         
$result = (mysqli_query($conn,$sql)); 



$sql = "update  `clean$ddd` set TAKE= 'GOLD' where regno='$svc' and GRADE between 2.25 and 2.99 ";
          
         
$result = (mysqli_query($conn,$sql)); 


$sql = "update  `clean$ddd` set TAKE= 'SILVER' where regno='$svc' and GRADE between 0.60 and 2.24 ";
          
         
$result = (mysqli_query($conn,$sql)); 





}

$sql ="ALTER TABLE `clean$ddd`
  DROP `GRADE`;";
          
$data=(mysqli_query($conn,$sql)); 


$sql ="update `clean$ddd` set `TAKE`='GRADE' where regno='0'";
          
$data=(mysqli_query($conn,$sql)); 

$sql =" 
select 
* from `clean$ddd` where `regno` =  '$svc'  ";
$data1=(mysqli_query($conn,$sql)); 
$rows1 = mysqli_num_rows($data1);






while($row= mysqli_fetch_array($data1))
{

$pp=  $row['POSITION'];
  



}











$sql ="ALTER TABLE `clean$ddd` DROP ibv ";
$data=(mysqli_query($conn,$sql)); 



$sql =" 
select 
*  from `clean$ddd` where `TAKE` ='DIAMOND'  ";
$data1=(mysqli_query($conn,$sql));  
$rows1D = mysqli_num_rows($data1);


$sql =" 
select 
*  from  `clean$ddd` where `TAKE` ='GOLD'  ";
$data1=(mysqli_query($conn,$sql));  
$rows1G = mysqli_num_rows($data1);



$sql =" 
select 
* from  `clean$ddd` where `TAKE` ='SILVER'  ";
$data1=(mysqli_query($conn,$sql)); 
$rows1S = mysqli_num_rows($data1);


$sql =" 
select 
* from  `clean$ddd` where `TAKE` ='BRONZE'  ";
$data1=(mysqli_query($conn,$sql)); 
$rows1B = mysqli_num_rows($data1);



$sql ="ALTER TABLE `stat$ddd` ADD `STA` varchar(30)      ";
(mysqli_query($conn,$sql)); 


$sql ="ALTER TABLE `stat$ddd` ADD `UNIY` varchar(30)      ";
(mysqli_query($conn,$sql)); 



$sql ="update `stat$ddd` set `STA`='DIAMOND', `UNIY`='$rows1D' where regno='1'";
          
$data=(mysqli_query($conn,$sql)); 

$sql ="update `stat$ddd` set `STA`='GOLD', `UNIY`='$rows1G' where regno='2'";
          
$data=(mysqli_query($conn,$sql)); 
$sql ="update `stat$ddd` set `STA`='SILVER',`UNIY`='$rows1S' where regno='3'";
          
$data=(mysqli_query($conn,$sql)); 
$sql ="update `stat$ddd` set `STA`='BRONZE', `UNIY`='$rows1B' where regno='4'";
          
$data=(mysqli_query($conn,$sql)); 




$sql = "SELECT SUM(AVERAGE) AS maxida FROM `clean$ddd`  ";
          
         
$result = (mysqli_query($conn,$sql)); 
    $result1 = mysqli_fetch_assoc($result);


$paav=  $result1['maxida'];

$peav= round(($paav ),2);


$aavc= round(($peav/$rows4y),2);


$sql ="ALTER TABLE `clean$ddd` CHANGE `AVERAGE` `AVERAGE` VARCHAR( 130 ) NULL DEFAULT NULL ";
$data=(mysqli_query($conn,$sql)); 
$sql ="update `clean$ddd` set `AVERAGE`='AVERAGE' where regno='0'";
          
$data=(mysqli_query($conn,$sql)); 




$sql ="
select * from `clean$ddd` where regno = 0  ";
$data22=(mysqli_query($conn,$sql));  
$rows = mysqli_num_rows($data22);

$sql ="
select * from `clean$ddd` where regno !=0 ";
$data2=(mysqli_query($conn,$sql));  
$rows = mysqli_num_rows($data2);


$sql ="
select * from `stat$ddd` where regno !=0 ";
$data12=(mysqli_query($conn,$sql)); 
 
print "<CENTER>\n";
print "<b><u>MASTERSHEET (100%)  SHEET for $clasx $sx </b></u></br>";
print "<table id=datatable>\n";
 

				//get row data as an associative array
while ($row = mysqli_fetch_assoc($data22)){
print "<tr >\n";
//look at each field
foreach ($row as $col=>$val){
print "<td class='rotate'><div><span>$val<div><span></td>\n";
} // end foreach
print "</tr>\n\n";
}// end while

	
while ($row = mysqli_fetch_assoc($data2)){
print "<tr>\n";
//look at each field
foreach ($row as $col=>$val){
print " <td align=center >$val</td>\n";
} // end foreach
print "</tr>\n\n";
}// end while

print "<tr>\n";
print " <td></td><td align=center ><b>CLASS METRICS</b></td>\n";

 
print "</table>\n";




//$sql ="
//drop table `clean$ddd`  ";
//$data22=(mysqli_query($conn,$sql)); 


//$sql ="
//drop table `cleand$ddd`   ";
//$data22=(mysqli_query($conn,$sql)); 

$sql ="
drop table `#crd$ddd`   ";
$data22=(mysqli_query($conn,$sql)); 
?>
<center></br>
<b>CLASS AVERAGE: <?php echo $aavc; ?></b> </BR>				
 </font> </br>
<a  href="cresult.php">Back</a>
 </br>


<a download="somedata.xls" href="#" onclick="return ExcellentExport.excel(this, 'datatable', 'dddddd');">Export Report to Excel</a>
  </br>


</body>
</html>
