-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadmin_settings.php
160 lines (130 loc) · 4.84 KB
/
admin_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
<?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/>.
/**
* Admin setttings objects for component 'theme_altitude'
*
* @package theme-altitude
* @author Eric Bjella <[email protected]>
* @copyright 2016 Remote Learner http://www.remote-learner.net/
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class altitude_admin_setting_tabs extends admin_setting {
protected $tabs = array(0 => array());
protected $selected;
protected $section;
protected $reload;
/**
* Config fileupload constructor
*
* @param string $name Unique ascii name, either 'mysetting' for settings that in
* config, or 'myplugin/mysetting' for ones in config_plugins.
* @param string $section Section name
* @param boolean $reload Whether to reload
*/
public function __construct($name, $section, $reload) {
parent::__construct($name, '', '', '');
global $PAGE;
global $CFG;
if (!$PAGE->requires->is_head_done()) {
if (file_exists($CFG->dirroot.'/theme/altitude/javascript/settings.js') && file_exists($CFG->dirroot.'/theme/altitude/style/settings.css')) {
$PAGE->requires->jquery();
$PAGE->requires->js('/theme/altitude/javascript/settings.js');
$PAGE->requires->css('/theme/altitude/style/settings.css');
}
}
$this->section = $section;
$this->reload = $reload;
$this->component = $this->plugin;
$this->theme = substr($this->component, 6);
// Check for direct links.
$this->selected = optional_param($this->get_full_name(), 0, PARAM_INT);
if ($this->reload) {
$newtab = optional_param($this->get_full_name() .'_new', -1, PARAM_INT);
if ($newtab != -1) {
$this->selected = $newtab;
}
}
}
/**
* Return the currently selected tab.
*
* @return int The id of the currently selected tab.
*/
public function get_setting() {
return $this->selected;
}
/**
* Write settings.
*
* In practice this actually runs the reset, import or export sub actions.
*
* @param array $data The submitted data to act upon.
* @return string Always returns an empty string
*/
public function write_setting($data) {
$result = '';
if (isset($data['action'])) {
if ($data['action'] == 1) {
$result = $this->reset();
} else if ($data['action'] == 2) {
$result = $this->import($data['picker']);
} else if ($data['action'] == 3) {
$result = $this->export();
}
}
return $result;
}
/**
* Add a tab to the tab row
*
* For now we only implement a single row. Multiple rows could be added as an extension
* later.
*
* @param int $id The tab id
* @param string $name The tab name
* @uses $CFG
*/
public function addtab($id, $name) {
global $CFG;
$url = $CFG->wwwroot .'/admin/settings.php?section='. $this->section .'&'
.$this->get_full_name().'='.$id.'" class="altitude-admin-tab';
$tab = new tabobject($id, $url, $name);
$this->tabs[0][] = $tab;
}
/**
* Returns an HTML string
*
* @param mixed $data Array or string depending on setting
* @param string $query Query
* @return string Returns an HTML string
*/
public function output_html($data, $query='') {
global $CFG, $PAGE;
$this->component = $this->plugin;
$this->theme = substr($this->component, 6);
$output = print_tabs($this->tabs, $this->selected, null, null, true);
$properties = array(
'type' => 'hidden',
'name' => $this->get_full_name(),
'value' => $this->get_setting()
);
$output .= html_writer::empty_tag('input', $properties);
$properties['id'] = $this->get_id();
$properties['name'] = $this->get_full_name() .'_new';
$output .= html_writer::empty_tag('input', $properties);
return $output;
}
}