<?php
session_start();
header("Access-Control-Allow-Headers: Authorization, Content-Type");
header("Access-Control-Allow-Origin: *");

//header("Access-Control-Allow-Origin: *"); 
if(!isset($_SESSION["etudiant_i"]) OR !isset($_SESSION["idEtablissement"])){
	header("Location:./");
	exit();
}



include_once('Library/Basededonnees.php');

$DB_DATABASE = $_SESSION["DB_DATABASE"];

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

include('/home/africawebstudent/public_html/gs/progicielgeststudent/footer.php');
include('Library/Identite.php');
include_once('Library/RequeteEtudiant.php');
$annee_acad= $bdd -> prepare('SELECT MAX(annee_acad) AS annee_acad FROM tabinscription WHERE matricule=?');
$annee_acad ->execute(array($_SESSION["etudiant_i"]));
$annee_acad = $annee_acad->fetch();

$info= $bdd -> prepare('SELECT idFiliere, annee, niveauFormation FROM tabinscription WHERE matricule=? AND annee_acad=?');
$info ->execute(array($_SESSION["etudiant_i"], $annee_acad['annee_acad']));
$info = $info->fetch();

$insert = 'YES';
$idFiliere 	= $info['idFiliere'];
$annee    	= $info['annee'];  
$niveau    	= $info['niveauFormation'];  
$anneeacad  = $annee_acad['annee_acad']; 
 
$ids1 = $annee * 2 - 1;
$ids2 = $annee * 2;

//Afficher les compositions du jour
$session_etudiant=$_SESSION["etudiant_i"];
$idEtablissement = $_SESSION["idEtablissement"];

$requeteetu= new RequeteEtudiant();
$recupereretour=$requeteetu->recupereRequete($session_etudiant, $bdd);


