Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 964 lines (895 sloc) 30.971 kb
d51e71f @lem9 was tbl_qbe
lem9 authored
1 <?php
817e790 synced/fixed vim line
Sebastian Mendel authored
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
d51e71f @lem9 was tbl_qbe
lem9 authored
3 /**
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
4 * query by example the whole database
374abd5 fixed/added page level docblock
Sebastian Mendel authored
5 *
e56949f @nijel Use package name PhpMyAdmin
nijel authored
6 * @package PhpMyAdmin
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
7 */
8
9 /**
10 * requirements
d51e71f @lem9 was tbl_qbe
lem9 authored
11 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
12 require_once 'libraries/common.inc.php';
d51e71f @lem9 was tbl_qbe
lem9 authored
13
14 /**
15 * Gets the relation settings
16 */
17 $cfgRelation = PMA_getRelationsParam();
18
19
20 /**
06d6b87 @lem9 This message was never displayed
lem9 authored
21 * A query has been submitted -> (maybe) execute it
d51e71f @lem9 was tbl_qbe
lem9 authored
22 */
06d6b87 @lem9 This message was never displayed
lem9 authored
23 $message_to_display = false;
9b7f22a cleanup
Sebastian Mendel authored
24 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
06d6b87 @lem9 This message was never displayed
lem9 authored
25 if (! preg_match('@^SELECT@i', $sql_query)) {
26 $message_to_display = true;
27 } else {
28 $goto = 'db_sql.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
29 include 'sql.php';
06d6b87 @lem9 This message was never displayed
lem9 authored
30 exit;
31 }
d51e71f @lem9 was tbl_qbe
lem9 authored
32 }
33
06d6b87 @lem9 This message was never displayed
lem9 authored
34 $sub_part = '_qbe';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
35 require 'libraries/db_common.inc.php';
06d6b87 @lem9 This message was never displayed
lem9 authored
36 $url_query .= '&amp;goto=db_qbe.php';
37 $url_params['goto'] = 'db_qbe.php';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
38 require 'libraries/db_info.inc.php';
06d6b87 @lem9 This message was never displayed
lem9 authored
39
40 if ($message_to_display) {
b2b1953 @lem9 Start to replace warning level with error level
lem9 authored
41 PMA_Message::error(__('You have to choose at least one column to display'))->display();
d51e71f @lem9 was tbl_qbe
lem9 authored
42 }
06d6b87 @lem9 This message was never displayed
lem9 authored
43 unset($message_to_display);
d51e71f @lem9 was tbl_qbe
lem9 authored
44
45 /**
46 * Initialize some variables
47 */
9b7f22a cleanup
Sebastian Mendel authored
48 $col_cnt = PMA_ifSetOr($_REQUEST['col_cnt'], 3, 'numeric');
49 $add_col = PMA_ifSetOr($_REQUEST['add_col'], 0, 'numeric');
50 $add_row = PMA_ifSetOr($_REQUEST['add_row'], 0, 'numeric');
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
51
9b7f22a cleanup
Sebastian Mendel authored
52 $rows = PMA_ifSetOr($_REQUEST['rows'], 0, 'numeric');
480cd61 @lem9 adding/removing criteria columns did not work
lem9 authored
53 $ins_col = PMA_ifSetOr($_REQUEST['ins_col'], null, 'array');
54 $del_col = PMA_ifSetOr($_REQUEST['del_col'], null, 'array');
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
55
4a62967 style upgrade
Sebastian Mendel authored
56 $prev_criteria = isset($_REQUEST['prev_criteria'])
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
57 ? $_REQUEST['prev_criteria']
58 : array();
4a62967 style upgrade
Sebastian Mendel authored
59 $criteria = isset($_REQUEST['criteria'])
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
60 ? $_REQUEST['criteria']
61 : array_fill(0, $col_cnt, '');
62
4a62967 style upgrade
Sebastian Mendel authored
63 $ins_row = isset($_REQUEST['ins_row'])
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
64 ? $_REQUEST['ins_row']
65 : array_fill(0, $col_cnt, '');
4a62967 style upgrade
Sebastian Mendel authored
66 $del_row = isset($_REQUEST['del_row'])
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
67 ? $_REQUEST['del_row']
68 : array_fill(0, $col_cnt, '');
4a62967 style upgrade
Sebastian Mendel authored
69 $and_or_row = isset($_REQUEST['and_or_row'])
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
70 ? $_REQUEST['and_or_row']
71 : array_fill(0, $col_cnt, '');
4a62967 style upgrade
Sebastian Mendel authored
72 $and_or_col = isset($_REQUEST['and_or_col'])
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
73 ? $_REQUEST['and_or_col']
74 : array_fill(0, $col_cnt, '');
d51e71f @lem9 was tbl_qbe
lem9 authored
75
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
76 // minimum width
77 $form_column_width = 12;
78 $col = max($col_cnt + $add_col, 0);
79 $row = max($rows + $add_row, 0);
d51e71f @lem9 was tbl_qbe
lem9 authored
80
81
82 // The tables list sent by a previously submitted form
9b7f22a cleanup
Sebastian Mendel authored
83 if (PMA_isValid($_REQUEST['TableList'], 'array')) {
84 foreach ($_REQUEST['TableList'] as $each_table) {
85 $tbl_names[$each_table] = ' selected="selected"';
d51e71f @lem9 was tbl_qbe
lem9 authored
86 }
87 } // end if
88
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
89
beca72f @lem9 deactivate some work in progress
lem9 authored
90 // this was a work in progress, deactivated for now
91 //$columns = PMA_DBI_get_columns_full($GLOBALS['db']);
92 //$tables = PMA_DBI_get_columns_full($GLOBALS['db']);
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
93
94
95 /**
96 * Prepares the form
97 */
98 $tbl_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
99 $tbl_result_cnt = PMA_DBI_num_rows($tbl_result);
0a745d9 @lem9 bug #1717477 Warning on Query page when db is empty
lem9 authored
100 if (0 == $tbl_result_cnt) {
7925c03 @lem9 gettext conversion
lem9 authored
101 PMA_Message::error(__('No tables found in database.'))->display();
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
102 include 'libraries/footer.inc.php';
0a745d9 @lem9 bug #1717477 Warning on Query page when db is empty
lem9 authored
103 exit;
104 }
105
d51e71f @lem9 was tbl_qbe
lem9 authored
106 // The tables list gets from MySQL
9b7f22a cleanup
Sebastian Mendel authored
107 while (list($tbl) = PMA_DBI_fetch_row($tbl_result)) {
87c970b @nijel No need to load full columns here (need names only anyway)
nijel authored
108 $fld_results = PMA_DBI_get_columns($db, $tbl);
d51e71f @lem9 was tbl_qbe
lem9 authored
109
9b7f22a cleanup
Sebastian Mendel authored
110 if (empty($tbl_names[$tbl]) && !empty($_REQUEST['TableList'])) {
d51e71f @lem9 was tbl_qbe
lem9 authored
111 $tbl_names[$tbl] = '';
112 } else {
113 $tbl_names[$tbl] = ' selected="selected"';
114 } // end if
115
116 // The fields list per selected tables
117 if ($tbl_names[$tbl] == ' selected="selected"') {
9b7f22a cleanup
Sebastian Mendel authored
118 $each_table = PMA_backquote($tbl);
119 $fld[] = $each_table . '.*';
120 foreach ($fld_results as $each_field) {
121 $each_field = $each_table . '.' . PMA_backquote($each_field['Field']);
122 $fld[] = $each_field;
d51e71f @lem9 was tbl_qbe
lem9 authored
123
124 // increase the width if necessary
9b7f22a cleanup
Sebastian Mendel authored
125 $form_column_width = max(strlen($each_field), $form_column_width);
126 } // end foreach
d51e71f @lem9 was tbl_qbe
lem9 authored
127 } // end if
9b7f22a cleanup
Sebastian Mendel authored
128 } // end while
b0cc4db @lem9 use PMA_DBI function
lem9 authored
129 PMA_DBI_free_result($tbl_result);
d51e71f @lem9 was tbl_qbe
lem9 authored
130
131 // largest width found
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
132 $realwidth = $form_column_width . 'ex';
d51e71f @lem9 was tbl_qbe
lem9 authored
133
134
135 /**
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
136 * Displays the Query by example form
d51e71f @lem9 was tbl_qbe
lem9 authored
137 */
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
138
9b7f22a cleanup
Sebastian Mendel authored
139 /**
140 * Enter description here...
141 *
142 * @param array $columns
4692e81 @nijel Correct type.
nijel authored
143 * @param integer $column_number
9b7f22a cleanup
Sebastian Mendel authored
144 * @param string $selected
145 */
4a62967 style upgrade
Sebastian Mendel authored
146 function showColumnSelectCell($columns, $column_number, $selected = '')
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
147 {
148 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
149 <td class="center">
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
150 <select name="Field[<?php echo $column_number; ?>]" size="1">
8eb4d37 @lem9 XHTML fixes
lem9 authored
151 <option value="">&nbsp;</option>
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
152 <?php
4a62967 style upgrade
Sebastian Mendel authored
153 foreach ($columns as $column) {
154 if ($column === $selected) {
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
155 $sel = ' selected="selected"';
156 } else {
157 $sel = '';
158 }
159 echo '<option value="' . htmlspecialchars($column) . '"' . $sel . '>'
b4c5dda bug #1699772 Visual space bug in table name (in browser)
Sebastian Mendel authored
160 . str_replace(' ', '&nbsp;', htmlspecialchars($column)) . '</option>' . "\n";
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
161 }
162 ?>
163 </select>
164 </td>
165 <?php
166 }
167
d51e71f @lem9 was tbl_qbe
lem9 authored
168 ?>
58a2724 @ankit042 link in query tab
ankit042 authored
169 <?php if (!empty($tab_designer['link'])) {
170 $tab_designer['link'] = htmlentities($tab_designer['link']);
171 $tab_designer['link'] = $tab_designer['link'] . PMA_generate_common_url($url_params);
172 if (! empty($tab_designer['args'])) {
173 foreach ($tab_designer['args'] as $param => $value) {
174 $tab_designer['link'] .= PMA_get_arg_separator('html') . urlencode($param) . '='
175 . urlencode($value);
176 }
177 }
178 }
179 if (! empty($tab['fragment'])) {
180 $tab['link'] .= $tab['fragment'];
181 }
8252f8a @nijel Offer switch to designer only if it is available.
nijel authored
182 if (isset($tab_designer['link'])) {
58a2724 @ankit042 link in query tab
ankit042 authored
183 ?>
18f6882 @lem9 do not show visual builder anchor if js is not enabled
lem9 authored
184 <div id="visual_builder_anchor" class="notice hide">
d553062 @nijel Replace tabs with spaces, cleanup identation
nijel authored
185 <span id="footnote_1">
3042739 @nijel Avoid composite messages
nijel authored
186 <?php printf(__('Switch to %svisual builder%s'), ' <a href="' . $tab_designer['link'] . PMA_get_arg_separator('html') . 'query=1">', '</a>'); ?>
b0fb491 @lem9 Use standard link
lem9 authored
187 </span>
58a2724 @ankit042 link in query tab
ankit042 authored
188 </div>
8252f8a @nijel Offer switch to designer only if it is available.
nijel authored
189 <?php
190 }
191 ?>
cac4247 @nijel Rename db_* files to drop useless _details part.
nijel authored
192 <form action="db_qbe.php" method="post">
bd3595f @lem9 patch #2498350 [cleanup] XHTML cleanup
lem9 authored
193 <fieldset>
4a62967 style upgrade
Sebastian Mendel authored
194 <table class="data" style="width: 100%;">
195 <tr class="odd noclick">
caa9844 @lem9 conform to relational terminology regarding columns and rows
lem9 authored
196 <th><?php echo __('Column'); ?>:</th>
d51e71f @lem9 was tbl_qbe
lem9 authored
197 <?php
198 $z = 0;
199 for ($x = 0; $x < $col; $x++) {
4a62967 style upgrade
Sebastian Mendel authored
200 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
cfeb306 coding standard: no spaces inside braces
Sebastian Mendel authored
201 showColumnSelectCell($fld, $z);
d51e71f @lem9 was tbl_qbe
lem9 authored
202 $z++;
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
203 }
d51e71f @lem9 was tbl_qbe
lem9 authored
204
4a62967 style upgrade
Sebastian Mendel authored
205 if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
206 continue;
207 }
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
208
209 $selected = '';
4a62967 style upgrade
Sebastian Mendel authored
210 if (isset($Field[$x])) {
9b7f22a cleanup
Sebastian Mendel authored
211 $selected = $Field[$x];
212 $curField[$z] = $Field[$x];
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
213 }
4a62967 style upgrade
Sebastian Mendel authored
214 showColumnSelectCell($fld, $z, $selected);
d51e71f @lem9 was tbl_qbe
lem9 authored
215 $z++;
216 } // end for
217 ?>
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
218 </tr>
d51e71f @lem9 was tbl_qbe
lem9 authored
219
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
220 <!-- Sort row -->
4a62967 style upgrade
Sebastian Mendel authored
221 <tr class="even noclick">
f55823f @lem9 strings to gettext, first batch
lem9 authored
222 <th><?php echo __('Sort'); ?>:</th>
d51e71f @lem9 was tbl_qbe
lem9 authored
223 <?php
224 $z = 0;
225 for ($x = 0; $x < $col; $x++) {
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
226 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
227 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
228 <td class="center">
4a62967 style upgrade
Sebastian Mendel authored
229 <select style="width: <?php echo $realwidth; ?>" name="Sort[<?php echo $z; ?>]" size="1">
8eb4d37 @lem9 XHTML fixes
lem9 authored
230 <option value="">&nbsp;</option>
f55823f @lem9 strings to gettext, first batch
lem9 authored
231 <option value="ASC"><?php echo __('Ascending'); ?></option>
232 <option value="DESC"><?php echo __('Descending'); ?></option>
4a62967 style upgrade
Sebastian Mendel authored
233 </select>
234 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
235 <?php
236 $z++;
237 } // end if
238 echo "\n";
239
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
240 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
241 continue;
242 }
243 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
244 <td class="center">
4a62967 style upgrade
Sebastian Mendel authored
245 <select style="width: <?php echo $realwidth; ?>" name="Sort[<?php echo $z; ?>]" size="1">
8eb4d37 @lem9 XHTML fixes
lem9 authored
246 <option value="">&nbsp;</option>
d51e71f @lem9 was tbl_qbe
lem9 authored
247 <?php
248 echo "\n";
249
250 // If they have chosen all fields using the * selector,
251 // then sorting is not available
79f320e @lem9 remove author names
lem9 authored
252 // Fix for Bug #570698
4a62967 style upgrade
Sebastian Mendel authored
253 if (isset($Sort[$x]) && isset($Field[$x])
9b7f22a cleanup
Sebastian Mendel authored
254 && substr($Field[$x], -2) == '.*') {
d51e71f @lem9 was tbl_qbe
lem9 authored
255 $Sort[$x] = '';
256 } //end if
257
258 if (isset($Sort[$x]) && $Sort[$x] == 'ASC') {
259 $curSort[$z] = $Sort[$x];
260 $sel = ' selected="selected"';
261 } else {
262 $sel = '';
263 } // end if
264 echo ' ';
f55823f @lem9 strings to gettext, first batch
lem9 authored
265 echo '<option value="ASC"' . $sel . '>' . __('Ascending') . '</option>' . "\n";
d51e71f @lem9 was tbl_qbe
lem9 authored
266 if (isset($Sort[$x]) && $Sort[$x] == 'DESC') {
267 $curSort[$z] = $Sort[$x];
268 $sel = ' selected="selected"';
269 } else {
270 $sel = '';
271 } // end if
272 echo ' ';
f55823f @lem9 strings to gettext, first batch
lem9 authored
273 echo '<option value="DESC"' . $sel . '>' . __('Descending') . '</option>' . "\n";
d51e71f @lem9 was tbl_qbe
lem9 authored
274 ?>
4a62967 style upgrade
Sebastian Mendel authored
275 </select>
276 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
277 <?php
278 $z++;
279 echo "\n";
280 } // end for
281 ?>
4a62967 style upgrade
Sebastian Mendel authored
282 </tr>
d51e71f @lem9 was tbl_qbe
lem9 authored
283
4a62967 style upgrade
Sebastian Mendel authored
284 <!-- Show row -->
285 <tr class="odd noclick">
f55823f @lem9 strings to gettext, first batch
lem9 authored
286 <th><?php echo __('Show'); ?>:</th>
d51e71f @lem9 was tbl_qbe
lem9 authored
287 <?php
288 $z = 0;
289 for ($x = 0; $x < $col; $x++) {
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
290 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
291 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
292 <td class="center">
4a62967 style upgrade
Sebastian Mendel authored
293 <input type="checkbox" name="Show[<?php echo $z; ?>]" />
294 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
295 <?php
296 $z++;
297 } // end if
298 echo "\n";
299
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
300 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
301 continue;
302 }
303 if (isset($Show[$x])) {
304 $checked = ' checked="checked"';
305 $curShow[$z] = $Show[$x];
306 } else {
307 $checked = '';
308 }
309 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
310 <td class="center">
4a62967 style upgrade
Sebastian Mendel authored
311 <input type="checkbox" name="Show[<?php echo $z; ?>]"<?php echo $checked; ?> />
312 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
313 <?php
314 $z++;
315 echo "\n";
316 } // end for
317 ?>
4a62967 style upgrade
Sebastian Mendel authored
318 </tr>
d51e71f @lem9 was tbl_qbe
lem9 authored
319
4a62967 style upgrade
Sebastian Mendel authored
320 <!-- Criteria row -->
321 <tr class="even noclick">
f55823f @lem9 strings to gettext, first batch
lem9 authored
322 <th><?php echo __('Criteria'); ?>:</th>
d51e71f @lem9 was tbl_qbe
lem9 authored
323 <?php
324 $z = 0;
325 for ($x = 0; $x < $col; $x++) {
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
326 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
327 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
328 <td class="center">
4a62967 style upgrade
Sebastian Mendel authored
329 <input type="text" name="criteria[<?php echo $z; ?>]" value="" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />
330 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
331 <?php
332 $z++;
333 } // end if
334 echo "\n";
335
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
336 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
337 continue;
338 }
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
339 if (isset($criteria[$x])) {
2586524 @lem9 gettext conversion; clarify code
lem9 authored
340 $tmp_criteria = $criteria[$x];
d51e71f @lem9 was tbl_qbe
lem9 authored
341 }
13b3195 @lem9 For easier reading, replace "!isset" with "! isset"
lem9 authored
342 if ((empty($prev_criteria) || ! isset($prev_criteria[$x]))
2586524 @lem9 gettext conversion; clarify code
lem9 authored
343 || $prev_criteria[$x] != htmlspecialchars($tmp_criteria)) {
344 $curCriteria[$z] = $tmp_criteria;
d51e71f @lem9 was tbl_qbe
lem9 authored
345 } else {
9b7f22a cleanup
Sebastian Mendel authored
346 $curCriteria[$z] = $prev_criteria[$x];
d51e71f @lem9 was tbl_qbe
lem9 authored
347 }
348 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
349 <td class="center">
9b7f22a cleanup
Sebastian Mendel authored
350 <input type="hidden" name="prev_criteria[<?php echo $z; ?>]" value="<?php echo htmlspecialchars($curCriteria[$z]); ?>" />
2586524 @lem9 gettext conversion; clarify code
lem9 authored
351 <input type="text" name="criteria[<?php echo $z; ?>]" value="<?php echo htmlspecialchars($tmp_criteria); ?>" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />
4a62967 style upgrade
Sebastian Mendel authored
352 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
353 <?php
354 $z++;
355 echo "\n";
356 } // end for
357 ?>
4a62967 style upgrade
Sebastian Mendel authored
358 </tr>
d51e71f @lem9 was tbl_qbe
lem9 authored
359
4a62967 style upgrade
Sebastian Mendel authored
360 <!-- And/Or columns and rows -->
d51e71f @lem9 was tbl_qbe
lem9 authored
361 <?php
362 $w = 0;
4a62967 style upgrade
Sebastian Mendel authored
363 $odd_row = true;
d51e71f @lem9 was tbl_qbe
lem9 authored
364 for ($y = 0; $y <= $row; $y++) {
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
365 if (isset($ins_row[$y]) && $ins_row[$y] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
366 $chk['or'] = ' checked="checked"';
367 $chk['and'] = '';
368 ?>
4a62967 style upgrade
Sebastian Mendel authored
369 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
20ddd10 Replaced HTML nowrap attribute with CSS for HTML5 validity
Jo Michael authored
370 <td class="<?php echo $cell_align_right; ?> nowrap">
4a62967 style upgrade
Sebastian Mendel authored
371 <!-- Row controls -->
372 <table cellpadding="0" cellspacing="0" border="0">
373 <tr>
20ddd10 Replaced HTML nowrap attribute with CSS for HTML5 validity
Jo Michael authored
374 <td class="<?php echo $cell_align_right; ?> nowrap">
f55823f @lem9 strings to gettext, first batch
lem9 authored
375 <small><?php echo __('Ins'); ?>:</small>
4a62967 style upgrade
Sebastian Mendel authored
376 <input type="checkbox" name="ins_row[<?php echo $w; ?>]" />
377 </td>
b9c474c Replaced *[align] with *[class] for HTML5 validity
Jo Michael authored
378 <td class="<?php echo $cell_align_right; ?>">
f55823f @lem9 strings to gettext, first batch
lem9 authored
379 <strong><?php echo __('And'); ?>:</strong>
4a62967 style upgrade
Sebastian Mendel authored
380 </td>
381 <td>
382 <input type="radio" name="and_or_row[<?php echo $w; ?>]" value="and"<?php echo $chk['and']; ?> />
383 &nbsp;
384 </td>
385 </tr>
386 <tr>
20ddd10 Replaced HTML nowrap attribute with CSS for HTML5 validity
Jo Michael authored
387 <td class="<?php echo $cell_align_right; ?> nowrap">
f55823f @lem9 strings to gettext, first batch
lem9 authored
388 <small><?php echo __('Del'); ?>:</small>
4a62967 style upgrade
Sebastian Mendel authored
389 <input type="checkbox" name="del_row[<?php echo $w; ?>]" />
390 </td>
b9c474c Replaced *[align] with *[class] for HTML5 validity
Jo Michael authored
391 <td class="<?php echo $cell_align_right; ?>">
f55823f @lem9 strings to gettext, first batch
lem9 authored
392 <strong><?php echo __('Or'); ?>:</strong>
4a62967 style upgrade
Sebastian Mendel authored
393 </td>
394 <td>
395 <input type="radio" name="and_or_row[<?php echo $w; ?>]" value="or"<?php echo $chk['or']; ?> />
396 &nbsp;
397 </td>
398 </tr>
399 </table>
400 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
401 <?php
402 $z = 0;
403 for ($x = 0; $x < $col; $x++) {
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
404 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
405 echo "\n";
406 $or = 'Or' . $w . '[' . $z . ']';
407 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
408 <td class="center">
a63410c @lem9 Use input field instead of textarea for additional criteria
lem9 authored
409 <input type="text" name="Or<?php echo $or; ?>" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />
4a62967 style upgrade
Sebastian Mendel authored
410 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
411 <?php
412 $z++;
413 } // end if
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
414 if (isset($del_col[$x]) && $del_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
415 continue;
416 }
417
418 echo "\n";
419 $or = 'Or' . $w . '[' . $z . ']';
420 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
421 <td class="center">
a63410c @lem9 Use input field instead of textarea for additional criteria
lem9 authored
422 <input type="text" name="Or<?php echo $or; ?>" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />
4a62967 style upgrade
Sebastian Mendel authored
423 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
424 <?php
425 $z++;
426 } // end for
427 $w++;
428 echo "\n";
429 ?>
4a62967 style upgrade
Sebastian Mendel authored
430 </tr>
d51e71f @lem9 was tbl_qbe
lem9 authored
431 <?php
4a62967 style upgrade
Sebastian Mendel authored
432 $odd_row =! $odd_row;
d51e71f @lem9 was tbl_qbe
lem9 authored
433 } // end if
434
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
435 if (isset($del_row[$y]) && $del_row[$y] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
436 continue;
437 }
438
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
439 if (isset($and_or_row[$y])) {
440 $curAndOrRow[$w] = $and_or_row[$y];
d51e71f @lem9 was tbl_qbe
lem9 authored
441 }
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
442 if (isset($and_or_row[$y]) && $and_or_row[$y] == 'and') {
d51e71f @lem9 was tbl_qbe
lem9 authored
443 $chk['and'] = ' checked="checked"';
444 $chk['or'] = '';
445 } else {
446 $chk['or'] = ' checked="checked"';
447 $chk['and'] = '';
448 }
449 echo "\n";
450 ?>
4a62967 style upgrade
Sebastian Mendel authored
451 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
20ddd10 Replaced HTML nowrap attribute with CSS for HTML5 validity
Jo Michael authored
452 <td class="<?php echo $cell_align_right; ?> nowrap">
4a62967 style upgrade
Sebastian Mendel authored
453 <!-- Row controls -->
03eeeb3 Removed: table[border] attribute (default is 0 anyways), a[rel] for non-...
Jo Michael authored
454 <table cellpadding="0" cellspacing="0">
4a62967 style upgrade
Sebastian Mendel authored
455 <tr>
20ddd10 Replaced HTML nowrap attribute with CSS for HTML5 validity
Jo Michael authored
456 <td class="<?php echo $cell_align_right; ?> nowrap">
f55823f @lem9 strings to gettext, first batch
lem9 authored
457 <small><?php echo __('Ins'); ?>:</small>
4a62967 style upgrade
Sebastian Mendel authored
458 <input type="checkbox" name="ins_row[<?php echo $w; ?>]" />
459 </td>
b9c474c Replaced *[align] with *[class] for HTML5 validity
Jo Michael authored
460 <td class="<?php echo $cell_align_right; ?>">
f55823f @lem9 strings to gettext, first batch
lem9 authored
461 <strong><?php echo __('And'); ?>:</strong>
4a62967 style upgrade
Sebastian Mendel authored
462 </td>
463 <td>
464 <input type="radio" name="and_or_row[<?php echo $w; ?>]" value="and"<?php echo $chk['and']; ?> />
465 </td>
466 </tr>
467 <tr>
20ddd10 Replaced HTML nowrap attribute with CSS for HTML5 validity
Jo Michael authored
468 <td class="<?php echo $cell_align_right; ?> nowrap">
f55823f @lem9 strings to gettext, first batch
lem9 authored
469 <small><?php echo __('Del'); ?>:</small>
4a62967 style upgrade
Sebastian Mendel authored
470 <input type="checkbox" name="del_row[<?php echo $w; ?>]" />
471 </td>
b9c474c Replaced *[align] with *[class] for HTML5 validity
Jo Michael authored
472 <td class="<?php echo $cell_align_right; ?>">
f55823f @lem9 strings to gettext, first batch
lem9 authored
473 <strong><?php echo __('Or'); ?>:</strong>
4a62967 style upgrade
Sebastian Mendel authored
474 </td>
475 <td>
476 <input type="radio" name="and_or_row[<?php echo $w; ?>]" value="or"<?php echo $chk['or']; ?> />
477 </td>
478 </tr>
479 </table>
480 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
481 <?php
482 $z = 0;
483 for ($x = 0; $x < $col; $x++) {
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
484 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
485 echo "\n";
486 $or = 'Or' . $w . '[' . $z . ']';
487 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
488 <td class="center">
a63410c @lem9 Use input field instead of textarea for additional criteria
lem9 authored
489 <input type="text" name="Or<?php echo $or; ?>" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />
4a62967 style upgrade
Sebastian Mendel authored
490 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
491 <?php
492 $z++;
493 } // end if
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
494 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
495 continue;
496 }
497
498 echo "\n";
499 $or = 'Or' . $y;
13b3195 @lem9 For easier reading, replace "!isset" with "! isset"
lem9 authored
500 if (! isset(${$or})) {
d51e71f @lem9 was tbl_qbe
lem9 authored
501 ${$or} = '';
502 }
503 if (!empty(${$or}) && isset(${$or}[$x])) {
2586524 @lem9 gettext conversion; clarify code
lem9 authored
504 $tmp_or = ${$or}[$x];
d51e71f @lem9 was tbl_qbe
lem9 authored
505 } else {
2586524 @lem9 gettext conversion; clarify code
lem9 authored
506 $tmp_or = '';
d51e71f @lem9 was tbl_qbe
lem9 authored
507 }
508 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
509 <td class="center">
2586524 @lem9 gettext conversion; clarify code
lem9 authored
510 <input type="text" name="Or<?php echo $w . '[' . $z . ']'; ?>" value="<?php echo htmlspecialchars($tmp_or); ?>" class="textfield" style="width: <?php echo $realwidth; ?>" size="20" />
4a62967 style upgrade
Sebastian Mendel authored
511 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
512 <?php
513 if (!empty(${$or}) && isset(${$or}[$x])) {
514 ${'cur' . $or}[$z] = ${$or}[$x];
515 }
516 $z++;
517 } // end for
518 $w++;
519 echo "\n";
520 ?>
4a62967 style upgrade
Sebastian Mendel authored
521 </tr>
d51e71f @lem9 was tbl_qbe
lem9 authored
522 <?php
523 echo "\n";
4a62967 style upgrade
Sebastian Mendel authored
524 $odd_row =! $odd_row;
d51e71f @lem9 was tbl_qbe
lem9 authored
525 } // end for
526 ?>
4a62967 style upgrade
Sebastian Mendel authored
527 <!-- Modify columns -->
528 <tr class="even noclick">
f55823f @lem9 strings to gettext, first batch
lem9 authored
529 <th><?php echo __('Modify'); ?>:</th>
d51e71f @lem9 was tbl_qbe
lem9 authored
530 <?php
531 $z = 0;
532 for ($x = 0; $x < $col; $x++) {
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
533 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
534 $curAndOrCol[$z] = $and_or_col[$y];
535 if ($and_or_col[$z] == 'or') {
d51e71f @lem9 was tbl_qbe
lem9 authored
536 $chk['or'] = ' checked="checked"';
537 $chk['and'] = '';
538 } else {
539 $chk['and'] = ' checked="checked"';
540 $chk['or'] = '';
541 }
542 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
543 <td class="center">
f55823f @lem9 strings to gettext, first batch
lem9 authored
544 <strong><?php echo __('Or'); ?>:</strong>
4a62967 style upgrade
Sebastian Mendel authored
545 <input type="radio" name="and_or_col[<?php echo $z; ?>]" value="or"<?php echo $chk['or']; ?> />
f55823f @lem9 strings to gettext, first batch
lem9 authored
546 &nbsp;&nbsp;<strong><?php echo __('And'); ?>:</strong>
4a62967 style upgrade
Sebastian Mendel authored
547 <input type="radio" name="and_or_col[<?php echo $z; ?>]" value="and"<?php echo $chk['and']; ?> />
548 <br />
f55823f @lem9 strings to gettext, first batch
lem9 authored
549 <?php echo __('Ins') . "\n"; ?>
4a62967 style upgrade
Sebastian Mendel authored
550 <input type="checkbox" name="ins_col[<?php echo $z; ?>]" />
f55823f @lem9 strings to gettext, first batch
lem9 authored
551 &nbsp;&nbsp;<?php echo __('Del') . "\n"; ?>
4a62967 style upgrade
Sebastian Mendel authored
552 <input type="checkbox" name="del_col[<?php echo $z; ?>]" />
553 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
554 <?php
555 $z++;
556 } // end if
557 echo "\n";
558
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
559 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
d51e71f @lem9 was tbl_qbe
lem9 authored
560 continue;
561 }
562
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
563 if (isset($and_or_col[$y])) {
564 $curAndOrCol[$z] = $and_or_col[$y];
d51e71f @lem9 was tbl_qbe
lem9 authored
565 }
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
566 if (isset($and_or_col[$z]) && $and_or_col[$z] == 'or') {
d51e71f @lem9 was tbl_qbe
lem9 authored
567 $chk['or'] = ' checked="checked"';
568 $chk['and'] = '';
569 } else {
570 $chk['and'] = ' checked="checked"';
571 $chk['or'] = '';
572 }
573 ?>
c36a911 Replaced td[align] with td[class] due to HTML5
Jo Michael authored
574 <td class="center">
f55823f @lem9 strings to gettext, first batch
lem9 authored
575 <strong><?php echo __('Or'); ?>:</strong>
4a62967 style upgrade
Sebastian Mendel authored
576 <input type="radio" name="and_or_col[<?php echo $z; ?>]" value="or"<?php echo $chk['or']; ?> />
f55823f @lem9 strings to gettext, first batch
lem9 authored
577 &nbsp;&nbsp;<strong><?php echo __('And'); ?>:</strong>
4a62967 style upgrade
Sebastian Mendel authored
578 <input type="radio" name="and_or_col[<?php echo $z; ?>]" value="and"<?php echo $chk['and']; ?> />
579 <br />
f55823f @lem9 strings to gettext, first batch
lem9 authored
580 <?php echo __('Ins') . "\n"; ?>
4a62967 style upgrade
Sebastian Mendel authored
581 <input type="checkbox" name="ins_col[<?php echo $z; ?>]" />
f55823f @lem9 strings to gettext, first batch
lem9 authored
582 &nbsp;&nbsp;<?php echo __('Del') . "\n"; ?>
4a62967 style upgrade
Sebastian Mendel authored
583 <input type="checkbox" name="del_col[<?php echo $z; ?>]" />
584 </td>
d51e71f @lem9 was tbl_qbe
lem9 authored
585 <?php
586 $z++;
587 echo "\n";
588 } // end for
589 ?>
590 </tr>
d9a2161 @lem9 redesign part 3
lem9 authored
591 </table>
d51e71f @lem9 was tbl_qbe
lem9 authored
592
d9a2161 @lem9 redesign part 3
lem9 authored
593 <!-- Other controls -->
4a62967 style upgrade
Sebastian Mendel authored
594 <?php
595 $w--;
596 $url_params['db'] = $db;
597 $url_params['col_cnt'] = $z;
598 $url_params['rows'] = $w;
599 echo PMA_generate_common_hidden_inputs($url_params);
600 ?>
f2c01ee @lem9 avoid a thick line on top of fieldset tblFooters
lem9 authored
601 </fieldset>
4a62967 style upgrade
Sebastian Mendel authored
602 <fieldset class="tblFooters">
03eeeb3 Removed: table[border] attribute (default is 0 anyways), a[rel] for non-...
Jo Michael authored
603 <table cellpadding="2" cellspacing="1">
4a62967 style upgrade
Sebastian Mendel authored
604 <tr>
20ddd10 Replaced HTML nowrap attribute with CSS for HTML5 validity
Jo Michael authored
605 <td class="nowrap">
caa9844 @lem9 conform to relational terminology regarding columns and rows
lem9 authored
606 <?php echo __('Add/Delete criteria rows'); ?>:
b459819 @lem9 style is already in theme CSS
lem9 authored
607 <select size="1" name="add_row">
4a62967 style upgrade
Sebastian Mendel authored
608 <option value="-3">-3</option>
609 <option value="-2">-2</option>
610 <option value="-1">-1</option>
611 <option value="0" selected="selected">0</option>
612 <option value="1">1</option>
613 <option value="2">2</option>
614 <option value="3">3</option>
615 </select>
616 </td>
2fddabf Replaced obsolete td[width] HTML attributes with CSS
Jo Michael authored
617 <td style="width: 10px">&nbsp;</td>
20ddd10 Replaced HTML nowrap attribute with CSS for HTML5 validity
Jo Michael authored
618 <td class="nowrap"><?php echo __('Add/Delete columns'); ?>:
b459819 @lem9 style is already in theme CSS
lem9 authored
619 <select size="1" name="add_col">
4a62967 style upgrade
Sebastian Mendel authored
620 <option value="-3">-3</option>
621 <option value="-2">-2</option>
622 <option value="-1">-1</option>
623 <option value="0" selected="selected">0</option>
624 <option value="1">1</option>
625 <option value="2">2</option>
626 <option value="3">3</option>
627 </select>
628 </td>
2fddabf Replaced obsolete td[width] HTML attributes with CSS
Jo Michael authored
629 <td style="width: 10px">&nbsp;</td>
4a62967 style upgrade
Sebastian Mendel authored
630 <!-- Generates a query -->
f55823f @lem9 strings to gettext, first batch
lem9 authored
631 <td><input type="submit" name="modify" value="<?php echo __('Update Query'); ?>" /></td>
4a62967 style upgrade
Sebastian Mendel authored
632 </tr>
633 </table>
634 </fieldset>
d51e71f @lem9 was tbl_qbe
lem9 authored
635
d1dd742 Replaced blind table by CSS-floating <div> in db_qbe
Jo Michael authored
636 <div class="floatleft">
637 <fieldset>
638 <legend><?php echo __('Use Tables'); ?></legend>
d51e71f @lem9 was tbl_qbe
lem9 authored
639 <?php
f55823f @lem9 strings to gettext, first batch
lem9 authored
640 $options = '';
d9a2161 @lem9 redesign part 3
lem9 authored
641 $numTableListOptions = 0;
d9eebc2 removed closing of db connection, closing database connection is only re...
Sebastian Mendel authored
642 foreach ($tbl_names as $key => $val) {
d1dd742 Replaced blind table by CSS-floating <div> in db_qbe
Jo Michael authored
643 $options .= ' ';
f55823f @lem9 strings to gettext, first batch
lem9 authored
644 $options .= '<option value="' . htmlspecialchars($key) . '"' . $val . '>'
b4c5dda bug #1699772 Visual space bug in table name (in browser)
Sebastian Mendel authored
645 . str_replace(' ', '&nbsp;', htmlspecialchars($key)) . '</option>' . "\n";
d9a2161 @lem9 redesign part 3
lem9 authored
646 $numTableListOptions++;
d51e71f @lem9 was tbl_qbe
lem9 authored
647 }
648 ?>
d1dd742 Replaced blind table by CSS-floating <div> in db_qbe
Jo Michael authored
649 <select name="TableList[]" multiple="multiple" id="listTable"
650 size="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>">
651 <?php echo $options; ?>
652 </select>
653 </fieldset>
654 <fieldset class="tblFooters">
655 <input type="submit" name="modify" value="<?php echo __('Update Query'); ?>" />
656 </fieldset>
657 </div>
658
659 <div class="floatleft">
660 <fieldset>
661 <legend><?php echo sprintf(__('SQL query on database <b>%s</b>:'), PMA_getDbLink($db)); ?>
662 </legend>
663 <textarea cols="80" name="sql_query" id="textSqlquery"
664 rows="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>"
665 dir="<?php echo $text_dir; ?>">
d51e71f @lem9 was tbl_qbe
lem9 authored
666 <?php
667 // 1. SELECT
668 $last_select = 0;
13b3195 @lem9 For easier reading, replace "!isset" with "! isset"
lem9 authored
669 if (! isset($qry_select)) {
d51e71f @lem9 was tbl_qbe
lem9 authored
670 $qry_select = '';
671 }
672 for ($x = 0; $x < $col; $x++) {
673 if (!empty($curField[$x]) && isset($curShow[$x]) && $curShow[$x] == 'on') {
674 if ($last_select) {
675 $qry_select .= ', ';
676 }
677 $qry_select .= $curField[$x];
678 $last_select = 1;
679 }
680 } // end for
681 if (!empty($qry_select)) {
682 echo 'SELECT ' . htmlspecialchars($qry_select) . "\n";
683 }
684
685 // 2. FROM
686
687 // Create LEFT JOINS out of Relations
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
688 // If we can use Relations we could make some left joins.
689 // First find out if relations are available in this database.
d51e71f @lem9 was tbl_qbe
lem9 authored
690
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
691 // First we need the really needed Tables - those in TableList might still be
692 // all Tables.
d51e71f @lem9 was tbl_qbe
lem9 authored
693 if (isset($Field) && count($Field) > 0) {
694 // Initialize some variables
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
695 $tab_all = array();
696 $col_all = array();
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
697 $tab_wher = array();
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
698 $tab_know = array();
699 $tab_left = array();
700 $col_where = array();
701 $fromclause = '';
d51e71f @lem9 was tbl_qbe
lem9 authored
702
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
703 // We only start this if we have fields, otherwise it would be dumb
d9eebc2 removed closing of db connection, closing database connection is only re...
Sebastian Mendel authored
704 foreach ($Field as $value) {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
705 $parts = explode('.', $value);
706 if (!empty($parts[0]) && !empty($parts[1])) {
9b7f22a cleanup
Sebastian Mendel authored
707 $tab_raw = $parts[0];
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
708 $tab = str_replace('`', '', $tab_raw);
709 $tab_all[$tab] = $tab;
c2b46ac Final batch of PHP3-Compatibility fixes. Please test. :-)
Garvin Hicking authored
710
9b7f22a cleanup
Sebastian Mendel authored
711 $col_raw = $parts[1];
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
712 $col_all[] = $tab . '.' . str_replace('`', '', $col_raw);
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
713 }
d51e71f @lem9 was tbl_qbe
lem9 authored
714 } // end while
715
c2b46ac Final batch of PHP3-Compatibility fixes. Please test. :-)
Garvin Hicking authored
716 // Check 'where' clauses
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
717 if ($cfgRelation['relwork'] && count($tab_all) > 0) {
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
718 // Now we need all tables that we have in the where clause
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
719 $crit_cnt = count($criteria);
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
720 for ($x = 0; $x < $crit_cnt; $x++) {
9b7f22a cleanup
Sebastian Mendel authored
721 $curr_tab = explode('.', $Field[$x]);
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
722 if (!empty($curr_tab[0]) && !empty($curr_tab[1])) {
9b7f22a cleanup
Sebastian Mendel authored
723 $tab_raw = $curr_tab[0];
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
724 $tab = str_replace('`', '', $tab_raw);
725
9b7f22a cleanup
Sebastian Mendel authored
726 $col_raw = $curr_tab[1];
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
727 $col1 = str_replace('`', '', $col_raw);
728 $col1 = $tab . '.' . $col1;
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
729 // Now we know that our array has the same numbers as $criteria
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
730 // we can check which of our columns has a where clause
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
731 if (!empty($criteria[$x])) {
732 if (substr($criteria[$x], 0, 1) == '=' || stristr($criteria[$x], 'is')) {
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
733 $col_where[$col] = $col1;
734 $tab_wher[$tab] = $tab;
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
735 }
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
736 } // end if
737 } // end if
d51e71f @lem9 was tbl_qbe
lem9 authored
738 } // end for
739
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
740 // Cleans temp vars w/o further use
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
741 unset($tab_raw);
742 unset($col_raw);
743 unset($col1);
d51e71f @lem9 was tbl_qbe
lem9 authored
744
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
745 if (count($tab_wher) == 1) {
746 // If there is exactly one column that has a decent where-clause
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
747 // we will just use this
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
748 $master = key($tab_wher);
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
749 } else {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
750 // Now let's find out which of the tables has an index
cfeb306 coding standard: no spaces inside braces
Sebastian Mendel authored
751 // (When the control user is the same as the normal user
287eac4 @lem9 qbe error when generating joins
lem9 authored
752 // because he is using one of his databases as pmadb,
753 // the last db selected is not always the one where we need to work)
2915b5c @derrabus Added MySQLi library; Removed calls to old mysql_wrappers library.
derrabus authored
754 PMA_DBI_select_db($db);
287eac4 @lem9 qbe error when generating joins
lem9 authored
755
d9eebc2 removed closing of db connection, closing database connection is only re...
Sebastian Mendel authored
756 foreach ($tab_all as $tab) {
57bea06 @Crack Use PMA_DBI_get_table_indexes_sql() only when really needed, in all othe...
Crack authored
757 $indexes = PMA_DBI_get_table_indexes($db, $tab);
758 foreach ($indexes as $ind) {
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
759 $col1 = $tab . '.' . $ind['Column_name'];
760 if (isset($col_all[$col1])) {
1f10c9b @Crack Fix incorrect array key (non_unique -> Non_unique) in qbe
Crack authored
761 if ($ind['Non_unique'] == 0) {
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
762 if (isset($col_where[$col1])) {
763 $col_unique[$col1] = 'Y';
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
764 } else {
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
765 $col_unique[$col1] = 'N';
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
766 }
767 } else {
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
768 if (isset($col_where[$col1])) {
769 $col_index[$col1] = 'Y';
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
770 } else {
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
771 $col_index[$col1] = 'N';
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
772 }
773 }
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
774 }
775 } // end while (each col of tab)
776 } // end while (each tab)
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
777 // now we want to find the best.
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
778 if (isset($col_unique) && count($col_unique) > 0) {
779 $col_cand = $col_unique;
780 $needsort = 1;
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
781 } elseif (isset($col_index) && count($col_index) > 0) {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
782 $col_cand = $col_index;
783 $needsort = 1;
6b4f751 fixed bug #1409972 PHP 5.1.2 compatibility
Sebastian Mendel authored
784 } elseif (isset($col_where) && count($col_where) > 0) {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
785 $col_cand = $tab_wher;
786 $needsort = 0;
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
787 } else {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
788 $col_cand = $tab_all;
789 $needsort = 0;
d51e71f @lem9 was tbl_qbe
lem9 authored
790 }
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
791
792 // If we came up with $col_unique (very good) or $col_index (still
793 // good) as $col_cand we want to check if we have any 'Y' there
794 // (that would mean that they were also found in the whereclauses
795 // which would be great). if yes, we take only those
796 if ($needsort == 1) {
d9eebc2 removed closing of db connection, closing database connection is only re...
Sebastian Mendel authored
797 foreach ($col_cand as $col => $is_where) {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
798 $tab = explode('.', $col);
799 $tab = $tab[0];
800 if ($is_where == 'Y') {
801 $vg[$col] = $tab;
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
802 } else {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
803 $sg[$col] = $tab;
7eea35c rewrote most of the logic that creates the LEFT JOIN stuff as i had real...
Mike Beck authored
804 }
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
805 }
806 if (isset($vg)) {
807 $col_cand = $vg;
c2b46ac Final batch of PHP3-Compatibility fixes. Please test. :-)
Garvin Hicking authored
808 // Candidates restricted in index+where
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
809 } else {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
810 $col_cand = $sg;
c2b46ac Final batch of PHP3-Compatibility fixes. Please test. :-)
Garvin Hicking authored
811 // None of the candidates where in a where-clause
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
812 }
7eea35c rewrote most of the logic that creates the LEFT JOIN stuff as i had real...
Mike Beck authored
813 }
7184bb8 @derrabus For Lo�c: Coding standards
derrabus authored
814
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
815 // If our array of candidates has more than one member we'll just
816 // find the smallest table.
817 // Of course the actual query would be faster if we check for
818 // the Criteria which gives the smallest result set in its table,
819 // but it would take too much time to check this
820 if (count($col_cand) > 1) {
821 // Of course we only want to check each table once
822 $checked_tables = $col_cand;
d9eebc2 removed closing of db connection, closing database connection is only re...
Sebastian Mendel authored
823 foreach ($col_cand as $tab) {
cfeb306 coding standard: no spaces inside braces
Sebastian Mendel authored
824 if ($checked_tables[$tab] != 1) {
1419fcf @lem9 remove deprecated parameter of PMA_Table::countRecords()
lem9 authored
825 $tsize[$tab] = PMA_Table::countRecords($db, $tab, false);
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
826 $checked_tables[$tab] = 1;
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
827 }
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
828 $csize[$tab] = $tsize[$tab];
d51e71f @lem9 was tbl_qbe
lem9 authored
829 }
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
830 asort($csize);
831 reset($csize);
c2b46ac Final batch of PHP3-Compatibility fixes. Please test. :-)
Garvin Hicking authored
832 $master = key($csize); // Smallest
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
833 } else {
1bb13b5 @lem9 bug 661758
lem9 authored
834 reset($col_cand);
c2b46ac Final batch of PHP3-Compatibility fixes. Please test. :-)
Garvin Hicking authored
835 $master = current($col_cand); // Only one single candidate
7eea35c rewrote most of the logic that creates the LEFT JOIN stuff as i had real...
Mike Beck authored
836 }
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
837 } // end if (exactly one where clause)
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
838
4670ada @lem9 JOIN generation did not work in 3.0 for multi-table queries
lem9 authored
839 $tab_left = $tab_all;
840 unset($tab_left[$master]);
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
841 $tab_know[$master] = $master;
d51e71f @lem9 was tbl_qbe
lem9 authored
842
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
843 $run = 0;
844 $emerg = '';
845 while (count($tab_left) > 0) {
846 if ($run % 2 == 0) {
847 PMA_getRelatives('master');
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
848 } else {
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
849 PMA_getRelatives('foreign');
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
850 }
851 $run++;
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
852 if ($run > 5) {
d51e71f @lem9 was tbl_qbe
lem9 authored
853
d9eebc2 removed closing of db connection, closing database connection is only re...
Sebastian Mendel authored
854 foreach ($tab_left as $tab) {
855 $emerg .= ', ' . PMA_backquote($tab);
856 unset($tab_left[$tab]);
4061729 the stuff i wrote for 2.3.0 that creates automatic JOINS in
Mike Beck authored
857 }
858 }
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
859 } // end while
b9b379d @nijel Backquote table name.
nijel authored
860 $qry_from = PMA_backquote($master) . $emerg . $fromclause;
4c272f6 Coding Standards (thanx to Loic)
Mike Beck authored
861 } // end if ($cfgRelation['relwork'] && count($tab_all) > 0)
d51e71f @lem9 was tbl_qbe
lem9 authored
862
863 } // end count($Field) > 0
864
4dfd10a @lem9 bug 751787
lem9 authored
865 // In case relations are not defined, just generate the FROM clause
866 // from the list of tables, however we don't generate any JOIN
867
ae5e52a @lem9 undefined variable
lem9 authored
868 if (empty($qry_from) && isset($tab_all)) {
4dfd10a @lem9 bug 751787
lem9 authored
869 $qry_from = implode(', ', $tab_all);
d51e71f @lem9 was tbl_qbe
lem9 authored
870 }
4dfd10a @lem9 bug 751787
lem9 authored
871 // Now let's see what we got
ae5e52a @lem9 undefined variable
lem9 authored
872 if (!empty($qry_from)) {
873 echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
874 }
d51e71f @lem9 was tbl_qbe
lem9 authored
875
876 // 3. WHERE
877 $qry_where = '';
878 $criteria_cnt = 0;
879 for ($x = 0; $x < $col; $x++) {
c485b4b @lem9 undefined offset and undefined variable
lem9 authored
880 if (!empty($curField[$x]) && !empty($curCriteria[$x]) && $x && isset($last_where) && isset($curAndOrCol)) {
d51e71f @lem9 was tbl_qbe
lem9 authored
881 $qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';
882 }
883 if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
884 $qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';
885 $last_where = $x;
886 $criteria_cnt++;
887 }
888 } // end for
889 if ($criteria_cnt > 1) {
890 $qry_where = '(' . $qry_where . ')';
891 }
4a71ee5 PHP3 fixes, optimization & coding standards
Loïc Chapeaux authored
892 // OR rows ${'cur' . $or}[$x]
13b3195 @lem9 For easier reading, replace "!isset" with "! isset"
lem9 authored
893 if (! isset($curAndOrRow)) {
d51e71f @lem9 was tbl_qbe
lem9 authored
894 $curAndOrRow = array();
895 }
896 for ($y = 0; $y <= $row; $y++) {
897 $criteria_cnt = 0;
898 $qry_orwhere = '';
899 $last_orwhere = '';
900 for ($x = 0; $x < $col; $x++) {
901 if (!empty($curField[$x]) && !empty(${'curOr' . $y}[$x]) && $x) {
902 $qry_orwhere .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' ';
903 }
904 if (!empty($curField[$x]) && !empty(${'curOr' . $y}[$x])) {
905 $qry_orwhere .= '(' . $curField[$x]
906 . ' '
2183740 @derrabus If magic_quotes_gpc is enabled, grab_globals calls stripslashes when ext...
derrabus authored
907 . ${'curOr' . $y}[$x]
d51e71f @lem9 was tbl_qbe
lem9 authored
908 . ')';
909 $last_orwhere = $x;
910 $criteria_cnt++;
911 }
912 } // end for
913 if ($criteria_cnt > 1) {
914 $qry_orwhere = '(' . $qry_orwhere . ')';
915 }
916 if (!empty($qry_orwhere)) {
917 $qry_where .= "\n"
918 . strtoupper(isset($curAndOrRow[$y]) ? $curAndOrRow[$y] . ' ' : '')
919 . $qry_orwhere;
920 } // end if
921 } // end for
922
923 if (!empty($qry_where) && $qry_where != '()') {
924 echo 'WHERE ' . htmlspecialchars($qry_where) . "\n";
925 } // end if
926
9b7f22a cleanup
Sebastian Mendel authored
927
d51e71f @lem9 was tbl_qbe
lem9 authored
928 // 4. ORDER BY
929 $last_orderby = 0;
13b3195 @lem9 For easier reading, replace "!isset" with "! isset"
lem9 authored
930 if (! isset($qry_orderby)) {
d51e71f @lem9 was tbl_qbe
lem9 authored
931 $qry_orderby = '';
932 }
933 for ($x = 0; $x < $col; $x++) {
934 if ($last_orderby && $x && !empty($curField[$x]) && !empty($curSort[$x])) {
935 $qry_orderby .= ', ';
936 }
937 if (!empty($curField[$x]) && !empty($curSort[$x])) {
938 // if they have chosen all fields using the * selector,
939 // then sorting is not available
79f320e @lem9 remove author names
lem9 authored
940 // Fix for Bug #570698
d51e71f @lem9 was tbl_qbe
lem9 authored
941 if (substr($curField[$x], -2) != '.*') {
942 $qry_orderby .= $curField[$x] . ' ' . $curSort[$x];
943 $last_orderby = 1;
944 }
945 }
946 } // end for
947 if (!empty($qry_orderby)) {
948 echo 'ORDER BY ' . htmlspecialchars($qry_orderby) . "\n";
949 }
950 ?>
d1dd742 Replaced blind table by CSS-floating <div> in db_qbe
Jo Michael authored
951 </textarea>
952 </fieldset>
953 <fieldset class="tblFooters">
954 <input type="submit" name="submit_sql" value="<?php echo __('Submit Query'); ?>" />
955 </fieldset>
956 </div>
d51e71f @lem9 was tbl_qbe
lem9 authored
957 </form>
958 <?php
959 /**
960 * Displays the footer
961 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
962 require 'libraries/footer.inc.php';
37d50c1 @derrabus Huge set of optimizations, please test!
derrabus authored
963 ?>
Something went wrong with that request. Please try again.