-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.php
More file actions
86 lines (72 loc) · 3.35 KB
/
settings.php
File metadata and controls
86 lines (72 loc) · 3.35 KB
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
<?php
defined('MOODLE_INTERNAL') || die();
global $CFG;
if ($hassiteconfig) {
// Create settings page - using simple strings to avoid language loading issues
$settings = new admin_settingpage('local_cpfformat', get_string('pluginname', 'local_cpfformat'));
if ($ADMIN->fulltree) {
// Instructions
$settings->add(new admin_setting_heading(
'local_cpfformat/instructions',
get_string('instructions', 'local_cpfformat'),
get_string('descinstructions', 'local_cpfformat')
));
// Enable/disable plugin setting
$settings->add(new admin_setting_configcheckbox(
'local_cpfformat/enabled',
get_string('enabled_register', 'local_cpfformat'),
get_string('enabled_desc', 'local_cpfformat'),
0 // Default disabled
));
$settings->add(new admin_setting_configcheckbox(
'local_cpfformat/formatusername',
get_string('formatusername', 'local_cpfformat'),
get_string('formatusername_desc', 'local_cpfformat'),
0 // Default value
));
$settings->add(new admin_setting_configcheckbox(
'local_cpfformat/modifynamesurname',
get_string('modifynamesurname', 'local_cpfformat'),
get_string('modifynamesurname_desc', 'local_cpfformat'),
0 // Default value
));
// Enable manual HTML injection setting
$settings->add(new admin_setting_heading(
'local_cpfformat/inject_html_manual',
get_string('inject_html_manual', 'local_cpfformat'),
get_string('manual_js_code_desc', 'local_cpfformat'),
));
// Enable/disable in login page plugin setting
$settings->add(new admin_setting_configcheckbox(
'local_cpfformat/enabledcpfformatedlogin',
get_string('enabledcpfformatedlogin', 'local_cpfformat'),
get_string('enabledcpfformatedlogin_desc', 'local_cpfformat'),
0 // Default disabled
));
}
// Development info
$plugininfo = core_plugin_manager::instance()->get_plugin_info('local_cpfformat');
$settings->add(new admin_setting_heading(
'local_cpfformat/development_info',
get_string('development_info', 'local_cpfformat'),
get_string('development_info_desc', 'local_cpfformat') . '<br><strong>' . get_string('development_info_version', 'local_cpfformat') . $plugininfo->release . '</strong>'
));
$ADMIN->add('localplugins', $settings);
}
// Manage the inclusion of the JS script in additionalhtmlhead based on the setting
$enableloginscript = get_config('local_cpfformat', 'enabledcpfformatedlogin') ?? 0;
$scriptlocal = '<script src="' . $CFG->wwwroot . '/local/cpfformat/cpfmask.js.php"></script>';
// If enabled, ensure the script is included in additionalhtmlhead
if ($enableloginscript) {
if (empty($CFG->additionalhtmlhead) ||
strpos($CFG->additionalhtmlhead, $scriptlocal) === false) {
set_config('additionalhtmlhead', $scriptlocal);
}
} else {
// If disabled, remove the script if it exists
if (!empty($CFG->additionalhtmlhead) &&
strpos($CFG->additionalhtmlhead, $scriptlocal) !== false) {
$newvalue = str_replace($scriptlocal, '', $CFG->additionalhtmlhead);
set_config('additionalhtmlhead', $newvalue);
}
}