Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include('is_logged.php');//Archivo verifica que el usario que intenta acceder a la URL esta logueado
  4. setlocale(LC_TIME, 'es_PE');
  5. // checking for minimum PHP version
  6. if (version_compare(PHP_VERSION, '5.3.7', '<')) {
  7. exit("Sorry, Simple PHP Login does not run on a PHP version smaller than 5.3.7 !");
  8. } else if (version_compare(PHP_VERSION, '5.5.0', '<')) {
  9. // if you are using PHP 5.3 or PHP 5.4 you have to include the password_api_compatibility_library.php
  10. // (this library adds the PHP 5.5 password hashing functions to older versions of PHP)
  11. require_once("../libraries/password_compatibility_library.php");
  12. }
  13.  
  14. if (empty($_POST['ticket'])){
  15. $errors[] = "Ticket Vacio";
  16. } elseif (empty($_POST['nro_encuesta'])){
  17. $errors[] = "Numero de encuesta vacio";
  18. } elseif (strlen($_POST['ticket'])!=6) {
  19. $errors[] = "Tamaño del ticket no es 6 caracteres";
  20. } elseif (strlen($_POST['nro_encuesta'])!=4) {
  21. $errors[] = "Tamaño de la encuesta no es 4 caracteres";
  22. } elseif (empty($_FILES['imagefile'])) {
  23. $errors[] = "Imagen vacio";
  24. }
  25. elseif (
  26. !empty($_POST['ticket'])
  27. && !empty($_POST['nro_encuesta'])
  28. && !empty($_FILES['imagefile'])
  29. // && !empty($_POST['calidad_servicio'])
  30. // && !empty($_POST['trato_personal'])
  31. //&& !empty($_POST['observaciones'])
  32. ) {
  33. require_once ("../config/db.php");//Contiene las variables de configuracion para conectar a la base de datos
  34. require_once ("../config/conexion.php");//Contiene funcion que conecta a la base de datos
  35.  
  36. // escaping, additionally removing everything that could be (html/javascript-) code
  37. $ticket = mysqli_real_escape_string($con,(strip_tags($_POST["ticket"],ENT_QUOTES)));
  38. $alias = $_SESSION['alias'];
  39. echo "<script>alert(".$alias.");</script>";
  40. $nro_encuesta = mysqli_real_escape_string($con,(strip_tags($_POST["nro_encuesta"],ENT_QUOTES)));
  41. $tiempo_respuesta = strtoupper(mysqli_real_escape_string($con,(strip_tags($_POST["tiempo_respuesta"],ENT_QUOTES))));
  42. $calidad_servicio = strtoupper(mysqli_real_escape_string($con,(strip_tags($_POST["calidad_servicio"],ENT_QUOTES))));
  43. $trato_personal = strtoupper(mysqli_real_escape_string($con,(strip_tags($_POST["trato_personal"],ENT_QUOTES))));
  44. $observaciones = strtoupper(mysqli_real_escape_string($con,(strip_tags($_POST["observaciones"],ENT_QUOTES))));
  45.  
  46. $date_added=date("Y-m-d H:i:s");
  47.  
  48.  
  49. // Recibo los datos de la imagen
  50. $nombre_img = $_FILES['imagefile']['name'];
  51. $tipo = $_FILES['imagefile']['type'];
  52. $tamano = $_FILES['imagefile']['size'];
  53.  
  54. //Si existe imagen y tiene un tamaño correcto
  55. if (($nombre_img == !NULL) && ($_FILES['imagefile']['size'] <= 200000))
  56. {
  57. //indicamos los formatos que permitimos subir a nuestro servidor
  58. if (($_FILES["imagefile"]["type"] == "image/jpeg") || ($_FILES["imagefile"]["type"] == "image/jpg") || ($_FILES["imagefile"]["type"] == "image/png")){
  59. // Ruta donde se guardarán las imágenes que subamos
  60. $directorio = $_SERVER['DOCUMENT_ROOT'].'/img/';
  61. // Muevo la imagen desde el directorio temporal a nuestra ruta indicada anteriormente
  62. move_uploaded_file($_FILES['imagefile']['tmp_name'],$directorio.$nombre_img);
  63. }
  64. else
  65. {
  66. //si no cumple con el formato
  67. $errors[] = "No se puede subir una imagen con ese formato ";
  68. }
  69. }
  70. else {
  71. //si existe la variable pero se pasa del tamaño permitido
  72. if($nombre_img == !NULL) {$errors[] = "La imagen es demasiado grande "; }
  73. }
  74.  
  75.  
  76.  
  77. // write new user's data into database
  78. $sql = "INSERT INTO ticket (ticket, alias, nro_encuesta, tiempo_respuesta, calidad_servicio, trato_personal, observaciones, imagen, user_id)
  79. VALUES('".$ticket."','".$alias."','".$nro_encuesta."','".$tiempo_respuesta."','".$calidad_servicio."','".$trato_personal."','".$observaciones. "','".$nombre_img."','".$_SESSION['user_id']."');";
  80. $query_new_ticket_insert = mysqli_query($con,$sql);
  81.  
  82. //if user has been added successfully
  83. if ($query_new_ticket_insert) {
  84. $messages[] = "La encuesta ha sido creado con éxito.";
  85. } else {
  86. $errors[] = "Lo sentimos , el registro falló. Por favor, regrese y vuelva a intentarlo.";
  87.  
  88. }
  89.  
  90.  
  91. } else {
  92. $errors[] = "Un error desconocido ocurrió.";
  93. }
  94.  
  95. if (isset($errors)){
  96.  
  97. ?>
  98. <div class="alert alert-danger" role="alert">
  99. <button type="button" class="close" data-dismiss="alert">&times;</button>
  100. <strong>Error!</strong>
  101. <?php
  102. foreach ($errors as $error) {
  103. echo $error;
  104. }
  105. ?>
  106. </div>
  107. <?php
  108. }
  109. if (isset($messages)){
  110.  
  111. ?>
  112. <div class="alert alert-success" role="alert">
  113. <button type="button" class="close" data-dismiss="alert">&times;</button>
  114. <strong>¡Bien hecho!</strong>
  115. <?php
  116. foreach ($messages as $message) {
  117. echo $message;
  118. }
  119. ?>
  120. </div>
  121. <?php
  122. }
  123.  
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement