-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_data.php
279 lines (212 loc) · 8.41 KB
/
block_data.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
<?php
require_once('../../config.php');
defined('MOODLE_INTERNAL') || die();
?>
<script class="jsbin" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<link rel="stylesheet" href="style/styles.css" />
<script>
function ajax_call(data,url,type,op,div){
//console.log(url);
$.ajax({
data: data,
url: url,
type: type,
contentType: false,
processData: false,
success: function (response){
document.getElementById(div).innerHTML = response;
if(op === 'create_activity'){
edit_activity(document.getElementById('activityid').value);
}
},
error: function(request,status,errorThrown) {
console.log(errorThrown);
}
});
}
function serialize(form) {
var formData = new FormData();
if (!form || form.nodeName !== "FORM") {
return;
}
var i, j;
for (i = form.elements.length - 1; i >= 0; i = i - 1) {
if (form.elements[i].name === "") {
continue;
}
switch (form.elements[i].nodeName) {
case 'INPUT':
switch (form.elements[i].type) {
case 'text':
case 'number':
case 'email':
case 'date':
case 'datetime-local':
case 'tel':
case 'hidden':
case 'password':
case 'button':
case 'reset':
//case 'submit':
formData.append(form.elements[i].name,form.elements[i].value);
break;
case 'checkbox':
case 'radio':
if (form.elements[i].checked) {
formData.append(form.elements[i].name,encodeURIComponent(form.elements[i].value));
}
break;
}
break;
case 'SELECT':
switch (form.elements[i].type) {
case 'select-one':
formData.append(form.elements[i].name,form.elements[i].value);
break;
case 'select-multiple':
var multiselect;
for (j = form.elements[i].options.length - 1; j >= 0; j = j - 1) {
if (form.elements[i].options[j].selected) {
multiselect += '&'+form.elements[i].options[j].value;
}
}
formData.append('category_name',multiselect);
break;
}
break;
/*case 'BUTTON':
switch (form.elements[i].type) {
case 'reset':
case 'submit':
case 'button':
formData.append(form.elements[i].name,encodeURIComponent(form.elements[i].value));
break;
}
break;*/
}
}
return formData;
}
//read forms
//Luis Sola
//XX022020
function read_form(e,form,operation){
e.preventDefault();
var formData = serialize(form);
formData.append('operation',operation);
ajax_call(formData,'data.php','POST',operation,"primer_contenedor");
}
function config_activity(idactivity,sceneid){
var formData = new FormData();
var operation='config_activity';
formData.append('operation','config_activity');
formData.append('scene',sceneid);
formData.append('id',idactivity);
ajax_call(formData,'data.php','POST',operation,"primer_contenedor");
}
function select_competence(requestid){
//console.log(requestid);
var operation='config_activity_backup';
var formData = new FormData();
formData.append('operation','config_activity_backup');
formData.append('requestid',requestid);
ajax_call(formData,'data.php','POST',operation,"primer_contenedor");
}
function select_query(select,buttom,form){
var selectedOption = select.options[select.selectedIndex];
var formData = new FormData();
formData.append('operation',selectedOption.value);
formData.append('form',form);
formData.append('buttom',buttom);
var operation = 'selectedOption.value';
ajax_call(formData,'query.php','POST',operation,"consultas");
}
function edit_activity(idactivity){
var URLdomain = window.location.host;
window.open('http://'+URLdomain+'/moodle/course/modedit.php?update='+idactivity,'_self');
if(document.getElementById('quizid')){
window.open('http://'+URLdomain+'/moodle/mod/quiz/edit.php?cmid='+idactivity, '_blank');
}
}
</script>
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*
*/
//Definición del URL de la página
$PAGE->set_url('/blocks/tfg/block_data.php', array());
//Recuperamos el parametro curso
$courseid = required_param('courseid', PARAM_INT);
//Definición del contexto en base al curso que venimos
$PAGE->set_context(context_course::instance($courseid));
//Definición del layout
$PAGE->set_pagelayout('course');
//Definición del titulo
$PAGE->set_title("Your title");
$_SESSION['course_id']=$courseid;
if (has_capability('block/tfg:createactivity', $PAGE->context)) {
if(isset($_GET['request'])){
//Delete request from 2 tables
$DB->delete_records("tfg_satisfy",array('requestid'=>$_GET['request']));
$DB->delete_records("tfg_teacher_comp_request",array('id'=>$_GET['request']));
}
$PAGE->set_heading("Creación de una actividad en base a una serie de competencias");
echo $OUTPUT->header();
$form = 'competences_teacher';
$buttom = 'Sugerir actividad';
$text = 'A continuación seleccione un número de competencias a cubrir en base al siguiente criterio::<br><br>';
$options = array('bt'=>'Básico','rq'=>'En base a las peticiones del estudiante','cc'=>'En base a cuantas veces ha sido cubierta');
}else if(has_capability('block/tfg:askactivity', $PAGE->context)){
$PAGE->set_heading("Pedir competencia");
echo $OUTPUT->header();
$form = 'competences_student';
$buttom = 'Pedir competencia';
$text = 'A continuación seleccione un número de competencias que quieres que sean cubiertas en base al siguiente criterio:<br><br>';
$options = array('bt'=>'Básico','lc'=>'La competencias menos solicitada');
}
$sql = "Select * from tfg_teacher_comp_request where usermodified = ".$USER->id." and courseid = ".$courseid." and myactivity_itemid is null";
echo '<span id="primer_contenedor">';
if($DB->record_exists_sql($sql)){
$request = $DB->get_records_sql($sql);
echo '<script type="text/javascript">select_competence('.$request[key($request)]->id.');</script>';
}
else{
echo html_writer::div($text, "", null);
$attrs = array(
'onchange' => "select_query(this,'".$buttom."','".$form."')"
);
echo html_writer::select($options, 'order', '0', null, $attrs);
echo '<span id="consultas">';
$sql_compentence = "
SELECT DISTINCT
(c.id),
c.name,
c.description
FROM
`tfg_appears` a
JOIN `tfg_competence` c ON
a.competenceid = c.id";
$competences = $DB->get_records_sql($sql_compentence);
echo
'<form onsubmit="read_form(event,this,\''.$form.'\')" method="POST" name="competences">
<div style="float:left">';
foreach($competences as $competence){
echo'
<div class="b_activities">
<div class="chk_comp '.$competence->id.'"><input title = "'.$competence->name.'" type="checkbox" name="'.$competence->id.'" value="'.$competence->id.'" /></div>
<div class="activity_text"><strong>'.$competence->name.':</strong><br>'.$competence->description.'</div>
</div>';
}
echo'</div>
<input name="suggest_activity" value = "'.$buttom.'" type="submit"></input>
</form>
</span>
';
}
echo '</span>';
echo $OUTPUT->footer();
?>