<?php
session_start();
header("Access-Control-Allow-Headers: Authorization, Content-Type");
header("Access-Control-Allow-Origin: *");
date_default_timezone_set('Africa/Porto-Novo'); 
//header("Access-Control-Allow-Origin: *"); 
if(!isset($_SESSION["etudiant_i"]) OR !isset($_SESSION["idEtablissement"])){
	header("Location:./");
	exit();
}
include('/home/africawebstudent/public_html/gs/progicielgeststudent/footer.php');
include('/home/africawebstudent/public_html/gs/progicielgeststudent/smsmail-functions.php');
include_once('Library/Basededonnees.php');

if(!isset($_POST['objet']) OR empty($_POST['objet']) OR 
   !isset($_POST['ec']) OR empty($_POST['ec']) OR 
   !isset($_POST['message']) OR empty($_POST['message'])){
	header("Location:f_reclamation.php");
}else{
	$cheminFiles	 	= 'fiches/'; 
	$cheminFiles	 	.= $_SESSION['idEtablissement']; 
	$cheminFiles	 	.= '/'; 
	$extension_upload    = strtolower(substr(strrchr(basename($_FILES['files']['name']), '.')  ,1));
	$cheminFiles        .= mt_rand().'.'.$extension_upload;
	if(basename($_FILES["files"]['name']) == "") {
	    $cheminFiles = '';
	}
    
	$idetudiant=$_SESSION["etudiant_i"];
	$message= htmlspecialchars($_POST['message']);
	$objet= htmlspecialchars($_POST['objet']);
	$dateenvoie= date("d/m/Y");
	$heureenvoie= date("H:i:s");
	$idcours=explode('*', $_POST['ec'])[0];
	$ec=explode('*', $_POST['ec'])[3];
    $DB_DATABASE = $_SESSION["DB_DATABASE"];
    $database = new Basededonnees($DB_DATABASE);
    $bdd = $database->getBdd();
    $etudiant= $bdd->prepare('INSERT INTO requeteetudiant(idetudiant,idecu,sujet,requete,requetefichier,etat,statut,dateenvoie,heureenvoie,reponse,reponsefichier) 
	VALUES (:idetudiant,:idecu,:sujet,:requete,:requetefichier,:etat,:statut,:dateenvoie,:heureenvoie,:reponse,:reponsefichier)');

	$etudiant->execute(array('idetudiant'=>$idetudiant,
							'idecu'=>$idcours,
							'sujet'=>$objet,
							'requete'=>$message.'<br /><br /> EC : '.$ec,
							'requetefichier'=>$cheminFiles,
							'etat'=>"N",
							'statut'=>"N",
							'dateenvoie'=>$dateenvoie,
							'heureenvoie'=>$heureenvoie,
							'reponse'=>"",
							'reponsefichier'=>"")) or die(print_r($etudiant->errorInfo()));
	if(basename($_FILES["files"]['name']) != ""){
    	move_uploaded_file($_FILES['files']['tmp_name'], '/home/iitech/progiciel.geststudent.net/Inscription/'.$cheminFiles);
	}
							
	$query="SELECT t.email, t.nom, t.prenom FROM tabetudiant AS t INNER JOIN requeteetudiant AS r ON t.matricule= r.idetudiant WHERE t.matricule=:id";
	$req= $bdd->prepare($query);
	$req->execute(array('id'=>$idetudiant));
    $donnees=$req->fetch();
    $email  = $donnees['email'];
    $nom    = $donnees['nom'];
    $prenom = $donnees['prenom'];

	$query="SELECT descreta FROM etablissement WHERE idEtablissement=:id";
	$req= $bdd->prepare($query);
	$req->execute(array('id'=>$_SESSION["idEtablissement"]));
    $donnees=$req->fetch();
    $descreta    = $donnees['descreta'];

    $sujet = "Une requête de $nom $prenom en attente d'une réponse";
    $body = '
    <html>
    <head>
        <meta charset="utf-8">
      <style>
        .wrapper {
          padding: 5px;
          color: #444;
          font-size: 1em;
        }
        a {
          text-decoration: none;
          color: #fff;
        }
      </style>
    </head>
        <body>
            <div style="display:inline-block ; text-align:center ; ">
                    <h2 style="color : #2653d4 ;" >'.$descreta.'</h2>
            </div>
            <div >
                <p>'.$message.'</p>
                <p>EC : '.$ec.'</p>
                <hr>
                <div >
                    <div style="text-align: center ; color:#808080; font-size:9px";>
                        <p  class="address">Si vous avez des questions ou besoins d\'aide , vous pouvez nous contacter<br>Siege Social: Abomey-Calavi  <br /> Tél: (00229) 61373500 <br /> iitech@iitech-benin.net <br />IITECH-BENIN : https://iitech-benin.net/</p>
                    </div>
                </div>
            </div>
        </body>
    </html>';
    $database1 = new Basededonnees('africawebstudent_universite');
    $bddg = $database1->getBdd();
    $etabli= $bddg->prepare('SELECT * FROM etablissement WHERE idEtablissement=?');
    $etabli->execute(array($_SESSION['idEtablissement']));
    $nomEtablissement= $etabli->fetch();
    $emailfrom = $nomEtablissement['email'];
    //$emailfrom = 'info@geststudent.net';
    $mailheader = 'GestStudent';
	envoyer_mail('csm.djara@gmail.com', $emailfrom, $mailheader, $body, utf8_decode($sujet));

}
?>
<!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">
    <!-- 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 -->
        <!-- ============================================================== -->
        <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">Requête réussie</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">Requête réussie</li>
                        </ol>
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <div class="row">
                    <div class="col-md-offset-1 col-md-10 row">
                        <div class="white-box col-md-offset-3 col-md-6 text-center">
													<img class="success-img" src="img/007-success.png" class="img-responsive" width = "100"/><br/><br/>
													<h3 class="box-title text-success">Opération réussie</h3> 
													<div class="text-center">
														Requête envoyée avec succès.
														<br/><br/><br/>
														<a href="f_reclamation.php"><button class="btn btn-success btn-lg"><i class="fa fa-chevron-left"></i> Retour</button></a>
													</div>
												</div>
                    </div>
                </div>
                <!-- ============================================================== -->
                <!-- 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>
    <!-- /#wrapper -->
    <!-- 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>
    <!-- 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>
</body>

</html>

