Passed
Push — master ( 965dbc...c6b243 )
by Felipe
11:26 queued 06:11
created

SqleditController::_printConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
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
    use ServersTrait;
1 ignored issue
show
introduced by
The trait PHPPgAdmin\Controller\ServersTrait requires some properties which are not provided by PHPPgAdmin\Controller\SqleditController: $EOF, $fields
Loading history...
17
18
    public $controller_name = 'SqleditController';
19
    public $query           = '';
20
    public $subject         = '';
21
    public $start_time;
22
    public $duration;
23
24
    /**
25
     * Default method to render the controller according to the action parameter.
26
     */
27
    public function render()
28
    {
29
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
30
31
        $action = $this->action;
32
33
        switch ($action) {
34
            case 'find':
35
                $title     = $this->lang['strfind'];
36
                $body_text = $this->doFind();
37
38
                break;
39
            case 'sql':
40
            default:
41
                $title     = $this->lang['strsql'];
42
                $body_text = $this->doDefault();
43
44
                break;
45
        }
46
47
        $this->setWindowName('sqledit');
48
49
        $this->scripts = '<script type="text/javascript">window.inPopUp=true;</script>';
50
51
        $this->printHeader($title, $this->scripts, true, 'header_sqledit.twig');
52
        $this->printBody(true, 'sql_edit');
53
        echo $body_text;
54
55
        $this->printFooter(true, 'footer_sqledit.twig');
56
    }
57
58
    /**
59
     * Allow execution of arbitrary SQL statements on a database.
60
     */
61
    public function doDefault()
62
    {
63
        $lang = $this->lang;
64
        $data = $this->misc->getDatabaseAccessor();
65
66
        if (!isset($_SESSION['sqlquery'])) {
67
            $_SESSION['sqlquery'] = '';
68
        }
69
70
        if (!isset($_REQUEST['search_path'])) {
71
            $_REQUEST['search_path'] = implode(',', $data->getSearchPath());
72
        }
73
        $search_path = htmlspecialchars($_REQUEST['search_path']);
74
        $sqlquery    = htmlspecialchars($_SESSION['sqlquery']);
75
76
        $default_html = $this->printTabs($this->misc->getNavTabs('popup'), 'sql', false);
77
78
        $default_html .= '<form action="' . \SUBFOLDER . '/src/views/sql" method="post" enctype="multipart/form-data" class="sqlform" id="sqlform" target="detail">';
79
        $default_html .= "\n";
80
        $default_html .= $this->printConnection('sql', false);
81
82
        $default_html .= "\n";
83
84
        $default_html .= ' <div class="searchpath">';
85
        $default_html .= '<label>';
86
        $default_html .= $this->misc->printHelp($lang['strsearchpath'], 'pg.schema.search_path', false);
87
88
        $default_html .= ': <input type="text" name="search_path" id="search_path" size="45" value="' . $search_path . '" />';
89
        $default_html .= "</label>\n";
90
91
        $default_html .= "</div>\n";
92
93
        $default_html .= '<div id="queryedition" style="padding:1%;width:98%;float:left;">';
94
        $default_html .= "\n";
95
        $default_html .= '<textarea style="width:98%;" rows="10" cols="50" name="query" id="query" resizable="true">' . $sqlquery . '</textarea>';
96
        $default_html .= "\n";
97
        $default_html .= "</div>\n";
98
99
        $default_html .= '<div class="sqledit_bottom_inputs" >';
100
101
        if (ini_get('file_uploads')) {
102
            // Don't show upload option if max size of uploads is zero
103
            $max_size = $this->misc->inisizeToBytes(ini_get('upload_max_filesize'));
104
            if (is_double($max_size) && $max_size > 0) {
105
                $default_html .= '<p class="upload_sql_script">';
106
                $default_html .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max_size . '" />';
107
                $default_html .= "\n";
108
                $default_html .= '<label for="script">' . $lang['struploadscript'] . '</label>';
109
                $default_html .= '&nbsp;&nbsp; <input class="btn btn-small"  id="script" name="script" type="file" /></p>';
110
                $default_html .= "</p>\n";
111
            }
112
        }
113
114
        // Check that file uploads are enabled
115
        $checked = (isset($_REQUEST['paginate']) ? ' checked="checked"' : '');
116
117
        $default_html .= '<p><input type="submit" class="btn btn-small" name="execute" accesskey="r" value="' . $lang['strexecute'] . '" />';
118
        $default_html .= "\n";
119
120
        $default_html .= '<input type="reset" class="btn btn-small"  accesskey="q" value="' . $lang['strreset'] . '" /></p>';
121
        $default_html .= "\n";
122
123
        $default_html .= '<p>';
124
        $default_html .= '<label for="paginate">';
125
        $default_html .= '<input type="checkbox" id="paginate" name="paginate"' . $checked . ' />&nbsp;' . $lang['strpaginate'] . '&nbsp;';
126
        $default_html .= "</label>\n";
127
        $default_html .= "</p>\n";
128
129
        $default_html .= "</div>\n";
130
        $default_html .= '</form>';
131
        $default_html .= "\n";
132
133
        // Default focus
134
        //$this->setFocus('forms[0].query');
135
        return $default_html;
136
    }
