user-binding.php 1.64 KB
Newer Older
Francois Gannaz's avatar
Francois Gannaz committed
1
2
3
4
<?php

/**
 * Inner HTL page.
Francois Gannaz's avatar
Francois Gannaz committed
5
 * Bind a Moodle user to a LabNbook account.
Francois Gannaz's avatar
Francois Gannaz committed
6
7
8
9
 *
 * @copyright   2019 Université Grenoble Alpes
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
Francois Gannaz's avatar
Francois Gannaz committed
10
use mod_labnbook\fetch;
Francois Gannaz's avatar
Francois Gannaz committed
11

Francois Gannaz's avatar
Francois Gannaz committed
12
require_once \dirname(__DIR__, 2) . '/config.php';
13

Francois Gannaz's avatar
Francois Gannaz committed
14
$returnUrl = \base64_decode(required_param('return', PARAM_ALPHANUM));
15
16
17
18
19
20
21
22
$courseid = required_param('courseid', PARAM_INT);
$create = optional_param('create', false, PARAM_BOOL);

$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
require_login($course);

$fetchInstitution = new fetch\institution();
$context = context_course::instance($courseid);
23
24
$isTeacher = has_capability('mod/labnbook:addinstance', $context);
$role = ($isTeacher ? 'teacher' : 'learner');
Francois Gannaz's avatar
Francois Gannaz committed
25
26
27

/* @var $PAGE moodle_page */
global $PAGE;
28
global $USER;
Francois Gannaz's avatar
Francois Gannaz committed
29
30
31
$PAGE->set_url('/mod/labnbook/user-binding.php');
$PAGE->set_title("LabNbook");
$PAGE->set_heading("LabNbook");
32
$PAGE->set_context($context);
Francois Gannaz's avatar
Francois Gannaz committed
33
34
35
36
37
38

/* @var $OUTPUT moodle_core_output */
global $OUTPUT;
echo $OUTPUT->header();
?>

39
40
41
42
43
44
45
<p>
    Vous n'avez pas de compte dans LabNbook, ou ce compte n'est pas encore connu de Moodle.
</p>

<div class="container-fluid">
    <div class="row">
        <div class="col" style="text-align: center">
Francois Gannaz's avatar
Francois Gannaz committed
46
            <form action="<?= $fetchInstitution->getRedirectUrl(); ?>" method="GET">
47
                <input type="hidden" name="token" value="<?= $fetchInstitution->getBindingTokenForRedirect($CFG->wwwroot . $returnUrl, $role, $USER); ?>" />
48
49
50
51
52
                <button type="submit" class="btn btn-primary">Se connecter à LabNbook</button>
            </form>
        </div>
    </div>
</div>
Francois Gannaz's avatar
Francois Gannaz committed
53
54
55

<?php
echo $OUTPUT->footer();