12 |
efrain |
1 |
<?php
|
|
|
2 |
header('Access-Control-Allow-Origin: *');
|
|
|
3 |
header('Access-Control-Allow-Methods: GET');
|
|
|
4 |
//POST, GET, DELETE, PUT, PATCH, OPTIONS
|
|
|
5 |
header('Access-Control-Allow-Headers: token, Content-Type');
|
|
|
6 |
header('Access-Control-Max-Age: 1728000');
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
header('Content-Type: application/json');
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
require_once(__DIR__ . '/config.php');
|
|
|
14 |
require_once(__DIR__ . '/../config.php');
|
|
|
15 |
global $DB, $PAGE, $CFG;
|
|
|
16 |
|
|
|
17 |
require_once($CFG->libdir.'/moodlelib.php');
|
|
|
18 |
require_once($CFG->libdir . '/externallib.php');
|
|
|
19 |
require_once($CFG->libdir.'/authlib.php');
|
|
|
20 |
require_once( $CFG->libdir . '/gdlib.php' );
|
|
|
21 |
|
|
|
22 |
require_once($CFG->dirroot.'/user/lib.php');
|
|
|
23 |
require_once __DIR__ . '/rsa.php';
|
|
|
24 |
require_once __DIR__ . '/lib.php';
|
|
|
25 |
|
42 |
efrain |
26 |
header('Content-type: text/plain');
|
|
|
27 |
|
39 |
efrain |
28 |
/*
|
12 |
efrain |
29 |
$username = trim(isset($_SERVER['HTTP_USERNAME']) ? filter_var($_SERVER['HTTP_USERNAME'], FILTER_SANITIZE_STRING) : '');
|
|
|
30 |
$password = trim(isset($_SERVER['HTTP_PASSWORD']) ? filter_var($_SERVER['HTTP_PASSWORD'], FILTER_SANITIZE_STRING) : '');
|
|
|
31 |
$timestamp = trim(isset($_SERVER['HTTP_TIMESTAMP']) ? filter_var($_SERVER['HTTP_TIMESTAMP'], FILTER_SANITIZE_STRING) : '');
|
|
|
32 |
$rand = intval(isset($_SERVER['HTTP_RAND']) ? filter_var($_SERVER['HTTP_RAND'], FILTER_SANITIZE_NUMBER_INT) : 0,10);
|
39 |
efrain |
33 |
$id = intval(isset($_GET['id']) ? filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT) : 0,10);
|
12 |
efrain |
34 |
|
|
|
35 |
|
|
|
36 |
if(empty($username) || empty($password) || empty($timestamp) || empty($rand) || !is_integer($rand)) {
|
|
|
37 |
echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY1']) ;
|
|
|
38 |
exit;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
if($username != LLWS_USERNAME) {
|
|
|
42 |
echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY2']) ;
|
|
|
43 |
exit;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
$dt = \DateTime::createFromFormat('Y-m-d\TH:i:s', $timestamp);
|
|
|
47 |
if(!$dt) {
|
|
|
48 |
echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY3']) ;
|
|
|
49 |
exit;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
$dt = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s', gmdate('Y-m-d\TH:i:s'));
|
|
|
53 |
$dtMax = $dt->add(\DateInterval::createFromDateString('5 minutes'));
|
|
|
54 |
$dtMin = $dt->sub(\DateInterval::createFromDateString('5 minutes'));
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
$t0 = $dt->getTimestamp();
|
|
|
58 |
$t1 = $dtMin->getTimestamp();
|
|
|
59 |
$t2 = $dtMax->getTimestamp();
|
|
|
60 |
|
|
|
61 |
if($t0 < $t1 || $t0 > $t2) {
|
|
|
62 |
echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
|
|
|
63 |
exit;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
if(!password_verify( $username.'-'. LLWS_PASSWORD. '-' . $rand. '-' . $timestamp, $password)) {
|
|
|
67 |
echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY5']) ;
|
|
|
68 |
exit;
|
|
|
69 |
}
|
39 |
efrain |
70 |
*/
|
12 |
efrain |
71 |
|
|
|
72 |
|
|
|
73 |
|
39 |
efrain |
74 |
$id = 81;
|
12 |
efrain |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
$course = get_course($id);
|
|
|
79 |
if(!$course) {
|
|
|
80 |
echo json_encode([
|
|
|
81 |
'success' => false,
|
|
|
82 |
'data' => 'El curso solicitado no existe'
|
|
|
83 |
]);
|
|
|
84 |
exit;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
$enrolmethod = 'manual';
|
|
|
88 |
$url_noimage = $CFG->wwwroot . '/theme/' . $PAGE->theme->name . '/pix/coursenoimage.jpg';
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
$enrol = enrol_get_plugin($enrolmethod);
|
|
|
92 |
if (!$enrol) {
|
|
|
93 |
echo json_encode([
|
|
|
94 |
'success' => false,
|
|
|
95 |
'data' => 'El Plugin de enrolamiento manual no esta disponible'
|
|
|
96 |
]);
|
|
|
97 |
exit;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
$instances = enrol_get_instances($course->id, true);
|
|
|
101 |
$manualinstance = null;
|
|
|
102 |
foreach ($instances as $instance)
|
|
|
103 |
{
|
|
|
104 |
if ($instance->enrol == $enrolmethod) {
|
|
|
105 |
$manualinstance = $instance;
|
|
|
106 |
break;
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
44 |
efrain |
110 |
|
12 |
efrain |
111 |
|
|
|
112 |
if (!$manualinstance) {
|
|
|
113 |
echo json_encode([
|
|
|
114 |
'success' => false,
|
|
|
115 |
'data' => 'Este curso no soporta en enrolamiento manual'
|
|
|
116 |
]);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
if ($course instanceof stdClass) {
|
|
|
120 |
$coreCourseList = new core_course_list_element($course);
|
|
|
121 |
} else {
|
|
|
122 |
$coreCourseList = [];
|
|
|
123 |
}
|
|
|
124 |
|
40 |
efrain |
125 |
$image = ''; // $url_noimage;
|
12 |
efrain |
126 |
foreach ($coreCourseList->get_course_overviewfiles() as $file)
|
|
|
127 |
{
|
|
|
128 |
$isimage = $file->is_valid_image();
|
40 |
efrain |
129 |
if($isimage) {
|
|
|
130 |
// $image = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
|
|
|
131 |
//if (!$isimage) {
|
|
|
132 |
// $image = $url_noimage;
|
|
|
133 |
//}
|
|
|
134 |
|
45 |
efrain |
135 |
// echo "file \r\n";
|
|
|
136 |
// print_r($file);
|
40 |
efrain |
137 |
|
45 |
efrain |
138 |
// echo "\r\n\r\n";
|
|
|
139 |
// echo "context \r\n";
|
41 |
efrain |
140 |
|
|
|
141 |
$course_context = \context_course::instance($course->id);
|
46 |
efrain |
142 |
|
40 |
efrain |
143 |
$fs = get_file_storage();
|
44 |
efrain |
144 |
// $file = $fs->get_file($file->get_contextid(), $file->get_component(), $file->get_filearea(), $course->id, $file->get_filepath(), $file->get_filename());
|
40 |
efrain |
145 |
|
44 |
efrain |
146 |
|
47 |
efrain |
147 |
// $file = $fs->get_file($course_context->id, 'course', $file->get_filearea(), 0, $file->get_filepath(), $file->get_filename());
|
44 |
efrain |
148 |
|
46 |
efrain |
149 |
if($file) {
|
|
|
150 |
echo 'file';
|
50 |
efrain |
151 |
|
49 |
efrain |
152 |
print_r(get_class_methods($file));
|
51 |
efrain |
153 |
print_r($file->get_filename());
|
|
|
154 |
print_r($file->get_filesize());
|
52 |
efrain |
155 |
print_r($file->get_content());
|
48 |
efrain |
156 |
//$stored_file = new stored_file($fs, $file);
|
|
|
157 |
//print_r($stored_file);
|
46 |
efrain |
158 |
}
|
40 |
efrain |
159 |
|
46 |
efrain |
160 |
|
40 |
efrain |
161 |
|
46 |
efrain |
162 |
|
12 |
efrain |
163 |
}
|
40 |
efrain |
164 |
|
|
|
165 |
|
12 |
efrain |
166 |
}
|
40 |
efrain |
167 |
exit;
|
|
|
168 |
|
|
|
169 |
//ttps:\/\/moodle4-dev.leaderslinked.com\/pluginfile.php\/22898\/course\/overviewfiles\/HOME_APLICACIONES_-17.png
|
|
|
170 |
|
|
|
171 |
/*
|
|
|
172 |
$course_context = context_course::instance($course->id);
|
|
|
173 |
|
|
|
174 |
$fs = get_file_storage();
|
|
|
175 |
$file = $fs->get_file($course_context ->id, 'mod_course', $filearea, $course->id, $filepath, $filename);
|
|
|
176 |
if (!$file) {
|
|
|
177 |
// The file does not exist.
|
|
|
178 |
return false;
|
|
|
179 |
}*/
|
12 |
efrain |
180 |
|
|
|
181 |
|
|
|
182 |
echo json_encode([
|
|
|
183 |
'success' => true,
|
|
|
184 |
'data' =>
|
|
|
185 |
[
|
|
|
186 |
'courseid' => $course->id,
|
|
|
187 |
'courseimage' => $image,
|
|
|
188 |
'enddate' => $course->enddate,
|
|
|
189 |
'fullname' => $course->fullname,
|
|
|
190 |
'idnumber' => $course->idnumber,
|
|
|
191 |
'shortname' => $course->shortname,
|
|
|
192 |
'startdate' => $course->startdate,
|
|
|
193 |
'summary' => $course->summary,
|
|
|
194 |
]
|
|
|
195 |
]);
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|