-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock_cegep_createcourse_form.php
68 lines (51 loc) · 2.39 KB
/
block_cegep_createcourse_form.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
<?php
require_once($CFG->libdir.'/formslib.php');
class cegep_createcourse_form extends moodleform {
const LIGNES = 8;
function definition() {
global $PAGE;
$mform =& $this->_form;
$mform->addElement('hidden', 'coursecode', $this->_customdata['coursecode']);
$mform->setType('coursecode', PARAM_ALPHANUM);
$mform->addRule('coursecode', get_string('required'), 'required');
$mform->addElement('static', '_coursecode', get_string('coursecode', 'block_cegep'), $mform->_elements[0]->_attributes['value']);
$mform->addElement('text', 'fullname', get_string('fullnamecourse').' :', 'size="64", maxlength="255"');
$mform->setDefault('fullname', $this->_customdata['coursetitle']);
$mform->addHelpButton('fullname', 'fullnamecourse');
$mform->setType('fullname', PARAM_TEXT);
$mform->addRule('fullname', get_string('required'), 'required');
$choices = array();
$choices['0'] = get_string('hide');
$choices['1'] = get_string('show');
$mform->addElement('select', 'visible', get_string('visible'), $choices);
$mform->addHelpButton('visible', 'visible');
$mform->setDefault('visible', 0);
$mform->addRule('visible', get_string('required'), 'required');
$mform->addElement('html', "<p>Ce cours sera créé immédiatement lorsque vous cliquez le bouton <strong>Enregistrer</strong>.</p><p>Vous serez ensuite redirigé vers le formulaire d'inscriptions des groupes-cours.</p>");
$this->add_action_buttons();
}
function validation($data, $files) {
global $DB, $USER;
$errors = parent::validation($data, $files);
$allowed = FALSE;
// Admins and teachers can create courses
if (is_siteadmin($USER)) {
$allowed = TRUE;
}
else {
// Check if the current user is a teacher enrolled in this course
$enrolments = cegep_local_get_teacher_enrolments($USER->idnumber, cegep_local_current_term());
foreach ($enrolments as $enrolment) {
if ($enrolment['coursecode'] == $data['coursecode']) {
$allowed = TRUE;
break;
}
}
}
if (!$allowed) {
$errors['_coursecode'] = get_string('errormustbeteachercourse', 'block_cegep');
}
return $errors;
}
}
?>