<!DOCTYPE html>




<?php
error_reporting(0);

$nombre_contacto=$_POST["nombre_contacto"];
$mensaje=$_POST["message-text"];
$email_contacto=$_POST["email_contacto"];
$idArticulo=$_POST["identArticulo"];




//generate email and send!

$to      = 'tricahuesoluciones@gmail.com';
$subject = 'Nuevo Comentario';
$message = "Nombre:".$nombre_contacto.",\n \n"."email:".$email_contacto.",\n \n"."Mensaje:".$mensaje;
$headers = 'From: contacto@tricahuesoluciones.cl';
 try {
 mail($to, $subject, $message, $headers);

} catch (Exception $e) {
  //  echo 'Excepción capturada: ',  $e->getMessage(), "\n";
}



	// }




?>

<html>
<head>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- /// font icons /// -->
        <link rel="stylesheet" type="text/css" href="../css/font-awesome.min.css">
        <link rel="stylesheet" type="text/css" href="../css/linecons.css">

        <link href="css" rel="stylesheet" type="text/css">
        <link rel="stylesheet" type="text/css" href="../css/animate.css">
        <!--<link rel="stylesheet" type="text/css" href="css/bootstrap-select.css">-->
       <link rel="stylesheet" type="text/css" href="../css/bootstrap.css">
        <link rel="stylesheet" type="text/css" href="../css/main.css">


        <!-- /// plugins /// -->
        <script src="../js/bootstrap-modal.js"></script>
            <script src="../js/bootstrap-select.min.js"></script>
             <script src="../js/countdown.js"></script>

        <script src="../js/plugins.js"></script>
        <script src="../js/custom.js"></script>

		<script src="../js/jquery-1.11.0.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
		   <script src="../js/jquery.form-validator.min.js"></script>

</head>


<body>

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
        aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                               <button type="button" class="close" data-dismiss="modal">&times;</button>

                        <h4 class="modal-title" id="myModalLabel">Gracias por su comentario</h4>
                    </div>
                    <div class="modal-body">

              <?php echo "hemos publicado su mensaje"; ?>
                    </div>

                     <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="redireccionar()" data-dismiss="modal">OK</button>
                    </div>
                </div>
            </div>
        </div>
         <!-- fin Modal -->


</body>



<?php
$servername = "localhost";
$username = "tricahue_user";
$password = "Tricahue.soluciones";
$bdname="tricahue_tricahue";

// Create connection
$conn = new mysqli($servername, $username, $password,$bdname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$hoy = getdate();
$hora=localtime();
$hora=$hora[2].":".$hora[1].":".$hora[0];
$hoy= $hoy[mday]." de ".$hoy[month]." del ".$hoy[year]." a las ".$hora;

$sql = "INSERT INTO comentario (id_articulo, fecha,nombre,comentario,mail)
VALUES ('".$idArticulo."','".$hoy."','".$nombre_contacto."', '".$mensaje."', '".$email_contacto."')";

if ($conn->query($sql) === TRUE) {
  //  echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();


?>









<script>
               // $("#myModal").modal('backdrop');



    $("#myModal").modal({                    // wire up the actual modal functionality and show the dialog
      "backdrop"  : "static",
      "keyboard"  : false,
      "show"      : true                     // ensure the modal is shown immediately
    });




  function redireccionar(){
window.location = document.referrer;
//history.back();
//window.location = "http://localhost/tricahue/blog/blog.php?mostrar=1";
  }






</script>

</html>
