<?php
//Permet de ne pas charger de cache
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé

require 'config.php';
include('../commun/connection_bdd.php');
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <!--<title>editor email</title>-->

        <!-- styles -->

        <link href="<?= $path ?>/css/colpick.css" rel="stylesheet"  type="text/css"/>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
        <link href="<?= $path ?>/css/themes/default.css" rel="stylesheet" type="text/css"/>
        <link href="<?= $path ?>/css/template.editor.css" rel="stylesheet"/>
        <link href="<?= $path ?>/css/responsive-table.css" rel="stylesheet"/>
        <link href="<?= $path ?>/css/style.css" rel="stylesheet"/>
        <link href="<?= $path ?>/css/responsive.css" rel="stylesheet"/>

        <!--[if lt IE 9]>
                <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
        <![endif]-->
        <script type="text/javascript"> var path = '<?= $path; ?>';</script>
        <script type="text/javascript" src="http://feather.aviary.com/js/feather.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script type="text/javascript" src="https://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>

        <script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.2.6/plugins/colorpicker/plugin.min.js"></script>
        <script type="text/javascript" src="<?= $path ?>/js/colpick.js"></script>
        <script type="text/javascript" src="<?= $path ?>/js/template.editor.js"></script>

        
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
      <script>
    jQuery(function($){
                                                                       
            //Lorsque vous cliquez sur un lien de la classe poplight
            $('a.poplight').on('click', function() {
                    var popID = $(this).data('rel'); //Trouver la pop-up correspondante
                    var popWidth = $(this).data('width'); //Trouver la largeur
    
                    //Faire apparaitre la pop-up et ajouter le bouton de fermeture
                    $('#' + popID).fadeIn().css({ 'width': popWidth}).prepend('<a href="#" class="close enleveclose"><i class="glyphicon-remove glyphicon icone_croix_pop_up"></i></a>');
                    
                    //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS
                    var popMargTop = ($('#' + popID).height() + 80) / 2;
                    var popMargLeft = ($('#' + popID).width() + 80) / 2;
                    
                    //Apply Margin to Popup
                    $('#' + popID).css({ 
                            'margin-top' : -popMargTop,
                            'margin-left' : -popMargLeft
                    });
                    
                    //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues d'anciennes versions de IE
                    $('body').append('<div id="fade"></div>');
                    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
                    
                    return false;
            });
            
            
            //Close Popups and Fade Layer
            $('body').on('click', 'a.close, #fade', function() { //Au clic sur le body...
                    $('#fade , .popup_block').fadeOut(function() {
                            $('#fade, a.close').remove();  
            }); //...ils disparaissent ensemble
                    
                    return false;
            });
    
            
    });
    
    </script>
    
    
	<!--POP UP-->
	<!-- Bootstrap Core CSS - Uses Bootswatch Flatly Theme: http://bootswatch.com/flatly/ -->
	<!--<link href="js/pop-up/css/bootstrap.min.css" rel="stylesheet">-->
    
	<!-- Custom CSS -->
	<!--<link href="js/pop-up/css/style.css" rel="stylesheet">-->
    
	<link href='https://fonts.googleapis.com/css?family=Quicksand:400,300,700' rel='stylesheet' type='text/css'>
	<link rel="stylesheet" href="js/pop-up/css/animate.css">
	<link rel="stylesheet" href="js/pop-up/css/replete-modal.css">
    
	<!-- Custom Fonts -->
	<link href="js/pop-up/fonts/css/font-awesome.min.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" href="js/pop-up/fonts/stylesheet.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]-->
	<!--FIN POP UP-->

    </head>
    <body class="edit2">
        <div class="navbar navbar-inverse navbar-fixed-top navbar-layoutit">
            <div class="navbar-header">
                <button data-target="navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button">
                    <span class="glyphicon-bar"></span>
                    <span class="glyphicon-bar"></span>
                    <span class="glyphicon-bar"></span>
                </button>
                <a class="btn btn-archive" href="index.php">RETOUR</a>
                <!--<button type="button" class="btn btn btn-default" id="sourcepreview"onclick="return confirm('message for exit action');"><i class="glyphicon-folder glyphicon"></i> Archives</button>-->
            </div>

            <div class="collapse navbar-collapse">
                <ul class="nav" id="menu-layoutit">
                    <li>
                    </li>
                </ul>
            </div><!--/.navbar-collapse -->
        </div><!--/.navbar-fixed-top -->
        
        <?php
            
            $dir_nom = 'tmp'; // dossier listé (pour lister le répertoir courant : $dir_nom = '.'  --> ('point')
            
            $dir = opendir($dir_nom) or die('Erreur de listage : le répertoire n\'existe pas'); // on ouvre le contenu du dossier courant
            $fichier= array(); // on déclare le tableau contenant le nom des fichiers
            //$dossier= array(); // on déclare le tableau contenant le nom des dossiers
            
            while($element = readdir($dir)) {
                    if($element != '.' && $element != '..') {
                            if (!is_dir($dir_nom.'/'.$element)) {$fichier[] = $element;}
                            else {$dossier[] = $element;}
                    }
            }
            
            closedir($dir);
            //if(!empty($dossier)) {
            //        sort($dossier); // pour le tri croissant, rsort() pour le tri décroissant
            //        echo "Liste des dossiers accessibles dans '$dir_nom' : \n\n";
            //        echo "\t\t<ul>\n";
            //                foreach($dossier as $lien){
            //                        echo "\t\t\t<li><a href=\"$dir_nom/$lien \">$lien</a></li>\n";
            //                }
            //        echo "\t\t</ul>";
            //}
            
            if(!empty($fichier)){
                    rsort($fichier);// sort() pour le tri croissant, rsort() pour le tri décroissant
                        
                        $_request = "body_";
                        
                        //include '../db.php';

                            //foreach($fichier as $lien) {
                            //    
                            //    $_string = "$lien";
                            //    $_request = "body_";
                            //    if( preg_match('#'.$_request.'#', $_string) ){
                            //    } else {
                            //
				$reponse = $bdd->query("SELECT * FROM `newsletter` ") or die(print_r($bdd->errorInfo()));
				$donnees =  $reponse->fetchAll();
				    foreach ($donnees as $donnee)
				    {
	    
					if( $lien = $donnee['filename'] ) {
					    
					    echo "  <div class='mini_news'>
							<b>".$donnee['titre']."</b>
							<div class='taille_iframe_news'>
							    <iframe src=\"$dir_nom/$lien \" class='iframe_mini_news'></iframe>
							</div>
							<div style='width:100%;height:5px;'></div>
							<a class='btn bouton_blanc' href='$dir_nom/$lien' target='_blank'>VOIR</a>
							<a class='btn bouton_bleu' href='".$path."index-archieves.php?filename=$lien'>MODIFIER</a>
						 ";
					    include ('form_envoie_news.php');
					    echo "      <a class='btn bouton_rouge' onclick=\"return(confirm('Êtes-vous sûr de vouloir supprimer cette newsletter '))\" href='".$path."supprimer.php?filename=$lien'>SUPPRIMER</a>
						    </div>
						 ";
					}
	    
                                    //$sth  = $pdo->prepare('SELECT * FROM newsletter WHERE filename = :filename');
                                    //$sth ->execute(['filename' => $lien]);
                                    //$r = $sth->fetchAll();
                                    //$titre = isset($r[0]['titre']) ? $r[0]['titre']:'';
//                                    echo "  <div class='mini_news'>
//						<b>".$donnee['titre']."</b>
//                                                <div class='taille_iframe_news'>
//                                                    <iframe src=\"$dir_nom/$lien \" class='iframe_mini_news'></iframe>
//                                                </div>
//						<div style='width:100%;height:5px;'></div>
//                                                <a class='btn bouton_blanc' href='$dir_nom/$lien' target='_blank'>VOIR</a>
//                                                <a class='btn bouton_vert' href='".$path."index-archieves.php?filename=$lien'>MODIFIER</a>
//                                         ";
//                                    include ('form_envoie_news.php');
//                                    echo "      <a class='btn bouton_rouge' onclick=\"return(confirm('Êtes-vous sûr de vouloir supprimer cette newsletter '))\" href='".$path."supprimer.php?filename=$lien'>SUPPRIMER</a>
//                                            </div>
//                                         ";
				    }
                                //}
				
                            }
                    
            //}
        ?>
        
                                                    <!--<iframe src=\"$dir_nom/$lien \" width=\"320\" height=\"450\" ></iframe>-->
                                                    
                                                    <!--<br><br>$lien-->
                                                    <!--<br><br>$num_news-->
                                                    
                                                    <!--<br><a href='$dir_nom/$lien' target='_blank'>Voir la newsletter</a>-->
                                                    <!--<br><a href='".$path."index.php?filename=$lien'>Modifier la newsletter</a>-->
                                                    <!--<br><a href='".$path."supprimer.php?filename=$lien'>Supprimer la newsletter</a>-->
                                                    

    
	<!--POP UP-->
            <!-- jQuery -->
            <script src="js/pop-up/js/jquery.js"></script>
        
        
            <!-- Bootstrap Core JavaScript -->
            <script src="js/pop-up/js/bootstrap.min.js"></script>
        
            <!-- This is what you need -->
            <script src="js/pop-up/js/replete-modal.js"></script>
            <script src="js/pop-up/js/custom.js"></script>
        
            <!-- Plugin JavaScript -->
            <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
            <script src="js/pop-up/js/classie.js"></script>
        
            <!-- Custom Theme JavaScript -->
            <script src="js/pop-up/js/demo.js"></script>
    
	<!--FIN POP UP-->

    </body>
</html>