?>
<!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" />
 	<!--Data table CSS -->
	<link href="https://progiciel.africawebstudent.org/plugins/bower_components/datatables/jquery.dataTables.min.css" rel="stylesheet" type="text/css" />
    <!-- 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 -->
	<!-- Menu CSS -->
    <link rel="stylesheet" href="https://progiciel.africawebstudent.org/plugins/bower_components/dropify/dist/css/dropify.min.css">
    <link href="https://progiciel.africawebstudent.org/plugins/bower_components/sweetalert/sweetalert.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]-->
        <style>

            body {
                font-family: "Lucida Sans", Verdana, sans-serif;
                background-size:cover;
                padding-top:0px;
            }

            .white-boxx{background:#fff;padding:25px;margin-bottom:30px;border: 3px solid rgba(255, 0, 0, 0.55);}
            .white-box{background:#fff;padding:25px;margin-bottom:30px;border: 3px solid rgba(0, 0, 255, 1);}
        </style>
</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 -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- 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 srcset="https://progiciel.africawebstudent.org/plugins/images/gs_36.png 36w, https://progiciel.africawebstudent.org/plugins/images/gsr2.png 196w" sizes="(max-width: 320px) 30px, (max-width: 480px) 36px, 150px" src="../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"><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"><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="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 active'><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">REQUETE</h4> </div>
                    <div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
                        <ol class="breadcrumb">
                            <li><a href="javascript:void(0)">GESTSTUDENT</a></li>
                            <li class="active">REQUETE</li>
                        </ol>
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <div class="row">
                    <div class="col-md-offset-1 col-md-10">
                        <div class="white-box">
                            <h3 class="box-title">Formuler une requête</h3> 
							<form enctype="multipart/form-data"  method="post" action="requetetraitement.php">
								<div class="form-group">
									<label>EC concerné</label>
									<select class="form-control" name="ec" required>
										<option value=''>Sélectionnez l'EC</option>
										<?php
                                            //configpdf
                                            $configpdf= $bdd->prepare('SELECT modeResultat FROM `configpdf`');
                                            $configpdf->execute();
                                            $nomConfigpdf			= $configpdf->fetch();
                                            $modeResultat           = $nomConfigpdf['modeResultat'];
                                        	if($modeResultat != 'U') {
                                            		$sql1 = "SELECT code_unite FROM unites WHERE idFiliere =:idFiliere AND annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad  AND semestre =:semestre";
                                            		$statement1 = $bdd->prepare($sql1);
                                            		$statement1->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            		$statement1->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            		$statement1->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            		$statement1->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            		$statement1->bindParam(':semestre', 	$ids1, PDO::PARAM_STR);
                                            		$res1 = $statement1->execute();
                                            		$nb1 = $statement1->rowCount();
                                            
                                            		$sql2 = "SELECT code_unite FROM unites WHERE idFiliere =:idFiliere AND annee =:annee AND niveauFormation =:niveau  AND  annee_acad =:anneeacad  AND semestre =:semestre";       	 
                                            		$statement2 = $bdd->prepare($sql2);
                                            		$statement2->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            		$statement2->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            		$statement2->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            		$statement2->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            		$statement2->bindParam(':semestre', 	$ids2, PDO::PARAM_STR);
                                            		$res2 = $statement2->execute();
                                            		$nb2 = $statement2->rowCount();
                                            		
                                            		$statement11 = $bdd->prepare($sql1);
                                            		$statement11->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            		$statement11->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            		$statement11->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            		$statement11->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            		$statement11->bindParam(':semestre', 	$ids1, PDO::PARAM_STR);
                                            		$statement11->execute();
                                            
                                            		$statement12 = $bdd->prepare($sql2);
                                            		$statement12->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            		$statement12->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            		$statement12->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            		$statement12->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            		$statement12->bindParam(':semestre', 	$ids2, PDO::PARAM_STR);
                                            		$statement12->execute();
                                            		
                                            		$i = 0; $j = 0;//compteur ecus non renseignés.
                                            		$i1 = 0; $j1 = 0;
                                            		if( $nb1 != 0 && $nb2 != 0 ){
                                            			//On vérifie si il y a des ecus non renseignés (les notes).
                                            			while($row1 = $statement1->fetch(PDO::FETCH_ASSOC))  {
                                            				$code_unite = $row1['code_unite'];
                                            				$sql3 = "SELECT code_ecu, intituleEcu FROM ecu  WHERE (insertion =:inser AND annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad AND ";
                                            				$sql3 .= "idFiliere =:idFiliere AND code_unite =:code_unite)";
                                            				$statement3 = $bdd->prepare($sql3);
                                            				$statement3->bindParam(':inser', 		$insert, PDO::PARAM_STR);
                                            				$statement3->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            				$statement3->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            				$statement3->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            				$statement3->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            				$statement3->bindParam(':code_unite', 	$code_unite, PDO::PARAM_STR);
                                            				$statement3->execute();
                                            				$nb3 = $statement3->rowCount();						
                                            				if($nb3 != 0){
                                            				  $i = $i + $nb3;
                                            				}
                                            				$sql3 = "SELECT code_ecu, intituleEcu FROM ecu  WHERE (annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad AND ";
                                            				$sql3 .= "idFiliere =:idFiliere AND code_unite =:code_unite)";
                                            				$statement3 = $bdd->prepare($sql3);
                                            				$statement3->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            				$statement3->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            				$statement3->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            				$statement3->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            				$statement3->bindParam(':code_unite', 	$code_unite, PDO::PARAM_STR);
                                            				$statement3->execute();
                                            				$t3 = $statement3->rowCount();	
                                            				$i1 = $i1 + $t3;					
                                            			}
                                            			
                                            			while($row2 = $statement2->fetch(PDO::FETCH_ASSOC))  {
                                            				$code_unite = $row2['code_unite'];
                                            				$sql4 = "SELECT code_ecu, intituleEcu FROM ecu  WHERE (insertion =:inser AND annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad AND ";
                                            				$sql4 .= "idFiliere =:idFiliere AND code_unite =:code_unite)";
                                            				$statement4 = $bdd->prepare($sql4);
                                            				$statement4->bindParam(':inser', 		$insert, PDO::PARAM_STR);
                                            				$statement4->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            				$statement4->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            				$statement4->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            				$statement4->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            				$statement4->bindParam(':code_unite', 	$code_unite, PDO::PARAM_STR);
                                            				$statement4->execute();
                                            				$nb4 = $statement4->rowCount();						
                                            				if($nb4 != 0){
                                            				  $j = $j + $nb4;
                                            				}
                                            				$sql4 = "SELECT code_ecu, intituleEcu FROM ecu  WHERE (annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad AND ";
                                            				$sql4 .= "idFiliere =:idFiliere AND code_unite =:code_unite)";
                                            				$statement4 = $bdd->prepare($sql4);
                                            				$statement4->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            				$statement4->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            				$statement4->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            				$statement4->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            				$statement4->bindParam(':code_unite', 	$code_unite, PDO::PARAM_STR);
                                            				$statement4->execute();
                                            				$t4 = $statement4->rowCount();	
                                            				$j1 = $j1 + $t4;						
                                            			}
                                            			
                                            			//S'il existe des ecus non renseignés on les sélectionnent
                                            			//if( ($i + $j) > 0) {
                                            				$ec = 'ECs non renseignés...';
                                            				echo "<optgroup label='-====================================Semestre $ids1====================================-'><option disabled>$ec : $i / $i1</option>";
                                            				while($row1 = $statement11->fetch(PDO::FETCH_ASSOC))  {
                                            					$code_unite = $row1['code_unite'];
                                            					//$insert = 'YES';
                                            					$sql5 = "SELECT idEC, insertion, code_ecu, intituleEcu FROM ecu  WHERE (annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad AND ";
                                            					$sql5 .= "idFiliere =:idFiliere AND code_unite =:code_unite)";
                                            					$statement5 = $bdd->prepare($sql5);
                                            					//$statement5->bindParam(':inser', 		$insert, PDO::PARAM_STR);
                                            					$statement5->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            					$statement5->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            					$statement5->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            					$statement5->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            					$statement5->bindParam(':code_unite', 	$code_unite, PDO::PARAM_STR);
                                            					$statement5->execute();
                                            					
                                            					$sql6 = "SELECT intituleUnite FROM unites WHERE idFiliere =:idFiliere AND annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad   AND code_unite =:code_unite";
                                            					$statement6 = $bdd->prepare($sql6);
                                            					$statement6->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            					$statement6->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            					$statement6->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            					$statement6->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            					$statement6->bindParam(':code_unite', 	$code_unite, PDO::PARAM_STR);
                                            					$statement6->execute();
                                            					$tab = $statement6->fetch(PDO::FETCH_ASSOC);						
                                            					$unite = $tab['intituleUnite'];
                                            					
                                            					echo "<optgroup label='$unite'>";
                                            					$traite = ' #Traité';
                                            					//disabled
                                            					while($row5 = $statement5->fetch(PDO::FETCH_ASSOC)) {
                                            						$i++;
                                            						$code  = "$row5[idEC]*$row5[code_ecu]*$row1[code_unite]*$row5[intituleEcu]";
                                            						$utf8_encode 	= $row5["intituleEcu"];
                                            						$insertion 		= $row5["insertion"]; 
                                            						if(strcmp($insertion, 'YES') == 0){
                                            							echo "<option value=\"$code\">$utf8_encode</option>";
                                            						}else{
                                            							echo "<option value=\"$code\" >$utf8_encode.$traite</option>";
                                            						}						
                                            					}
                                            					echo "</optgroup>";
                                            				}
                                            				echo "</optgroup>";					
                                            				echo "<optgroup label='-====================================Semestre $ids2====================================-'><option disabled>$ec : $j / $j1</option>";
                                            				while($row2 = $statement12->fetch(PDO::FETCH_ASSOC))  {
                                            					$code_unite = $row2['code_unite'];
                                            					//$insert = 'YES';
                                            					$sql6 = "SELECT idEC, insertion, code_ecu, intituleEcu FROM ecu  WHERE (annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad AND ";
                                            					$sql6 .= "idFiliere =:idFiliere AND code_unite =:code_unite)";
                                            					$statement6 = $bdd->prepare($sql6);
                                            					//$statement6->bindParam(':inser', 		$insert, PDO::PARAM_STR);
                                            					$statement6->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            					$statement6->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            					$statement6->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            					$statement6->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            					$statement6->bindParam(':code_unite', 	$code_unite, PDO::PARAM_STR);
                                            					$statement6->execute();
                                            					
                                            					$sql7 = "SELECT intituleUnite FROM unites WHERE idFiliere =:idFiliere AND annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad   AND code_unite =:code_unite";
                                            					$statement7 = $bdd->prepare($sql7);
                                            					$statement7->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            					$statement7->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            					$statement7->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            					$statement7->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            					$statement7->bindParam(':code_unite', 	$code_unite, PDO::PARAM_STR);
                                            					$statement7->execute();
                                            					$tab = $statement7->fetch(PDO::FETCH_ASSOC);						
                                            					$unite = $tab['intituleUnite'];
                                            					
                                            					echo "<optgroup label='$unite'>";
                                            					$traite = ' #Traité';
                                            					//disabled
                                            					while($row6 = $statement6->fetch(PDO::FETCH_ASSOC)) {
                                            						$i++;
                                            						$code  = "$row6[idEC]*$row6[code_ecu]*$row2[code_unite]*$row6[intituleEcu]";
                                            						$utf8_encode 	= $row6["intituleEcu"];
                                            						$insertion 		= $row6["insertion"]; 
                                            						if(strcmp($insertion, 'YES') == 0){
                                            							echo "<option value=\"$code\">$utf8_encode</option>";
                                            						}else{
                                            							echo "<option value=\"$code\" >$utf8_encode.$traite</option>";
                                            						}
                                            					}
                                            					echo "</optgroup>";
                                            				}
                                            				echo "</optgroup>";
                                            			/*}else{
                                            				$utf8_encode = utf8_encode('Traitement terminé pour cette filière...');
                                            				echo "<option value='-1'>$utf8_encode</option>";
                                            			}*/
                                                      }else{
                                            			   $utf8_encode = utf8_encode('Traitement tableau de spécification en cours...');
                                                           echo "<option value='-1'>$utf8_encode</option>";     
                                                      }
                                        	}else{
                                        	        //On compte le nombre d'ue non traité
                                            		$sql1 = "SELECT code_unite FROM unites WHERE insertion =:inser AND idFiliere =:idFiliere AND annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad  AND semestre =:semestre";
                                            		$statement1 = $bdd->prepare($sql1);
                                            		$statement1->bindParam(':inser', 		$insert, PDO::PARAM_STR);
                                            		$statement1->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            		$statement1->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            		$statement1->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            		$statement1->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            		$statement1->bindParam(':semestre', 	$ids1, PDO::PARAM_STR);
                                            		$res1 = $statement1->execute();
                                            		$nb1 = $statement1->rowCount();
                                            
                                            		$sql2 = "SELECT code_unite FROM unites WHERE  insertion =:inser AND idFiliere =:idFiliere AND annee =:annee AND niveauFormation =:niveau  AND  annee_acad =:anneeacad  AND semestre =:semestre";       	 
                                            		$statement2 = $bdd->prepare($sql2);
                                            		$statement2->bindParam(':inser', 		$insert, PDO::PARAM_STR);
                                            		$statement2->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            		$statement2->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            		$statement2->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            		$statement2->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            		$statement2->bindParam(':semestre', 	$ids2, PDO::PARAM_STR);
                                            		$res2 = $statement2->execute();
                                            		$nb2 = $statement2->rowCount();
                                                    ///////////////////////////////////////////////////////////////////
                                                    
                                                    //On compte le nombre total d'ue
                                            		$sql11 = "SELECT * FROM unites WHERE idFiliere =:idFiliere AND annee =:annee AND niveauFormation =:niveau AND  annee_acad =:anneeacad  AND semestre =:semestre";
                                            		$statement11 = $bdd->prepare($sql11);
                                            		$statement11->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            		$statement11->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            		$statement11->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            		$statement11->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            		$statement11->bindParam(':semestre', 	$ids1, PDO::PARAM_STR);
                                            		$res11 = $statement11->execute();
                                            		$nb11 = $statement11->rowCount();
                                            
                                            		$sql21 = "SELECT * FROM unites WHERE idFiliere =:idFiliere AND annee =:annee AND niveauFormation =:niveau  AND  annee_acad =:anneeacad  AND semestre =:semestre";       	 
                                            		$statement21 = $bdd->prepare($sql21);
                                            		$statement21->bindParam(':idFiliere', 	$idFiliere, PDO::PARAM_STR);
                                            		$statement21->bindParam(':annee', 		$annee, PDO::PARAM_STR);
                                            		$statement21->bindParam(':niveau', 		$niveau, PDO::PARAM_STR);
                                            		$statement21->bindParam(':anneeacad', 	$anneeacad, PDO::PARAM_STR);
                                            		$statement21->bindParam(':semestre', 	$ids2, PDO::PARAM_STR);
                                            		$res21 = $statement21->execute();
                                            		$nb21 = $statement21->rowCount();
                                                    
                                        			$ue = 'UEs non renseignées...';
                                        			echo "<optgroup label='-====================================Semestre $ids1====================================-'><option disabled>$ue : $nb1 / $nb11</option>";
                                        			while($row1 = $statement11->fetch(PDO::FETCH_ASSOC))  {
                                        				$code_unite = $row1['code_unite'];
                                        				$unite = $row1['intituleUnite'];
                                        				$traite = ' #Traité';
                                        				$code  = "$code_unite*$code_unite*$unite";
                                        				$insertion 		= $row1["insertion"]; 
                                        				if(strcmp($insertion, 'YES') == 0){
                                        					echo "<option value=\"$code\">$unite</option>";
                                        				}else{
                                        					echo "<option value=\"$code\" >$unite.$traite</option>";
                                        				}						
                                        			}
                                        			echo "</optgroup>";					
                                        			echo "<optgroup label='-====================================Semestre $ids2====================================-'><option disabled>$ue : $nb2 / $nb21</option>";
                                        			while($row2 = $statement21->fetch(PDO::FETCH_ASSOC))  {
                                        				$code_unite = $row2['code_unite'];
                                        				$unite = $row2['intituleUnite'];
                                        				$traite = ' #Traité';
                                        				$code  = "$code_unite*$code_unite*$unite";
                                        				$insertion 		= $row2["insertion"]; 
                                        				if(strcmp($insertion, 'YES') == 0){
                                        					echo "<option value=\"$code\">$unite</option>";
                                        				}else{
                                        					echo "<option value=\"$code\" >$unite.$traite</option>";
                                        				}						
                                        			}
                                        			echo "</optgroup>";
                                        	}
										?>
									</select>
								</div>
								<div class="form-group">
									<label>Objet de la requête</label>
									<input type="text" name = "objet" placeholder="Objet de la requête..." class="form-control"  required>
								</div>
								<div class="form-group">
									<label>Intitulé de la requête</label>
									<textarea class="form-control" name="message" rows="7"  required></textarea>
								</div>
                                <div class="form-group">
                                    <label class="control-label">Joindre un fichier</label>
                                    <div class="form-group">
        								<input type="file" name = "files" id="files" class="dropify" data-max-file-size="0.5M" data-allowed-file-extensions=".pdf"/> 
        							</div>
                                </div>
								<input type="submit" class="btn btn-danger pull-right" value="Envoyer" /><br>
							</form>
						</div>
                    </div>
                </div>

                <!-- ============================================================== -->
                <!-- Blog-component -->
                <!-- ============================================================== -->
					  <div class="row">
						
						<!-- /.col -->
						<div class="col-md-offset-1 col-md-10">
						  <div class="box box-primary">
							<div class="box-header with-border">
							  <h3 class="box-title"><?php //echo $_SESSION["DB_DATABASE"];?> Vos requêtes</h3>
							  <!-- /.box-tools -->
							</div>
							<!-- /.box-header -->
							<div class="box-body no-padding">
							  <div class="table-responsive mailbox-messages white-box">
								<table class="table table-hover table-striped" id="examtable">
								  <thead>
									<th class="mailbox-name" style="width:30%;">Cours</th>
									<th class="mailbox-subject" style="width:60%;"><b>Aperçu de message</b>
									</th>
									<th class="mailbox-date" style="width:10%;">Instant d'envoi</th>
								  </thead>
								  <tbody>
								  <?php
									function affiche_date($date, $heure){
										$dateen=explode('/', $date);
										$heureen=explode(':', $heure);
										$dat=$dateen[1].'/'.$dateen[0].'/'.$dateen[2];
										$heu=$heureen[0].':'.$heureen[1];
										if($dat==date('d/m/Y'))
											return $heu;
										else
											return $dat;
									}
									while($donnees=$recupereretour->fetch()){
										$date=affiche_date($donnees['dateenvoie'], $donnees['heureenvoie']);
										$date = $donnees['dateenvoie'].' '.$donnees['heureenvoie']
										
								  ?>
									  <tr>
										<td class="mailbox-name"><?php 
										$cours=$donnees['matiere'];
										echo ($cours); ?></td>
										<td class="mailbox-subject"><b><a href="readrequete.php?somme=<?php echo $donnees['idrequete'];?>"><?php 
										if(strlen($donnees['sujet'])>50) $sujet=substr($donnees['sujet'],0,50).'...'; else $sujet=$donnees['sujet'];
										if(strlen($donnees['requete'])>100) $requete=substr($donnees['requete'],0,100).'...'; else $requete=$donnees['requete'];
										echo ($sujet.'</b></br> '.$requete); ?></a>
										</td>
										<td class="mailbox-date"><?php echo $date; ?></td>
									  </tr>
								  <?php
									}
								  ?>
								  </tbody>
								</table>
								<!-- /.table -->
							  </div>
							  <!-- /.mail-box-messages -->
							</div>							
						  </div>
						  <!-- /. box -->
						</div>
						<!-- /.col -->
					  </div>
					  <!-- /.row -->
                <!-- ============================================================== -->
                <!-- chats, message & profile widgets -->
                <!-- ============================================================== -->
                
                <!-- ============================================================== -->
                <!-- Right sidebar -->
                <!-- ============================================================== -->
                <!-- .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><b>With Dark sidebar</b></li>
                                <br/>
                                <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 all-demos">
                                <li><b>Choose other demos</b></li>
                            </ul>
                            <ul class="m-t-20 chatonline">
                                <li><b>Chat option</b></li>
                                <li>
                                    <a href="javascript:void(0)"><img src="../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="../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="../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="../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="../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="../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="../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="../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>
    <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>
	<!-- jQuery file upload -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/dropify/dist/js/dropify.min.js"></script>
    <script>
    $(document).ready(function() {
        // Basic
        $('.dropify').dropify();
        // Translated
        $('.dropify-fr').dropify({
            messages: {
                default: 'Glissez-déposez un fichier ici ou cliquez',
                replace: 'Glissez-déposez un fichier ou cliquez pour remplacer',
                remove: 'Supprimer',
                error: 'Désolé, le fichier trop volumineux'
            }
        });
        // Used events
        var drEvent = $('#input-file-events').dropify();
        drEvent.on('dropify.beforeClear', function(event, element) {
            return confirm("Do you really want to delete \"" + element.file.name + "\" ?");
        });
        drEvent.on('dropify.afterClear', function(event, element) {
            alert('File deleted');
        });
        drEvent.on('dropify.errors', function(event, element) {
            console.log('Has Errors');
        });
        var drDestroy = $('#input-file-to-destroy').dropify();
        drDestroy = drDestroy.data('dropify')
        $('#toggleDropify').on('click', function(e) {
            e.preventDefault();
            if (drDestroy.isDropified()) {
                drDestroy.destroy();
            } else {
                drDestroy.init();
            }
        })
    });
    </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>
    <!-- FormValidation -->
    <link rel="stylesheet" href="https://progiciel.africawebstudent.org/plugins/bower_components/jquery-wizard-master/libs/formvalidation/formValidation.min.css">
    <!-- FormValidation plugin and the class supports validating Bootstrap form -->
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/jquery-wizard-master/libs/formvalidation/formValidation.min.js"></script>
    <script src="https://progiciel.africawebstudent.org/plugins/bower_components/jquery-wizard-master/libs/formvalidation/bootstrap.min.js"></script>
	<!-- Data table  -->
	<script src="https://progiciel.africawebstudent.org/plugins/bower_components/datatables/jquery.dataTables.min.js"></script>

	<script type="text/javascript">  	
		 $( function(){
			$("#examtable").DataTable();
		 });
  </script>	
</body>

</html>
