<?php
session_start();
if(!isset($_SESSION["etudiant_i"]) OR !isset($_SESSION["idEtablissement"])){
	header("Location:index.php");
	exit();
}
define("COULEUR_1", "#8888FF");
define("COULEUR_2", "#CCCCFF");
function couleurAlterner()	{
	  static $couleur = COULEUR_1;
	  if (strcmp($couleur,COULEUR_1)==0)
		{
		 $couleur = COULEUR_2; 
		}
	   else
		{
		 $couleur = COULEUR_1; 
		}
	   return $couleur;
}

//fonction pour arrondir les notes
function myround($value, $places=0) {
    if ($places < 0) { 
      $places = 0; 
    }
    
    $mult = pow(10, $places);
    
    $number1  =  $value * $mult;
    $number2  = intval($number1);
    $number3  = $number1 - $number2;

    if($number3 >= 0.5) {
      return ceil($value * $mult) / $mult;
    } else {
      return floor($value * $mult) / $mult;
    }
}

include('/home/africawebstudent/public_html/gs/progicielgeststudent/footer.php');
include_once('Library/Basededonnees.php');

$DB_DATABASE = $_SESSION["DB_DATABASE"];

$database = new Basededonnees($DB_DATABASE);
$bdd = $database->getBdd();

include('Library/Identite.php');

$aff = 'YES';
$sql0 = "SELECT * FROM `resultats` where affiche= :aff and idEtablissement = :idEtablissement AND annee_acad = :acad";
$statement0 = $bdd->prepare($sql0);
$statement0->bindParam(':aff', $aff, PDO::PARAM_STR);
$statement0->bindParam(':idEtablissement', 	$_SESSION["eta_i"], PDO::PARAM_STR);
$statement0->bindParam(':acad', 	$_POST['academique'], PDO::PARAM_STR);
$statement0->execute();
$nb = $statement0->rowCount();
$row0=$statement0->fetch(PDO::FETCH_ASSOC);
$tauxrecouvrement = $row0['tauxRecouvrement'];

$acad = ($_POST['academique']-1).'-'.$_POST['academique'];
$today = date('d/m/Y');
//echo $today;
$sqlc 	 = "SELECT * FROM contrat WHERE datepayement <= :date AND matricule =:matr AND annee_acad = :acad";
$resc     = $bdd -> prepare($sqlc);
$resc     ->execute(array('date'=>$today, 'matr'=>$_SESSION["etudiant_i"], 'acad'=>$acad)) or die(print_r($resc->errorInfo()));
$montantC = 0;
while($donneec=$resc->fetch()) {
    $montantC = $montantC + $donneec['montant']; // On verifie ce que l'étudiant doit payer relativeement au contrat qui est signé.
}


$echeancie = '
		<tr>
			<td style="width:10%; text-align:center;">
				<b><i>N°</i></b>
			</td>
			<td style="width:45%; text-align:center;">
				<b><i>Echéancier de payement </i></b>
			</td>
			<td style="width:45%; text-align:center;">
				<b><i>Montant à payer en FCFA</i></b>
			</td>
		</tr>
';
$sqlcs 	 = "SELECT * FROM contrat WHERE matricule =:matr AND annee_acad = :acad";
$rescs     = $bdd -> prepare($sqlcs);
$rescs     ->execute(array('matr'=>$_SESSION["etudiant_i"], 'acad'=>$acad)) or die(print_r($rescs->errorInfo()));
$i = 1;
while($donneecs=$rescs->fetch()) {
    //$c = couleurAlterner();
    $echeancie .= '
		<tr style="background-color:'.$c.'">
			<td style="width:10%; text-align:center;">
				<i>'.$i.'</i>
			</td>
			<td style="width:45%; text-align:center;">
				<i>'.$donneecs['datepayement'].' </i>
			</td>
			<td style="width:45%; text-align:center;">
				<i><b>'.$donneecs['montant'].'</b></i>
			</td>
		</tr>
    ';
    $i++;
}

$reqA = "SELECT * FROM tabinscription WHERE annee_acad = :acad AND matricule = :matr";
$statementA = $bdd->prepare($reqA);
$statementA->bindParam(':acad',$_POST['academique'], PDO::PARAM_STR);
$statementA->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
$statementA->execute();
$rowA=$statementA->fetch(PDO::FETCH_ASSOC);
//Déterminer le montant
$resMontant = $bdd->prepare('SELECT * FROM montant WHERE idEtablissement=? AND idFiliere =? AND annee =? AND periode =? AND idStatut =?');
$resMontant->execute(array($_SESSION["eta_i"],$rowA['idFiliere'],$rowA['annee'],$_POST['academique'],$rowA['statut']));
$Montant            = $resMontant->fetch();
$montant       	    = $Montant['scolarite'] ;
$fraisInscription   = $Montant['fraisInscription'] ;//	

