1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.33 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\XHtml; |
8
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Base TreeController controller class. |
13
|
|
|
*/ |
14
|
|
|
class TreeController |
15
|
|
|
{ |
16
|
|
|
use \PHPPgAdmin\HelperTrait; |
|
|
|
|
17
|
|
|
|
18
|
|
|
protected $container; |
19
|
|
|
public $form = ''; |
20
|
|
|
public $href = ''; |
21
|
|
|
public $lang = []; |
22
|
|
|
public $action = ''; |
23
|
|
|
public $controller_name = 'TreeController'; |
24
|
|
|
public $controller_title = 'base'; |
25
|
|
|
|
26
|
|
|
// Constructor |
27
|
|
|
public function __construct(\Slim\Container $container, $controller_name = null) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->container = $container; |
30
|
|
|
$this->lang = $container->get('lang'); |
31
|
|
|
//$this->conf = $container->get('conf'); |
32
|
|
|
$this->view = $container->get('view'); |
33
|
|
|
$this->plugin_manager = $container->get('plugin_manager'); |
34
|
|
|
$this->appName = $container->get('settings')['appName']; |
35
|
|
|
$this->appVersion = $container->get('settings')['appVersion']; |
36
|
|
|
$this->appLangFiles = $container->get('appLangFiles'); |
37
|
|
|
$this->misc = $container->get('misc'); |
38
|
|
|
$this->conf = $this->misc->getConf(); |
39
|
|
|
$this->appThemes = $container->get('appThemes'); |
40
|
|
|
$this->action = $container->get('action'); |
41
|
|
|
if (null !== $controller_name) { |
42
|
|
|
$this->controller_name = $controller_name; |
43
|
|
|
} |
44
|
|
|
//\PC::debug($this->controller_name, 'instanced controller'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** Produce XML data for the browser tree |
|
|
|
|
48
|
|
|
* @param $treedata a set of records to populate the tree |
49
|
|
|
* @param $attrs Attributes for tree items |
|
|
|
|
50
|
|
|
* 'text' - the text for the tree node |
51
|
|
|
* 'icon' - an icon for node |
52
|
|
|
* 'openIcon' - an alternative icon when the node is expanded |
53
|
|
|
* 'toolTip' - tool tip text for the node |
54
|
|
|
* 'action' - URL to visit when single clicking the node |
55
|
|
|
* 'iconAction' - URL to visit when single clicking the icon node |
56
|
|
|
* 'branch' - URL for child nodes (tree XML) |
57
|
|
|
* 'expand' - the action to return XML for the subtree |
58
|
|
|
* 'nodata' - message to display when node has no children |
59
|
|
|
* @param $section The section where the branch is linked in the tree |
|
|
|
|
60
|
|
|
* @param mixed $print |
61
|
|
|
*/ |
62
|
|
|
public function printTree(&$_treedata, &$attrs, $section, $print = true) |
63
|
|
|
{ |
64
|
|
|
$plugin_manager = $this->plugin_manager; |
65
|
|
|
|
66
|
|
|
$treedata = []; |
67
|
|
|
|
68
|
|
|
if ($_treedata->recordCount() > 0) { |
69
|
|
|
while (!$_treedata->EOF) { |
70
|
|
|
$treedata[] = $_treedata->fields; |
71
|
|
|
$_treedata->moveNext(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$tree_params = [ |
76
|
|
|
'treedata' => &$treedata, |
77
|
|
|
'attrs' => &$attrs, |
78
|
|
|
'section' => $section, |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
$plugin_manager->do_hook('tree', $tree_params); |
82
|
|
|
|
83
|
|
|
if (isset($_REQUEST['json'])) { |
84
|
|
|
return $this->printTreeJSON($treedata, $attrs, $print); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->printTreeXML($treedata, $attrs, $print); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** Produce XML data for the browser tree |
|
|
|
|
91
|
|
|
* @param $treedata a set of records to populate the tree |
92
|
|
|
* @param $attrs Attributes for tree items |
93
|
|
|
* 'text' - the text for the tree node |
94
|
|
|
* 'icon' - an icon for node |
95
|
|
|
* 'openIcon' - an alternative icon when the node is expanded |
96
|
|
|
* 'toolTip' - tool tip text for the node |
97
|
|
|
* 'action' - URL to visit when single clicking the node |
98
|
|
|
* 'iconAction' - URL to visit when single clicking the icon node |
99
|
|
|
* 'branch' - URL for child nodes (tree XML) |
100
|
|
|
* 'expand' - the action to return XML for the subtree |
101
|
|
|
* 'nodata' - message to display when node has no children |
102
|
|
|
* @param mixed $print |
103
|
|
|
*/ |
104
|
|
|
private function printTreeXML(&$treedata, &$attrs, $print = true) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
$lang = $this->lang; |
107
|
|
|
|
108
|
|
|
$tree_xml = '<?xml version="1.0" encoding="UTF-8"?><tree>'; |
109
|
|
|
|
110
|
|
|
if (count($treedata) > 0) { |
111
|
|
|
foreach ($treedata as $rec) { |
112
|
|
|
$icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['icon'], $rec)); |
113
|
|
|
if (!empty($attrs['openicon'])) { |
114
|
|
|
$icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['openIcon'], $rec)); |
115
|
|
|
} |
116
|
|
|
$tree_xml .= '<tree>'; |
117
|
|
|
|
118
|
|
|
$text_xml = Decorator::value_xml_attr_tag('text', $attrs['text'], $rec); |
119
|
|
|
$action_xml = Decorator::value_xml_attr_tag('action', $attrs['action'], $rec); |
120
|
|
|
$src_xml = Decorator::value_xml_attr_tag('src', $attrs['branch'], $rec); |
121
|
|
|
$icon_xml = Decorator::value_xml_attr_tag('icon', $icon, $rec); |
122
|
|
|
$iconaction_xml = Decorator::value_xml_attr_tag('iconaction', $attrs['iconAction'], $rec); |
123
|
|
|
$openicon_xml = Decorator::value_xml_attr_tag('openicon', $icon, $rec); |
124
|
|
|
$tooltip_xml = Decorator::value_xml_attr_tag('tooltip', $attrs['toolTip'], $rec); |
125
|
|
|
|
126
|
|
|
$tree_xml .= $text_xml; |
127
|
|
|
$tree_xml .= $action_xml; |
128
|
|
|
$tree_xml .= $src_xml; |
129
|
|
|
$tree_xml .= $icon_xml; |
130
|
|
|
$tree_xml .= $iconaction_xml; |
131
|
|
|
$tree_xml .= $openicon_xml; |
132
|
|
|
$tree_xml .= $tooltip_xml; |
133
|
|
|
|
134
|
|
|
$tree_xml .= '</tree>'; |
135
|
|
|
} |
136
|
|
|
} else { |
137
|
|
|
$msg = isset($attrs['nodata']) ? $attrs['nodata'] : $lang['strnoobjects']; |
138
|
|
|
$tree_xml .= "<tree text=\"{$msg}\" onaction=\"tree.getSelected().getParent().reload()\" icon=\"" . $this->misc->icon('ObjectNotFound') . '" />' . "\n"; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$tree_xml .= '</tree>'; |
142
|
|
|
if (true === $print) { |
143
|
|
|
if (null === $this->container->requestobj->getAttribute('route')) { |
144
|
|
|
header('Content-Type: text/xml; charset=UTF-8'); |
145
|
|
|
header('Cache-Control: no-cache'); |
146
|
|
|
echo $tree_xml; |
147
|
|
|
} else { |
148
|
|
|
return $this |
149
|
|
|
->container |
150
|
|
|
->responseobj |
151
|
|
|
->withStatus(200) |
152
|
|
|
->withHeader('Content-Type', 'text/xml; charset=UTF-8') |
153
|
|
|
->write($tree_xml); |
154
|
|
|
} |
155
|
|
|
} else { |
156
|
|
|
return $tree_xml; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** Produce XML data for the browser tree |
|
|
|
|
161
|
|
|
* @param $treedata a set of records to populate the tree |
162
|
|
|
* @param $attrs Attributes for tree items |
163
|
|
|
* 'text' - the text for the tree node |
164
|
|
|
* 'icon' - an icon for node |
165
|
|
|
* 'openIcon' - an alternative icon when the node is expanded |
166
|
|
|
* 'toolTip' - tool tip text for the node |
167
|
|
|
* 'action' - URL to visit when single clicking the node |
168
|
|
|
* 'iconAction' - URL to visit when single clicking the icon node |
169
|
|
|
* 'branch' - URL for child nodes (tree XML) |
170
|
|
|
* 'expand' - the action to return XML for the subtree |
171
|
|
|
* 'nodata' - message to display when node has no children |
172
|
|
|
* @param mixed $print |
173
|
|
|
*/ |
174
|
|
|
private function printTreeJSON(&$treedata, &$attrs, $print = true) |
|
|
|
|
175
|
|
|
{ |
176
|
|
|
$lang = $this->lang; |
|
|
|
|
177
|
|
|
|
178
|
|
|
$parent = []; |
179
|
|
|
|
180
|
|
|
if (isset($attrs['is_root'])) { |
181
|
|
|
$parent = [ |
182
|
|
|
'id' => 'root', |
183
|
|
|
'children' => true, |
184
|
|
|
'icon' => \SUBFOLDER . '/images/themes/default/Servers.png', |
185
|
|
|
'state' => ['opened' => true], |
186
|
|
|
'url' => str_replace('//', '/', \SUBFOLDER . '/src/views/servers?action=tree'), |
187
|
|
|
'text' => '<a href="' . str_replace('//', '/', \SUBFOLDER . '/src/views/servers') . '" target="detail">Servers</a>', |
188
|
|
|
]; |
189
|
|
|
} elseif (count($treedata) > 0) { |
190
|
|
|
foreach ($treedata as $rec) { |
191
|
|
|
$icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['icon'], $rec)); |
192
|
|
|
if (!empty($attrs['openicon'])) { |
193
|
|
|
$icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['openIcon'], $rec)); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
$tree = [ |
197
|
|
|
'text' => Decorator::get_sanitized_value($attrs['text'], $rec), |
198
|
|
|
'id' => Decorator::get_sanitized_value($attrs['action'], $rec), |
199
|
|
|
'icon' => Decorator::get_sanitized_value($icon, $rec), |
200
|
|
|
'iconaction' => Decorator::get_sanitized_value($attrs['iconAction'], $rec), |
201
|
|
|
'openicon' => Decorator::get_sanitized_value($icon, $rec), |
202
|
|
|
'tooltip' => Decorator::get_sanitized_value($attrs['toolTip'], $rec), |
203
|
|
|
'children' => false, |
204
|
|
|
]; |
205
|
|
|
$url = Decorator::get_sanitized_value($attrs['branch'], $rec); |
206
|
|
|
if ($url && strpos($url, '/src/views') === false) { |
207
|
|
|
$url = str_replace('//', '/', \SUBFOLDER . '/src/views/' . $url); |
208
|
|
|
} |
209
|
|
|
if ($url) { |
210
|
|
|
$tree['url'] = $url; |
211
|
|
|
$tree['children'] = true; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
$tree['text'] = '<a href="' . $tree['id'] . '" target="detail">' . $tree['text'] . '</a>'; |
215
|
|
|
|
216
|
|
|
$parent[] = $tree; |
217
|
|
|
} |
218
|
|
|
} else { |
219
|
|
|
$parent = ['children' => false]; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
if (true === $print) { |
223
|
|
|
if (null === $this->container->requestobj->getAttribute('route')) { |
224
|
|
|
header('Content-Type: text/xml; charset=UTF-8'); |
225
|
|
|
header('Cache-Control: no-cache'); |
226
|
|
|
echo $tree_xml; |
|
|
|
|
227
|
|
|
} else { |
228
|
|
|
if (isset($_REQUEST['children'])) { |
229
|
|
|
$children = $parent; |
230
|
|
|
$parent = ['children' => $children]; |
231
|
|
|
} |
232
|
|
|
return $this |
233
|
|
|
->container |
234
|
|
|
->responseobj |
235
|
|
|
->withStatus(200) |
236
|
|
|
->withJson($parent); |
237
|
|
|
} |
238
|
|
|
} else { |
239
|
|
|
return $tree_xml; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function adjustTabsForTree(&$tabs) |
244
|
|
|
{ |
245
|
|
|
foreach ($tabs as $i => $tab) { |
246
|
|
|
if ((isset($tab['hide']) && true === $tab['hide']) || (isset($tab['tree']) && false === $tab['tree'])) { |
247
|
|
|
unset($tabs[$i]); |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
return new \PHPPgAdmin\ArrayRecordSet($tabs); |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|