-
Notifications
You must be signed in to change notification settings - Fork 0
/
crear-juego1.php
528 lines (447 loc) · 18.4 KB
/
crear-juego1.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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
<?php
include_once('config.php');
$pid = (isset($_GET['pid'])) ? $_GET['pid'] : 0;
$rel = (isset($_GET['rel'])) ? $_GET['rel'] : 0;
if ( (isset($_SESSION['username'])) && ($_SESSION['rol']) == ROL_ADMIN ){
include_once('jupiter/code/fxModelo.php');
include_once('jupiter/code/fxVista.php');
include_once('jupiter/code/db_procter.php');
$resultados = getTemas($rel, $db);
$opTemas = genTemasOP($resultados, $pid);
$jTipo = 1;
$resJuegos = getJuegos($pid, $jTipo, $db);
$tblJuego = genJuegosTR($resJuegos);
// Vars
$title = 'Crear Juegos P&G';
include_once('jupiter/code/fxMenu.php');
$mnuMain = crearMnuAdmin('entrenamiento', null);
$mnuMainMobile = crearMnuAdminMobile('entrenamiento', null);
} else {
// User No logeado
header ('Location: index.php');
}
?>
<!doctype html>
<html class="no-js" lang="es">
<head>
<?php include_once('code/header.php'); ?>
</head>
<body>
<div class="off-canvas-wrap" data-offcanvas>
<div class="inner-wrap">
<!-- Off Canvas Menu -->
<aside class="left-off-canvas-menu">
<?php print($mnuMainMobile); ?>
</aside>
<!-- Nav -->
<nav class="top-bar" data-topbar role="navigation">
<?php include_once('code/top-bar-title-admin.php'); ?>
<section class="top-bar-section">
<?php include_once('code/top-bar-admin.php'); ?>
</section>
</nav>
<!-- Menu -->
<div class="left-sidebar show-for-large-up">
<?php print($mnuMain); ?>
</div>
<main id="page" role="main" class="main mIzq45">
<section>
<div class="row pTop1">
<div class="large-12 columns">
<div class="row pDown1">
<div class="small-12 columns">
<div class="text-left azulMain">
<ul class="breadcrumbs mDown0">
<li><a href="crear-entrenamiento.php">Entrenamientos</a></li>
<li><a href="crear-curso.php">Cursos</a></li>
<li><a href="crear-tema.php?id=<?php print($pid); ?>">Temas</a></li>
<li><a href="">Juegos</a></li>
<li class="current"><a href="#">Crear</a></li>
</ul>
</div>
</div>
</div>
<div class="row text-left">
<div class="small-12 medium-6 columns">
<div class="row" id="frmData">
<div class="large-12 columns">
<h4 class="azulMain">TEMAS</h4><hr class="mTop0" />
<label>
<select id="cboTemas">
<?php echo $opTemas; ?>
</select>
</label>
</div>
<div class="large-12 columns">
<h4 class="azulMain">CREAR PREGUNTA PARA JUEGO<a id="btnNewItem" class="right" data-tooltip aria-haspopup="true" title="Agregar Nuevo"><i class="fa fa-plus"></i></a></h4><hr class="mTop0" />
</div>
<div class="large-12 columns">
<label>PREGUNTA
<input type="text" id="txtPregunta" placeholder="Ingresa Pregunta" maxlength="256" required/>
</label>
</div>
<div class="large-12 columns">
<label>Respuesta CORRECTA
<input type="text" id="txtCorrecta" placeholder="Respuesta Correcta" maxlength="256" required/>
</label>
</div>
<div class="large-12 columns">
<label>Distractor 1
<input type="text" id="txtDistractor1" placeholder="Distractor 1" maxlength="256" required/>
</label>
</div>
<div class="large-12 columns">
<label>Distractor 2
<input type="text" id="txtDistractor2" placeholder="Distractor 2" maxlength="256" required/>
</label>
</div>
<div class="large-12 columns">
<label>Distractor 3
<input type="text" id="txtDistractor3" placeholder="Distractor 3" maxlength="256" required/>
</label>
</div>
<div class="large-12 columns">
<label>Pista
<input type="text" id="txtPista" placeholder="Pista" maxlength="256" required/>
</label>
</div>
<div class="large-12 columns">
<label>Feedback
<input type="text" id="txtFeedback" placeholder="Feedback" maxlength="256" required/>
</label>
</div>
<div class="large-12 columns">
<div class="clearfix">
<a class="small round button success" id="btnGrabar">GRABAR PREGUNTA</a> <span id="msgbox"></span>
</div>
</div>
<div class="large-12 columns">
<div class="row">
<div class="large-6 columns"><h6>Portada</h6>
<form id="frmPicture1" action="code/upload-picture.php" class="dropzone">
<div id="picture1"><img src="static/images/pantallas/pregunta02.jpg" alt="Picture" /></div>
<input type="file" name="fileUpload" id="fileUpload1" class="inputfile" />
<label for="fileUpload1"><span class="icon"><i class="fa fa-cloud-upload" aria-hidden="true"></i></span> <span class="msgbox">Seleccionar un archivo…</span></label>
</form>
</div>
<div class="large-6 columns"><h6>Fondo</h6>
<form id="frmPicture2" action="code/upload-picture.php" class="dropzone">
<div id="picture2"><img src="static/images/pantallas/pregunta02.jpg" alt="Picture" /></div>
<input type="file" name="fileUpload" id="fileUpload2" class="inputfile" />
<label for="fileUpload2"><span class="icon"><i class="fa fa-cloud-upload" aria-hidden="true"></i></span> <span class="msgbox">Seleccionar un archivo…</span></label>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="small-12 medium-6 columns">
<div class="row">
<div class="large-12 columns">
<h4 class="azulMain">PREGUNTAS DEL JUEGO</h4><hr class="mTop0" />
</div>
<div class="large-12 columns">
<table id="tblJuego" width="100%">
<thead>
<tr>
<th width="50%">Pregunta</th>
<th width="30%">Respuesta</th>
<th width="20%">Acciones</th>
</tr>
</thead>
<tbody>
<?php print $tblJuego; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<footer>
<?php include_once('code/footer.php'); ?>
</footer>
</main>
<!-- close the off-canvas menu -->
<a class="exit-off-canvas"></a>
</div>
</div>
<div id="myDelete" class="reveal-modal small" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
<h2 id="modalTitle">BORRAR PREGUNTA</h2>
<p id="modalDescrip" class="rojo">¿Estas seguro de borrarlo?</p>
<a class="close-reveal-modal" aria-label="Close">×</a>
<a class="button secondary custom-close-reveal-modal">Cancelar</a>
<a id="btnBorrarOk" class="button alert">Borrar</a>
</div>
<?php include_once('code/script.php'); ?>
<script>
var auth = 0;
var ajaxReq = "jupiter/api.php";
var curControl = null;
var rel = null;
var tr = null;
var json = null;
var codigo = -1;
var jTipo = 1;
function basename(str, sep) {
return str.substr(str.lastIndexOf(sep) + 1);
};
$(document).on('ready', iniciar);
function iniciar(){
$(document).foundation();
$('a.custom-close-reveal-modal').click(function(){
$('#myDelete').foundation('reveal', 'close');
});
$('#btnGrabar').on('click', grabarDB);
$('#btnNewItem').on('click', newItem);
$('#tblJuego tbody tr td.tableActs .delete').on('click', eliminarFila);
$('#tblJuego tbody tr td .edit').on('click', editarFila);
$('#btnBorrarOk').on('click', eliminarFilaOk);
$('#cboTemas').on('change', reloadJuegos);
$('#fileUpload1').on('change', showFile1);
$("#fileUpload2").on('change', showFile2);
$('#frmPicture1').on('submit', uploadData);
$('#frmPicture2').on('submit', uploadData);
};
$( '.inputfile' ).each( function(){
var $input = $( this ),
$label = $input.next( 'label' ),
labelVal = $label.html();
$input.on( 'change', function( e ){
var fileName = '';
if( this.files && this.files.length > 1 )
fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length );
else if( e.target.value )
fileName = e.target.value.split( '\\' ).pop();
if( fileName )
$label.find( 'span' ).html( fileName );
else
$label.html( labelVal );
});
// Firefox bug fix
$input
.on( 'focus', function(){ $input.addClass( 'has-focus' ); })
.on( 'blur', function(){ $input.removeClass( 'has-focus' ); });
});
function isBlank( data ) {
return ( $.trim(data).length == 0 );
};
function is_url(str) {
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(str);
};
function verifyData () {
var rpta = true;
$("#frmData :input").each(function(){
$(this).removeClass('err');
});
if ( $('#cboTemas').val() == -1){
$('#cboTemas').addClass('err');
rpta = false;
}
$("#frmData input[type=text]").each(function(){
var input = $(this);
if ( isBlank(input.val()) ){
input.addClass('err');
rpta = false;
}
});
return rpta;
};
function grabarDB(){
if (verifyData()){
var pregunta = $('#txtPregunta').val();
var correcta = $('#txtCorrecta').val();
var distractor1 = $('#txtDistractor1').val();
var distractor2 = $('#txtDistractor2').val();
var distractor3 = $('#txtDistractor3').val();
var pista = $('#txtPista').val();
var feedback = $('#txtFeedback').val();
var masterID = $('#cboTemas').val();
var pic1 = $("#frmPicture1 label span.msgbox").html();
var pic2 = $("#frmPicture2 label span.msgbox").html();
if (codigo === -1){
grabarInsert(pregunta, jTipo, correcta, distractor1, distractor2, distractor3, pista, feedback, pic1, pic2, masterID);
} else {
grabarUpdate(pregunta, jTipo, correcta, distractor1, distractor2, distractor3, pista, feedback, pic1, pic2, masterID);
}
} else {
$('#msgbox').html('Revisa los campos marcados.');
}
};
function grabarInsert(pregunta, jTipo, correcta, distractor1, distractor2, distractor3, pista, feedback, pic1, pic2, masterID){
$('#msgbox').html('<i class="fa fa-cog fa-spin"></i> Procesando');
$.post(ajaxReq, {action:"newJuego", eAuth:auth, eJuegoTipo:jTipo, ePregunta:pregunta, eCorrecta:correcta, eDistractor1:distractor1, eDistractor2:distractor2, eDistractor3:distractor3, ePista:pista, eFeedback:feedback, ePic1:pic1, ePic2:pic2, eMasterID:masterID, rand:Math.random()},
function(data){
if( data !== '-1' || data !== -1 ){
// OK!
$('#msgbox').html('¡Bien! Se agrego satisfactoriamente.');
$('#tblJuego > Tbody:first').append('<tr><td><a rel="' + data + '" class="edit">' + pregunta + '</a></td><td>' + correcta + '</td><td class=\"tableActs\"> <a rel="'+ data + '" data-reveal-id="myDelete" class="pLeft5 delete rojo" title="Borrar"><i class=\"fa fa-trash-o fa-lg\"></i></a></td></tr>');
$('#tblJuego tbody tr td.tableActs .delete').on('click', eliminarFila);
$('#tblJuego tbody tr td .edit').on('click', editarFila);
$(document).foundation('tooltip', 'reflow');
limpiar();
} else {
$('#msgbox').html('Msg: [' + data + ']');
}
});
};
function grabarUpdate(pregunta, jTipo, correcta, distractor1, distractor2, distractor3, pista, feedback, pic1, pic2, masterID){
$('#msgbox').html('<i class="fa fa-cog fa-spin"></i> Procesando');
$.post(ajaxReq, {action:"updateJuego", eAuth:auth, eRel:codigo, eJuegoTipo:jTipo, ePregunta:pregunta, eCorrecta:correcta, eDistractor1:distractor1, eDistractor2:distractor2, eDistractor3:distractor3, ePista:pista, eFeedback:feedback, ePic1:pic1, ePic2:pic2, eMasterID:masterID, rand:Math.random()},
function(data){
if( data !== '-1' || data !== -1 ){
// OK!
$('#msgbox').html('¡Bien! Se actualizo satisfactoriamente.');
curControl.text(pregunta);
$(document).foundation('tooltip', 'reflow');
newItem();
} else {
$('#msgbox').html('Msg: [' + data + ']');
}
});
};
function eliminarFila() {
curControl = $(this);
rel = curControl.attr('rel');
tr = curControl.parent().parent();
};
function eliminarFilaOk(){
newItem();
$('#msgbox').html('<i class="fa fa-cog fa-spin"></i> Eliminando');
$.post(ajaxReq, {action:"delJuego", eAuth:auth, eRel:rel, rand:Math.random()},
function(data){
if( data !== '-1' || data !== -1 ){
// OK!
$('#myDelete').foundation('reveal', 'close');
tr.remove();
$('.tooltip').hide();
$('#msgbox').html('Eliminado correctamente.');
} else {
$('#msgbox').html('Msg: [' + data + ']');
}
});
};
function editarFila(){
curControl = $(this);
codigo = curControl.attr('rel');
$("#tblJuego tbody tr td.bgVerdeL").removeClass('bgVerdeL');
curControl.parent().addClass('bgVerdeL');
limpiar();
$('#msgbox').html('<i class="fa fa-cog fa-spin"></i> Cargando');
$.post(ajaxReq, {action:"getJuego", eAuth:auth, eRel:codigo, rand:Math.random()},
function(data){
json = data;
$('#msgbox').html('');
$('#txtPregunta').val(json[0].pregunta);
$('#txtCorrecta').val(json[0].respuesta);
$('#txtDistractor1').val(json[0].distractor1);
$('#txtDistractor2').val(json[0].distractor2);
$('#txtDistractor3').val(json[0].distractor3);
$('#txtPista').val(json[0].pista);
$('#txtFeedback').val(json[0].feedback);
$('#picture1').html('<img src="'+ json[0].portada+ '">');
$('#picture2').html('<img src="'+ json[0].fondo+ '">');
$("#frmPicture1 label span.msgbox").html(basename(json[0].portada, '/'));
$("#frmPicture2 label span.msgbox").html(basename(json[0].fondo, '/'));
});
};
function newItem() {
codigo = -1;
$("#tblJuego tbody tr td.bgVerdeL").removeClass('bgVerdeL');
limpiar();
};
function limpiar() {
$('#frmData input').removeClass('err');
$("#frmData input[type=text]").each(function(){
var input = $(this);
input.val('');
});
$("#frmPicture1 label span.msgbox").html('');
$("#frmPicture2 label span.msgbox").html('');
$('#picture1').html('');
$('#picture2').html('');
$('#txtPregunta').focus();
};
function reloadJuegos(){
newItem();
var master = $('#cboTemas').val();
$("#tblJuego tbody").html('');
$('#msgbox').html('<i class="fa fa-cog fa-spin"></i> Cargando');
$.post(ajaxReq, {action:"getJuegos", eAuth:auth, eRel:master, eJuegoTipo:jTipo, rand:Math.random()},
function(data){
json = data;
$('#msgbox').html('');
$('#txtNombre').focus();
for (i in json) {
$('#tblJuego > Tbody:first').append('<tr><td><a rel="' + json[i].id + '" class="edit">' + json[i].pregunta + '</a></td><td>' + json[i].respuesta + '</td><td class=\"tableActs\"> <a rel="'+ json[i].id + '" data-reveal-id="myDelete" class="pLeft5 delete rojo" title="Borrar"><i class=\"fa fa-trash-o fa-lg\"></i></a></td></tr>');
}
// reFlow
$('#tblJuego tbody tr td.tableActs .delete').on('click', eliminarFila);
$('#tblJuego tbody tr td .edit').on('click', editarFila);
$(document).foundation('tooltip', 'reflow');
});
};
function showFile1(e){ showFile($(this)[0], $('#picture1'), '#frmPicture1') };
function showFile2(e){ showFile($(this)[0], $('#picture2'), '#frmPicture2') };
function showFile($this, image_holder, form){
var countFiles = $this.files.length;
var imgPath = $this.value;
var extn = imgPath.substring(imgPath.lastIndexOf('.') + 1).toLowerCase();
image_holder.empty();
var fileName = "";
if (extn == "png" || extn == "jpg" || extn == "jpeg") {
if (typeof (FileReader) != "undefined") {
//loop for each file selected for uploaded.
for (var i = 0; i < countFiles; i++) {
var reader = new FileReader();
reader.onload = function (e) {
fileName = e.target.result.split( '\\' ).pop();
$("<img />", {
"src": e.target.result,
"class": "thumb-image"
}).appendTo(image_holder);
}
image_holder.show();
reader.readAsDataURL($this.files[i]);
}
//$('#frmPicture1').submit();
$( form ).submit();
} else {
alert("El formato de imagen no es soportado. Intente con JPG o PNG");
}
} else {
alert("Solo valido para imagenes JPG | PNG");
}
};
function uploadData(e){
e.preventDefault();
var $msgbox = $(this).find('span.msgbox');
var $details = $(this).find('span.icon');
$details.html('<i class="fa fa-spinner fa-pulse"></i> ');
$msgbox.html('Cargando');
$.ajax({
url: "code/upload-picture.php?f=juegos",
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data){
data = jQuery.parseJSON( data );
if (data.rpta == 'ok'){
$details.html('<i class="fa fa-check-circle-o"></i> ');
$msgbox.html(data.msg);
} else {
$details.html('<i class="fa fa-exclamation-triangle"></i> ');
$msgbox.html(' No permitido');
//$('#lblUploadMsg').html('Error: ' + data.msg);
}
}
});
};
</script>
</body>
</html>