$montTotaleDu = 0; //pour l'ensemble des années
/** Pour chaque étudiant, on fait la recherche de ces dettes antérieures */
$sqlm 	 = "SELECT * FROM tabinscription WHERE annee_acad < :acad AND matricule =:matr";
$resm     = $bdd -> prepare($sqlm);
$resm     ->execute(array('acad'=>$_POST['academique'], 'matr'=>$_SESSION["etudiant_i"])) or die(print_r($resm->errorInfo()));
while($donneem=$resm->fetch()) {
	//Déterminer le montant
	$resMontantm = $bdd->prepare('SELECT * FROM montant WHERE idEtablissement=? AND idFiliere =? AND annee =? AND periode =? AND idStatut =?');
	$resMontantm->execute(array($_SESSION["eta_i"],$donneem['idFiliere'],$donneem['annee'],$donneem['annee_acad'],$donneem['statut']));
	$Montantm   = $resMontantm->fetch();
	$fraism     = $Montantm['scolarite'] + $Montantm['fraisInscription'];
	
	$p = ($donneem['annee_acad']-1).'-'.$donneem['annee_acad'];
	$montantDu = $fraism - $donneem['montant'];
	$affiche .= '['.$p.' : '.$montantDu.' FCFA]   ';
	$montTotaleDu = $montTotaleDu + $montantDu;
}

$scolarite = $montant + $fraisInscription + $montTotaleDu;

//Monatnt dû 
//=======================================Evaluation du montant total payé par l'etudiant===========================================================//
$valeurpayer = 0;
$totalpayer= $bdd->prepare('SELECT * FROM facture WHERE matricule =? AND annee=? AND niveau =? AND annee_acad =? AND idFiliere =?');
$totalpayer->execute(array($_SESSION["etudiant_i"], $rowA['annee'], $rowA['niveauFormation'], $_POST['academique'], $rowA['idFiliere'])) or die(print_r($totalpayer->errorInfo()));
while($total=$totalpayer->fetch()) {
	if($total['statutOperation'] ==0) { //Si l'opération a réussie....
        if($total['typefacture'] == 'FV') {
            $valeurpayer += $total['montant'];
        }else{
            $valeurpayer -= $total['montant'];
        }
	}
}
//=======================================Evaluation du montant total payé par l'etudiant===========================================================//
$soldedu = $scolarite - $valeurpayer;


