|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin v6.0.0-beta.33 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Controller; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Base controller class. |
|
11
|
|
|
* |
|
12
|
|
|
* @package PHPPgAdmin |
|
13
|
|
|
*/ |
|
14
|
|
|
class SqleditController extends BaseController |
|
15
|
|
|
{ |
|
16
|
|
|
public $controller_name = 'SqleditController'; |
|
17
|
|
|
public $query = ''; |
|
18
|
|
|
public $subject = ''; |
|
19
|
|
|
public $start_time; |
|
20
|
|
|
public $duration; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Default method to render the controller according to the action parameter. |
|
24
|
|
|
*/ |
|
25
|
|
|
public function render() |
|
26
|
|
|
{ |
|
27
|
|
|
$lang = $this->lang; |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
$action = $this->action; |
|
30
|
|
|
|
|
31
|
|
|
switch ($action) { |
|
32
|
|
|
case 'find': |
|
33
|
|
|
$title = $this->lang['strfind']; |
|
34
|
|
|
$body_text = $this->doFind(); |
|
35
|
|
|
|
|
36
|
|
|
break; |
|
37
|
|
|
case 'sql': |
|
38
|
|
|
default: |
|
39
|
|
|
$title = $this->lang['strsql']; |
|
40
|
|
|
$body_text = $this->doDefault(); |
|
41
|
|
|
|
|
42
|
|
|
break; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->setWindowName('sqledit'); |
|
46
|
|
|
|
|
47
|
|
|
$this->scripts = '<script type="text/javascript">window.inPopUp=true;</script>'; |
|
48
|
|
|
|
|
49
|
|
|
$this->printHeader($title, $this->scripts, true, 'header_sqledit.twig'); |
|
50
|
|
|
$this->printBody(true, 'sql_edit'); |
|
51
|
|
|
echo $body_text; |
|
52
|
|
|
|
|
53
|
|
|
$this->printFooter(true, 'footer_sqledit.twig'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Allow execution of arbitrary SQL statements on a database. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function doDefault() |
|
60
|
|
|
{ |
|
61
|
|
|
$lang = $this->lang; |
|
62
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
63
|
|
|
|
|
64
|
|
|
if (!isset($_SESSION['sqlquery'])) { |
|
65
|
|
|
$_SESSION['sqlquery'] = ''; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if (!isset($_REQUEST['search_path'])) { |
|
69
|
|
|
$_REQUEST['search_path'] = implode(',', $data->getSearchPath()); |
|
70
|
|
|
} |
|
71
|
|
|
$search_path = htmlspecialchars($_REQUEST['search_path']); |
|
72
|
|
|
$sqlquery = htmlspecialchars($_SESSION['sqlquery']); |
|
73
|
|
|
|
|
74
|
|
|
$default_html = $this->printTabs($this->misc->getNavTabs('popup'), 'sql', false); |
|
75
|
|
|
|
|
76
|
|
|
$default_html .= '<form action="' . \SUBFOLDER . '/src/views/sql" method="post" enctype="multipart/form-data" class="sqlform" id="sqlform" target="detail">'; |
|
77
|
|
|
$default_html .= "\n"; |
|
78
|
|
|
$default_html .= $this->_printConnection('sql'); |
|
79
|
|
|
|
|
80
|
|
|
$default_html .= "\n"; |
|
81
|
|
|
|
|
82
|
|
|
$default_html .= ' <div class="searchpath">'; |
|
83
|
|
|
$default_html .= '<label>'; |
|
84
|
|
|
$default_html .= $this->misc->printHelp($lang['strsearchpath'], 'pg.schema.search_path', false); |
|
85
|
|
|
|
|
86
|
|
|
$default_html .= ': <input type="text" name="search_path" size="45" value="' . $search_path . '" />'; |
|
87
|
|
|
$default_html .= "</label>\n"; |
|
88
|
|
|
|
|
89
|
|
|
$default_html .= "</div>\n"; |
|
90
|
|
|
|
|
91
|
|
|
$default_html .= '<div id="queryedition" style="padding:1%;width:98%;float:left;">'; |
|
92
|
|
|
$default_html .= "\n"; |
|
93
|
|
|
$default_html .= '<textarea style="width:98%;" rows="10" cols="50" name="query" id="query" resizable="true">' . $sqlquery . '</textarea>'; |
|
94
|
|
|
$default_html .= "\n"; |
|
95
|
|
|
$default_html .= "</div>\n"; |
|
96
|
|
|
|
|
97
|
|
|
$default_html .= '<div class="sqledit_bottom_inputs" >'; |
|
98
|
|
|
|
|
99
|
|
|
if (ini_get('file_uploads')) { |
|
100
|
|
|
// Don't show upload option if max size of uploads is zero |
|
101
|
|
|
$max_size = $this->misc->inisizeToBytes(ini_get('upload_max_filesize')); |
|
102
|
|
|
if (is_double($max_size) && $max_size > 0) { |
|
103
|
|
|
$default_html .= '<p class="upload_sql_script">'; |
|
104
|
|
|
$default_html .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max_size . '" />'; |
|
105
|
|
|
$default_html .= "\n"; |
|
106
|
|
|
$default_html .= '<label for="script">' . $lang['struploadscript'] . '</label>'; |
|
107
|
|
|
$default_html .= ' <input class="btn btn-small" id="script" name="script" type="file" /></p>'; |
|
108
|
|
|
$default_html .= "</p>\n"; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// Check that file uploads are enabled |
|
113
|
|
|
$checked = (isset($_REQUEST['paginate']) ? ' checked="checked"' : ''); |
|
114
|
|
|
|
|
115
|
|
|
$default_html .= '<p><input type="submit" class="btn btn-small" name="execute" accesskey="r" value="' . $lang['strexecute'] . '" />'; |
|
116
|
|
|
$default_html .= "\n"; |
|
117
|
|
|
|
|
118
|
|
|
$default_html .= '<input type="reset" class="btn btn-small" accesskey="q" value="' . $lang['strreset'] . '" /></p>'; |
|
119
|
|
|
$default_html .= "\n"; |
|
120
|
|
|
|
|
121
|
|
|
$default_html .= '<p>'; |
|
122
|
|
|
$default_html .= '<label for="paginate">'; |
|
123
|
|
|
$default_html .= '<input type="checkbox" id="paginate" name="paginate"' . $checked . ' /> ' . $lang['strpaginate'] . ' '; |
|
124
|
|
|
$default_html .= "</label>\n"; |
|
125
|
|
|
$default_html .= "</p>\n"; |
|
126
|
|
|
|
|
127
|
|
|
$default_html .= "</div>\n"; |
|
128
|
|
|
$default_html .= '</form>'; |
|
129
|
|
|
$default_html .= "\n"; |
|
130
|
|
|
|
|
131
|
|
|
// Default focus |
|
132
|
|
|
//$this->setFocus('forms[0].query'); |
|
133
|
|
|
return $default_html; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Private function to display server and list of databases. |
|
138
|
|
|
* |
|
139
|
|
|
* @param mixed $action |
|
140
|
|
|
*/ |
|
141
|
|
|
public function _printConnection($action) |
|
|
|
|
|
|
142
|
|
|
{ |
|
143
|
|
|
$lang = $this->lang; |
|
|
|
|
|
|
144
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
// The javascript action on the select box reloads the |
|
147
|
|
|
// popup whenever the server or database is changed. |
|
148
|
|
|
// This ensures that the correct page encoding is used. |
|
149
|
|
|
$onchange = "onchange=\"location.href='" . \SUBFOLDER . '/sqledit/' . |
|
150
|
|
|
urlencode($action) . "?server=' + encodeURI(server.options[server.selectedIndex].value) + '&database=' + encodeURI(database.options[database.selectedIndex].value) + "; |
|
151
|
|
|
|
|
152
|
|
|
// The exact URL to reload to is different between SQL and Find mode, however. |
|
153
|
|
|
if ('find' == $action) { |
|
154
|
|
|
$onchange .= "'&term=' + encodeURI(term.value) + '&filter=' + encodeURI(filter.value) + '&'\""; |
|
155
|
|
|
} else { |
|
156
|
|
|
$onchange .= "'&query=' + encodeURI(query.value) + '&search_path=' + encodeURI(search_path.value) + (paginate.checked ? '&paginate=on' : '') + '&'\""; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
return $this->misc->printConnection($onchange, false); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Searches for a named database object. |
|
164
|
|
|
*/ |
|
165
|
|
|
public function doFind() |
|
166
|
|
|
{ |
|
167
|
|
|
$lang = $this->lang; |
|
168
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
169
|
|
|
|
|
170
|
|
|
if (!isset($_REQUEST['term'])) { |
|
171
|
|
|
$_REQUEST['term'] = ''; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
if (!isset($_REQUEST['filter'])) { |
|
175
|
|
|
$_REQUEST['filter'] = ''; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
$default_html = $this->printTabs($this->misc->getNavTabs('popup'), 'find', false); |
|
179
|
|
|
|
|
180
|
|
|
$default_html .= "<form action=\"database\" method=\"post\" target=\"detail\">\n"; |
|
181
|
|
|
$default_html .= $this->_printConnection('find'); |
|
182
|
|
|
$default_html .= '<p><input class="focusme" name="term" value="' . htmlspecialchars($_REQUEST['term']) . "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n"; |
|
183
|
|
|
|
|
184
|
|
|
// Output list of filters. This is complex due to all the 'has' and 'conf' feature possibilities |
|
185
|
|
|
$default_html .= "<select name=\"filter\">\n"; |
|
186
|
|
|
$default_html .= "\t<option value=\"\"" . ('' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strallobjects']}</option>\n"; |
|
187
|
|
|
$default_html .= "\t<option value=\"SCHEMA\"" . ('SCHEMA' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strschemas']}</option>\n"; |
|
188
|
|
|
$default_html .= "\t<option value=\"TABLE\"" . ('TABLE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strtables']}</option>\n"; |
|
189
|
|
|
$default_html .= "\t<option value=\"VIEW\"" . ('VIEW' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strviews']}</option>\n"; |
|
190
|
|
|
$default_html .= "\t<option value=\"SEQUENCE\"" . ('SEQUENCE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strsequences']}</option>\n"; |
|
191
|
|
|
$default_html .= "\t<option value=\"COLUMN\"" . ('COLUMN' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strcolumns']}</option>\n"; |
|
192
|
|
|
$default_html .= "\t<option value=\"RULE\"" . ('RULE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strrules']}</option>\n"; |
|
193
|
|
|
$default_html .= "\t<option value=\"INDEX\"" . ('INDEX' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strindexes']}</option>\n"; |
|
194
|
|
|
$default_html .= "\t<option value=\"TRIGGER\"" . ('TRIGGER' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strtriggers']}</option>\n"; |
|
195
|
|
|
$default_html .= "\t<option value=\"CONSTRAINT\"" . ('CONSTRAINT' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strconstraints']}</option>\n"; |
|
196
|
|
|
$default_html .= "\t<option value=\"FUNCTION\"" . ('FUNCTION' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strfunctions']}</option>\n"; |
|
197
|
|
|
$default_html .= "\t<option value=\"DOMAIN\"" . ('DOMAIN' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strdomains']}</option>\n"; |
|
198
|
|
|
if ($this->conf['show_advanced']) { |
|
199
|
|
|
$default_html .= "\t<option value=\"AGGREGATE\"" . ('AGGREGATE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['straggregates']}</option>\n"; |
|
200
|
|
|
$default_html .= "\t<option value=\"TYPE\"" . ('TYPE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strtypes']}</option>\n"; |
|
201
|
|
|
$default_html .= "\t<option value=\"OPERATOR\"" . ('OPERATOR' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['stroperators']}</option>\n"; |
|
202
|
|
|
$default_html .= "\t<option value=\"OPCLASS\"" . ('OPCLASS' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['stropclasses']}</option>\n"; |
|
203
|
|
|
$default_html .= "\t<option value=\"CONVERSION\"" . ('CONVERSION' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strconversions']}</option>\n"; |
|
204
|
|
|
$default_html .= "\t<option value=\"LANGUAGE\"" . ('LANGUAGE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strlanguages']}</option>\n"; |
|
205
|
|
|
} |
|
206
|
|
|
$default_html .= "</select>\n"; |
|
207
|
|
|
|
|
208
|
|
|
$default_html .= "<input type=\"submit\" value=\"{$lang['strfind']}\" />\n"; |
|
209
|
|
|
$default_html .= "<input type=\"hidden\" name=\"action\" value=\"find\" /></p>\n"; |
|
210
|
|
|
$default_html .= "</form>\n"; |
|
211
|
|
|
|
|
212
|
|
|
// Default focus |
|
213
|
|
|
$this->setFocus('forms[0].term'); |
|
214
|
|
|
|
|
215
|
|
|
return $default_html; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|