|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin v6.0.0-beta.45 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\XHtml; |
|
8
|
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Base HTMLController controller class. |
|
13
|
|
|
*/ |
|
14
|
|
|
class HTMLController |
|
15
|
|
|
{ |
|
16
|
|
|
use \PHPPgAdmin\Traits\HelperTrait; |
|
17
|
|
|
|
|
18
|
|
|
protected $container; |
|
19
|
|
|
public $form = ''; |
|
20
|
|
|
public $href = ''; |
|
21
|
|
|
public $lang = []; |
|
22
|
|
|
public $action = ''; |
|
23
|
|
|
public $controller_name = 'HTMLController'; |
|
24
|
|
|
public $controller_title = 'html'; |
|
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->view = $container->get('view'); |
|
32
|
|
|
$this->plugin_manager = $container->get('plugin_manager'); |
|
33
|
|
|
$this->appName = $container->get('settings')['appName']; |
|
34
|
|
|
$this->appVersion = $container->get('settings')['appVersion']; |
|
35
|
|
|
$this->appLangFiles = $container->get('appLangFiles'); |
|
36
|
|
|
$this->misc = $container->get('misc'); |
|
37
|
|
|
$this->conf = $this->misc->getConf(); |
|
38
|
|
|
$this->appThemes = $container->get('appThemes'); |
|
39
|
|
|
$this->action = $container->get('action'); |
|
40
|
|
|
|
|
41
|
|
|
if (null !== $controller_name) { |
|
42
|
|
|
$this->controller_name = $controller_name; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
//\PC::debug($this->_name, 'instanced controller'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getContainer() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->container; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns URL given an action associative array. |
|
55
|
|
|
* NOTE: this function does not html-escape, only url-escape. |
|
56
|
|
|
* |
|
57
|
|
|
* @param $action An associative array of the follow properties: |
|
|
|
|
|
|
58
|
|
|
* 'url' => The first part of the URL (before the ?) |
|
59
|
|
|
* 'urlvars' => Associative array of (URL variable => field name) |
|
|
|
|
|
|
60
|
|
|
* these are appended to the URL |
|
61
|
|
|
* @param $fields field data from which 'urlfield' and 'vars' are obtained |
|
62
|
|
|
* @param null|mixed $from |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function getActionUrl(&$action, &$fields, $from = null) |
|
65
|
|
|
{ |
|
66
|
|
|
if (null === $from) { |
|
67
|
|
|
$from = __METHOD__; |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$url = Decorator::get_sanitized_value($action['url'], $fields); |
|
71
|
|
|
|
|
72
|
|
|
if (false === $url) { |
|
73
|
|
|
return ''; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if (!empty($action['urlvars'])) { |
|
77
|
|
|
$urlvars = Decorator::get_sanitized_value($action['urlvars'], $fields); |
|
78
|
|
|
} else { |
|
79
|
|
|
$urlvars = []; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// set server, database and schema parameter if not presents |
|
83
|
|
|
if (isset($urlvars['subject'])) { |
|
84
|
|
|
$subject = Decorator::get_sanitized_value($urlvars['subject'], $fields); |
|
85
|
|
|
} else { |
|
86
|
|
|
$subject = ''; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$server = $this->container->server; |
|
90
|
|
|
$database = $this->container->database; |
|
91
|
|
|
$schema = $this->container->schema; |
|
92
|
|
|
|
|
93
|
|
|
/* |
|
94
|
|
|
$server = $this->container->has('server') ? $this->container->server : $_REQUEST['server']; |
|
95
|
|
|
$database = $this->container->has('database') ? $this->container->database : $_REQUEST['database']; |
|
96
|
|
|
$schema = $this->container->has('schema') ? $this->container->schema : $_REQUEST['schema']; |
|
97
|
|
|
*/ |
|
98
|
|
|
|
|
99
|
|
|
//$this->prtrace('server', $server, 'database', $database, 'schema', $schema); |
|
100
|
|
|
|
|
101
|
|
|
if ($server && !isset($urlvars['server']) && 'root' != $subject) { |
|
102
|
|
|
$urlvars['server'] = $server; |
|
103
|
|
|
if ($database && !isset($urlvars['database']) && 'server' != $subject) { |
|
104
|
|
|
$urlvars['database'] = $database; |
|
105
|
|
|
if ($schema && !isset($urlvars['schema']) && 'database' != $subject) { |
|
106
|
|
|
$urlvars['schema'] = $schema; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$sep = '?'; |
|
112
|
|
|
|
|
113
|
|
|
ksort($urlvars); |
|
114
|
|
|
foreach ($urlvars as $var => $varfield) { |
|
115
|
|
|
$url .= $sep.Decorator::value_url($var, $fields).'='.Decorator::value_url($varfield, $fields); |
|
116
|
|
|
$sep = '&'; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $url; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Display a link. |
|
124
|
|
|
* |
|
125
|
|
|
* @param $link An associative array of link parameters to print |
|
126
|
|
|
* link = array( |
|
127
|
|
|
* 'attr' => array( // list of A tag attribute |
|
128
|
|
|
* 'attrname' => attribute value |
|
129
|
|
|
* ... |
|
130
|
|
|
* ), |
|
131
|
|
|
* 'content' => The link text |
|
132
|
|
|
* 'fields' => (optionnal) the data from which content and attr's values are obtained |
|
133
|
|
|
* ); |
|
134
|
|
|
* the special attribute 'href' might be a string or an array. If href is an array it |
|
135
|
|
|
* will be generated by getActionUrl. See getActionUrl comment for array format. |
|
136
|
|
|
* @param mixed $do_print |
|
137
|
|
|
* @param null|mixed $from |
|
138
|
|
|
*/ |
|
139
|
|
|
public function printLink($link, $do_print = true, $from = null) |
|
140
|
|
|
{ |
|
141
|
|
|
if (!isset($link['fields'])) { |
|
142
|
|
|
$link['fields'] = $_REQUEST; |
|
143
|
|
|
} |
|
144
|
|
|
if (null === $from || false === $from) { |
|
145
|
|
|
$from = __METHOD__; |
|
146
|
|
|
} |
|
147
|
|
|
$tag = '<a '; |
|
148
|
|
|
foreach ($link['attr'] as $attr => $value) { |
|
149
|
|
|
if ('href' == $attr and is_array($value)) { |
|
150
|
|
|
$tag .= 'href="'.htmlentities($this->getActionUrl($value, $link['fields'], $from)).'" '; |
|
151
|
|
|
} else { |
|
152
|
|
|
$tag .= htmlentities($attr).'="'.Decorator::get_sanitized_value($value, $link['fields'], 'html').'" '; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
$tag .= '>'.Decorator::get_sanitized_value($link['content'], $link['fields'], 'html')."</a>\n"; |
|
156
|
|
|
|
|
157
|
|
|
if ($do_print) { |
|
158
|
|
|
echo $tag; |
|
159
|
|
|
} else { |
|
160
|
|
|
return $tag; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Display a list of links. |
|
166
|
|
|
* |
|
167
|
|
|
* @param array $links An associative array of links to print. See printLink function for |
|
168
|
|
|
* the links array format. |
|
169
|
|
|
* @param string $class an optional HTML class or list of classes seprated by a space |
|
170
|
|
|
* WARNING: This field is NOT escaped! No user should be able to inject something here, use with care |
|
171
|
|
|
* @param bool $do_print true to echo, false to return |
|
172
|
|
|
* @param null|string $from which method is calling this one |
|
173
|
|
|
*/ |
|
174
|
|
|
protected function printLinksList($links, $class = '', $do_print = true, $from = null) |
|
175
|
|
|
{ |
|
176
|
|
|
if (null === $from || false === $from) { |
|
177
|
|
|
$from = __METHOD__; |
|
178
|
|
|
} |
|
179
|
|
|
$list_html = "<ul class=\"{$class}\">\n"; |
|
180
|
|
|
foreach ($links as $link) { |
|
181
|
|
|
if ($from === 'PHPPgAdmin\Controller\BaseController::printNavLinks') { |
|
182
|
|
|
$this->prtrace($link); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$list_html .= "\t<li>"; |
|
186
|
|
|
$list_html .= str_replace('.php', '', $this->printLink($link, false, $from)); |
|
187
|
|
|
$list_html .= "</li>\n"; |
|
188
|
|
|
} |
|
189
|
|
|
$list_html .= "</ul>\n"; |
|
190
|
|
|
if ($do_print) { |
|
191
|
|
|
echo $list_html; |
|
192
|
|
|
} else { |
|
193
|
|
|
return $list_html; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Prints a combox box. |
|
199
|
|
|
* |
|
200
|
|
|
* @param $arrOptions associative array storing options and values of combo should be Option => Value |
|
|
|
|
|
|
201
|
|
|
* @param $szName string to specify the name of the form element |
|
202
|
|
|
* @param bool $bBlankEntry |
|
203
|
|
|
* @param string $szDefault |
|
204
|
|
|
* @param bool $bMultiple |
|
205
|
|
|
* @param int $iSize |
|
206
|
|
|
* |
|
207
|
|
|
* @return string with the generated HTML select box |
|
208
|
|
|
* |
|
209
|
|
|
* @internal param $ (optional) $bBlankEntry bool to specify whether or not we want a blank selection |
|
210
|
|
|
* @internal param $ (optional) $szDefault string to specify the default VALUE selected |
|
211
|
|
|
* @internal param $ (optional) $bMultiple bool to specify whether or not we want a multi select combo box |
|
212
|
|
|
* @internal param $ (optional) $iSize int to specify the size IF a multi select combo |
|
213
|
|
|
*/ |
|
214
|
|
|
public static function printCombo(&$arrOptions, $szName, $bBlankEntry = true, $szDefault = '', $bMultiple = false, $iSize = 10) |
|
215
|
|
|
{ |
|
216
|
|
|
$htmlOut = ''; |
|
217
|
|
|
if ($bMultiple) { |
|
218
|
|
|
// If multiple select combo |
|
219
|
|
|
$htmlOut .= "<select rel=\"printCombo\" name=\"${szName}\" id=\"${szName}\" multiple=\"multiple\" size=\"${iSize}\">"."\n"; |
|
220
|
|
|
} else { |
|
221
|
|
|
$htmlOut .= "<select rel=\"printCombo\" class=\"select2\" name=\"${szName}\" id=\"${szName}\">"."\n"; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
if ($bBlankEntry) { |
|
225
|
|
|
$htmlOut .= "<option value=\"\"></option>\n"; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
foreach ($arrOptions as $curKey => $curVal) { |
|
229
|
|
|
$curVal = htmlspecialchars($curVal); |
|
230
|
|
|
$curKey = htmlspecialchars($curKey); |
|
231
|
|
|
if ($curVal == $szDefault) { |
|
232
|
|
|
$htmlOut .= "<option value=\"${curVal}\" selected=\"selected\">${curKey}</option>\n"; |
|
233
|
|
|
} else { |
|
234
|
|
|
$htmlOut .= "<option value=\"${curVal}\">${curKey}</option>\n"; |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
$htmlOut .= "</select>\n"; |
|
238
|
|
|
|
|
239
|
|
|
return $htmlOut; |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|