Last active
February 11, 2022 20:15
-
-
Save 71walceli/e5ef86264a66d5c556902d3e099873ec to your computer and use it in GitHub Desktop.
PhpRecepies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mysqli = new mysqli("localhost", "5sa_practica_examen4", "examen", "5sa_practica_examen4"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once("{$_SERVER["CONTEXT_DOCUMENT_ROOT"]}/utils/db.php"); | |
header('Content-Type: application/json'); | |
$response = []; | |
if ($_SERVER["REQUEST_METHOD"] == "GET") { | |
$response = [ | |
"data" => [], | |
"mysqli_errno" => 0, | |
"mysqli_error" => "", | |
]; | |
$rows = $mysqli->query("SELECT * FROM ticket")->fetch_all(MYSQLI_ASSOC); | |
if ($rows) { | |
$response["data"] = $rows; | |
} | |
} elseif ($_SERVER["REQUEST_METHOD"] == "POST") { | |
$json_input = json_decode(file_get_contents("php://input"), true); | |
$response = [ | |
"mysqli_errno" => 0, | |
"mysqli_error" => "", | |
]; | |
$result = $mysqli->query( | |
"INSERT INTO ticket VALUES ( | |
${json_input['codigo']}, | |
${json_input['funcion_id']}, | |
${json_input['sucursal_id']}, | |
${json_input['cliente_id']} | |
)" | |
); | |
if (!$result) { | |
$response = [ | |
"mysqli_errno" => $mysqli->errno, | |
"mysqli_error" => $mysqli->error, | |
]; | |
http_response_code(401); | |
} | |
} elseif ($_SERVER["REQUEST_METHOD"] == "PUT") { | |
$json_input = json_decode(file_get_contents("php://input"), true); | |
$response = [ | |
"mysqli_errno" => 0, | |
"mysqli_error" => "", | |
]; | |
$result = $mysqli->query( | |
"UPDATE ticket SET | |
codigo = ${json_input['codigo']}, | |
funcion_id = ${json_input['funcion_id']}, | |
sucursal_id = ${json_input['sucursal_id']}, | |
cliente_id = ${json_input['cliente_id']} | |
WHERE codigo = ${json_input['codigo']} | |
" | |
); | |
if (!$result) { | |
$response = [ | |
"mysqli_errno" => $mysqli->errno, | |
"mysqli_error" => $mysqli->error, | |
]; | |
http_response_code(401); | |
} | |
} elseif ($_SERVER["REQUEST_METHOD"] == "DELETE") { | |
$json_input = json_decode(file_get_contents("php://input"), true); | |
$response = [ | |
"mysqli_errno" => 0, | |
"mysqli_error" => "", | |
]; | |
$result = $mysqli->query( | |
"UPDATE ticket SET | |
codigo = ${json_input['codigo']}, | |
funcion_id = ${json_input['funcion_id']}, | |
sucursal_id = ${json_input['sucursal_id']}, | |
cliente_id = ${json_input['cliente_id']} | |
" | |
); | |
if (!$result) { | |
$response = [ | |
"mysqli_errno" => $mysqli->errno, | |
"mysqli_error" => $mysqli->error, | |
]; | |
http_response_code(401); | |
} | |
} else { | |
unset($response["mysqli_errno"]); | |
unset($response["mysqli_error"]); | |
http_response_code(401); | |
} | |
echo json_encode($response, JSON_PRETTY_PRINT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php require_once("utils/sql.php"); ?> | |
<html> | |
<head> | |
<title>Registro de pedidos - Western Union</title> | |
</head> | |
<body> | |
<?php require_once("elementos/nav.php"); ?> | |
<?php | |
if (isset($_GET["accion"]) && $_GET["accion"]=="nuevo_pedido") { | |
$sql = "INSERT INTO encomienda VALUES (?,?,?,?,?,?,?)"; | |
$sqlPreparado = $mysqli->prepare($sql); | |
$sqlPreparado->bind_param("iiissis", | |
$_POST["pedido_id"], | |
$_POST["pedido_ciudad"], | |
$_POST["pedido_cedula"], | |
$_POST["pedido_nombre_cliente"], | |
$_POST["pedido_direccion_cliente"], | |
$_POST["pedido_numero_cliente"], | |
$_POST["pedido_descripcion"] | |
); | |
if ($sqlPreparado->execute()) { | |
echo "<div style='background: #afa'>Guardado correcto</div>"; | |
} else { | |
echo "<div style='background: #faa'>Error $mysqli->errno: $mysqli->error</div>"; | |
} | |
} | |
?> | |
<form action="registro_pedido?accion=nuevo_pedido" method="POST"> | |
<table> | |
<tr> | |
<td>Código</td> | |
<td><input type="number" name="pedido_id" /></td> | |
</tr> | |
<tr> | |
<td>Provincia</td> | |
<td> | |
<select name="pedido_provincia" > | |
<?php | |
$resultado = $mysqli->query("SELECT id, nombre FROM provincia") | |
->fetch_all(MYSQLI_ASSOC); | |
foreach ($resultado as $registro) { | |
$id = $registro["id"]; | |
$nombre = $registro["nombre"]; | |
echo "<option value='{$id}'>{$nombre}</option>"; | |
} | |
?> | |
</select> | |
</td> | |
</tr> | |
<tr> | |
<td>Ciudad</td> | |
<td> | |
<select name="pedido_ciudad" > | |
<?php | |
$resultado = $mysqli->query("SELECT id, nombre FROM ciudad") | |
->fetch_all(MYSQLI_ASSOC); | |
foreach ($resultado as $registro) { | |
$id = $registro["id"]; | |
$nombre = $registro["nombre"]; | |
echo "<option value='{$id}'>{$nombre}</option>"; | |
} | |
?> | |
</select> | |
</td> | |
</tr> | |
<tr> | |
<td>Cédula</td> | |
<td><input type="number" name="pedido_cedula" /></td> | |
</tr> | |
<tr> | |
<td>Nombre completo del cliente</td> | |
<td><input type="text" name="pedido_nombre_cliente" /></td> | |
</tr> | |
<tr> | |
<td>Dirección del cliente</td> | |
<td><input type="text" name="pedido_direccion_cliente" /></td> | |
</tr> | |
<tr> | |
<td>Teléfono/Celular</td> | |
<td><input type="number" name="pedido_numero_cliente" /></td> | |
</tr> | |
<tr> | |
<td>Descripción</td> | |
<td><textarea name="pedido_descripcion"></textarea></td> | |
</tr> | |
</table> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$paginaTitulo = "Registro de tickets"; | |
require_once("{$_SERVER["CONTEXT_DOCUMENT_ROOT"]}/partes/htmlCabecera.php"); | |
?> | |
<div> | |
<table> | |
<tr> | |
<td>Código</td> | |
<td><input type="number" name="codigo" id="codigo" /></td> | |
</tr> | |
<tr> | |
<td>Función</td> | |
<td> | |
<select name="funcion_id" id="funcion_id"> | |
<option value="0">-- Seleccionar --</option> | |
</select> | |
</td> | |
</tr> | |
<tr> | |
<td>Sucursal</td> | |
<td> | |
<select name="sucursal_id" id="sucursal_id"> | |
<option value="0">-- Seleccionar --</option> | |
</select> | |
</td> | |
</tr> | |
<tr> | |
<td>Cliente</td> | |
<td> | |
<select name="cliente_id" id="cliente_id"> | |
<option value="0">-- Seleccionar --</option> | |
</select> | |
</td> | |
</tr> | |
</table> | |
<button onclick="guardar()">Guardar</button> | |
</div> | |
<script> | |
fetch("http://5sa-practica-examen.com/api/funciones") | |
.then(response => response.json()) | |
.then( | |
response => { | |
select = document.getElementById("funcion_id"); | |
response.data.map(item => | |
{ | |
option = document.createElement("option") | |
option.setAttribute("value", item.codigo) | |
option.innerText | |
= `#${item.codigo} (${item.fechahora}): ${item.pelicula}` | |
select.appendChild(option) | |
} | |
) | |
} | |
) | |
fetch("http://5sa-practica-examen.com/api/sucursales") | |
.then(response => response.json()) | |
.then( | |
response => { | |
select = document.getElementById("sucursal_id"); | |
response.data.map(item => | |
{ | |
option = document.createElement("option") | |
option.setAttribute("value", item.codigo) | |
option.innerText | |
= `#${item.codigo} ${item.fechahora} - ${item.direccion}` | |
select.appendChild(option) | |
} | |
) | |
} | |
) | |
fetch("http://5sa-practica-examen.com/api/clientes") | |
.then(response => response.json()) | |
.then( | |
response => { | |
select = document.getElementById("cliente_id"); | |
response.data.map(item => | |
{ | |
option = document.createElement("option") | |
option.setAttribute("value", item.codigo) | |
option.innerText | |
= `#${item.codigo}: ${item.apellidos} ${item.nombres}` | |
select.appendChild(option) | |
} | |
) | |
} | |
) | |
async function guardar() { | |
await fetch("http://5sa-practica-examen.com/api/tickets" | |
, { | |
method: "POST", | |
body: JSON.stringify( | |
{ | |
codigo: document.getElementById("codigo").value, | |
funcion_id: document.getElementById("funcion_id").value, | |
sucursal_id: document.getElementById("sucursal_id").value, | |
cliente_id: document.getElementById("cliente_id").value, | |
} | |
), | |
} | |
) | |
.then(response => response.json()) | |
.then( | |
response => { | |
if (!response.mysqli_errno) { | |
alert("Guardado correctamente") | |
} else { | |
alert(`Error: ${response.mysqli_errno} ${response.mysqli_error}`) | |
} | |
} | |
) | |
} | |
</script> | |
<?php | |
require_once("{$_SERVER["CONTEXT_DOCUMENT_ROOT"]}/partes/htmlPie.php"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once("{$_SERVER["CONTEXT_DOCUMENT_ROOT"]}/utils/db.php"); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title> | |
<?php echo "$paginaTitulo - SUPERCINES"; ?> | |
</title> | |
</head> | |
<body> | |
<nav> | |
<img src="https://www.supercines.com/assets/img/home/supercinesLogo.png"> | |
<ul> | |
<li><a href="/">Inicio</a></li> | |
<li><a href="tickets/formulario">Registro de tickets</a></li> | |
<li><a href="tickets/consulta">Consulta de tickets</a></li> | |
</ul> | |
</nav> | |
<h1> | |
<?php echo "$paginaTitulo"; ?> | |
</h1> | |
<!-- INICIO CONTENIDO --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- FIN CONTENIDO --> | |
<footer> | |
©> 2022 SUPERCINES | |
</footer> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php require_once("utils/sql.php"); ?> | |
<html> | |
<head> | |
<title>Consulta de pedidos - Western Union</title> | |
</head> | |
<body> | |
<?php require_once("elementos/nav.php"); ?> | |
<?php | |
$resultado = $mysqli->query( | |
"SELECT e.*, p.nombre p_nombre, c.nombre c_nombre | |
FROM encomienda e | |
JOIN ciudad c on e.ciudad_id=c.id | |
JOIN provincia p on c.provincia_id=p.id | |
" | |
)->fetch_all(MYSQLI_ASSOC); | |
foreach ($resultado as $registro) { | |
$id = $registro["id"]; | |
$ciudad = $registro["c_nombre"]; | |
$provincia = $registro["p_nombre"]; | |
$cedula = $registro["cedula"]; | |
$nombre_cliente = $registro["nombre_cliente"]; | |
$direccion_cliente = $registro["direccion_cliente"]; | |
$numero_cliente = $registro["numero_cliente"]; | |
$descripcion = $registro["descripcion"]; | |
echo "<table>"; | |
echo "<tr>"; | |
echo "<td><b>ID</b></td>"; | |
echo "<td>$id</td>"; | |
echo "</tr>"; | |
echo "<tr>"; | |
echo "<td><b>Ciudad</b></td>"; | |
echo "<td>$ciudad</td>"; | |
echo "</tr>"; | |
echo "<tr>"; | |
echo "<td><b>Provincia</b></td>"; | |
echo "<td>$provincia</td>"; | |
echo "</tr>"; | |
echo "<tr>"; | |
echo "<td><b>Cédula del cliente</b></td>"; | |
echo "<td>$cedula</td>"; | |
echo "</tr>"; | |
echo "<tr>"; | |
echo "<td><b>Nombre completo del cliente</b></td>"; | |
echo "<td>$nombre_cliente</td>"; | |
echo "</tr>"; | |
echo "<tr>"; | |
echo "<td><b>Dirección del cliente</b></td>"; | |
echo "<td>$direccion_cliente</td>"; | |
echo "</tr>"; | |
echo "<tr>"; | |
echo "<td><b>Teléfono/Celular del cliente</b></td>"; | |
echo "<td>$numero_cliente</td>"; | |
echo "</tr>"; | |
echo "<tr>"; | |
echo "<td><b>Descripción</b></td>"; | |
echo "<td>$descripcion</td>"; | |
echo "</tr>"; | |
echo "</table>"; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment