-
Notifications
You must be signed in to change notification settings - Fork 0
/
salapesas.php
110 lines (99 loc) · 3.2 KB
/
salapesas.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
<?php
// Configuracion de la pagina
require_once (dirname ( __FILE__ ) . '/conf.php');
$params = array ();
$PAGE->set_context ( $context );
$PAGE->set_url ( '/local/wellness/salapesas.php', $params );
$PAGE->set_pagelayout ( 'mydashboard' );
$PAGE->set_pagetype ( 'local-salapesas-index' );
$PAGE->blocks->add_region ( 'content' );
$PAGE->set_subpage ( $currentpage->id );
$PAGE->set_title ( get_string ( 'navsalapesas', 'local_wellness' ) );
$PAGE->set_heading ( $header );
$PAGE->navbar->add ( get_string ( 'navsalapesas', 'local_wellness' ), new moodle_url ( '/local/wellness/salapesas.php' ) );
// Header
echo $OUTPUT->header ();
// Capabilities
if (has_capability ( "local/wellness:seebutton", $context )) {
//boton al banco de rutinas
$banco = new moodle_url('/course/view.php?id=2');
echo html_writer::link ( $banco, 'Editar rutinas sala de pesas', array (
'class' => 'btn',
'id' => 'editar_rutina',
'name' => 'editar_rutina'
), null ) . " ";
// incluir formularios
require_once ('forms/formulariofotorutinas_form.php');
require_once ('forms/formulariofotorutinaseditar_form.php');
// Se inicia formulario
$formadd = new formulariofotorutinas_form ();
// Url de redireccion
$url = 'salapesas.php';
if ($formadd->is_cancelled ()) {
die ();
}
$nombre_imagen = $formadd->get_new_filename ( 'imagen' );
$imagen = $formadd->get_file_content ( 'imagen' );
if ($dataadd = $formadd->get_data ()) {
$nombre = $dataadd->selectrutinas;
$newimg = new stdClass ();
$newimg->nombre = $nombre;
$newimg->imagen = $imagen;
$newimg->nombre_imagen = $nombre_imagen;
$subir = $DB->insert_record ( 'imagenes', $newimg );
if ($subir) {
echo get_string ( 'imgexito', 'local_wellness' ) . $nombre_imagen;
redirect ( $url );
die ();
} else {
echo get_string ( 'erroroc', 'local_wellness' );
$formadd->display ();
}
} else {
$formadd->display ();
}
$formeditar = new formulariofotorutinaseditar_form ();
$nombre_imagen1 = $formeditar->get_new_filename ( 'imagen' );
$imagen = $formeditar->get_file_content ( 'imagen' );
if ($formeditar->is_cancelled ()) {
die ();
}
if ($dataeditar = $formeditar->get_data ()) {
$nombre = $dataeditar->selectrutinas;
$sql = "UPDATE `imagenes` SET `imagen`=?,`nombre_imagen`=?
WHERE `nombre`=?";
$update = $DB->execute ( $sql, array (
$imagen,
$nombre_imagen1,
$nombre
) );
if (! $update) {
echo get_string ( 'imgerror', 'local_wellness' );
die ();
} else {
echo get_string ( 'imgactexito', 'local_wellness' ) . $nombre_imagen1;
redirect ( $url );
die ();
}
} else {
$formeditar->display ();
}
}
// Query
$result = $DB->get_recordset_sql ( "SELECT DISTINCT cm.id, im.* FROM mdl_course_modules as cm
INNER JOIN mdl_page as mp ON cm.instance = mp.id
INNER JOIN mdl_imagenes as im ON mp.name = im.nombre
WHERE mp.course = 2
AND cm.module = 15
GROUP BY mp.name" );
foreach ( $result as $rs ) {
$imagen = $rs->imagen;
echo '<div class="img">';
echo "<a href='../../mod/page/view.php?id=" . $rs->id . "'>";
echo '<img src="data:image/jpeg;base64,' . base64_encode ( $imagen ) . '"/></img></a>';
echo '<div class="desc">' . $rs->nombre . '</div></div>';
}
$result->close ();
// Footer
echo $OUTPUT->footer ();
?>