-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactas_session.php
More file actions
112 lines (103 loc) · 4 KB
/
Copy pathactas_session.php
File metadata and controls
112 lines (103 loc) · 4 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
<?php
session_start();
function promediar($aNumeros) {
$total = 0;
foreach ($aNumeros as $num) {
$total += $num;
}
return $total / count($aNumeros);
}
$notasPorAlumno = 3;
$aAlumnos = $_SESSION["aAlumnos"] ?? [];
if ($_POST) {
if(isset($_POST["btnDelete"])) {
if ($_POST["pos"] >= 0) {
unset($aAlumnos[$_POST["pos"]]);
}
} else {
$nombre = $_POST["txtNombre"];
$aNotas = [];
for ($i=1; $i <= $notasPorAlumno; $i++) {
$aNotas[] = (float)$_POST["txtNota".$i];
}
$aAlumnos[] = [
"nombre" => $nombre,
"aNotas" => $aNotas
];
}
$_SESSION["aAlumnos"] = $aAlumnos;
}
$sumClase = 0;
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Actas Session</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" integrity="sha256-PI8n5gCcz9cQqQXm3PEtDuPG8qx9oFsFctPg0S5zb8g=" crossorigin="anonymous">
</head>
<body>
<main class="container">
<h1 class="text-center mb-4">Actas</h1>
<table class="table table-hover border">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Alumno</th>
<?php for ($i=1; $i <= $notasPorAlumno; $i++): ?>
<th scope="col">Nota <?php echo $i; ?></th>
<?php endfor; ?>
<th scope="col">Promedio</th>
<th scope="col">Acciones</th>
</tr>
</thead>
<tbody>
<?php foreach ($aAlumnos as $id => $alumno):
$promedio = promediar($alumno["aNotas"]);
$sumClase += $promedio;
$ultimaNota = array_pop($alumno["aNotas"]);
?>
<tr>
<th scope="row"><?php echo $id + 1; ?></th>
<td><?php echo $alumno["nombre"]; ?></td>
<?php foreach ($alumno["aNotas"] as $nota): ?>
<td><?php echo $nota; ?></td>
<?php endforeach; ?>
<td colspan="<?php echo $notasPorAlumno - count($alumno["aNotas"]); ?>"><?php echo $ultimaNota; ?></td>
<td><?php echo number_format($promedio, 2, ","); ?></td>
<td>
<form action="" method="post">
<input type="hidden" name="pos" value="<?php echo $id; ?>">
<input type="submit" name="btnDelete" value="Eliminar" class="btn btn-link">
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<form action="" method="post" class="mb-3">
<div class="row">
<div class="col">
<label for="txtNombre" class="form-label">Nombre:</label>
<input type="text" name="txtNombre" id="txtNombre" class="form-control" required>
</div>
<?php for ($i=1; $i <= $notasPorAlumno; $i++):
$fieldName = "txtNota".$i;
?>
<div class="col">
<label for="<?php echo $fieldName; ?>" class="form-label">Nota <?php echo $i; ?>:</label>
<input type="number" name="<?php echo $fieldName; ?>" id="<?php echo $fieldName; ?>" class="form-control" placeholder="0">
</div>
<?php endfor; ?>
<div class="col d-flex align-items-end">
<input type="submit" value="Añadir" class="btn btn-primary">
</div>
</div>
</form>
<?php if (count($aAlumnos) > 0): ?>
<h5>Promedio de la cursada: <?php echo number_format($sumClase / count($aAlumnos), 2, ","); ?></h5>
<?php endif; ?>
</main>
</body>
</html>