Add input for region and city for other countries

This commit is contained in:
coolneng 2020-07-09 22:24:25 +02:00
parent c0764276e1
commit 01902f3757
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
7 changed files with 339 additions and 13 deletions

View File

@ -12,6 +12,8 @@ source database/provincias.sql;
source database/municipios.sql; source database/municipios.sql;
source database/paises.sql;
CREATE TABLE IF NOT EXISTS paciente ( CREATE TABLE IF NOT EXISTS paciente (
id INT AUTO_INCREMENT PRIMARY KEY, id INT AUTO_INCREMENT PRIMARY KEY,
nombre VARCHAR(50) NOT NULL, nombre VARCHAR(50) NOT NULL,

247
database/paises.sql Normal file
View File

@ -0,0 +1,247 @@
CREATE TABLE `paises` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` char(2) DEFAULT NULL,
`nombre` varchar(80) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
INSERT INTO `paises` VALUES(1, 'AF', 'Afganistán');
INSERT INTO `paises` VALUES(2, 'AX', 'Islas Gland');
INSERT INTO `paises` VALUES(3, 'AL', 'Albania');
INSERT INTO `paises` VALUES(4, 'DE', 'Alemania');
INSERT INTO `paises` VALUES(5, 'AD', 'Andorra');
INSERT INTO `paises` VALUES(6, 'AO', 'Angola');
INSERT INTO `paises` VALUES(7, 'AI', 'Anguilla');
INSERT INTO `paises` VALUES(8, 'AQ', 'Antártida');
INSERT INTO `paises` VALUES(9, 'AG', 'Antigua y Barbuda');
INSERT INTO `paises` VALUES(10, 'AN', 'Antillas Holandesas');
INSERT INTO `paises` VALUES(11, 'SA', 'Arabia Saudí');
INSERT INTO `paises` VALUES(12, 'DZ', 'Argelia');
INSERT INTO `paises` VALUES(13, 'AR', 'Argentina');
INSERT INTO `paises` VALUES(14, 'AM', 'Armenia');
INSERT INTO `paises` VALUES(15, 'AW', 'Aruba');
INSERT INTO `paises` VALUES(16, 'AU', 'Australia');
INSERT INTO `paises` VALUES(17, 'AT', 'Austria');
INSERT INTO `paises` VALUES(18, 'AZ', 'Azerbaiyán');
INSERT INTO `paises` VALUES(19, 'BS', 'Bahamas');
INSERT INTO `paises` VALUES(20, 'BH', 'Bahréin');
INSERT INTO `paises` VALUES(21, 'BD', 'Bangladesh');
INSERT INTO `paises` VALUES(22, 'BB', 'Barbados');
INSERT INTO `paises` VALUES(23, 'BY', 'Bielorrusia');
INSERT INTO `paises` VALUES(24, 'BE', 'Bélgica');
INSERT INTO `paises` VALUES(25, 'BZ', 'Belice');
INSERT INTO `paises` VALUES(26, 'BJ', 'Benin');
INSERT INTO `paises` VALUES(27, 'BM', 'Bermudas');
INSERT INTO `paises` VALUES(28, 'BT', 'Bhután');
INSERT INTO `paises` VALUES(29, 'BO', 'Bolivia');
INSERT INTO `paises` VALUES(30, 'BA', 'Bosnia y Herzegovina');
INSERT INTO `paises` VALUES(31, 'BW', 'Botsuana');
INSERT INTO `paises` VALUES(32, 'BV', 'Isla Bouvet');
INSERT INTO `paises` VALUES(33, 'BR', 'Brasil');
INSERT INTO `paises` VALUES(34, 'BN', 'Brunéi');
INSERT INTO `paises` VALUES(35, 'BG', 'Bulgaria');
INSERT INTO `paises` VALUES(36, 'BF', 'Burkina Faso');
INSERT INTO `paises` VALUES(37, 'BI', 'Burundi');
INSERT INTO `paises` VALUES(38, 'CV', 'Cabo Verde');
INSERT INTO `paises` VALUES(39, 'KY', 'Islas Caimán');
INSERT INTO `paises` VALUES(40, 'KH', 'Camboya');
INSERT INTO `paises` VALUES(41, 'CM', 'Camerún');
INSERT INTO `paises` VALUES(42, 'CA', 'Canadá');
INSERT INTO `paises` VALUES(43, 'CF', 'República Centroafricana');
INSERT INTO `paises` VALUES(44, 'TD', 'Chad');
INSERT INTO `paises` VALUES(45, 'CZ', 'República Checa');
INSERT INTO `paises` VALUES(46, 'CL', 'Chile');
INSERT INTO `paises` VALUES(47, 'CN', 'China');
INSERT INTO `paises` VALUES(48, 'CY', 'Chipre');
INSERT INTO `paises` VALUES(49, 'CX', 'Isla de Navidad');
INSERT INTO `paises` VALUES(50, 'VA', 'Ciudad del Vaticano');
INSERT INTO `paises` VALUES(51, 'CC', 'Islas Cocos');
INSERT INTO `paises` VALUES(52, 'CO', 'Colombia');
INSERT INTO `paises` VALUES(53, 'KM', 'Comoras');
INSERT INTO `paises` VALUES(54, 'CD', 'República Democrática del Congo');
INSERT INTO `paises` VALUES(55, 'CG', 'Congo');
INSERT INTO `paises` VALUES(56, 'CK', 'Islas Cook');
INSERT INTO `paises` VALUES(57, 'KP', 'Corea del Norte');
INSERT INTO `paises` VALUES(58, 'KR', 'Corea del Sur');
INSERT INTO `paises` VALUES(59, 'CI', 'Costa de Marfil');
INSERT INTO `paises` VALUES(60, 'CR', 'Costa Rica');
INSERT INTO `paises` VALUES(61, 'HR', 'Croacia');
INSERT INTO `paises` VALUES(62, 'CU', 'Cuba');
INSERT INTO `paises` VALUES(63, 'DK', 'Dinamarca');
INSERT INTO `paises` VALUES(64, 'DM', 'Dominica');
INSERT INTO `paises` VALUES(65, 'DO', 'República Dominicana');
INSERT INTO `paises` VALUES(66, 'EC', 'Ecuador');
INSERT INTO `paises` VALUES(67, 'EG', 'Egipto');
INSERT INTO `paises` VALUES(68, 'SV', 'El Salvador');
INSERT INTO `paises` VALUES(69, 'AE', 'Emiratos Árabes Unidos');
INSERT INTO `paises` VALUES(70, 'ER', 'Eritrea');
INSERT INTO `paises` VALUES(71, 'SK', 'Eslovaquia');
INSERT INTO `paises` VALUES(72, 'SI', 'Eslovenia');
INSERT INTO `paises` VALUES(73, 'ES', 'España');
INSERT INTO `paises` VALUES(74, 'UM', 'Islas ultramarinas de Estados Unidos');
INSERT INTO `paises` VALUES(75, 'US', 'Estados Unidos');
INSERT INTO `paises` VALUES(76, 'EE', 'Estonia');
INSERT INTO `paises` VALUES(77, 'ET', 'Etiopía');
INSERT INTO `paises` VALUES(78, 'FO', 'Islas Feroe');
INSERT INTO `paises` VALUES(79, 'PH', 'Filipinas');
INSERT INTO `paises` VALUES(80, 'FI', 'Finlandia');
INSERT INTO `paises` VALUES(81, 'FJ', 'Fiyi');
INSERT INTO `paises` VALUES(82, 'FR', 'Francia');
INSERT INTO `paises` VALUES(83, 'GA', 'Gabón');
INSERT INTO `paises` VALUES(84, 'GM', 'Gambia');
INSERT INTO `paises` VALUES(85, 'GE', 'Georgia');
INSERT INTO `paises` VALUES(86, 'GS', 'Islas Georgias del Sur y Sandwich del Sur');
INSERT INTO `paises` VALUES(87, 'GH', 'Ghana');
INSERT INTO `paises` VALUES(88, 'GI', 'Gibraltar');
INSERT INTO `paises` VALUES(89, 'GD', 'Granada');
INSERT INTO `paises` VALUES(90, 'GR', 'Grecia');
INSERT INTO `paises` VALUES(91, 'GL', 'Groenlandia');
INSERT INTO `paises` VALUES(92, 'GP', 'Guadalupe');
INSERT INTO `paises` VALUES(93, 'GU', 'Guam');
INSERT INTO `paises` VALUES(94, 'GT', 'Guatemala');
INSERT INTO `paises` VALUES(95, 'GF', 'Guayana Francesa');
INSERT INTO `paises` VALUES(96, 'GN', 'Guinea');
INSERT INTO `paises` VALUES(97, 'GQ', 'Guinea Ecuatorial');
INSERT INTO `paises` VALUES(98, 'GW', 'Guinea-Bissau');
INSERT INTO `paises` VALUES(99, 'GY', 'Guyana');
INSERT INTO `paises` VALUES(100, 'HT', 'Haití');
INSERT INTO `paises` VALUES(101, 'HM', 'Islas Heard y McDonald');
INSERT INTO `paises` VALUES(102, 'HN', 'Honduras');
INSERT INTO `paises` VALUES(103, 'HK', 'Hong Kong');
INSERT INTO `paises` VALUES(104, 'HU', 'Hungría');
INSERT INTO `paises` VALUES(105, 'IN', 'India');
INSERT INTO `paises` VALUES(106, 'ID', 'Indonesia');
INSERT INTO `paises` VALUES(107, 'IR', 'Irán');
INSERT INTO `paises` VALUES(108, 'IQ', 'Iraq');
INSERT INTO `paises` VALUES(109, 'IE', 'Irlanda');
INSERT INTO `paises` VALUES(110, 'IS', 'Islandia');
INSERT INTO `paises` VALUES(111, 'IL', 'Israel');
INSERT INTO `paises` VALUES(112, 'IT', 'Italia');
INSERT INTO `paises` VALUES(113, 'JM', 'Jamaica');
INSERT INTO `paises` VALUES(114, 'JP', 'Japón');
INSERT INTO `paises` VALUES(115, 'JO', 'Jordania');
INSERT INTO `paises` VALUES(116, 'KZ', 'Kazajstán');
INSERT INTO `paises` VALUES(117, 'KE', 'Kenia');
INSERT INTO `paises` VALUES(118, 'KG', 'Kirguistán');
INSERT INTO `paises` VALUES(119, 'KI', 'Kiribati');
INSERT INTO `paises` VALUES(120, 'KW', 'Kuwait');
INSERT INTO `paises` VALUES(121, 'LA', 'Laos');
INSERT INTO `paises` VALUES(122, 'LS', 'Lesotho');
INSERT INTO `paises` VALUES(123, 'LV', 'Letonia');
INSERT INTO `paises` VALUES(124, 'LB', 'Líbano');
INSERT INTO `paises` VALUES(125, 'LR', 'Liberia');
INSERT INTO `paises` VALUES(126, 'LY', 'Libia');
INSERT INTO `paises` VALUES(127, 'LI', 'Liechtenstein');
INSERT INTO `paises` VALUES(128, 'LT', 'Lituania');
INSERT INTO `paises` VALUES(129, 'LU', 'Luxemburgo');
INSERT INTO `paises` VALUES(130, 'MO', 'Macao');
INSERT INTO `paises` VALUES(131, 'MK', 'ARY Macedonia');
INSERT INTO `paises` VALUES(132, 'MG', 'Madagascar');
INSERT INTO `paises` VALUES(133, 'MY', 'Malasia');
INSERT INTO `paises` VALUES(134, 'MW', 'Malawi');
INSERT INTO `paises` VALUES(135, 'MV', 'Maldivas');
INSERT INTO `paises` VALUES(136, 'ML', 'Malí');
INSERT INTO `paises` VALUES(137, 'MT', 'Malta');
INSERT INTO `paises` VALUES(138, 'FK', 'Islas Malvinas');
INSERT INTO `paises` VALUES(139, 'MP', 'Islas Marianas del Norte');
INSERT INTO `paises` VALUES(140, 'MA', 'Marruecos');
INSERT INTO `paises` VALUES(141, 'MH', 'Islas Marshall');
INSERT INTO `paises` VALUES(142, 'MQ', 'Martinica');
INSERT INTO `paises` VALUES(143, 'MU', 'Mauricio');
INSERT INTO `paises` VALUES(144, 'MR', 'Mauritania');
INSERT INTO `paises` VALUES(145, 'YT', 'Mayotte');
INSERT INTO `paises` VALUES(146, 'MX', 'México');
INSERT INTO `paises` VALUES(147, 'FM', 'Micronesia');
INSERT INTO `paises` VALUES(148, 'MD', 'Moldavia');
INSERT INTO `paises` VALUES(149, 'MC', 'Mónaco');
INSERT INTO `paises` VALUES(150, 'MN', 'Mongolia');
INSERT INTO `paises` VALUES(151, 'MS', 'Montserrat');
INSERT INTO `paises` VALUES(152, 'MZ', 'Mozambique');
INSERT INTO `paises` VALUES(153, 'MM', 'Myanmar');
INSERT INTO `paises` VALUES(154, 'NA', 'Namibia');
INSERT INTO `paises` VALUES(155, 'NR', 'Nauru');
INSERT INTO `paises` VALUES(156, 'NP', 'Nepal');
INSERT INTO `paises` VALUES(157, 'NI', 'Nicaragua');
INSERT INTO `paises` VALUES(158, 'NE', 'Níger');
INSERT INTO `paises` VALUES(159, 'NG', 'Nigeria');
INSERT INTO `paises` VALUES(160, 'NU', 'Niue');
INSERT INTO `paises` VALUES(161, 'NF', 'Isla Norfolk');
INSERT INTO `paises` VALUES(162, 'NO', 'Noruega');
INSERT INTO `paises` VALUES(163, 'NC', 'Nueva Caledonia');
INSERT INTO `paises` VALUES(164, 'NZ', 'Nueva Zelanda');
INSERT INTO `paises` VALUES(165, 'OM', 'Omán');
INSERT INTO `paises` VALUES(166, 'NL', 'Países Bajos');
INSERT INTO `paises` VALUES(167, 'PK', 'Pakistán');
INSERT INTO `paises` VALUES(168, 'PW', 'Palau');
INSERT INTO `paises` VALUES(169, 'PS', 'Palestina');
INSERT INTO `paises` VALUES(170, 'PA', 'Panamá');
INSERT INTO `paises` VALUES(171, 'PG', 'Papúa Nueva Guinea');
INSERT INTO `paises` VALUES(172, 'PY', 'Paraguay');
INSERT INTO `paises` VALUES(173, 'PE', 'Perú');
INSERT INTO `paises` VALUES(174, 'PN', 'Islas Pitcairn');
INSERT INTO `paises` VALUES(175, 'PF', 'Polinesia Francesa');
INSERT INTO `paises` VALUES(176, 'PL', 'Polonia');
INSERT INTO `paises` VALUES(177, 'PT', 'Portugal');
INSERT INTO `paises` VALUES(178, 'PR', 'Puerto Rico');
INSERT INTO `paises` VALUES(179, 'QA', 'Qatar');
INSERT INTO `paises` VALUES(180, 'GB', 'Reino Unido');
INSERT INTO `paises` VALUES(181, 'RE', 'Reunión');
INSERT INTO `paises` VALUES(182, 'RW', 'Ruanda');
INSERT INTO `paises` VALUES(183, 'RO', 'Rumania');
INSERT INTO `paises` VALUES(184, 'RU', 'Rusia');
INSERT INTO `paises` VALUES(185, 'EH', 'Sahara Occidental');
INSERT INTO `paises` VALUES(186, 'SB', 'Islas Salomón');
INSERT INTO `paises` VALUES(187, 'WS', 'Samoa');
INSERT INTO `paises` VALUES(188, 'AS', 'Samoa Americana');
INSERT INTO `paises` VALUES(189, 'KN', 'San Cristóbal y Nevis');
INSERT INTO `paises` VALUES(190, 'SM', 'San Marino');
INSERT INTO `paises` VALUES(191, 'PM', 'San Pedro y Miquelón');
INSERT INTO `paises` VALUES(192, 'VC', 'San Vicente y las Granadinas');
INSERT INTO `paises` VALUES(193, 'SH', 'Santa Helena');
INSERT INTO `paises` VALUES(194, 'LC', 'Santa Lucía');
INSERT INTO `paises` VALUES(195, 'ST', 'Santo Tomé y Príncipe');
INSERT INTO `paises` VALUES(196, 'SN', 'Senegal');
INSERT INTO `paises` VALUES(197, 'CS', 'Serbia y Montenegro');
INSERT INTO `paises` VALUES(198, 'SC', 'Seychelles');
INSERT INTO `paises` VALUES(199, 'SL', 'Sierra Leona');
INSERT INTO `paises` VALUES(200, 'SG', 'Singapur');
INSERT INTO `paises` VALUES(201, 'SY', 'Siria');
INSERT INTO `paises` VALUES(202, 'SO', 'Somalia');
INSERT INTO `paises` VALUES(203, 'LK', 'Sri Lanka');
INSERT INTO `paises` VALUES(204, 'SZ', 'Suazilandia');
INSERT INTO `paises` VALUES(205, 'ZA', 'Sudáfrica');
INSERT INTO `paises` VALUES(206, 'SD', 'Sudán');
INSERT INTO `paises` VALUES(207, 'SE', 'Suecia');
INSERT INTO `paises` VALUES(208, 'CH', 'Suiza');
INSERT INTO `paises` VALUES(209, 'SR', 'Surinam');
INSERT INTO `paises` VALUES(210, 'SJ', 'Svalbard y Jan Mayen');
INSERT INTO `paises` VALUES(211, 'TH', 'Tailandia');
INSERT INTO `paises` VALUES(212, 'TW', 'Taiwán');
INSERT INTO `paises` VALUES(213, 'TZ', 'Tanzania');
INSERT INTO `paises` VALUES(214, 'TJ', 'Tayikistán');
INSERT INTO `paises` VALUES(215, 'IO', 'Territorio Británico del Océano Índico');
INSERT INTO `paises` VALUES(216, 'TF', 'Territorios Australes Franceses');
INSERT INTO `paises` VALUES(217, 'TL', 'Timor Oriental');
INSERT INTO `paises` VALUES(218, 'TG', 'Togo');
INSERT INTO `paises` VALUES(219, 'TK', 'Tokelau');
INSERT INTO `paises` VALUES(220, 'TO', 'Tonga');
INSERT INTO `paises` VALUES(221, 'TT', 'Trinidad y Tobago');
INSERT INTO `paises` VALUES(222, 'TN', 'Túnez');
INSERT INTO `paises` VALUES(223, 'TC', 'Islas Turcas y Caicos');
INSERT INTO `paises` VALUES(224, 'TM', 'Turkmenistán');
INSERT INTO `paises` VALUES(225, 'TR', 'Turquía');
INSERT INTO `paises` VALUES(226, 'TV', 'Tuvalu');
INSERT INTO `paises` VALUES(227, 'UA', 'Ucrania');
INSERT INTO `paises` VALUES(228, 'UG', 'Uganda');
INSERT INTO `paises` VALUES(229, 'UY', 'Uruguay');
INSERT INTO `paises` VALUES(230, 'UZ', 'Uzbekistán');
INSERT INTO `paises` VALUES(231, 'VU', 'Vanuatu');
INSERT INTO `paises` VALUES(232, 'VE', 'Venezuela');
INSERT INTO `paises` VALUES(233, 'VN', 'Vietnam');
INSERT INTO `paises` VALUES(234, 'VG', 'Islas Vírgenes Británicas');
INSERT INTO `paises` VALUES(235, 'VI', 'Islas Vírgenes de los Estados Unidos');
INSERT INTO `paises` VALUES(236, 'WF', 'Wallis y Futuna');
INSERT INTO `paises` VALUES(237, 'YE', 'Yemen');
INSERT INTO `paises` VALUES(238, 'DJ', 'Yibuti');
INSERT INTO `paises` VALUES(239, 'ZM', 'Zambia');
INSERT INTO `paises` VALUES(240, 'ZW', 'Zimbabue');

View File

@ -7,7 +7,7 @@ $(document).ready(function()
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "../ajax.php", url: "ajax.php",
data: post_id, data: post_id,
cache: false, cache: false,
success: function(response) success: function(response)

17
src/change_input_type.js Normal file
View File

@ -0,0 +1,17 @@
function changeInputType(){
country = document.getElementById("pais").value;
region = document.getElementById("provincia");
city = document.getElementById("localidad");
if(country == 73){
region.hidden = false;
city.hidden = false;
} else {
region.hidden = true;
city.hidden = true;
region_input = document.getElementById("provincia2");
city_input = document.getElementById("localidad2");
region_input.type = "text";
city_input.type = "text";
}
}

View File

@ -23,11 +23,49 @@ function listRows($pdo, $table)
return $result; return $result;
} }
function fetchLatestRegion($pdo){
$query = "SELECT id_provincia FROM provincias ORDER BY id_provincia DESC LIMIT 1;";
$result = $pdo->prepare($query);
$result->execute();
$data = $result->fetch();
return $data;
}
function fetchLatestCity($pdo){
$query = "SELECT id_municipio FROM municipios ORDER BY id_municipio DESC LIMIT 1;";
$result = $pdo->prepare($query);
$result->execute();
$data = $result->fetch();
return $data;
}
function createRegion($pdo, $data){
$query = "INSERT INTO provincias (id_provincia, provincia) VALUES (?,?)";
$row = fetchLatestRegion($pdo);
$index = $row["id_provincia"];
$next_index = $index + 1;
$pdo->prepare($query)->execute([$next_index, $data["provincia2"]]);
return $index;
}
function createCity($pdo, $data, $region){
$query = "INSERT INTO municipios (id_provincia, cod_municipio, DC, nombre) VALUES (?,?,?,?)";
$pdo->prepare($query)->execute([$region, 999, 999, $data["localidad2"]]);
$city = fetchLatestCity($pdo);
return $city["id_municipio"];
}
function createPatient($pdo, $data) function createPatient($pdo, $data)
{ {
$query = "INSERT INTO paciente $query = "INSERT INTO paciente
(nombre, apellido, fecha_de_nacimiento, documento_identificativo, tipo_documento, direccion, localidad, provincia, pais) (nombre, apellido, fecha_de_nacimiento, documento_identificativo, tipo_documento, direccion, localidad, provincia, pais)
VALUES (?,?,?,?,?,?,?,?,?)"; VALUES (?,?,?,?,?,?,?,?,?)";
if($data["provincia"] == "empty" and $data["localidad"] == "empty"){
$region = createRegion($pdo, $data);
$city = createCity($pdo, $data, $region);
$data["provincia"] = $region;
$data["localidad"] = $city;
}
$pdo->prepare($query)->execute([$data["nombre"], $data["apellido"], $data["fecha_de_nacimiento"], $pdo->prepare($query)->execute([$data["nombre"], $data["apellido"], $data["fecha_de_nacimiento"],
$data["documento_identificativo"], $data["tipo_documento"], $data["direccion"], $data["documento_identificativo"], $data["tipo_documento"], $data["direccion"],
$data["localidad"], $data["provincia"], $data["pais"]]); $data["localidad"], $data["provincia"], $data["pais"]]);
@ -138,9 +176,11 @@ function findUser($pdo, $input)
function listPatients($pdo) function listPatients($pdo)
{ {
$query = "SELECT paciente.id, paciente.nombre, paciente.apellido, paciente.fecha_de_nacimiento, paciente.documento_identificativo, $query = "SELECT paciente.id, paciente.nombre, paciente.apellido, paciente.fecha_de_nacimiento, paciente.documento_identificativo,
paciente.tipo_documento, paciente.direccion, municipios.nombre, provincias.provincia, paciente.pais, cita.id, informe.titulo paciente.tipo_documento, paciente.direccion, paises.nombre, provincias.provincia, municipios.nombre, cita.id, informe.titulo
FROM paciente INNER JOIN municipios ON paciente.localidad = municipios.id_municipio FROM paciente
INNER JOIN paises ON paciente.pais = paises.id
INNER JOIN provincias ON paciente.provincia = provincias.id_provincia INNER JOIN provincias ON paciente.provincia = provincias.id_provincia
INNER JOIN municipios ON paciente.localidad = municipios.id_municipio
LEFT JOIN cita ON paciente.id=cita.paciente LEFT JOIN informe ON paciente.id=informe.paciente LEFT JOIN cita ON paciente.id=cita.paciente LEFT JOIN informe ON paciente.id=informe.paciente
GROUP BY paciente.id, cita.id, informe.titulo"; GROUP BY paciente.id, cita.id, informe.titulo";
$result = $pdo->prepare($query); $result = $pdo->prepare($query);
@ -178,6 +218,16 @@ function fetchCities($pdo, $id)
return $data; return $data;
} }
function fetchCountries($pdo)
{
$query = "SELECT * FROM paises";
$result = $pdo->prepare($query);
$result->execute();
$data = $result->fetchAll();
return $data;
}
function fetchRegions($pdo) function fetchRegions($pdo)
{ {
$query = "SELECT * FROM provincias"; $query = "SELECT * FROM provincias";

View File

@ -28,9 +28,9 @@
<th>Documento identificativo</th> <th>Documento identificativo</th>
<th>Tipo de documento</th> <th>Tipo de documento</th>
<th>Dirección</th> <th>Dirección</th>
<th>Pais</th>
<th>Provincia</th> <th>Provincia</th>
<th>Localidad</th> <th>Localidad</th>
<th>Pais</th>
<th>Citas</th> <th>Citas</th>
<th>Informes</th> <th>Informes</th>
<th colspan="2">Acciones</th> <th colspan="2">Acciones</th>

View File

@ -9,6 +9,7 @@
<script src="static/jquery-3.5.1.min.js"></script> <script src="static/jquery-3.5.1.min.js"></script>
<script src="ajax.js"></script> <script src="ajax.js"></script>
<script src="validate_patient.js"></script> <script src="validate_patient.js"></script>
<script src="change_input_type.js"></script>
</head> </head>
<body> <body>
<?php include 'navbar.php'; ?> <?php include 'navbar.php'; ?>
@ -16,6 +17,7 @@
include 'database.php'; include 'database.php';
$pdo = connectDatabase(); $pdo = connectDatabase();
$countries = fetchCountries($pdo);
$regions = fetchRegions($pdo); $regions = fetchRegions($pdo);
?> ?>
<form name="create_form" method="post" action="patient_management.php" onsubmit="return validatePatient();"> <form name="create_form" method="post" action="patient_management.php" onsubmit="return validatePatient();">
@ -47,22 +49,30 @@
<input type="text" name="direccion" value=""> <input type="text" name="direccion" value="">
</div> </div>
<div class="input-group"> <div class="input-group">
<label>provincia</label> <label>pais</label>
<select id="provincia" name="provincia"> <select id="pais" name="pais" onchange="changeInputType();">
<?php foreach ($regions as $row) : ?> <option>Selecciona el país</option>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option> <?php foreach ($countries as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[2]; ?></option>
<?php endforeach ?> <?php endforeach ?>
</select> </select>
</div> </div>
<div class="input-group"> <div class="input-group">
<label>localidad</label> <label>provincia</label>
<select id="localidad" name="localidad"> <select id="provincia" name="provincia">
<option>Selecciona la localidad</option> <option value="empty">Selecciona la provincia</option>
<?php foreach ($regions as $row) : ?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[1]; ?></option>
<?php endforeach ?>
</select> </select>
<input type="hidden" id="provincia2" name="provincia2" value="">
</div> </div>
<div class="input-group"> <div class="input-group">
<label>pais</label> <label>localidad</label>
<input type="text" name="pais" value=""> <select id="localidad" name="localidad">
<option value="empty">Selecciona la localidad</option>
</select>
<input type="hidden" id="localidad2" name="localidad2" value="">
</div> </div>
<div class="input-group"> <div class="input-group">
<button class="btn" type="submit" name="create">Guardar</button> <button class="btn" type="submit" name="create">Guardar</button>