$percent = 0;
if($montantC != 0) {
    $percent = ($valeurpayer/$montantC)*100;
    $tauxrecouvrement = 100;
}else {
    if($scolarite != 0) {
        $percent = ($valeurpayer/$scolarite)*100;
    }
}
//echo $percent;
//$nb = 1;
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" type="image/png" sizes="16x16" href="https://progiciel.africawebstudent.org/plugins/images/favicon.png">
    <title>GestStudent E-Services</title>
    <!-- Bootstrap Core CSS -->
    <link href="bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Menu CSS -->
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.css" rel="stylesheet">
    <!-- toast CSS -->
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/toast-master/css/jquery.toast.css" rel="stylesheet">
    <!-- morris CSS -->
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/morrisjs/morris.css" rel="stylesheet">
    <!-- chartist CSS -->
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/chartist-js/dist/chartist.min.css" rel="stylesheet">
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/chartist-plugin-tooltip-master/dist/chartist-plugin-tooltip.css" rel="stylesheet">
    <!-- Calendar CSS -->
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/calendar/dist/fullcalendar.css" rel="stylesheet" />
    <!-- animation CSS -->
    <link href="css/animate.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="css/style.css" rel="stylesheet">
    <!-- color CSS -->
    <link href="css/colors/megna-dark.css" id="theme" rel="stylesheet">
	<!--alerts CSS -->
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/sweetalert/sweetalert.css" rel="stylesheet" type="text/css">
 	<!--Data table CSS -->
	<link href="https://progiciel.africawebstudent.org/plugins/bower_components/datatables/jquery.dataTables.min.css" rel="stylesheet" type="text/css" />
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body class="fix-header">
    <!-- ============================================================== -->
    <!-- Preloader -->
    <!-- ============================================================== -->
    <div class="preloader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" />
        </svg>
    </div>
    <!-- ============================================================== -->
    <!-- Wrapper -->
    <!-- ============================================================== -->
    <div id="wrapper">
        <!-- ============================================================== -->
        <!-- Topbar header - style you can find in pages.scss -->
        <!-- ============================================================== -->
        <nav class="navbar navbar-default navbar-static-top m-b-0">
            <div class="navbar-header">
                <div class="top-left-part">
                    <!-- Logo -->
                    <a class="logo" href="accueil.php">
                        <!-- Logo icon image, you can use font-icon also --><b><span class="hidden-xs">
                        <!--This is light logo icon--><img src="https://progiciel.africawebstudent.org/plugins/images/gsr2.png" alt="home" class="light-logo" />
						</span> </b>
					</a>
                </div>
                <!-- /Logo -->
                <!-- Search input and Toggle icon -->
                <ul class="nav navbar-top-links navbar-left">
                    <li><a href="javascript:void(0)" class="open-close waves-effect waves-light visible-xs"><i class="ti-close ti-menu"></i></a></li>
                    <!-- .Task dropdown -->
                
                    <!-- .Megamenu -->

                    <!-- /.Megamenu -->
                </ul>
                <ul class="nav navbar-top-links navbar-right pull-right">
                    <li>
                        <form role="search" class="app-search hidden-sm hidden-xs m-r-10">
                            <input type="text" placeholder="Search..." class="form-control"> <a href=""><i class="fa fa-search"></i></a> </form>
                    </li>
                    <li class="dropdown">
                        <?php
														include('include/affiche_identite.php');
                        ?>
                        <!-- /.dropdown-user -->
                    </li>
                    <!-- /.dropdown -->
                </ul>
            </div>
            <!-- /.navbar-header -->
            <!-- /.navbar-top-links -->
            <!-- /.navbar-static-side -->
        </nav>
        <!-- End Top Navigation -->
        <!-- ============================================================== -->
        <!-- Left Sidebar - style you can find in sidebar.scss  -->
        <!-- ============================================================== -->
        <div class="navbar-default sidebar" role="navigation">
            <div class="sidebar-nav">
                <div class="sidebar-head">
                    <h3><span class="fa-fw open-close"><i class="ti-menu hidden-xs"></i><i class="ti-close visible-xs"></i></span> <span class="hide-menu">Navigation</span></h3> </div>
                <ul class="nav" id="side-menu">
                    <li class="user-pro">
                        <a href="javascript:void(0)" class="waves-effect active"><img src="img/profil.png" alt="user-img" class="img-circle"> <span class="hide-menu"><?php echo $infoEtudiant['nom'].'  '.$infoEtudiant['prenom']?> <span class="fa arrow"></span></span>
                        </a>
                    </li>
                    <li> <a href="accueil.php" class="waves-effect active"><i class="mdi mdi-av-timer fa-fw" data-icon="v"></i> <span class="hide-menu"> Accueil <span class="fa arrow"></span> <span class="label label-rouded label-inverse pull-right"></span></span></a>
                    </li>
                    <li> <a href="f_scolarite.php" class="waves-effect"><i class="mdi mdi-av-timer fa-fw" data-icon="v"></i> <span class="hide-menu"> Scolarité <span class="fa arrow"></span> <span class="label label-rouded label-inverse pull-right"></span></span></a>
                    </li>
                    <!-- <li> <a href="javascript:void(0)" class="waves-effect"><i class="mdi mdi-av-timer fa-fw" data-icon="v"></i> <span class="hide-menu"> Mes résultats académiques <span class="fa arrow"></span> <span class="label label-rouded label-inverse pull-right"></span></span></a>
                    </li>-->
                    <li> <a href="parcourt.php" class="waves-effect"><i class="mdi mdi-av-timer fa-fw" data-icon="v"></i> <span class="hide-menu"> Parcourt <span class="fa arrow"></span> <span class="label label-rouded label-inverse pull-right"></span></span></a>
                    </li>
					<li> <a href='javascript:void(0)' class='waves-effect'><i class='mdi mdi-content-copy fa-fw'></i> <span class='hide-menu'>Demande<span class='fa arrow'></span><span class='label label-rouded label-warning pull-right'>3</span></span></a>
						<ul class='nav nav-second-level'>
                            <li> <a href="f_reclamation.php" class="waves-effect"><i class="mdi mdi-av-timer fa-fw" data-icon="v"></i> <span class="hide-menu"> Réclamation <span class="fa arrow"></span> <span class="label label-rouded label-inverse pull-right"></span></span></a>
                            </li>
                            <li> <a href="f_demande.php" class="waves-effect"><i class="mdi mdi-av-timer fa-fw" data-icon="v"></i> <span class="hide-menu">Documents <span class="fa arrow"></span> <span class="label label-rouded label-inverse pull-right"></span></span></a>
                            </li>
						</ul>
					</li>
                </ul>
            </div>
        </div>
        <!-- ============================================================== -->
        <!-- End Left Sidebar -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Page Content -->
        <!-- ============================================================== -->
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row bg-title">
                    <div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
                        <h4 class="page-title"><font color = red>SOLDE DÛ : <?php echo $soldedu; ?> FCFA </font>  ::::::  <font color = blue>MONTANT PAYE : <?php echo $valeurpayer; ?> FCFA </font></h4>  
                    </div>
                    <div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
                        <ol class="breadcrumb">
                            <li><a href="accueil.php">ACCUEIL</a></li>
                            <li class="active">MES RESULTATS ACADEMIQUES</li>
                        </ol>
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
                <!-- ============================================================== -->
                <!-- Different data widgets -->
                <!-- ============================================================== -->

                <!-- ============================================================== -->
                <!-- Blog-component -->
                <!-- ============================================================== -->
					  <div class="row">
						
						<!-- /.col -->
						<div class="col-md-12">
						  <div class="box box-primary">
							<div class="box-header with-border">
							  <h3 class="box-title">Résultats</h3>
							  <!-- /.box-tools -->
							</div>
							<!-- /.box-header -->
							<div class="box-body no-padding">
							  <div class="table-responsive mailbox-messages white-box">
									<?php
									if($percent >= $tauxrecouvrement) {
    									if($nb>0){
    										$html = '';
    										$annee    		= 0;  
    										$niveau  		= 0;   
    										$anneeacad   	= $_POST['academique'];     
    										$idFiliere  	= $rowA['idFiliere'];
    										$ajour          = 'YES';
    										$req = "";
    										$resS1 = "";
    										$resS2 = "";
    										$perS1 = "";
    										$perS2 = "";
    										try{
    											$reqE = "SELECT * FROM tabinscription WHERE annee_acad = :acad AND matricule = :matr";
    											//$reqE = "SELECT * FROM tabinscription WHERE annee_acad = :acad AND matricule = :matr AND estAjour = :ajour";
    											$statementE = $bdd->prepare($reqE);
    											$statementE->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    											$statementE->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    											//$statementE->bindParam(':ajour',$jour, PDO::PARAM_STR);
    											$statementE->execute();
    											$nombreLigne = $statementE->rowCount();
    											$row=$statementE->fetch(PDO::FETCH_ASSOC);
    											$resS1 = $row['resultatS1'];
    											$resS2 = $row['resultatS2'];
    											$perS1 = $row['percentS1'];
    											$perS2 = $row['percentS2'];
    											$annee    		= $row['annee'];  
    											$niveau  		= $row['niveauFormation'];   
    											$req = "SELECT DISTINCT annee FROM unites WHERE idFiliere = :idF  AND annee = :an AND niveauFormation = :niveau AND annee_acad = :acad";
    											$statement0 = $bdd->prepare($req);
    											$statement0->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    											$statement0->bindParam(':an',  $row['annee'], PDO::PARAM_STR);
    											$statement0->bindParam(':niveau',  $row['niveauFormation'], PDO::PARAM_STR);
    											$statement0->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    											$statement0->execute();
    										}catch(PDOException  $e ){
    											echo '
    											<div class="col-md-4">
    												<div class="modal-dialog">
    													<div class="modal-content">
    														<div class="modal-header">
    															<button type="button" class="close" data-dismiss="modal" aria-hidden="false">×</button>
    															<h4 class="modal-title" id="myModalLabel"></h4> 
    														</div>
    														<div class="modal-body text-danger">
    															<p>'.$e->getMessage( ).' </p>
    														</div>
    													</div>
    													<!-- /.modal-content -->
    												</div>
    											</div>';
    										}
    										
    										while($row0=$statement0->fetch(PDO::FETCH_ASSOC)){	
    											$html .= '
    											
    											<table class="table-condensed table-hover"  border = "1" width="100%">
    											<thead>
    												<tr style="background-color:#ffe6e6;color:#0000FF;">
    													<td width="3%"  align="center">#</td>
    													<td width="8%"  align="center">DECISION</td>
    													<td width="8%" align="center">MOY UE</td>
    													<td width="27%" class="rotate" ><div>INTITULE UNITE D\'ENSEIGNEMENT</div></td>
    													<td width="8%"  align="center">CODE EC</td>
    													<td width="22%" >INTITULE  ELEMENT CONSTITUTIF (EC)</td>
    													<td width="8%" align="center">CC</td>
    													<td width="8%" align="center">EX</td>
    													<td width="8%" align="center">Moy</td>
    												</tr>
    											</thead>';
    											if($annee == 1) {
    												$ids1 = 1;
    												$ids2 = 2;
    											}else if($annee == 2) {
    												$ids1 = 3;
    												$ids2 = 4;
    											} else if($annee == 3){
    												$ids1 = 5;
    												$ids2 = 6;
    											}
    												  											  
    											  
    											$reqS1 = "SELECT credit, code_unite, intituleUnite, type_ue FROM unites WHERE idFiliere = :idF AND annee = :an AND niveauFormation = :niveau AND annee_acad = :acad AND semestre = :id";
    											$statement = $bdd->prepare($reqS1);
    											$statement->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    											$statement->bindParam(':an',  $annee, PDO::PARAM_STR);
    											$statement->bindParam(':niveau',  $niveau, PDO::PARAM_STR);
    											$statement->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    											$statement->bindParam(':id',  $ids1, PDO::PARAM_STR);
    											$statement->execute();
    
    											$html .= "<tr style=\"background-color:#d7e4db;color:#0000FF;\">
    												<td width=\"3%\" ></td>
    												<td width=\"8%\"  align=\"center\" bgcolor = \"\"></td>
    												<td width=\"8%\" ></td>
    												<td width=\"27%\"></td>
    												<td width=\"8%\" align=\"center\">SEMESTRE $ids1</td>
    												<td width=\"22%\" ></td>
    												<td width=\"8%\" ></td>
    												<td width=\"8%\" ></td>
    												<td width=\"8%\" ></td>
    											</tr>";
    											$j = 0;
    											while($row=$statement->fetch(PDO::FETCH_ASSOC)){
    													$c = couleurAlterner();  
    													$j++;
    													$code = $row['code_unite'];
    													$type_ue = $row['type_ue'];			
    													if($type_ue == 0) {
    														$couleur = '#000000';
    													}else if($type_ue == 1) {
    														$couleur = '#ff0000';
    													}else if($type_ue == 2) {
    														$couleur = '#0000ff';
    													}else if($type_ue == 3) {
    														$couleur = '#008100';
    													}
    													
    													$reqS1 = "SELECT * FROM ecu WHERE idFiliere = :idF AND annee = :an AND annee_acad = :acad AND code_unite = :code";
    													$statement2 = $bdd->prepare($reqS1);
    													$statement2->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    													$statement2->bindParam(':an',  $annee, PDO::PARAM_STR);
    													$statement2->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    													$statement2->bindParam(':code',  $code, PDO::PARAM_STR);
    													$statement2->execute();
    													$total = $statement2->rowCount();
    													$row1 = $statement2->fetch(PDO::FETCH_ASSOC);
    													
    													$reqE = "SELECT noteCC, noteEX, noteEcu FROM noteEcu WHERE idFiliere = :idF AND annee = :an AND annee_acad = :acad AND code_unite = :code AND code_ecu = :ecu AND matricule = :matr";
    													$statementE = $bdd->prepare($reqE);
    													$statementE->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    													$statementE->bindParam(':an',  $annee, PDO::PARAM_STR);
    													$statementE->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    													$statementE->bindParam(':code',  $code, PDO::PARAM_STR);
    													$statementE->bindParam(':ecu',  $row1["code_ecu"], PDO::PARAM_STR);
    													$statementE->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    													$statementE->execute();
    													$rowN=$statementE->fetch(PDO::FETCH_ASSOC);
    													
    													$reqM = "SELECT AVG(noteEcu) AS moy FROM noteEcu WHERE idFiliere = :idF AND annee = :an AND annee_acad = :acad AND code_unite = :code AND matricule = :matr";
    													$statementM = $bdd->prepare($reqM);
    													$statementM->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    													$statementM->bindParam(':an',  $annee, PDO::PARAM_STR);
    													$statementM->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    													$statementM->bindParam(':code',  $code, PDO::PARAM_STR);
    													$statementM->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    													$statementM->execute();
    													$rowM=$statementM->fetch(PDO::FETCH_ASSOC);
    													
    													$noteUE = myround($rowM['moy'], 2);
    													
    													$reqUE = "SELECT resultat FROM tabinscriunite WHERE idFiliere = :idF AND annee = :an AND premiere_inscription = :acad AND code_unite = :code  AND matricule = :matr";
    													$statementUE = $bdd->prepare($reqUE);
    													$statementUE->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    													$statementUE->bindParam(':an',  $annee, PDO::PARAM_STR);
    													$statementUE->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    													$statementUE->bindParam(':code',  $code, PDO::PARAM_STR);
    													$statementUE->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    													$statementUE->execute();
    													$rowUE=$statementUE->fetch(PDO::FETCH_ASSOC);
    													
    													if($rowUE['resultat'] == 'A'){
    														$res = 'Validée';
    														$c   = '#ffffff';
    													}else{
    														$res = 'Non Validée';
    														$c   = '#ffff0f';
    													}
    													$html .= "<tr>   	 	
    															<td width=\"3%\"   align=\"center\" rowspan=\"$total\">$j</td>
    															<td width=\"8%\" align=\"center\" bgcolor = \"$c\"  rowspan=\"$total\" >$res</td>
    															<td width=\"8%\"  align=\"center\" rowspan=\"$total\" >$noteUE</td>
    															<td width=\"27%\"  rowspan=\"$total\" ><font color = \"$couleur\">$row[intituleUnite]</font></td>
    															<td width=\"8%\"  align=\"center\">$row1[code_ecu]</td>
    															<td width=\"22%\" >$row1[intituleEcu]</td>
    															<td  width=\"8%\"align=\"center\">$rowN[noteCC]</td>
    															<td  width=\"8%\"align=\"center\">$rowN[noteEX]</td>
    															<td  width=\"8%\"align=\"center\">$rowN[noteEcu]</td>
    															</tr>";
    													$i = 0;
    													while($row2=$statement2->fetch(PDO::FETCH_ASSOC)) {
    														$statementE->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    														$statementE->bindParam(':an',  $annee, PDO::PARAM_STR);
    														$statementE->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    														$statementE->bindParam(':code',  $code, PDO::PARAM_STR);
    														$statementE->bindParam(':ecu',  $row2["code_ecu"], PDO::PARAM_STR);
    														$statementE->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    														$statementE->execute();
    														$rowN=$statementE->fetch(PDO::FETCH_ASSOC);
    														$i++;   
    														   	
    														$html .= "
    														<tr>
    																<td width=\"8%\" align=\"center\">$row2[code_ecu]</td>
    																<td width=\"22%\" >$row2[intituleEcu]</td>
    																<td width=\"8%\" align=\"center\" >$rowN[noteCC]</td>
    																<td width=\"8%\" align=\"center\" >$rowN[noteEX]</td>
    																<td width=\"8%\" align=\"center\" >$rowN[noteEcu]</td>
    														</tr>";
    													}
    											}
    											$html .= "<tr style=\"background-color:#d7e4db;color:#0000FF;\">
    												<td colspan = \"8\" align=\"center\">
    													DECISION SEMESTRE $ids1
    												</td>
    												<td align=\"center\"  bgcolor = \"\">$perS1 % | $resS1</td>
    											</tr></table><br />";	
    											
    											$html .= '
    											
    											<table class="table-condensed table-hover"  border = "1" width="100%">
    											<thead>
    												<tr style="background-color:#ffe6e6;color:#0000FF;">
    													<td width="3%"  align="center">#</td>
    													<td width="8%"  align="center">DECISION</td>
    													<td width="8%" align="center">MOY UE</td>
    													<td width="27%" class="rotate" ><div>INTITULE UNITE D\'ENSEIGNEMENT</div></td>
    													<td width="8%"  align="center">CODE EC</td>
    													<td width="22%" >INTITULE  ELEMENT CONSTITUTIF (EC)</td>
    													<td width="8%" align="center">CC</td>
    													<td width="8%" align="center">EX</td>
    													<td width="8%" align="center">Moy</td>
    												</tr>
    											</thead>';
    
    											$reqS1 = "SELECT credit, code_unite, intituleUnite, type_ue FROM unites WHERE idFiliere = :idF AND annee = :an AND niveauFormation = :niveau AND annee_acad = :acad AND semestre = :id";
    											$statement = $bdd->prepare($reqS1);
    											$statement->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    											$statement->bindParam(':an',  $annee, PDO::PARAM_STR);
    											$statement->bindParam(':niveau',  $niveau, PDO::PARAM_STR);
    											$statement->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    											$statement->bindParam(':id',  $ids2, PDO::PARAM_STR);
    											$statement->execute();
    															
    											$html .= "<tr style=\"background-color:#d7e4db;color:#0000FF;\">
    												<td width=\"3%\"  align=\"center\"></td>
    												<td width=\"8%\"  align=\"center\" bgcolor = \"\"></td>
    												<td width=\"8%\" ></td>
    												<td width=\"27%\"></td>
    												<td width=\"8%\"  align=\"center\"  >SEMESTRE $ids2</td>
    												<td width=\"22%\"></td>
    												<td width=\"8%\" ></td>
    												<td width=\"8%\" ></td>
    												<td width=\"8%\" ></td>
    											</tr>";
    
    											while($row=$statement->fetch(PDO::FETCH_ASSOC)){
    													$c = couleurAlterner();  
    													$j++;
    													$code = $row['code_unite'];
    													$type_ue = $row['type_ue'];			
    													if($type_ue == 0) {
    														$couleur = '#000000';
    													}else if($type_ue == 1) {
    														$couleur = '#ff0000';
    													}else if($type_ue == 2) {
    														$couleur = '#0000ff';
    													}else if($type_ue == 3) {
    														$couleur = '#008100';
    													}
    													
    													$reqS1 = "SELECT * FROM ecu WHERE idFiliere = :idF AND annee = :an AND annee_acad = :acad AND code_unite = :code";
    													$statement2 = $bdd->prepare($reqS1);
    													$statement2->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    													$statement2->bindParam(':an',  $annee, PDO::PARAM_STR);
    													$statement2->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    													$statement2->bindParam(':code',  $code, PDO::PARAM_STR);
    													$statement2->execute();
    													$total = $statement2->rowCount();
    													
    													$row1 = $statement2->fetch(PDO::FETCH_ASSOC);
    													$reqE = "SELECT noteCC, noteEX, noteEcu FROM noteEcu WHERE idFiliere = :idF AND annee = :an AND annee_acad = :acad AND code_unite = :code AND code_ecu = :ecu AND matricule = :matr";
    													$statementE = $bdd->prepare($reqE);
    													$statementE->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    													$statementE->bindParam(':an',  $annee, PDO::PARAM_STR);
    													$statementE->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    													$statementE->bindParam(':code',  $code, PDO::PARAM_STR);
    													$statementE->bindParam(':ecu',  $row1["code_ecu"], PDO::PARAM_STR);
    													$statementE->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    													$statementE->execute();
    													$rowN=$statementE->fetch(PDO::FETCH_ASSOC);
    
    					
    													$reqM = "SELECT AVG(noteEcu) AS moy FROM noteEcu WHERE idFiliere = :idF AND annee = :an AND annee_acad = :acad AND code_unite = :code AND matricule = :matr";
    													$statementM = $bdd->prepare($reqM);
    													$statementM->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    													$statementM->bindParam(':an',  $annee, PDO::PARAM_STR);
    													$statementM->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    													$statementM->bindParam(':code',  $code, PDO::PARAM_STR);
    													$statementM->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    													$statementM->execute();
    													$rowM=$statementM->fetch(PDO::FETCH_ASSOC);
    													
    													$noteUE = myround($rowM['moy'], 2);
    													
    													$reqUE = "SELECT resultat FROM tabinscriunite WHERE idFiliere = :idF AND annee = :an AND premiere_inscription = :acad AND code_unite = :code  AND matricule = :matr";
    													$statementUE = $bdd->prepare($reqUE);
    													$statementUE->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    													$statementUE->bindParam(':an',  $annee, PDO::PARAM_STR);
    													$statementUE->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    													$statementUE->bindParam(':code',  $code, PDO::PARAM_STR);
    													$statementUE->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    													$statementUE->execute();
    													$rowUE=$statementUE->fetch(PDO::FETCH_ASSOC);
    													if($rowUE['resultat'] == 'A'){
    														$res = 'Validée';
    														$c   = '#ffffff';
    													}else{
    														$res = 'Non Validée';
    														$c   = '#ffff0f';
    													}
    													
    													$html .= "<tr>   	 	
    															<td width=\"3%\"   align=\"center\" rowspan=\"$total\">$j</td>
    															<td width=\"8%\" align=\"center\" bgcolor = \"$c\"  rowspan=\"$total\" >$res</td>
    															<td width=\"8%\"  align=\"center\" rowspan=\"$total\" >$noteUE</td>
    															<td width=\"27%\"  rowspan=\"$total\" ><font color = \"$couleur\">$row[intituleUnite]</font></td>
    															<td width=\"8%\"  align=\"center\">$row1[code_ecu]</td>
    															<td width=\"22%\" >$row1[intituleEcu]</td>
    															<td  width=\"8%\"align=\"center\">$rowN[noteCC]</td>
    															<td  width=\"8%\"align=\"center\">$rowN[noteEX]</td>
    															<td  width=\"8%\"align=\"center\">$rowN[noteEcu]</td>
    															</tr>";
    													$i = 0;
    													while($row2=$statement2->fetch(PDO::FETCH_ASSOC)) {
    														$statementE->bindParam(':idF', $idFiliere, PDO::PARAM_STR);
    														$statementE->bindParam(':an',  $annee, PDO::PARAM_STR);
    														$statementE->bindParam(':acad',$anneeacad, PDO::PARAM_STR);
    														$statementE->bindParam(':code',  $code, PDO::PARAM_STR);
    														$statementE->bindParam(':ecu',  $row2["code_ecu"], PDO::PARAM_STR);
    														$statementE->bindParam(':matr',$_SESSION["etudiant_i"], PDO::PARAM_STR);
    														$statementE->execute();
    														$rowN=$statementE->fetch(PDO::FETCH_ASSOC);
    														$i++;          	
    														$html .= "
    														<tr>
    																<td width=\"8%\" align=\"center\">$row2[code_ecu]</td>
    																<td width=\"22%\" >$row2[intituleEcu]</td>
    																<td width=\"8%\" align=\"center\" >$rowN[noteCC]</td>
    																<td width=\"8%\" align=\"center\" >$rowN[noteEX]</td>
    																<td width=\"8%\" align=\"center\" >$rowN[noteEcu]</td>
    														</tr>";
    													}
    											}
    											$html .= "<tr style=\"background-color:#d7e4db;color:#0000FF;\">
    												<td colspan = \"8\" align=\"center\">
    													DECISION SEMESTRE $ids2
    												</td>
    												<td align=\"center\"  bgcolor = \"\">$perS2 % | $resS2</td>
    											</tr></table><br />";	
    										}	
    										
    										if($nombreLigne == 1) {
        										$html .= '<table class="table-condensed table-hover" border = "1" style="margin:0;padding:5;padding-top:20px;">
        											<tr>
        												<td width="47%" bgcolor = "#d7e4db" colspan = "2" align="center"> LEGENDE TABLEAU DE SPECIFICATION</td>
        											</tr>
        											<tr>
        												<td width="7%" bgcolor = "#000000"> </td>
        												
        												<td width="40%"> Unité de Connaissance Fondamentales </td>
        											</tr>
        											
        											<tr>
        												<td width="7%" bgcolor = "#ff0000"> </td>
        												
        												<td width="40%" > Unité de Spécialité </td>
        											</tr>
        											
        											<tr>
        												<td width="7%" bgcolor = "#0000ff"> </td>
        												
        												<td width="40%" > Unité de Méthodologie </td>
        											</tr>
        											
        											<tr>
        												<td width="7%" bgcolor = "#008100"> </td>
        												
        												<td width="40%" > Unité de Culture Générale </td>
        											</tr>
        										</table><br />';
    										}else{
        										echo('
        										
        											<div class="col-md-offset-3 col-md-7">
        													<div class="white-box">
        														<h3><span class="btn btn-danger btn-circle btn-lg text-white"><i class="ti-bell"></i></span>	Pas de résultats</h3>
        														<p>
        														   PASSER A LA COMPTABILITE POUR SOLDER VOTRE SCOLARITE. MERCI POUR LA COMPREHENSION...
        														</p>
        													</div>
        											</div>'
        										
        										);
    										}
    									?>
    									<?php
    										echo $html;
    									}else{
    										echo('
    										
    											<div class="col-md-offset-3 col-md-6">
    													<div class="white-box">
    														<h3><span class="btn btn-danger btn-circle btn-lg text-white"><i class="ti-bell"></i></span>	Pas de résultats</h3>
    														<p>
    														Aucun résultats n\'est disponible pour le moment. Veuillez revenir plustard .
    														</p>
    													</div>
    											</div>'
    										
    										);
    									}
									}else{
										echo('
											<div class="col-md-offset-3 col-md-7">
													<div class="white-box">
														<h3><span class="btn btn-danger btn-circle btn-lg text-white"><i class="ti-bell"></i></span> Oooof</h3>
														<p>
														    NOUS SOMMES AU REGRET DE NE PAS POUVOIR VOUS COMMUNIQUER VOS RESULTATS. <b>RAISON: </b> VOUS ETES EN RETARD DANS LE REGLEMENT DE VOS FRAIS DE 
														    SCOLARITE A CE JOUR (<b>'.$today.'</b>) PAR RAPPORT A L\'ECHEANCIER. MERCI DE PASSER AU SERVICE COMPTABILITE POUR VOUS METTRE A JOUR D\'ABORD.
														</p>
													</div>
											</div>'
										);
										if($montantC != 0) {
    										echo('<div class="col-md-offset-3 col-md-7">
                                			<table cellspacing="5" cellpadding="15" style="font-family:Helvetica;font-size:15px;" border="2" align = "center">
                                			'.$echeancie.'
                                			</table>
                                			</div>');
                            			}
									}
									?>

							  </div>
							  <!-- /.mail-box-messages -->
							</div>							
						  </div>
						  <!-- /. box -->
						</div>
						<!-- /.col -->
					  </div>
					  <!-- /.row -->
                <!-- ============================================================== -->
                <!-- chats, message & profile widgets -->
                <!-- ============================================================== -->

                <!-- ============================================================== -->
                <!-- start right sidebar -->
                <!-- ============================================================== -->
                <div class="right-sidebar">
                    <div class="slimscrollright">
                        <div class="rpanel-title"> Service Panel <span><i class="ti-close right-side-toggle"></i></span> </div>
                        <div class="r-panel-body">
                            <ul id="themecolors" class="m-t-20">
                                <li><b>With Light sidebar</b></li>
                                <li><a href="javascript:void(0)" data-theme="default" class="default-theme">1</a></li>
                                <li><a href="javascript:void(0)" data-theme="green" class="green-theme">2</a></li>
                                <li><a href="javascript:void(0)" data-theme="gray" class="yellow-theme">3</a></li>
                                <li><a href="javascript:void(0)" data-theme="blue" class="blue-theme">4</a></li>
                                <li><a href="javascript:void(0)" data-theme="purple" class="purple-theme">5</a></li>
                                <li><a href="javascript:void(0)" data-theme="megna" class="megna-theme">6</a></li>
                                <li class="full-width"><b>With Dark sidebar</b></li>
                                <li><a href="javascript:void(0)" data-theme="default-dark" class="default-dark-theme">7</a></li>
                                <li><a href="javascript:void(0)" data-theme="green-dark" class="green-dark-theme">8</a></li>
                                <li><a href="javascript:void(0)" data-theme="gray-dark" class="yellow-dark-theme">9</a></li>
                                <li><a href="javascript:void(0)" data-theme="blue-dark" class="blue-dark-theme">10</a></li>
                                <li><a href="javascript:void(0)" data-theme="purple-dark" class="purple-dark-theme">11</a></li>
                                <li><a href="javascript:void(0)" data-theme="megna-dark" class="megna-dark-theme working">12</a></li>
                            </ul>
                            <ul class="m-t-20 chatonline">
                                <li><b>Chat option</b></li>
                                <li>
                                    <a href="javascript:void(0)"><img src="https://progiciel.africawebstudent.org/plugins/images/users/varun.jpg" alt="user-img" class="img-circle"> <span>Varun Dhavan <small class="text-success">online</small></span></a>
                                </li>
                                <li>
                                    <a href="javascript:void(0)"><img src="https://progiciel.africawebstudent.org/plugins/images/users/genu.jpg" alt="user-img" class="img-circle"> <span>Genelia Deshmukh <small class="text-warning">Away</small></span></a>
                                </li>
                                <li>
                                    <a href="javascript:void(0)"><img src="https://progiciel.africawebstudent.org/plugins/images/users/ritesh.jpg" alt="user-img" class="img-circle"> <span>Ritesh Deshmukh <small class="text-danger">Busy</small></span></a>
                                </li>
                                <li>
                                    <a href="javascript:void(0)"><img src="https://progiciel.africawebstudent.org/plugins/images/users/arijit.jpg" alt="user-img" class="img-circle"> <span>Arijit Sinh <small class="text-muted">Offline</small></span></a>
                                </li>
                                <li>
                                    <a href="javascript:void(0)"><img src="https://progiciel.africawebstudent.org/plugins/images/users/govinda.jpg" alt="user-img" class="img-circle"> <span>Govinda Star <small class="text-success">online</small></span></a>
                                </li>
                                <li>
                                    <a href="javascript:void(0)"><img src="https://progiciel.africawebstudent.org/plugins/images/users/hritik.jpg" alt="user-img" class="img-circle"> <span>John Abraham<small class="text-success">online</small></span></a>
                                </li>
                                <li>
                                    <a href="javascript:void(0)"><img src="https://progiciel.africawebstudent.org/plugins/images/users/john.jpg" alt="user-img" class="img-circle"> <span>Hritik Roshan<small class="text-success">online</small></span></a>
                                </li>
                                <li>
                                    <a href="javascript:void(0)"><img src="https://progiciel.africawebstudent.org/plugins/images/users/pawandeep.jpg" alt="user-img" class="img-circle"> <span>Pwandeep rajan <small class="text-success">online</small></span></a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- ============================================================== -->
                <!-- end right sidebar -->
                <!-- ============================================================== -->
            </div>
            <!-- /.container-fluid -->
            <?php footer() ?>
        </div>
        <!-- ============================================================== -->
        <!-- End Page Content -->
        <!-- ============================================================== -->
    </div>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- Menu Plugin JavaScript -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/sidebar-nav/dist/sidebar-nav.min.js"></script>
    <!--slimscroll JavaScript -->
    <script src="js/jquery.slimscroll.js"></script>
    <!--Wave Effects -->
    <script src="js/waves.js"></script>
    <!--Counter js -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/waypoints/lib/jquery.waypoints.js"></script>
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/counterup/jquery.counterup.min.js"></script>
    <!-- chartist chart -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/chartist-js/dist/chartist.min.js"></script>
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/chartist-plugin-tooltip-master/dist/chartist-plugin-tooltip.min.js"></script>
    <!-- Calendar JavaScript -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/moment/moment.js"></script>
    <script src='https://progiciel.africawebstudent.org/plugins/bower_components/calendar/dist/fullcalendar.min.js'></script>
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/calendar/dist/cal-init.js"></script>
    <!-- Custom Theme JavaScript -->
    <script src="js/custom.min.js"></script>
	<!-- Custom JavaScript
    <script src="js/custom/accueil.js"></script> -->
    <!-- Custom tab JavaScript -->
    <script src="js/cbpFWTabs.js"></script>
    <script type="text/javascript">
    (function() {
        [].slice.call(document.querySelectorAll('.sttabs')).forEach(function(el) {
            new CBPFWTabs(el);
        });
    })();
    </script>
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/toast-master/js/jquery.toast.js"></script>
    <!--Style Switcher -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/styleswitcher/jQuery.style.switcher.js"></script>
	<!-- Sweet-Alert  -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/sweetalert/sweetalert.min.js"></script>
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/sweetalert/jquery.sweet-alert.custom.js"></script>
	<!-- Data table  -->
	<script src="https://progiciel.africawebstudent.org/plugins/bower_components/datatables/jquery.dataTables.min.js"></script>

	<script type="text/javascript">  	
		 $( function(){
			$('.tout').click(function(){
				if ($('.clique:checked').length == $('.clique').length) {
					$('.clique').removeAttr( "checked" );
				}
				else
				{
					$('.clique').prop( "checked", true );
				}
			});
			
			$(document).on('change', '.clique', function() {
				
				if($(".clique:checked").length > 0){
				$('.supp').css('display','block');
				}else{
				$('.supp').css('display','none');
				}
			});
			$("#examtable").DataTable();
		 });
  </script>	
</body>

</html>
