diff --git a/alumnos/delete_post.php b/alumnos/delete_post.php new file mode 100644 index 0000000..0ece7ea --- /dev/null +++ b/alumnos/delete_post.php @@ -0,0 +1,5 @@ + diff --git a/alumnos/index.php b/alumnos/index.php index b04b1b8..e8f7c98 100644 --- a/alumnos/index.php +++ b/alumnos/index.php @@ -1,3 +1,5 @@ + + - Restaurant - - - - + - -
-

Alumnos

- - - - - - - - - - - +
+
#RutNombreControles
+ - - - - + + + + - - -
get_id() ?>get_rut() ?>get_nombre() ?> - Link - Link - #RutNombre
+ + + + + get_id() ?> + get_rut() ?> + get_nombre() ?> + +
+ Modificar + + +
+ + + + + +
- - - + diff --git a/alumnos/modificar.php b/alumnos/modificar.php index e69de29..4f21d37 100644 --- a/alumnos/modificar.php +++ b/alumnos/modificar.php @@ -0,0 +1,32 @@ + + + + + + + + + + + +
+

Modificar Alumno

+
+ +
+ + +
+
+ + +
+ +
+
+ + + diff --git a/alumnos/modificar_post.php b/alumnos/modificar_post.php new file mode 100644 index 0000000..9a35b48 --- /dev/null +++ b/alumnos/modificar_post.php @@ -0,0 +1,28 @@ +set_id($id); +$alumno->set_rut($rut); +$alumno->set_nombre($nombre); + +if($alumno->update()) +{ + header("location: /alumnos/index.php"); +} +else +{ + header("location: /alumnos/modificar.php?id=$id"); +} +?> diff --git a/alumnos/register_post.php b/alumnos/register_post.php index a7d36ad..416f1d0 100644 --- a/alumnos/register_post.php +++ b/alumnos/register_post.php @@ -3,10 +3,10 @@ require_once('../models/alumno.php'); require_once('../rut_validacion.php'); $rut = $_POST['rut']; +$nombre = $_POST['nombre']; + if(!validar_rut($rut)){ - echo "ERROR"; header("location: /alumnos/registrar.php"); - var_dump("OH NO"); exit(); } @@ -14,8 +14,5 @@ $alumno = new Alumno(); $alumno->set_rut($_POST['rut']); $alumno->set_nombre($_POST['nombre']); -if($alumno->save()) -{ - header("location: /alumnos/index.php"); -} +if($alumno->save()) header("location: /alumnos/index.php"); ?> diff --git a/alumnos/registrar.php b/alumnos/registrar.php index 30a6c2b..f24f304 100644 --- a/alumnos/registrar.php +++ b/alumnos/registrar.php @@ -1,39 +1,13 @@ + + - Restaurant - - - - + - -
+ +

Registrar Alumno

@@ -47,8 +21,5 @@
- - - - + diff --git a/includes/_config.php b/includes/_config.php new file mode 100644 index 0000000..fcce6b5 --- /dev/null +++ b/includes/_config.php @@ -0,0 +1,31 @@ + diff --git a/includes/_head.php b/includes/_head.php new file mode 100644 index 0000000..ba8c612 --- /dev/null +++ b/includes/_head.php @@ -0,0 +1,5 @@ +Universidad - <?php echo $PAGE_TITLE ?> + + + + diff --git a/includes/_navbar.php b/includes/_navbar.php new file mode 100644 index 0000000..859428e --- /dev/null +++ b/includes/_navbar.php @@ -0,0 +1,16 @@ + diff --git a/includes/_scripts.php b/includes/_scripts.php new file mode 100644 index 0000000..5f32eb3 --- /dev/null +++ b/includes/_scripts.php @@ -0,0 +1,3 @@ + + + diff --git a/index.php b/index.php index f83ad54..dad9a20 100644 --- a/index.php +++ b/index.php @@ -1,40 +1,12 @@ + + - Restaurant - - - - + - - - - + + diff --git a/models/alumno.php b/models/alumno.php index 9750a12..7a29e21 100644 --- a/models/alumno.php +++ b/models/alumno.php @@ -28,6 +28,37 @@ class Alumno return $result > 0; } + public function update() + { + $db = new DB(); + $result = $db->dml( + "update alumno set rut = ?, nombre = ? where id = ?", + $this->rut, $this->nombre, $this->id + ); + return $result > 0; + } + + public static function delete($id) { + $db = new DB(); + error_log("id: $id"); + $result = $db->dml("delete from alumno where id = ?", $id); + return $result > 0; + } + + public static function get($id) { + $db = new DB(); + $results = $db->query("select * from alumno where id = ?", $id); + + foreach($results as $result) { + $alumno = new Alumno(); + $alumno->set_id($result['id']); + $alumno->set_rut($result['rut']); + $alumno->set_nombre($result['nombre']); + } + + return $alumno; + } + public static function getAll() { $db = new DB(); $results = $db->query("select * from alumno"); diff --git a/rut_validacion.php b/rut_validacion.php index 8286126..7a9d32e 100644 --- a/rut_validacion.php +++ b/rut_validacion.php @@ -14,8 +14,9 @@ function validar_rut($rut){ } $digito_verificador_calculado = 11 - ($suma % 11); - if($digito_verificador_calculado == 11) $dvr = 0; + if($digito_verificador_calculado == 11) $digito_verificador_calculado = 0; if($digito_verificador_calculado == 10) $digito_verificador_calculado = 'K'; + error_log("Rut: " . $rut . " Deberia tener digito verificador " . $digito_verificador_calculado); return $digito_verificador_calculado == strtoupper($digito_verificador); } ?> diff --git a/style.css b/style.css index cf7a324..2f09a44 100644 --- a/style.css +++ b/style.css @@ -1,3 +1,15 @@ -.navbar { - margin-bottom: 1em; +.main { + padding-top: 5em; +} + +.btn { + margin-right: .5em; +} + +.btn.btn-fix-width { + width: 6em; +} + +.control-cell { + width: min-content; }