Advertisement
Guest User

Untitled

a guest
May 26th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /* CONECTO A LA BASE DE DATOS */
  5. require_once('bd_connection.php');
  6. /* CONECTO A LA BASE DE DATOS */
  7.  
  8. $sql = "SELECT * FROM propiedad WHERE nombre = '".$_POST["nombre"]."';";
  9. $resultadoCHECK = $conn->query($sql);
  10. if($resultadoCHECK->num_rows >= 1){
  11. header("Location: "."altaPropiedad.php?warning=1");
  12. } else {
  13.  
  14. /* CARGO DIRECCION EN LA BASE DE DATOS */
  15. $sql = "INSERT INTO direccion (id_localidad,pais,codigoPostal,calle,numero,provincia,ciudad)";
  16. $sql .= "VALUES(NULL,'".$_POST["pais"]."','".$_POST["codigoPostal"]."','".$_POST["calle"]."','".$_POST["numero"]."','".$_POST["provincia"]."','".$_POST["ciudad"]."');";
  17. $resultDireccion = $conn->query($sql);
  18. /* CARGO DIRECCION EN LA BASE DE DATOS */
  19.  
  20. /* CARGO PROPIEDAD EN LA BASE DE DATOS */
  21. $ultima_id_dir = mysqli_insert_id($conn);
  22. $sql = "INSERT INTO propiedad (id_propiedad,nombre,cantPersonas,id_direccion,monto) ";
  23. $sql .= "VALUES(NULL,'".$_POST["nombre"]."','".$_POST["cantPersonas"]."','".$ultima_id_dir."','".$_POST["monto"]."');";
  24. $resultPropiedad = $conn->query($sql);
  25. /* CARGO PROPIEDAD EN LA BASE DE DATOS */
  26.  
  27. /* CARGO ESTADIAS EN LA BASE DE DATOS */
  28. $fechaInicio = substr($_POST["daterange"],-23,10);
  29. $fechaFin = substr($_POST["daterange"],-10);
  30. $fechaInicio = new DateTime($fechaInicio);
  31. $fechaFin = new DateTime($fechaFin);
  32. $diff = abs(strtotime($fechaInicio->format('Y-m-d')) - strtotime($fechaFin->format('Y-m-d')));
  33. $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
  34. $ultima_id_prop = mysqli_insert_id($conn);
  35. for ($i=1;$i <= round($days/7);$i++){
  36. $fecha_inicio = ($fechaInicio->format('Y-m-d'));
  37. $fecha_fin = date('Y-m-d',strtotime($fechaInicio->format('Y-m-d').'+ 7 days'));
  38. $sql = "INSERT INTO estadia (id_estadia,fecha_inicio,fecha_fin,id_propiedad)";
  39. $sql .= "VALUES(NULL,'".$fecha_inicio."','".$fecha_fin."','".$ultima_id_prop."');";
  40. $key = strval($i);
  41. $result.$key = $conn->query($sql);
  42. $fechaInicio = $fechaInicio->modify('+7 days');
  43. }
  44.  
  45. /* CARGO ESTADIAS EN LA BASE DE DATOS */
  46.  
  47. /* CARGO FOTOS DE LA PROPIEDAD EN LA BASE DE DATOS */
  48. $uploads_dir = 'files/picturesPropiedades/'.str_replace(' ','',$_POST["nombre"]);
  49. mkdir($uploads_dir);
  50. foreach ($_FILES["pictures"]["error"] as $key => $error){
  51. if($error == UPLOAD_ERR_OK) {
  52. $name = basename(str_replace(' ','',$_POST["nombre"])."_".str_replace(' ','',$_FILES["pictures"]["name"][$key]));
  53. $path = "$uploads_dir/$name";
  54. move_uploaded_file($_FILES["pictures"]["tmp_name"][$key],$path);
  55. $sql = "INSERT INTO foto (id_foto,id_propiedad,link)";
  56. $sql .= "VALUES(NULL,'".$ultima_id_prop."','".$path."');";
  57. $result.$key = $conn->query($sql);
  58. }
  59. }
  60. /* CARGO FOTOS DE LA PROPIEDAD EN LA BASE DE DATOS */
  61.  
  62. /* CIERRO CONEXION CON BASE DE DATOS */
  63. mysqli_close($conn);
  64. /* CIERRO CONEXION CON BASE DE DATOS */
  65. header("Location: "."info_p.php?id=".$ultima_id_prop);
  66. }
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement