-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
104 lines (86 loc) · 3.08 KB
/
lib.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
<?php
defined('MOODLE_INTERNAL') || die();
function local_moodle_survey_extend_navigation(global_navigation $nav) {
global $PAGE;
$PAGE->requires->css(new moodle_url('/local/moodle_survey/css/styles.css'));
}
function local_moodle_survey_before_http_headers() {
global $CFG;
local_moodle_survey_redirect_homepage();
$currenturl = $_SERVER['REQUEST_URI'];
if (strpos($currenturl, '/blocks/iomad_company_admin/index.php') !== false) {
redirect($CFG->wwwroot . '/theme/academi/moodle_school/manage_school.php');
}
}
function local_moodle_survey_redirect_homepage() {
global $SESSION;
$isexistinguser = isloggedin() && !isguestuser();
if ($isexistinguser) {
if (!empty($SESSION->wantsurl)) {
$returnurl = new moodle_url('/');
unset($SESSION->wantsurl);
redirect($returnurl);
}
}
}
function is_sel_admin() {
return is_siteadmin();
}
function is_counsellor() {
global $USER, $DB;
$systemcontextid = \context_system::instance()->id;
$role = $DB->get_record('role', ['shortname' => 'counsellor'], 'id', MUST_EXIST);
return user_has_role_assignment($USER->id, $role->id, $systemcontextid);
}
function is_teacher() {
global $USER, $DB;
$systemcontextid = \context_system::instance()->id;
$role = $DB->get_record('role', ['shortname' => 'teacher'], 'id', MUST_EXIST);
return user_has_role_assignment($USER->id, $role->id, $systemcontextid);
}
function is_school_admin() {
global $USER, $DB;
$systemcontextid = \context_system::instance()->id;
$role = $DB->get_record('role', ['shortname' => 'schooladmin'], 'id', MUST_EXIST);
return user_has_role_assignment($USER->id, $role->id, $systemcontextid);
}
function is_principal() {
global $USER, $DB;
$systemcontextid = \context_system::instance()->id;
$role = $DB->get_record('role', ['shortname' => 'principal'], 'id', MUST_EXIST);
return user_has_role_assignment($USER->id, $role->id, $systemcontextid);
}
function is_student() {
global $USER, $DB;
$systemcontextid = \context_system::instance()->id;
$role = $DB->get_record('role', ['shortname' => 'student'], 'id', MUST_EXIST);
return user_has_role_assignment($USER->id, $role->id, $systemcontextid);
}
function get_user_role() {
global $USER;
$context = \context_system::instance();
$roles = get_user_roles($context, $USER->id);
foreach ($roles as $role) {
return $role->shortname;
}
return 'sel_admin';
}
function get_user_grade() {
global $DB, $USER;
return $DB->get_record('cc_user_grade', ['user_id' => $USER->id]);
}
function get_user_school() {
global $USER, $DB;
return $DB->get_record('company_users', ['userid' => $USER->id]);
}
function get_school() {
global $USER, $DB;
return $DB->get_record('company', ['id' => get_user_school()->companyid]);
}
function get_user_school_department($schoolshortname=null) {
global $USER, $DB;
if (!$schoolshortname) {
$schoolshortname = get_school()->shortname;
}
return $DB->get_record('department', ['shortname' => $schoolshortname]);
}