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