-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.php
109 lines (87 loc) · 3.53 KB
/
index.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
<?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/>.
/**
* Environment bar setup page.
*
* @package local_envbar
* @author Grigory Baleevskiy ([email protected])
* @author Nicholas Hoobin <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use local_envbar\local\envbarlib;
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
global $DB;
admin_externalpage_setup('local_envbar_settings');
$records = envbarlib::get_records();
$gensecretkey = random_string(25);
$form = new \local_envbar\form\config(null, array('records' => $records, 'gensecretkey' => $gensecretkey));
if ($data = $form->get_data()) {
envbarlib::setprodwwwroot($data->prodwwwroot);
set_config('prodbgcolour', $data->prodbgcolour, 'local_envbar');
set_config('prodtextcolour', $data->prodtextcolour, 'local_envbar');
if (!envbarlib::is_secret_key_overridden()) {
set_config('secretkey', $data->secretkey, 'local_envbar');
}
if (!empty($data->id)) {
$keys = array_keys($data->id);
foreach ($keys as $key => $value) {
$item = new stdClass();
$item->id = $data->id[$value];
$item->colourbg = $data->colourbg[$value];
$item->colourtext = $data->colourtext[$value];
$item->matchpattern = $data->matchpattern[$value];
$item->showtext = $data->showtext[$value];
// Do not update the database with manual set config.php items.
if (!empty($data->locked[$value])) {
continue;
}
if ($data->delete[$value] == 1) {
envbarlib::delete_envbar($value);
} else {
// Update an item as the id has been set.
envbarlib::update_envbar($item);
}
}
}
if (!empty($data->repeatid)) {
$repeats = array_keys($data->repeatid);
foreach ($repeats as $key => $value) {
$item = new stdClass();
// ID, $item->id not set.
$item->colourbg = $data->repeatcolourbg[$value];
$item->colourtext = $data->repeatcolourtext[$value];
$item->matchpattern = $data->repeatmatchpattern[$value];
$item->showtext = $data->repeatshowtext[$value];
envbarlib::update_envbar($item);
}
}
redirect(new moodle_url('/local/envbar/index.php'));
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('header_envbar', 'local_envbar'));
echo get_string('help', 'local_envbar');
$config = get_config('local_envbar');
if (isset($config->prodlastcheck)) {
$show = format_time(time() - $config->prodlastcheck);
$num = strtok($show, ' ');
$unit = strtok(' ');
$show = "$num $unit";
echo get_string('prodlasttimestamp', 'local_envbar', $show);
}
echo $form->display();
echo $OUTPUT->footer();