-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_personal.php
More file actions
137 lines (108 loc) · 4.31 KB
/
mod_personal.php
File metadata and controls
137 lines (108 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php require("sesion.php");
require("conexion.php");
if(!$_SESSION["usuario"]){
header("location:login.php?error=si");
}
?>
<!-- Inclución de archivos requeridos -->
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8"/>
<title>Modificar personal</title>
<link type="text/css" href="estilo.css" rel="stylesheet">
</head>
<body>
<div class="contenedor">
<div class= "encabezado">
<div class="izq">
<p>Bienvenido/a:<br>
<?php echo ucfirst($_SESSION["nombre"])." ".ucfirst($_SESSION["apellido"])?>
</p>
</div>
<div class="centro">
<a href=principalAdmin.php><center><img src='imagenes/home.png'><br>Home</center></a>
</div>
<div class="derecha">
<a href="salir.php?sal=si"><img src="imagenes/cerrar.png"><br>Salir</a>
</div>
</div>
<br><h1 align='center'>REGISTROS EXISTENTES</h1><br>
<?php
$consulta="SELECT * FROM personal";
$ejecutar=mysql_query($consulta,$conexion);
echo "<table width='80%' align='center'><tr>";
echo "<th width='20%'>RUT</th>";
echo "<th width='20%'>NOMBRE</th>";
echo "<th width='20%'>APELLIDO</th>";
echo "<th width='20%'>CARGO</th>";
echo "</tr>";
while($result=mysql_fetch_array($ejecutar)){
echo "<tr>";
echo '<td width=20%>'.$result['rut'].'</td>';
echo '<td width=20%>'.$result['nombre'].'</td>';
echo '<td width=20%>'. $result['apellido'].'</td>';
echo '<td width=20%>'.$result['cargo'].'</td>';
echo "</tr>";
}
echo "</table></br>";
?>
<div class="encabezado">
<h1>Modificar personal</h1>
</div>
<div class="formulario">
<form id="registro" method="post" action="" enctype="application/x-www-form-urlencoded">
<div class="campo">
<label name="Seleccionar">Ingresa el Rut del registro a modificar:</label>
<input name='seleccionar' type="text" required>
</div>
<div class="campo">
<div class="en-linea izquierdo">
<label for="nombre">Nombre:</label>
<input type="text" name="nombre" required/>
</div>
<div class="en-linea">
<label for="apellido">Apellido:</label>
<input type="text" name="apellido" required/>
</div>
</div>
<div class="campo">
<label for="cargo">cargo:</label>
<select name="cargo" required>
<option>Admin</option>
<option>Bodega</option>
</select>
</div>
<div class="botones">
<input type="submit" name="modificar" value="Modificar"/>
</div>
</form>
<?php
// La siguiente línea verifica que la varible del boton submit "modificar" este creada.
if (isset($_POST['modificar'])) {
//La siguiente linea recupera la variable donde se ingreso el rut a modificar.
$seleccionar = $_POST['seleccionar'];
// Las siguientes 2 líneas verifican que el registro que se desea modificar no corresponda al rut del Admin y se muestra alerta con mensaje.
if ($seleccionar == '180332403') {
echo "<script lenguaje='javascript'>alert('Admin general no puede ser modificado');</script>";
}else {
/* Si no corresponde al rut del Admin entonces:
Recuperar las variables con los datos ingresados.
Realizar la actualización de los datos.
Redirigir el flujo a esta misma página para visualizar los cambios */
$rut = $_POST["seleccionar"];
$nombre = $_POST["nombre"];
$apellido = $_POST["apellido"];
$cargo = $_POST["cargo"];
$consulta="UPDATE personal SET
nombre='$nombre',apellido='$apellido',cargo='$cargo'
WHERE rut='$rut'";
$ejecutar=mysql_query($consulta,$conexion);
header("location:mod_personal.php");
};
};
?>
</div>
</div>
</body>
</html>