-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
103 lines (88 loc) · 3 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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This block generates a simple list of links based on the users profile.
*
* @package block_links
* @copyright 2014 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Define some constants.
define('BLOCK_LINKS_INSTITUTION', 1);
define('BLOCK_LINKS_DEPARTMENT', 2);
define('BLOCK_LINKS_CITY', 3);
define('BLOCK_LINKS_COUNTRY', 4);
define('BLOCK_LINKS_DESCRIPTION', 5);
define('BLOCK_LINKS_SHOWLINK', 1);
define('BLOCK_LINKS_HIDELINK', 0);
define('BLOCK_LINKS_SHOW_EVERYONE', 'All');
define('BLOCK_LINKS_WINDOW_NEW', '_blank');
define('BLOCK_LINKS_WINDOW_PARENT', '_parent');
define('BLOCK_LINKS_WINDOW_SELF', '_self');
/**
* Checks permissions whether a user can access a specific link.
* @param stdclass $link
* @return boolean
*/
function block_links_check_permissions($link) {
global $USER, $DB;
// Check to see if the link is hidden.
if ($link->defaultshow == BLOCK_LINKS_HIDELINK) {
return false;
}
// Can everyone see it?
if ($link->department == BLOCK_LINKS_SHOW_EVERYONE) {
return true;
}
// Do they match the user profile restriction?.
$blockconfig = get_config('block_links');
switch($blockconfig->profile_field) {
case BLOCK_LINKS_INSTITUTION:
if ($link->department == $USER->institution) {
return true;
}
break;
case BLOCK_LINKS_DEPARTMENT:
if ($link->department == $USER->department) {
return true;
}
break;
case BLOCK_LINKS_CITY:
if ($link->department == $USER->city) {
return true;
}
break;
case BLOCK_LINKS_COUNTRY:
if ($link->department == $USER->country) {
return true;
}
break;
case BLOCK_LINKS_DESCRIPTION:
// TODO: CONVERT THIS TO MUC.
static $description;
if (!isset($description)) {
$description = $DB->get_field('user', 'description', array('id' => $USER->id));
$description = clean_param($description, PARAM_NOTAGS);
}
if ($link->department == $description) {
return true;
}
break;
default:
return false;
}
return false;
}