137
138
    /**
139
     * Searches for a named database object.
140
     */
141
    public function doFind()
142
    {
143
        $lang = $this->lang;
144
        $data = $this->misc->getDatabaseAccessor();
145
146
        if (!isset($_REQUEST['term'])) {
147
            $_REQUEST['term'] = '';
148
        }
149
150
        if (!isset($_REQUEST['filter'])) {
151
            $_REQUEST['filter'] = '';
152
        }
153
154
        $default_html = $this->printTabs($this->misc->getNavTabs('popup'), 'find', false);
155
156
        $default_html .= "<form action=\"database\" method=\"post\" target=\"detail\">\n";
157
        $default_html .= $this->printConnection('find', false);
158
        $default_html .= '<p><input class="focusme" name="term" id="term" value="' . htmlspecialchars($_REQUEST['term']) . "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n";
159
160
        // Output list of filters.  This is complex due to all the 'has' and 'conf' feature possibilities
161
        $default_html .= "<select id='filter' name=\"filter\">\n";
162
        $default_html .= "\t<option value=\"\"" . ('' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strallobjects']}</option>\n";
163
        $default_html .= "\t<option value=\"SCHEMA\"" . ('SCHEMA' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strschemas']}</option>\n";
164
        $default_html .= "\t<option value=\"TABLE\"" . ('TABLE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strtables']}</option>\n";
165
        $default_html .= "\t<option value=\"VIEW\"" . ('VIEW' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strviews']}</option>\n";
166
        $default_html .= "\t<option value=\"SEQUENCE\"" . ('SEQUENCE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strsequences']}</option>\n";
167
        $default_html .= "\t<option value=\"COLUMN\"" . ('COLUMN' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strcolumns']}</option>\n";
168
        $default_html .= "\t<option value=\"RULE\"" . ('RULE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strrules']}</option>\n";
169
        $default_html .= "\t<option value=\"INDEX\"" . ('INDEX' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strindexes']}</option>\n";
170
        $default_html .= "\t<option value=\"TRIGGER\"" . ('TRIGGER' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strtriggers']}</option>\n";
171
        $default_html .= "\t<option value=\"CONSTRAINT\"" . ('CONSTRAINT' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strconstraints']}</option>\n";
172
        $default_html .= "\t<option value=\"FUNCTION\"" . ('FUNCTION' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strfunctions']}</option>\n";
173
        $default_html .= "\t<option value=\"DOMAIN\"" . ('DOMAIN' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strdomains']}</option>\n";
174
        if ($this->conf['show_advanced']) {
175
            $default_html .= "\t<option value=\"AGGREGATE\"" . ('AGGREGATE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['straggregates']}</option>\n";
176
            $default_html .= "\t<option value=\"TYPE\"" . ('TYPE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strtypes']}</option>\n";
177
            $default_html .= "\t<option value=\"OPERATOR\"" . ('OPERATOR' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['stroperators']}</option>\n";
178
            $default_html .= "\t<option value=\"OPCLASS\"" . ('OPCLASS' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['stropclasses']}</option>\n";
179
            $default_html .= "\t<option value=\"CONVERSION\"" . ('CONVERSION' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strconversions']}</option>\n";
180
            $default_html .= "\t<option value=\"LANGUAGE\"" . ('LANGUAGE' == $_REQUEST['filter'] ? ' selected="selected" ' : '') . ">{$lang['strlanguages']}</option>\n";
181
        }
182
        $default_html .= "</select>\n";
183
184
        $default_html .= "<input type=\"submit\" value=\"{$lang['strfind']}\" />\n";
185
        $default_html .= "<input type=\"hidden\" name=\"action\" value=\"find\" /></p>\n";
186
        $default_html .= "</form>\n";
187
188
        // Default focus
189
        $this->setFocus('forms[0].term');
190
191
        return $default_html;
192
    }
193
}
194