Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include('is_logged.php');//Archivo verifica que el usario que intenta acceder a la URL esta logueado
- setlocale(LC_TIME, 'es_PE');
- // checking for minimum PHP version
- if (version_compare(PHP_VERSION, '5.3.7', '<')) {
- exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !");
- } else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
- // if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php
- // (this library adds the PHP 5.5 password hashing functions to older versions of PHP)
- require_once("../libraries/password_compatibility_library.php");
- }
- if (empty($_POST['ticket'])){
- $errors[] = "Ticket Vacio";
- } elseif (empty($_POST['nro_encuesta'])){
- $errors[] = "Numero de encuesta vacio";
- } elseif (strlen($_POST['ticket'])!=6) {
- $errors[] = "Tamaño del ticket no es 6 caracteres";
- } elseif (strlen($_POST['nro_encuesta'])!=4) {
- $errors[] = "Tamaño de la encuesta no es 4 caracteres";
- } elseif (empty($_FILES['imagefile'])) {
- $errors[] = "Imagen vacio";
- }
- elseif (
- !empty($_POST['ticket'])
- && !empty($_POST['nro_encuesta'])
- && !empty($_FILES['imagefile'])
- // && !empty($_POST['calidad_servicio'])
- // && !empty($_POST['trato_personal'])
- //&& !empty($_POST['observaciones'])
- ) {
- require_once ("../config/db.php");//Contiene las variables de configuracion para conectar a la base de datos
- require_once ("../config/conexion.php");//Contiene funcion que conecta a la base de datos
- // escaping, additionally removing everything that could be (html/javascript-) code
- $ticket = mysqli_real_escape_string($con,(strip_tags($_POST["ticket"],ENT_QUOTES)));
- $alias = $_SESSION['alias'];
- echo "<script>alert(".$alias.");</script>";
- $nro_encuesta = mysqli_real_escape_string($con,(strip_tags($_POST["nro_encuesta"],ENT_QUOTES)));
- $tiempo_respuesta = strtoupper(mysqli_real_escape_string($con,(strip_tags($_POST["tiempo_respuesta"],ENT_QUOTES))));
- $calidad_servicio = strtoupper(mysqli_real_escape_string($con,(strip_tags($_POST["calidad_servicio"],ENT_QUOTES))));
- $trato_personal = strtoupper(mysqli_real_escape_string($con,(strip_tags($_POST["trato_personal"],ENT_QUOTES))));
- $observaciones = strtoupper(mysqli_real_escape_string($con,(strip_tags($_POST["observaciones"],ENT_QUOTES))));
- $date_added=date("Y-m-d H:i:s");
- // Recibo los datos de la imagen
- $nombre_img = $_FILES['imagefile']['name'];
- $tipo = $_FILES['imagefile']['type'];
- $tamano = $_FILES['imagefile']['size'];
- //Si existe imagen y tiene un tamaño correcto
- if (($nombre_img == !NULL) && ($_FILES['imagefile']['size'] <= 200000))
- {
- //indicamos los formatos que permitimos subir a nuestro servidor
- if (($_FILES["imagefile"]["type"] == "image/jpeg") || ($_FILES["imagefile"]["type"] == "image/jpg") || ($_FILES["imagefile"]["type"] == "image/png")){
- // Ruta donde se guardarán las imágenes que subamos
- $directorio = $_SERVER['DOCUMENT_ROOT'].'/img/';
- // Muevo la imagen desde el directorio temporal a nuestra ruta indicada anteriormente
- move_uploaded_file($_FILES['imagefile']['tmp_name'],$directorio.$nombre_img);
- }
- else
- {
- //si no cumple con el formato
- $errors[] = "No se puede subir una imagen con ese formato ";
- }
- }
- else {
- //si existe la variable pero se pasa del tamaño permitido
- if($nombre_img == !NULL) {$errors[] = "La imagen es demasiado grande "; }
- }
- // write new user's data into database
- $sql = "INSERT INTO ticket (ticket, alias, nro_encuesta, tiempo_respuesta, calidad_servicio, trato_personal, observaciones, imagen, user_id)
- VALUES('".$ticket."','".$alias."','".$nro_encuesta."','".$tiempo_respuesta."','".$calidad_servicio."','".$trato_personal."','".$observaciones. "','".$nombre_img."','".$_SESSION['user_id']."');";
- $query_new_ticket_insert = mysqli_query($con,$sql);
- //if user has been added successfully
- if ($query_new_ticket_insert) {
- $messages[] = "La encuesta ha sido creado con éxito.";
- } else {
- $errors[] = "Lo sentimos , el registro falló. Por favor, regrese y vuelva a intentarlo.";
- }
- } else {
- $errors[] = "Un error desconocido ocurrió.";
- }
- if (isset($errors)){
- ?>
- <div class="alert alert-danger" role="alert">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <strong>Error!</strong>
- <?php
- foreach ($errors as $error) {
- echo $error;
- }
- ?>
- </div>
- <?php
- }
- if (isset($messages)){
- ?>
- <div class="alert alert-success" role="alert">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <strong>¡Bien hecho!</strong>
- <?php
- foreach ($messages as $message) {
- echo $message;
- }
- ?>
- </div>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement