Proyectos de Subversion Moodle

Rev

Rev 16 | Rev 18 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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';
15 efrain 25
/*
12 efrain 26
 
27
$username   = trim(isset($_SERVER['HTTP_USERNAME']) ? filter_var($_SERVER['HTTP_USERNAME'], FILTER_SANITIZE_STRING) : '');
28
$password   = trim(isset($_SERVER['HTTP_PASSWORD']) ? filter_var($_SERVER['HTTP_PASSWORD'], FILTER_SANITIZE_STRING) : '');
29
$timestamp  = trim(isset($_SERVER['HTTP_TIMESTAMP']) ? filter_var($_SERVER['HTTP_TIMESTAMP'], FILTER_SANITIZE_STRING) : '');
30
$rand       = intval(isset($_SERVER['HTTP_RAND']) ? filter_var($_SERVER['HTTP_RAND'], FILTER_SANITIZE_NUMBER_INT) : 0,10);
31
 
32
 
33
 
34
if(empty($username) || empty($password) || empty($timestamp) || empty($rand) || !is_integer($rand)) {
35
    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY1']) ;
36
    exit;
37
}
38
 
39
if($username != LLWS_USERNAME) {
40
    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY2']) ;
41
    exit;
42
}
43
 
44
$dt = \DateTime::createFromFormat('Y-m-d\TH:i:s', $timestamp);
45
if(!$dt) {
46
    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY3']) ;
47
    exit;
48
}
49
 
50
$dt = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s',  gmdate('Y-m-d\TH:i:s'));
51
$dtMax = $dt->add(\DateInterval::createFromDateString('5 minutes'));
52
$dtMin = $dt->sub(\DateInterval::createFromDateString('5 minutes'));
53
 
54
 
55
$t0 = $dt->getTimestamp();
56
$t1 = $dtMin->getTimestamp();
57
$t2 = $dtMax->getTimestamp();
58
 
59
if($t0 < $t1 || $t0 > $t2) {
60
    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY4']) ;
61
    exit;
62
}
63
 
64
if(!password_verify( $username.'-'. LLWS_PASSWORD. '-' . $rand. '-' . $timestamp, $password)) {
65
    echo json_encode(['success' => false, 'data' => 'ERROR_SECURITY5']) ;
66
    exit;
67
}
15 efrain 68
*/
12 efrain 69
 
70
 
71
$response = [
72
    'success' => true,
73
    'data' => []
74
];
75
 
76
$enrolmethod = 'manual';
77
$url_noimage =  $CFG->wwwroot . '/theme/' . $PAGE->theme->name . '/pix/coursenoimage.jpg';
78
 
79
//$courses_with_autoenrol  = $DB->get_records('enrol', ['enrol' => 'manual', 'status' => 0]);
80
//print_r($courses_with_autoenrol); exit;
81
 
82
$enrol = enrol_get_plugin($enrolmethod);
83
if ($enrol) {
84
 
17 efrain 85
 
16 efrain 86
 
12 efrain 87
    $courses = get_courses();
88
    foreach($courses as $course)
89
    {
17 efrain 90
        print_r($course); exit;
12 efrain 91
 
92
        $instances = enrol_get_instances($course->id, true);
93
 
94
        $manualinstance = null;
95
        foreach ($instances as $instance)
96
        {
97
            if ($instance->enrol == $enrolmethod) {
98
                $manualinstance = $instance;
99
                break;
100
            }
101
        }
102
 
103
 
104
        if (!$manualinstance) {
105
            continue;
106
        }
107
 
108
        if ($course instanceof stdClass) {
109
            $coreCourseList = new core_course_list_element($course);
110
        } else {
111
            $coreCourseList = [];
112
        }
113
 
114
        $image = $url_noimage;
115
        foreach ($coreCourseList->get_course_overviewfiles() as $file)
116
        {
117
            $isimage = $file->is_valid_image();
118
            $image = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
119
            if (!$isimage) {
120
                $image = $url_noimage;
121
            }
122
        }
123
 
124
 
125
 
126
        array_push($response['data'], [
127
           'courseid' => $course->id,
128
           'courseimage' => $image,
129
           'enddate' => $course->enddate,
130
           'fullname' => $course->fullname,
131
           'idnumber' => $course->idnumber,
132
           'shortname' => $course->shortname,
133
           'startdate' => $course->startdate,
134
           'summary' => $course->summary,
135
        ]);
136
 
137
    }
138
}
139
 
140
echo json_encode($response) ;
141
 
142
 
143
 
144