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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
<?php
/**
* PHPPgAdmin v6.0.0-RC8
*/
namespace PHPPgAdmin\XHtml;
use PHPPgAdmin\Decorators\Decorator;
/**
* Base HTMLController controller class.
*/
class HTMLController
{
use \PHPPgAdmin\Traits\HelperTrait;
protected $container;
public $form = '';
public $href = '';
public $lang = [];
public $action = '';
public $controller_name = 'HTMLController';
public $controller_title = 'html';
// Constructor
public function __construct(\Slim\Container $container, $controller_name = null)
{
$this->container = $container;
$this->lang = $container->get('lang');
$this->view = $container->get('view');
$this->appName = $container->get('settings')['appName'];
$this->appVersion = $container->get('settings')['appVersion'];
$this->appLangFiles = $container->get('appLangFiles');
$this->misc = $container->get('misc');
$this->conf = $this->misc->getConf();
$this->appThemes = $container->get('appThemes');
$this->action = $container->get('action');
if (null !== $controller_name) {
$this->controller_name = $controller_name;
}
}
public function getContainer()
{
return $this->container;
}
/**
* Returns URL given an action associative array.
* NOTE: this function does not html-escape, only url-escape.
*
* @param array $action An associative array of the follow properties:
* 'url' => The first part of the URL (before the ?)
* 'urlvars' => Associative array of (URL variable => field name)
* these are appended to the URL
* @param array $fields field data from which 'urlfield' and 'vars' are obtained
* @param null|mixed $from
*/
protected function getActionUrl(&$action, &$fields, $from = null)
{
$from = $from ? $from : __METHOD__;
$url = Decorator::get_sanitized_value($action['url'], $fields);
if (false === $url) {
return '';
}
if (!empty($action['urlvars'])) {
$urlvars = Decorator::get_sanitized_value($action['urlvars'], $fields);
} else {
$urlvars = [];
}
// set server, database and schema parameter if not presents
if (isset($urlvars['subject'])) {
$subject = Decorator::get_sanitized_value($urlvars['subject'], $fields);
} else {
$subject = '';
}
$server = $this->container->server;
$database = $this->container->database;
$schema = $this->container->schema;
/*
$server = $this->container->has('server') ? $this->container->server : $_REQUEST['server'];
$database = $this->container->has('database') ? $this->container->database : $_REQUEST['database'];
$schema = $this->container->has('schema') ? $this->container->schema : $_REQUEST['schema'];
*/
//$this->prtrace('server', $server, 'database', $database, 'schema', $schema);
if ($server && !isset($urlvars['server']) && 'root' != $subject) {
$urlvars['server'] = $server;
if ($database && !isset($urlvars['database']) && 'server' != $subject) {
$urlvars['database'] = $database;
if ($schema && !isset($urlvars['schema']) && 'database' != $subject) {
$urlvars['schema'] = $schema;
}
}
}
$sep = '?';
ksort($urlvars);
foreach ($urlvars as $var => $varfield) {
$url .= $sep.Decorator::value_url($var, $fields).'='.Decorator::value_url($varfield, $fields);
$sep = '&';
}
return $url;
}
/**
* Display a link.
*
* @param array $link An associative array of link parameters to print
* link = array(
* 'attr' => array( // list of A tag attribute
* 'attrname' => attribute value
* ...
* ),
* 'content' => The link text
* 'fields' => (optionnal) the data from which content and attr's values are obtained
* );
* the special attribute 'href' might be a string or an array. If href is an array it
* will be generated by getActionUrl. See getActionUrl comment for array format.
* @param mixed $do_print
* @param null|mixed $from
*/
public function printLink($link, $do_print = true, $from = null)
{
if (!isset($link['fields'])) {
$link['fields'] = $_REQUEST;
}
$from = $from ? $from : __METHOD__;
$tag = '<a ';
foreach ($link['attr'] as $attr => $value) {
if ('href' == $attr and is_array($value)) {
$tag .= 'href="'.htmlentities($this->getActionUrl($value, $link['fields'], $from)).'" ';
} else {
$tag .= htmlentities($attr).'="'.Decorator::get_sanitized_value($value, $link['fields'], 'html').'" ';
}
}
$tag .= '>'.Decorator::get_sanitized_value($link['content'], $link['fields'], 'html').'</a>'.PHP_EOL;
if ($do_print) {
echo $tag;
} else {
return $tag;
}
}
/**
* Display a list of links.
*
* @param array $links An associative array of links to print. See printLink function for
* the links array format.
* @param string $class an optional HTML class or list of classes seprated by a space
* WARNING: This field is NOT escaped! No user should be able to inject something here, use with care
* @param bool $do_print true to echo, false to return
* @param null|string $from which method is calling this one
*/
protected function printLinksList($links, $class = '', $do_print = true, $from = null)
{
if (null === $from || false === $from) {
$from = __METHOD__;
}
$list_html = "<ul class=\"{$class}\">".PHP_EOL;
foreach ($links as $link) {
if ($from === 'PHPPgAdmin\Controller\BaseController::printNavLinks') {
//$this->prtrace($link);
}
$list_html .= "\t<li>";
$list_html .= str_replace('.php', '', $this->printLink($link, false, $from));
$list_html .= '</li>'.PHP_EOL;
}
$list_html .= '</ul>'.PHP_EOL;
if ($do_print) {
echo $list_html;
} else {
return $list_html;
}
}
/**
* Prints a combox box.
*
* @param array $arrOptions associative array storing options and values of combo should be Option => Value
* @param string $szName string to specify the name of the form element
* @param bool $bBlankEntry either to insert a blank option at the beggining of the combo
* @param string $szDefault the current selected value
* @param bool $bMultiple enable multible selection
* @param int $iSize combobox size
*
* @return string with the generated HTML select box
*
* @internal param $ (optional) $bBlankEntry bool to specify whether or not we want a blank selection
* @internal param $ (optional) $szDefault string to specify the default VALUE selected
* @internal param $ (optional) $bMultiple bool to specify whether or not we want a multi select combo box
* @internal param $ (optional) $iSize int to specify the size IF a multi select combo
*/
public static function printCombo(&$arrOptions, $szName, $bBlankEntry = true, $szDefault = '', $bMultiple = false, $iSize = 10)
{
$htmlOut = '';
if ($bMultiple) {
// If multiple select combo
$htmlOut .= "<select rel=\"printCombo\" name=\"${szName}\" id=\"${szName}\" multiple=\"multiple\" size=\"${iSize}\">".PHP_EOL;
} else {
$htmlOut .= "<select rel=\"printCombo\" name=\"${szName}\" id=\"${szName}\" class=\"select2\" >".PHP_EOL;
}
if ($bBlankEntry) {
$htmlOut .= '<option value=""></option>'.PHP_EOL;
}
foreach ($arrOptions as $curKey => $curVal) {
$curVal = htmlspecialchars($curVal);
$curKey = htmlspecialchars($curKey);
$htmlOut .= sprintf('<option value="%s" %s >%s</option>%s', $curVal, ($curVal == $szDefault) ? 'selected="selected"' : '', $curKey, PHP_EOL);
}
$htmlOut .= '</select>'.PHP_EOL;
return $htmlOut;
}
}
|