Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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