<?php
session_start();
include('../connexion.php');
if (!isset($_SESSION['celest']))
{
	header ('Location: index.php');
}
$active='newsletter';
?>
	<?php include('tete.php'); ?>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="css/local.css" />
    <link rel="stylesheet" type="text/css" href="style/style_admin.css" />

    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
	<script src="http://www.destinationabidjan.ci/ckeditor/ckeditor.js"></script>

</head>
<body>
    <div id="wrapper">
    	<?php include('menu_admin.php'); ?>
        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-2 col-md-1"></div>
                <div class="col-lg-8 col-md-10 col-sm-11 col-xs-12" id="administration">
                    <div id="titro_admin">Newsletter</div>
					<div align="center">
						<?php
						if (isset($_POST['valider']))
						{
							$date_mise=date('Y-m-d H:i:s');
							$nom=addslashes(($_POST['nom']));	
							$present=addslashes(($_POST['present']));	
							if (empty($present) or empty($nom))
							{
								echo '<div class="alert alert-danger">Veuillez renseigner l\'objet</div>';
							}
							if (empty($present))
							{
								echo '<div class="alert alert-danger">Veuillez renseigner le messagee</div>';
							}
							else
							{
								$req='INSERT INTO message VALUES (NULL, "'.$nom.'", "'.$present.'", "'.$dat_mis.'")';
								$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
								
								$sql = 'SELECT MAX(id_message) FROM message';
								$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
								$data =$reponse->fetch();
								$id_message=$data[0];
								
								$sql2= 'SELECT * FROM newsletter';
								$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
								while($data2=$reponse2->fetch())
								{
									$req='INSERT INTO message_news VALUES ("'.$id_message.'", "'.$data2[0].'", "'.$dat_mis.'")';
									$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
									
									/*ini_set('SMTP','smtp.aviso.ci');
									$sujet = $nom;
									$email=$data2['lib_newsletter'];
									$message = $present;
									$headers = "From: \"Front populaire ivoirien\"<ngopama@yahoo.fr>\n";
									$headers .= "Reply-To: fpi.matca-ci.com\n";
									$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"";
									if(mail($email,$sujet,$message,$headers))
									{
										echo '';
									}
									else
									{
										echo '
										<div class="alert alert-danger">
											Une erreur c\'est produite lors de l\'envoi de l\'email.
										</div>';
									}*/
								}
							?>
							<script type="text/javascript">window.setTimeout("location=('envoyer_mail.php');",11000);</script>
							<?php
							}
						}
						?>
                        </div>
                     	<form method="post" action="" enctype="multipart/form-data">
                        <div>
                        	<h5>Objet</h5>
                        	<input type="text" class="form-control" name="nom" value="<?php if (isset($_POST['valider'])){echo $_POST['nom'];} ?>">
                            <h5>Description</h5>
                            <textarea class="form-control" name="present"><?php if (isset($_POST['valider'])){echo $_POST['present'];}?></textarea>
                            <script>
                                CKEDITOR.replace('present');
                            </script>
                        </div>
						
                        <div id="valider">
                            <input type="submit" class="btn btn-primary" value="Valider" name="valider">
                            &nbsp; <a href="gestionnaire-table.php?W9mvyDvFWE5=newsletter"><i class="fa fa-reply"></i> Retour</a>
                        </div>
						</form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>