-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
executable file
·175 lines (151 loc) · 5.75 KB
/
settings.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?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/>.
/**
* @package local_syllabusuploader
* @copyright 2023 onwards LSU Online & Continuing Education
* @copyright 2023 onwards Robert Russo, David Lowe
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
// Set the context.
$context = \context_system::instance();
// Check the cap and set the accressrule accordingly.
$permitted = has_capability('local/syllabusuploader:admin', $context);
$isadmin = is_siteadmin();
// Get the allowed users from config.
$alloweduserlist = get_config('moodle', 'local_syllabusuploader_admins');
// Make an array out of the list.
$allowedusers = explode(',', $alloweduserlist);
// Loop through them and see if the user requesting access is allowed.
foreach ($allowedusers as $alloweduser) {
// We're using emails.
if ($alloweduser == $USER->email && $permitted) {
$allowed = true;
break;
} else if ($alloweduser == $USER->username && $permitted) {
// We're using usernames.
$allowed = true;
break;
}
// You suck.
$allowed = false;
}
// Set the string for use later.
$fn = new lang_string('foldername', 'local_syllabusuploader');
// Create the folder / submenu.
if ($isadmin) {
$ADMIN->add('localplugins', new admin_category('local_syllabusuploader_folder', $fn));
}
// Create the local settings.
$settings = new admin_settingpage($section = "syllabusuploader", get_string('settings'));
// Make sure only admins see this one.
if ($ADMIN->fulltree) {
// ----------------------------------------------
// Path Settings Title.
$settings->add(
new admin_setting_heading(
'local_syllabusuploader_path_settings',
get_string('syllabusuploader_path_settings_title', 'local_syllabusuploader'),
''
)
);
// Copy File Settings.
$settings->add(
new admin_setting_configtext(
'local_syllabusuploader_copy_file',
get_string('syllabusuploader_copy_file', 'local_syllabusuploader'),
get_string('syllabusuploader_copy_file_desc', 'local_syllabusuploader'),
'/var/moodledata/syllabus/' // Default.
)
);
// The public path setting.
$settings->add(
new admin_setting_configtext(
'local_syllabusuploader_public_path',
get_string('syllabusuploader_public_path', 'local_syllabusuploader'),
get_string('syllabusuploader_public_path_desc', 'local_syllabusuploader'),
'/syllabus/' // Default.
)
);
// ----------------------------------------------
// User Settings Title.
$settings->add(
new admin_setting_heading(
'local_syllabusuploader_user_settings',
get_string('syllabusuploader_user_settings_title', 'local_syllabusuploader'),
''
)
);
// The named users setting.
$settings->add(
new admin_setting_configtext(
'local_syllabusuploader_admins',
get_string('syllabusuploader_admins', 'local_syllabusuploader'),
get_string('syllabusuploader_admins_desc', 'local_syllabusuploader'),
'[email protected]' // Default.
)
);
// ----------------------------------------------
// File Manager Title.
$settings->add(
new admin_setting_heading(
'local_syllabusuploader_manager_settings',
get_string('syllabusuploader_manager_settings_title', 'local_syllabusuploader'),
''
)
);
// Max files to be uploaded.
$settings->add(
new admin_setting_configtext(
'local_syllabusuploader_manager_max_files',
get_string('syllabusuploader_manager_max_files_title', 'local_syllabusuploader'),
get_string('syllabusuploader_manager_max_files_desc', 'local_syllabusuploader'),
'1' // Default.
)
);
// Accepted file types.
$settings->add(
new admin_setting_configtext(
'local_syllabusuploader_manager_acceptedtypes',
get_string('syllabusuploader_manager_acceptedtypes_title', 'local_syllabusuploader'),
get_string('syllabusuploader_manager_acceptedtypes_desc', 'local_syllabusuploader'),
'pdf' // Default.
)
);
}
// Add the folder.
if ($isadmin) {
$ADMIN->add('local_syllabusuploader_folder', $settings);
}
// Prevent Moodle from adding settings local in standard location.
$settings = null;
// Set the url for the ProctorU file uploader.
$suuploader = new admin_externalpage(
'syllabusuploader_uploader',
new lang_string('manage_uploader', 'local_syllabusuploader'),
"$CFG->wwwroot/local/syllabusuploader/uploader.php"
);
// Set the url for the ProctorU file viewer.
$suviewer = new admin_externalpage(
'syllabusuploader_viewer',
new lang_string('manage_viewer', 'local_syllabusuploader'),
"$CFG->wwwroot/local/syllabusuploader/view.php"
);
// Add the additional links for those who have access.
if ($allowed && $isadmin) {
$ADMIN->add('local_syllabusuploader_folder', $suuploader);
$ADMIN->add('local_syllabusuploader_folder', $suviewer);
}