-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdCrear.php
304 lines (284 loc) · 15.7 KB
/
AdCrear.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!DOCTYPE html>
<html lang="es">
<?php include "php/Conexion.php";?>
<head>
<title>Sistema de votos</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<script defer src="https://use.fontawesome.com/releases/v5.0.10/js/all.js" integrity="sha384-slN8GvtUJGnv6ca26v8EzVaR9DC58QEwsIk9q1QXdCU8Yu8ck/tL/5szYlBbqmS+" crossorigin="anonymous"></script>
<script type="text/javascript" href="./js/scripts.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/Estilos.css">
</head>
<body>
<?php if (isset($_GET["repetido"])){ ?>
<script type="text/javascript">
window.onload = function(){ $('#error2').modal('show') };
</script>
<div class="modal fade" id="error2" tabindex="-1" role="dialog" aria-labelledby="fm-modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Error</h5>
<button class="close" data-dismiss="modal" aria-label="Cerrar">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Este nombre para una encuesta ya existe, por favor ingrese otro.</p>
</div>
</div>
</div>
</div>
<?php } ?>
<?php if (isset($_GET["errorfechas"])){ ?>
<script type="text/javascript">
window.onload = function(){ $('#error3').modal('show') };
</script>
<div class="modal fade" id="error3" tabindex="-1" role="dialog" aria-labelledby="fm-modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Error</h5>
<button class="close" data-dismiss="modal" aria-label="Cerrar">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>La fecha escogida debe ser mayor a la actual.</p>
</div>
</div>
</div>
</div>
<?php } ?>
<?php if (isset($_GET["creado"])){ ?>
<script type="text/javascript">
window.onload = function(){ $('#error4').modal('show') };
</script>
<div class="modal fade" id="error4" tabindex="-1" role="dialog" aria-labelledby="fm-modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Encuesta creada</h5>
<button class="close" data-dismiss="modal" aria-label="Cerrar">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>La encuesta se a creado correctamente.</p>
</div>
</div>
</div>
</div>
<?php } ?>
<nav class="navbar navbar-expand-xl navbar-dark bg-primary">
<div class="container">
<a href="Panel.php" class="navbar-brand">
<div class="Titulo align-content-center">
<strong class="d-none d-sm-inline-block text-center" >Sistema de votos</strong>
</div>
</a>
<div class="col-auto ml-auto">
<?php include "php/Autentificacion.php";?>
</div>
</div>
</nav>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<div class="collapse navbar-collapse" id="navbarColor02">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="Encuestas.php">Ver encuestas</a>
</li>
<li class="nav-item">
<a class="nav-link" href="MiVoto.php">Mis votos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Panel.php">Cuenta</a>
</li>
<?php include "php/AutentificacionAdmin.php"; include "php/Autentificacion2.php";?>
</ul>
</div>
</div>
</nav>
<div class="container">
<main class="InPrincipal row justify-content-center">
<div class="col-11 my-4">
<div class="row">
<h3 class="mx-3 my-auto col-auto">Crear encuesta</h3>
</div>
<hr class="mx-3">
</div>
<div class="col-11 mb-4">
<div class="card rounded border-secondary">
<div class="card-body">
<form action="php/InsertEncuesta.php" name="Encuesta" method="POST">
<div class="form-group">
<label>Nombre de la encuesta:</label>
<input class="form-control form-control-sm mb-2" placeholder="Nombre" name="nombre" id="nombre" type="text" required>
<label for="">Fecha de finalización:</label><br>
<?php
$fm = date("Y-m-d",mktime(0,0,0,date("m"),date("d")+1,date("Y")));
?>
<input name="date" id="date" type="date" value="<?php echo $fm; ?>" min="<?php echo $fm; ?>" required><br>
<label>Cantidad de opciones:</label><br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="Cantidad" id="c2" value="2" checked>
<label class="form-check-label" for="inlineRadio2">2</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="Cantidad" id="c3" value="3">
<label class="form-check-label" for="inlineRadio3">3</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="Cantidad" id="c4" value="4">
<label class="form-check-label" for="inlineRadio3">4</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="Cantidad" id="c5" value="5">
<label class="form-check-label" for="inlineRadio3">5</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="Cantidad" id="c6" value="6">
<label class="form-check-label" for="inlineRadio1">6</label>
</div>
<button type="button" onclick="GuardarDatos()" class="Ingresar btn btn-info btn-block mt-3 mb-3" data-toggle="collapse" href="#collapseform" role="button" aria-expanded="false" aria-controls="collapseform" name="registro" id="adencuesta"> Agregar datos de opciones </button>
</div>
<div class="collapse multi-collapse" id="collapseform">
</div>
</form>
</div>
</div>
</div>
</main>
</div>
<footer>
<div class="container">
<div class="row justify-content-around">
<div class="col-auto">
<h6 class="m-2">Información</h6>
<a href="">Sobre Nosotros</a><br>
<a href="">Politicas de uso</a><br>
</div>
<div class="col-auto mr-auto">
<h6 class="m-2">Servicio al Cliente</h6>
<a href="">Contacto</a><br>
<a href="">Preguntas Frecuentes</a><br><br>
</div>
<div class="col-auto">
<div class="row">
<h6 class="m-2">*Nombre del Proyecto* <i class="fa fa-copyright" aria-hidden="true"></i> Derechos reservados</h6>
</div>
<div class="row justify-content-around">
<!--<a href=""><i class="fa fa-instagram fa-3x" aria-hidden="true"></i></a>
<a href=""><i class="fa fa-youtube fa-3x" aria-hidden="true"></i></a>
<a href=""><i class="fa fa-twitter-square fa-3x" aria-hidden="true"></i></a>
<a href=""><i class="fa fa-facebook-official fa-3x" aria-hidden="true"></i></a>-->
</div>
</div>
</div>
</div>
</footer>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
var name = "";
var date = "";
var op = "";
function GuardarDatos() {
name = document.forms["Encuesta"]["nombre"].value;
date = document.forms["Encuesta"]["date"].value;
op = document.forms["Encuesta"]["Cantidad"].value;
if (name == "" || date == "" || op == "" ) {return 0}
console.log(name);
console.log(date);
console.log(op);
var cuerpo = document.getElementById("collapseform");
var capa = document.createElement("div");
capa.setAttribute("class", "row justify-content-center");
capa.setAttribute("id", "contenedor");
for (var i = 1; i <= op; i++) {
var divcoll = document.createElement("div");
divcoll.setAttribute("class", " col-3 card card-body my-2 mx-4 bg-light");
var title = document.createElement("h5");
title.setAttribute("class", "mx-2 my-0");
title.innerHTML = "Opción "+i;
divcoll.appendChild(title);
var hr = document.createElement("hr");
divcoll.appendChild(hr);
var labelin = document.createElement("label");
labelin.innerHTML = "nombre de la opción:";
divcoll.appendChild(labelin);
var input = document.createElement("input");
input.setAttribute("class", "form-control form-control-sm mb-2");
input.setAttribute("placeholder", "Nombre de opción");
input.setAttribute("name", "nombre_opcion[]");
input.setAttribute("type", "text");
input.setAttribute("required", "true");
divcoll.appendChild(input);
var labeltx = document.createElement("label");
labeltx.innerHTML = "Descripción:";
divcoll.appendChild(labeltx);
var textarea = document.createElement("textarea");
textarea.setAttribute("name", "descripcion[]");
textarea.setAttribute("style", "width: 100%; height: 100px;");
divcoll.appendChild(textarea);
capa.appendChild(divcoll);
}
var divbtn = document.createElement("div");
divbtn.setAttribute("class", "col-12");
var row = document.createElement("div");
row.setAttribute("class", "row my-2");
var columnabtn1 = document.createElement("div");
columnabtn1.setAttribute("class", "col-auto ml-5");
var link = document.createElement("button");
link.setAttribute("onclick", "VolverPrincipal()");
link.setAttribute("class", "btn btn-info");
link.setAttribute("type", "button");
link.setAttribute("data-toggle", "collapse");
link.setAttribute("href", "#collapseform");
link.setAttribute("role", "button");
link.setAttribute("aria-expanded", "true");
link.setAttribute("aria-controls", "collapseform");
link.setAttribute("name", "registro2");
link.setAttribute("id", "adencuesta2");
link.innerHTML = "Cambiar datos de la Encuesta";
columnabtn1.appendChild(link);
row.appendChild(columnabtn1);
var columnabtn2 = document.createElement("div");
columnabtn2.setAttribute("class", "col-auto mr-5 ml-auto");
var input = document.createElement("input");
input.setAttribute("class", "btn btn-success");
input.setAttribute("value", "Agregar encuesta");
input.setAttribute("name", "Enviar");
input.setAttribute("type", "submit");
columnabtn2.appendChild(input);
row.appendChild(columnabtn2);
divbtn.appendChild(row);
capa.appendChild(divbtn);
cuerpo.appendChild(capa);
document.getElementById('nombre').readOnly = true
document.getElementById('date').readOnly = true
if (document.getElementById('c2').checked == false) {document.getElementById('c2').disabled = true}
if (document.getElementById('c3').checked == false) {document.getElementById('c3').disabled = true}
if (document.getElementById('c4').checked == false) {document.getElementById('c4').disabled = true}
if (document.getElementById('c5').checked == false) {document.getElementById('c5').disabled = true}
if (document.getElementById('c6').checked == false) {document.getElementById('c6').disabled = true}
setTimeout ("document.getElementById('adencuesta').disabled = true;", 50);
}
function VolverPrincipal() {
document.getElementById('nombre').readOnly = false
document.getElementById('date').readOnly = false
document.getElementById('c2').disabled = false
document.getElementById('c3').disabled = false
document.getElementById('c4').disabled = false
document.getElementById('c5').disabled = false
document.getElementById('c6').disabled = false
setTimeout ("document.getElementById('adencuesta').disabled = false;", 50);
document.getElementById("contenedor").parentNode.removeChild(document.getElementById("contenedor"));
}
</script>
</body>
</html>