-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroladorOnEscrutinio.php
126 lines (102 loc) · 2.9 KB
/
controladorOnEscrutinio.php
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
<?php
session_start();
include 'conexionBD.php';
$cont = 1;
if (isset($_REQUEST['validacion']))
$cont = 0;
if ($cont == 1) {
function array_sort($array, $on, $order = SORT_ASC)
{
$new_array = array();
$sortable_array = array();
if (count($array) > 0) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $on) {
$sortable_array[$k] = $v2;
}
}
} else {
$sortable_array[$k] = $v;
}
}
switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
case SORT_DESC:
arsort($sortable_array);
break;
}
foreach ($sortable_array as $k => $v) {
$new_array[$k] = $array[$k];
}
}
return $new_array;
}
$sql = "SELECT count(*) FROM convocatoria";
$memory = $conexion->query($sql);
if ($memory->num_rows > 0) {
$info = $memory->fetch_array();
$num = $info[0];
$num = (int) $num;
}
$cont = 0;
$conList = array();
for ($cont2 = 0; $cont < $num; $cont2++) {
$sql1 = "SELECT id,fecha FROM convocatoria WHERE id=" . $cont2 . "";
$memory1 = $conexion->query($sql1);
if ($memory1 && $memory1->num_rows > 0) {
$info1 = $memory1->fetch_array();
$sql1 = "SELECT * FROM resultado WHERE convocatoria=" . $info1['id'] . "";
$memory1 = $conexion->query($sql1);
if ($memory1 && $memory1->num_rows <= 0) {
$conList[$cont]['id'] = $info1['id'];
$conList[$cont]['fecha'] = $info1['fecha'];
}
$cont++;
}
}
$conList = array_sort($conList, 'fecha', SORT_ASC);
$listC = array_slice($conList, 0, 1);
foreach ($listC as $value) {
foreach ($value as $key => $value) {
if ($key == 'id')
$solucion = $value;
}
}
$sql2 = "SELECT * FROM convocatoria where id='" . $solucion . "' ";
$memory2 = $conexion->query($sql2);
if ($memory2 && $memory2->num_rows > 0)
$info3 = $memory2->fetch_array();
$_SESSION['convocat']['denominacion'] = $info3['denominacion'];
$_SESSION['convocat']['id'] = $info3['id'];
$sql2 = "SELECT * FROM convocatoria where escrutinio='Abierto' ";
$memory2 = $conexion->query($sql2);
if ($memory2 && $memory2->num_rows > 0) {
$_SESSION['mensajeBD'] = "Ya esta abierta la convocatoria.";
$_SESSION['set'] = 1;
}
header("Location:vistaOnEscrutinio.php");
exit;
}
$sql2 = "SELECT * FROM convocatoria where escrutinio='Abierto' ";
$memory2 = $conexion->query($sql2);
if ($memory2 && $memory2->num_rows > 0) {
$_SESSION['mensajeBD'] = "No puedes abrir si ya esta abierto";
header("Location:MensajeErrores.php");
exit;
} else {
unset($_SESSION['mas']);
$sql3 = "UPDATE votante SET votante='No'";
$check = $conexion->query($sql3);
$_SESSION['votante'] = 'No';
$sql3 = "UPDATE convocatoria SET escrutinio='Abierto' WHERE id='" . $_SESSION['convocat']['id'] . "'";
$check = $conexion->query($sql3);
if ($conexion->affected_rows > 0) {
$_SESSION['mensajeBD'] = "¡Escrutinio Abierto!";
header("Location:MensajeErrores.php");
exit;
}
} ?>