2.2.4
[phpmyadmin/arisferyanto.git] / tbl_qbe.php3
blob64163fb87f47f54caa34cc32d857196fd88ba399
1 <?php
2 /* $Id$ */
5 /**
6 * Gets the values of the variables posted or sent to this script and displays
7 * the headers
8 */
9 require('./libraries/grab_globals.lib.php3');
10 require('./libraries/common.lib.php3');
13 /**
14 * A query has been submitted -> executes it, else displays the headers
16 if (isset($submit_sql)) {
17 $goto = 'db_details.php3';
18 $zero_rows = htmlspecialchars($strSuccess);
19 $sql_query = urldecode($encoded_sql_query);
20 if (get_magic_quotes_gpc()) {
21 $sql_query = addslashes($sql_query);
23 include('./sql.php3');
24 exit();
25 } else {
26 include('./header.inc.php3');
30 /**
31 * Initializes some variables
33 if (empty($Columns)) {
34 $Columns = 3; // Initial number of columns
36 if (!isset($Add_Col)) {
37 $Add_Col = '';
39 if (!isset($Add_Row)) {
40 $Add_Row = '';
42 if (!isset($Rows)) {
43 $Rows = '';
45 if (!isset($InsCol)) {
46 $InsCol = '';
48 if (!isset($DelCol)) {
49 $DelCol = '';
51 if (!isset($prev_Criteria)) {
52 $prev_Criteria = '';
54 // workaround for a PHP3 problem
55 if (!isset($Criteria)) {
56 //$Criteria = '';
57 $Criteria = array();
58 for ($i = 0; $i < $Columns; $i++) {
59 $Criteria[$i] = '';
62 if (!isset($InsRow)) {
63 // $InsRow = '';
64 $InsRow = array();
65 for ($i = 0; $i < $Columns; $i++) {
66 $InsRow[$i] = '';
69 if (!isset($DelRow)) {
70 // $DelRow = '';
71 $DelRow = array();
72 for ($i = 0; $i < $Columns; $i++) {
73 $DelRow[$i] = '';
76 if (!isset($AndOrRow)) {
77 // $AndOrRow = '';
78 $AndOrRow = array();
79 for ($i = 0; $i < $Columns; $i++) {
80 $AndOrRow[$i] = '';
83 if (!isset($AndOrCol)) {
84 // $AndOrCol = '';
85 $AndOrCol = array();
86 for ($i = 0; $i < $Columns; $i++) {
87 $AndOrCol[$i] = '';
90 $wid = 12;
91 $widem = $wid . 'em';
92 $col = $Columns + $Add_Col;
93 if ($col < 0) {
94 $col = 0;
96 $row = $Rows + $Add_Row;
97 if ($row < 0) {
98 $row = 0;
103 * Prepares the form
105 $tbl_result = mysql_list_tables($db);
106 $tbl_result_cnt = mysql_num_rows($tbl_result);
107 $i = 0;
108 $k = 0;
110 // The tables list sent by a previously submitted form
111 if (!empty($TableList)) {
112 for ($x = 0; $x < sizeof($TableList); $x++) {
113 $tbl_names[$TableList[$x]] = ' selected="selected"';
115 } // end if
117 // The tables list gets from MySQL
118 while ($i < $tbl_result_cnt) {
119 $tbl = mysql_tablename($tbl_result, $i);
120 $fld_results = mysql_list_fields($db, $tbl);
121 $fld_results_cnt = mysql_num_fields($fld_results);
122 $j = 0;
124 if (empty($tbl_names[$tbl]) && !empty($TableList)) {
125 $tbl_names[$tbl] = '';
126 } else {
127 $tbl_names[$tbl] = ' selected="selected"';
128 } // end if
130 // The fields list per selected tables
131 if ($tbl_names[$tbl] == ' selected="selected"') {
132 $fld[$k++] = PMA_backquote($tbl) . '.*';
133 while ($j < $fld_results_cnt) {
134 $fld[$k] = mysql_field_name($fld_results, $j);
135 $fld[$k] = PMA_backquote($tbl) . '.' . PMA_backquote($fld[$k]);
136 $k++;
137 $j++;
138 } // end while
139 } // end if
140 mysql_free_result($fld_results);
142 $i++;
143 } // end if
144 mysql_free_result($tbl_result);
148 * Displays the form
152 <!-- Query by example form -->
153 <form action="tbl_qbe.php3" method="post">
154 <table border="<?php echo $cfgBorder; ?>">
156 <!-- Fields row -->
157 <tr>
158 <td align="<?php echo $cell_align_right; ?>" bgcolor="<?php echo $cfgThBgcolor; ?>">
159 <b><?php echo $strField; ?>&nbsp;:&nbsp;</b>
160 </td>
161 <?php
162 $z = 0;
163 for ($x = 0; $x < $col; $x++) {
164 if (!empty($InsCol) && isset($InsCol[$x]) && $InsCol[$x] == 'on') {
166 <td align="center" bgcolor="<?php echo $cfgBgcolorOne; ?>">
167 <select style="width: <?php echo $widem; ?>" name="Field[<?php echo $z; ?>]" size="1">
168 <option value=""></option>
169 <?php
170 echo "\n";
171 for ($y = 0; $y < sizeof($fld); $y++) {
172 if ($fld[$y] == '') {
173 $sel = ' selected="selected"';
174 } else {
175 $sel = '';
177 echo ' ';
178 echo '<option value="' . urlencode($fld[$y]) . '"' . $sel . '>' . htmlspecialchars($fld[$y]) . '</option>' . "\n";
179 } // end for
181 </select>
182 </td>
183 <?php
184 $z++;
185 } // end if
186 echo "\n";
188 if (!empty($DelCol) && isset($DelCol[$x]) && $DelCol[$x] == 'on') {
189 continue;
192 <td align="center" bgcolor="<?php echo $cfgBgcolorOne; ?>">
193 <select style="width: <?php echo $widem; ?>" name="Field[<?php echo $z; ?>]" size="1">
194 <option value=""></option>
195 <?php
196 echo "\n";
197 for ($y = 0; $y < sizeof($fld); $y++) {
198 if (isset($Field[$x]) && $fld[$y] == urldecode($Field[$x])) {
199 $curField[$z] = urldecode($Field[$x]);
200 $sel = ' selected="selected"';
201 } else {
202 $sel = '';
203 } // end if
204 echo ' ';
205 echo '<option value="' . urlencode($fld[$y]) . '"' . $sel . '>' . htmlspecialchars($fld[$y]) . '</option>' . "\n";
206 } // end for
208 </select>
209 </td>
210 <?php
211 $z++;
212 echo "\n";
213 } // end for
215 </tr>
217 <!-- Sort row -->
218 <tr>
219 <td align="<?php echo $cell_align_right; ?>" bgcolor="<?php echo $cfgThBgcolor; ?>">
220 <b><?php echo $strSort; ?>&nbsp;:&nbsp;</b>
221 </td>
222 <?php
223 $z = 0;
224 for ($x = 0; $x < $col; $x++) {
225 if (!empty($InsCol) && isset($InsCol[$x]) && $InsCol[$x] == 'on') {
227 <td align="center" bgcolor="<?php echo $cfgBgcolorTwo; ?>">
228 <select style="width: <?php echo $widem; ?>" name="Sort[<?php echo $z; ?>]" size="1">
229 <option value=""></option>
230 <option value="ASC"><?php echo $strAscending; ?></option>
231 <option value="DESC"><?php echo $strDescending; ?></option>
232 </select>
233 </td>
234 <?php
235 $z++;
236 } // end if
237 echo "\n";
239 if (!empty($DelCol) && isset($DelCol[$x]) && $DelCol[$x] == 'on') {
240 continue;
243 <td align="center" bgcolor="<?php echo $cfgBgcolorTwo; ?>">
244 <select style="width: <?php echo $widem; ?>" name="Sort[<?php echo $z; ?>]" size="1">
245 <option value=""></option>
246 <?php
247 echo "\n";
248 if (isset($Sort[$x]) && $Sort[$x] == 'ASC') {
249 $curSort[$z] = $Sort[$x];
250 $sel = ' selected="selected"';
251 } else {
252 $sel = '';
253 } // end if
254 echo ' ';
255 echo '<option value="ASC"' . $sel . '>' . $strAscending . '</option>' . "\n";
256 if (isset($Sort[$x]) && $Sort[$x] == 'DESC') {
257 $curSort[$z] = $Sort[$x];
258 $sel = ' selected="selected"';
259 } else {
260 $sel = '';
261 } // end if
262 echo ' ';
263 echo '<option value="DESC"' . $sel . '>' . $strDescending . '</option>' . "\n";
265 </select>
266 </td>
267 <?php
268 $z++;
269 echo "\n";
270 } // end for
272 </tr>
274 <!-- Show row -->
275 <tr>
276 <td align="<?php echo $cell_align_right; ?>" bgcolor="<?php echo $cfgThBgcolor; ?>">
277 <b><?php echo $strShow; ?>&nbsp;:&nbsp;</b>
278 </td>
279 <?php
280 $z = 0;
281 for ($x = 0; $x < $col; $x++) {
282 if (!empty($InsCol) && isset($InsCol[$x]) && $InsCol[$x] == 'on') {
284 <td align="center" bgcolor="<?php echo $cfgBgcolorOne; ?>">
285 <input type="checkbox" name="Show[<?php echo $z; ?>]" />
286 </td>
287 <?php
288 $z++;
289 } // end if
290 echo "\n";
292 if (!empty($DelCol) && isset($DelCol[$x]) && $DelCol[$x] == 'on') {
293 continue;
295 if (isset($Show[$x])) {
296 $checked = ' checked="checked"';
297 $curShow[$z] = $Show[$x];
298 } else {
299 $checked = '';
302 <td align="center" bgcolor="<?php echo $cfgBgcolorOne; ?>">
303 <input type="checkbox" name="Show[<?php echo $z; ?>]"<?php echo $checked; ?> />
304 </td>
305 <?php
306 $z++;
307 echo "\n";
308 } // end for
310 </tr>
312 <!-- Criteria row -->
313 <tr>
314 <td align="<?php echo $cell_align_right; ?>" bgcolor="<?php echo $cfgThBgcolor; ?>">
315 <b><?php echo $strCriteria; ?>&nbsp;:&nbsp;</b>
316 </td>
317 <?php
318 $z = 0;
319 for ($x = 0; $x < $col; $x++) {
320 if (!empty($InsCol) && isset($InsCol[$x]) && $InsCol[$x] == 'on') {
322 <td align="center" bgcolor="<?php echo $cfgBgcolorTwo; ?>">
323 <input type="text" name="Criteria[<?php echo $z; ?>]" value="" style="width: <?php echo $widem; ?>" size="20" />
324 </td>
325 <?php
326 $z++;
327 } // end if
328 echo "\n";
330 if (!empty($DelCol) && isset($DelCol[$x]) && $DelCol[$x] == 'on') {
331 continue;
333 if (isset($Criteria[$x])) {
334 if (get_magic_quotes_gpc()) {
335 $stripped_Criteria = stripslashes($Criteria[$x]);
336 } else {
337 $stripped_Criteria = $Criteria[$x];
340 if ((empty($prev_Criteria) || !isset($prev_Criteria[$x]))
341 || urldecode($prev_Criteria[$x]) != htmlspecialchars($stripped_Criteria)) {
342 $curCriteria[$z] = $stripped_Criteria;
343 $encoded_Criteria = urlencode($stripped_Criteria);
344 } else {
345 $curCriteria[$z] = urldecode($prev_Criteria[$x]);
346 $encoded_Criteria = $prev_Criteria[$x];
349 <td align="center" bgcolor="<?php echo $cfgBgcolorTwo; ?>">
350 <input type="hidden" name="prev_Criteria[<?php echo $z; ?>]" value="<?php echo $encoded_Criteria; ?>" />
351 <input type="text" name="Criteria[<?php echo $z; ?>]" value="<?php echo htmlspecialchars($stripped_Criteria); ?>" style="width: <?php echo $widem; ?>" size="20" />
352 </td>
353 <?php
354 $z++;
355 echo "\n";
356 } // end for
358 </tr>
360 <!-- And/Or columns and rows -->
361 <?php
362 $w = 0;
363 for ($y = 0; $y <= $row; $y++) {
364 $bgcolor = ($y % 2) ? $cfgBgcolorOne : $cfgBgcolorTwo;
365 if (isset($InsRow[$y]) && $InsRow[$y] == 'on') {
366 $chk['or'] = ' checked="checked"';
367 $chk['and'] = '';
369 <tr>
370 <td align="<?php echo $cell_align_right; ?>" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap">
371 <!-- Row controls -->
372 <table bgcolor="<?php echo $bgcolor; ?>">
373 <tr>
374 <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">
375 <small><?php echo $strQBEIns; ?>&nbsp;:</small>
376 <input type="checkbox" name="InsRow[<?php echo $w; ?>]" />
377 </td>
378 <td align="<?php echo $cell_align_right; ?>">
379 <b><?php echo $strAnd; ?>&nbsp;:</b>
380 </td>
381 <td>
382 <input type="radio" name="AndOrRow[<?php echo $w; ?>]" value="and"<?php echo $chk['and']; ?> />
383 &nbsp;
384 </td>
385 </tr>
386 <tr>
387 <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">
388 <small><?php echo $strQBEDel; ?>&nbsp;:</small>
389 <input type="checkbox" name="DelRow[<?php echo $w; ?>]" />
390 </td>
391 <td align="<?php echo $cell_align_right; ?>">
392 <b><?php echo $strOr; ?>&nbsp;:</b>
393 </td>
394 <td>
395 <input type="radio" name="AndOrRow[<?php echo $w; ?>]" value="or"<?php echo $chk['or']; ?> />
396 &nbsp;
397 </td>
398 </tr>
399 </table>
400 </td>
401 <?php
402 $z = 0;
403 for ($x = 0; $x < $col; $x++) {
404 if ($InsCol[$x] == 'on') {
405 echo "\n";
406 $or = 'Or' . $w . '[' . $z . ']';
408 <td align="center" bgcolor="<?php echo $bgcolor; ?>">
409 <textarea cols="20" rows="2" style="width: <?php echo $widem; ?>" name="<?php echo $or; ?>"></textarea>
410 </td>
411 <?php
412 $z++;
413 } // end if
414 if ($DelCol[$x] == 'on') {
415 continue;
418 echo "\n";
419 $or = 'Or' . $w . '[' . $z . ']';
421 <td align="center" bgcolor="<?php echo $bgcolor; ?>">
422 <textarea cols="20" rows="2" style="width: <?php echo $widem; ?>" name="<?php echo $or; ?>"></textarea>
423 </td>
424 <?php
425 $z++;
426 } // end for
427 $w++;
428 echo "\n";
430 </tr>
431 <?php
432 } // end if
434 if (isset($DelRow[$y]) && $DelRow[$y] == 'on') {
435 continue;
438 if (isset($AndOrRow[$y])) {
439 $curAndOrRow[$w] = $AndOrRow[$y];
441 if (isset($AndOrRow[$y]) && $AndOrRow[$y] == 'and') {
442 $chk['and'] = ' checked="checked"';
443 $chk['or'] = '';
444 } else {
445 $chk['or'] = ' checked="checked"';
446 $chk['and'] = '';
448 echo "\n";
450 <tr>
451 <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">
452 <!-- Row controls -->
453 <table bgcolor="<?php echo $bgcolor; ?>">
454 <tr>
455 <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">
456 <small><?php echo $strQBEIns; ?>&nbsp;:</small>
457 <input type="checkbox" name="InsRow[<?php echo $w; ?>]" />
458 </td>
459 <td align="<?php echo $cell_align_right; ?>">
460 <b><?php echo $strAnd; ?>&nbsp;:</b>
461 </td>
462 <td>
463 <input type="radio" name="AndOrRow[<?php echo $w; ?>]" value="and"<?php echo $chk['and']; ?> />
464 </td>
465 </tr>
466 <tr>
467 <td align="<?php echo $cell_align_right; ?>" nowrap="nowrap">
468 <small><?php echo $strQBEDel; ?>&nbsp;:</small>
469 <input type="checkbox" name="DelRow[<?php echo $w; ?>]" />
470 </td>
471 <td align="<?php echo $cell_align_right; ?>">
472 <b><?php echo $strOr; ?>&nbsp;:</b>
473 </td>
474 <td>
475 <input type="radio" name="AndOrRow[<?php echo $w; ?>]" value="or"<?php echo $chk['or']; ?> />
476 </td>
477 </tr>
478 </table>
479 </td>
480 <?php
481 $z = 0;
482 for ($x = 0; $x < $col; $x++) {
483 if (!empty($InsCol) && isset($InsCol[$x]) && $InsCol[$x] == 'on') {
484 echo "\n";
485 $or = 'Or' . $w . '[' . $z . ']';
487 <td align="center" bgcolor="<?php echo $bgcolor; ?>">
488 <textarea cols="20" rows="2" style="width: <?php echo $widem; ?>" name="<?php echo $or; ?>"></textarea>
489 </td>
490 <?php
491 $z++;
492 } // end if
493 if (!empty($DelCol) && isset($DelCol[$x]) && $DelCol[$x] == 'on') {
494 continue;
497 echo "\n";
498 $or = 'Or' . $y;
499 if (!isset(${$or})) {
500 ${$or} = '';
502 if (!empty(${$or}) && isset(${$or}[$x])) {
503 if (get_magic_quotes_gpc()) {
504 $stripped_or = stripslashes(${$or}[$x]);
505 } else {
506 $stripped_or = ${$or}[$x];
508 } else {
509 $stripped_or = '';
512 <td align="center" bgcolor="<?php echo $bgcolor; ?>">
513 <textarea cols="20" rows="2" style="width: <?php echo $widem; ?>" name="Or<?php echo $w . '[' . $z . ']'; ?>"><?php echo htmlspecialchars($stripped_or); ?></textarea>
514 </td>
515 <?php
516 if (!empty(${$or}) && isset(${$or}[$x])) {
517 ${'cur' . $or}[$z] = ${$or}[$x];
519 $z++;
520 } // end for
521 $w++;
522 echo "\n";
524 </tr>
525 <?php
526 echo "\n";
527 } // end for
530 <!-- Modify columns -->
531 <tr>
532 <td align="<?php echo $cell_align_right; ?>" bgcolor="<?php echo $cfgThBgcolor; ?>">
533 <b><?php echo $strModify; ?>&nbsp;:&nbsp;</b>
534 </td>
535 <?php
536 $z = 0;
537 for ($x = 0; $x < $col; $x++) {
538 if (!empty($InsCol) && isset($InsCol[$x]) && $InsCol[$x] == 'on') {
539 $curAndOrCol[$z] = $AndOrCol[$y];
540 if ($AndOrCol[$z] == 'or') {
541 $chk['or'] = ' checked="checked"';
542 $chk['and'] = '';
543 } else {
544 $chk['and'] = ' checked="checked"';
545 $chk['or'] = '';
548 <td align="center" bgcolor="<?php echo $cfgBgcolorTwo; ?>">
549 <b><?php echo $strOr; ?>&nbsp;:</b>
550 <input type="radio" name="AndOrCol[<?php echo $z; ?>]" value="or"<?php echo $chk['or']; ?> />
551 &nbsp;&nbsp;<b><?php echo $strAnd; ?>&nbsp;:</b>
552 <input type="radio" name="AndOrCol[<?php echo $z; ?>]" value="and"<?php echo $chk['and']; ?> />
553 <br />
554 <?php echo $strQBEIns . "\n"; ?>
555 <input type="checkbox" name="InsCol[<?php echo $z; ?>]" />
556 &nbsp;&nbsp;<?php echo $strQBEDel . "\n"; ?>
557 <input type="checkbox" name="DelCol[<?php echo $z; ?>]" />
558 </td>
559 <?php
560 $z++;
561 } // end if
562 echo "\n";
564 if (!empty($DelCol) && isset($DelCol[$x]) && $DelCol[$x] == 'on') {
565 continue;
568 if (isset($AndOrCol[$y])) {
569 $curAndOrCol[$z] = $AndOrCol[$y];
571 if (isset($AndOrCol[$z]) && $AndOrCol[$z] == 'or') {
572 $chk['or'] = ' checked="checked"';
573 $chk['and'] = '';
574 } else {
575 $chk['and'] = ' checked="checked"';
576 $chk['or'] = '';
579 <td align="center" bgcolor="<?php echo $cfgBgcolorTwo; ?>">
580 <b><?php echo $strOr; ?>&nbsp;:</b>
581 <input type="radio" name="AndOrCol[<?php echo $z; ?>]" value="or"<?php echo $chk['or']; ?> />
582 &nbsp;&nbsp;<b><?php echo $strAnd; ?>&nbsp;:</b>
583 <input type="radio" name="AndOrCol[<?php echo $z; ?>]" value="and"<?php echo $chk['and']; ?> />
584 <br />
585 <?php echo $strQBEIns . "\n"; ?>
586 <input type="checkbox" name="InsCol[<?php echo $z; ?>]" />
587 &nbsp;&nbsp;<?php echo $strQBEDel . "\n"; ?>
588 <input type="checkbox" name="DelCol[<?php echo $z; ?>]" />
589 </td>
590 <?php
591 $z++;
592 echo "\n";
593 } // end for
595 </tr>
596 </table>
599 <!-- Other controls -->
600 <table border="0">
601 <tr>
602 <td valign="top">
603 <table border="0" align="<?php echo $cell_align_left; ?>">
604 <tr>
605 <td rowspan="4" valign="top">
606 <?php echo $strUseTables; ?>&nbsp;:
607 <br />
608 <select name="TableList[]" size="7" multiple="multiple">
609 <?php
610 while (list($key, $val) = each($tbl_names)) {
611 echo ' ';
612 echo '<option value="' . urlencode($key) . '"' . $val . '>' . htmlspecialchars($key) . '</option>' . "\n";
615 </select>
616 </td>
617 <td align="<?php echo $cell_align_right; ?>" valign="bottom">
618 <input type="hidden" value="<?php echo $db; ?>" name="db" />
619 <input type="hidden" value="<?php echo $z; ?>" name="Columns" />
620 <?php
621 $w--;
623 <input type="hidden" value="<?php echo $w; ?>" name="Rows" />
624 <?php echo $strAddDeleteRow; ?>&nbsp;:
625 <select size="1" name="Add_Row">
626 <option value="-3">-3</option>
627 <option value="-2">-2</option>
628 <option value="-1">-1</option>
629 <option value="0" selected="selected">0</option>
630 <option value="1">1</option>
631 <option value="2">2</option>
632 <option value="3">3</option>
633 </select>
634 </td>
635 </tr>
636 <tr>
637 <td align="<?php echo $cell_align_right; ?>" valign="bottom">
638 <?php echo $strAddDeleteColumn; ?>&nbsp;:
639 <select size="1" name="Add_Col">
640 <option value="-3">-3</option>
641 <option value="-2">-2</option>
642 <option value="-1">-1</option>
643 <option value="0" selected="selected">0</option>
644 <option value="1">1</option>
645 <option value="2">2</option>
646 <option value="3">3</option>
647 </select>
648 </td>
649 </tr>
650 <!-- Generates a query -->
651 <tr align="center" valign="top">
652 <td>
653 <input type="submit" name="modify" value="<?php echo $strUpdateQuery; ?>" />
654 <input type="hidden" name="server" value="<?php echo $server; ?>" />
655 <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
656 </td>
657 </tr>
658 <!-- Executes a query -->
659 <tr align="center" valign="top">
660 <td>
661 <input type="submit" name="submit_sql" value="<?php echo $strRunQuery; ?>" />
662 </td>
663 </tr>
664 </table>
665 </td>
666 <td>
667 <!-- Displays the current query -->
668 <?php echo sprintf($strQueryOnDb, htmlspecialchars($db)); ?><br />
669 <textarea cols="30" rows="7" name="sql_query">
670 <?php
671 // 1. SELECT
672 $last_select = 0;
673 $encoded_qry = '';
674 if (!isset($qry_select)) {
675 $qry_select = '';
677 for ($x = 0; $x < $col; $x++) {
678 if (!empty($curField[$x]) && isset($curShow[$x]) && $curShow[$x] == 'on') {
679 if ($last_select) {
680 $qry_select .= ', ';
682 $qry_select .= $curField[$x];
683 $last_select = 1;
685 } // end for
686 if (!empty($qry_select)) {
687 $encoded_qry .= urlencode('SELECT ' . $qry_select . "\n");
688 echo 'SELECT ' . htmlspecialchars($qry_select) . "\n";
691 // 2. FROM
692 if (!isset($TableList)) {
693 $TableList = array();
695 if (!isset($qry_from)) {
696 $qry_from = '';
698 for ($x = 0; $x < sizeof($TableList); $x++) {
699 if ($x) {
700 $qry_from .= ', ';
702 $qry_from .= PMA_backquote(urldecode($TableList[$x]));
703 } // end for
704 if (!empty($qry_from)) {
705 $encoded_qry .= urlencode('FROM ' . $qry_from . "\n");
706 echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
709 // 3. WHERE
710 $qry_where = '';
711 $criteria_cnt = 0;
712 for ($x = 0; $x < $col; $x++) {
713 if (!empty($curField[$x]) && !empty($curCriteria[$x]) && $x && isset($last_where)) {
714 $qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';
716 if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
717 $qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';
718 $last_where = $x;
719 $criteria_cnt++;
721 } // end for
722 if ($criteria_cnt > 1) {
723 $qry_where = '(' . $qry_where . ')';
726 // OR rows ${"cur".$or}[$x]
727 if (!isset($curAndOrRow)) {
728 $curAndOrRow = array();
730 for ($y = 0; $y <= $row; $y++) {
731 $criteria_cnt = 0;
732 $qry_orwhere = '';
733 $last_orwhere = '';
734 for ($x = 0; $x < $col; $x++) {
735 if (!empty($curField[$x]) && !empty(${'curOr' . $y}[$x]) && $x) {
736 $qry_orwhere .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' ';
738 if (!empty($curField[$x]) && !empty(${'curOr' . $y}[$x])) {
739 $qry_orwhere .= '(' . $curField[$x]
740 . ' '
741 . (get_magic_quotes_gpc() ? stripslashes(${'curOr' . $y}[$x]) : ${'curOr' . $y}[$x])
742 . ')';
743 $last_orwhere = $x;
744 $criteria_cnt++;
746 } // end for
747 if ($criteria_cnt > 1) {
748 $qry_orwhere = '(' . $qry_orwhere . ')';
750 if (!empty($qry_orwhere)) {
751 $qry_where .= "\n"
752 . strtoupper(isset($curAndOrRow[$y]) ? $curAndOrRow[$y] . ' ' : '')
753 . $qry_orwhere;
754 } // end if
755 } // end for
757 if (!empty($qry_where) && $qry_where != '()') {
758 $encoded_qry .= urlencode('WHERE ' . $qry_where . "\n");
759 echo 'WHERE ' . htmlspecialchars($qry_where) . "\n";
760 } // end if
762 // 4. ORDER BY
763 $last_orderby = 0;
764 if (!isset($qry_orderby)) {
765 $qry_orderby = '';
767 for ($x = 0; $x < $col; $x++) {
768 if ($last_orderby && $x && !empty($curField[$x]) && !empty($curSort[$x])) {
769 $qry_orderby .= ', ';
771 if (!empty($curField[$x]) && !empty($curSort[$x])) {
772 $qry_orderby .= $curField[$x] . ' ' . $curSort[$x];
773 $last_orderby = 1;
775 } // end for
776 if (!empty($qry_orderby)) {
777 $encoded_qry .= urlencode('ORDER BY ' . $qry_orderby);
778 echo 'ORDER BY ' . htmlspecialchars($qry_orderby) . "\n";
781 </textarea>
782 <input type="hidden" name="encoded_sql_query" value="<?php echo $encoded_qry; ?>" />
783 </td>
784 </tr>
785 </table>
787 </form>
790 <?php
792 * Displays the footer
794 require('./footer.inc.php3');