3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Gets some core libraries
9 require('./libraries/grab_globals.lib.php3');
10 require('./libraries/common.lib.php3');
11 require('./libraries/relation.lib.php3'); // foreign keys
15 * Defines arrays of functions (should possibly be in config.inc.php3
16 * so it can also be used in tbl_qbe.php3)
18 $numfunctions = array('=', '>', '>=', '<', '<=', '!=');
19 $textfunctions = array('LIKE', '=', '!=');
23 * Not selection yet required -> displays the selection form
25 if (!isset($param) ||
$param[0] == '') {
26 // Gets some core libraries
27 include('./tbl_properties_common.php3');
28 //$err_url = 'tbl_select.php3' . $err_url;
29 $url_query .= '&goto=tbl_select.php3&back=tbl_select.php3';
30 include('./tbl_properties_table_info.php3');
33 $goto = $cfg['DefaultTabTable'];
35 // Defines the url to return to in case of error in the next sql statement
36 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
38 // Gets the list and number of fields
39 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
40 $result = @PMA_mysql_query
($local_query);
42 PMA_mysqlDie('', $local_query, '', $err_url);
45 $fields_cnt = mysql_num_rows($result);
46 while ($row = PMA_mysql_fetch_array($result)) {
47 $fields_list[] = $row['Field'];
49 // reformat mysql query output - staybyte - 9. June 2001
50 $shorttype = substr($type, 0, 3);
51 if ($shorttype == 'set' ||
$shorttype == 'enu') {
52 $type = eregi_replace(',', ', ', $type);
54 $type = eregi_replace('BINARY', '', $type);
55 $type = eregi_replace('ZEROFILL', '', $type);
56 $type = eregi_replace('UNSIGNED', '', $type);
61 $fields_type[] = $type;
63 mysql_free_result($result);
66 // retrieve keys into foreign fields, if any
67 $cfgRelation = PMA_getRelationsParam();
68 // check also foreigners even if relwork is FALSE (to get
69 // foreign keys from innodb)
70 //$foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
71 $foreigners = PMA_getForeigners($db, $table);
73 <form method
="post" action
="tbl_select.php3">
74 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
75 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
76 <input type
="hidden" name
="back" value
="tbl_select.php3" />
77  
; 
; 
; 
; 
;
78 <?php
echo $strSelectFields; ?
> 
;:<br
/>
79  
; 
; 
; 
; 
;
80 <select name
="param[]" size
="<?php echo ($fields_cnt < 10) ? $fields_cnt : 10; ?>" multiple
="multiple">
83 // Displays the list of the fields
84 for ($i = 0 ; $i < $fields_cnt; $i++
) {
85 echo ' <option value="' . htmlspecialchars($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
91 <div style
="margin-bottom: 10px">
92 <?php
echo $strLimitNumRows . "\n"; ?
>
93 <input type
="text" size
="4" name
="session_max_rows" value
="<?php echo $cfg['MaxRows']; ?>" class="textfield" />
97 <?php
echo $strAddSearchConditions; ?
><br
/>
98 <input type
="text" name
="where" class="textfield" /> 
;
99 <?php
echo PMA_showMySQLDocu('Reference', 'Functions') . "\n"; ?
>
101 <?php
echo '<i>' . $strOr . '</i> ' . $strDoAQuery; ?
><br
/>
102 <table border
="<?php echo $cfg['Border']; ?>">
104 <th
><?php
echo $strField; ?
></th
>
105 <th
><?php
echo $strType; ?
></th
>
106 <th
><?php
echo $strFunction; ?
></th
>
107 <th
><?php
echo $strValue; ?
></th
>
110 for ($i = 0; $i < $fields_cnt; $i++
) {
112 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
115 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo htmlspecialchars($fields_list[$i]); ?
></td
>
116 <td bgcolor
="<?php echo $bgcolor; ?>"><?php
echo $fields_type[$i]; ?
></td
>
117 <td bgcolor
="<?php echo $bgcolor; ?>">
118 <select name
="func[]">
120 reset($numfunctions);
121 reset($textfunctions);
122 if (eregi('char|blob|text|set|enum', $fields_type[$i])) {
123 while (list($k, $fc) = each($textfunctions)) {
125 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
128 while (list($k, $fc) = each($numfunctions)) {
130 . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
132 } // end if... else...
137 <td bgcolor
="<?php echo $bgcolor; ?>">
140 $field = $fields_list[$i];
142 include('./libraries/get_foreign.lib.php3');
145 // we got a bug report: in some cases, even if $disp is true,
146 // there are no rows, so we add a fetch_array
147 if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp && @PMA_mysql_fetch_array
($disp)) {
148 // f o r e i g n k e y s
149 echo ' <select name="fields[]">' . "\n";
150 echo ' <option value=""></option>' . "\n";
151 // go back to first row
152 mysql_data_seek($disp,0);
153 while ($relrow = @PMA_mysql_fetch_array
($disp)) {
154 $key = $relrow[$foreign_field];
155 $value = (($foreign_display != FALSE) ?
'-' . htmlspecialchars($relrow[$foreign_display]) : '');
156 echo ' <option value="' . htmlspecialchars($key) . '">'
157 . htmlspecialchars($key) . $value . '</option>' . "\n";
159 echo ' </select>' . "\n";
160 } else if (substr($fields_type[$i], 0, 3)=='enu'){
162 $enum_value=explode(", ",str_replace("'", "", substr($fields_type[$i], 5, -1)));
163 echo ' <select name="fields[]">' . "\n";
164 echo ' <option value=""></option>' . "\n";
165 for ($j=0; $j<count($enum_value);$j++
){
166 echo ' <option value="' . $enum_value[$j] . '">' . $enum_value[$j] . '</option>';
168 echo ' </select>' . "\n";
170 // o t h e r c a s e s
171 echo ' <input type="text" name="fields[]" size="40" class="textfield" />' . "\n";
175 <input type
="hidden" name
="names[]" value
="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
176 <input type
="hidden" name
="types[]" value
="<?php echo $fields_type[$i]; ?>" />
186 <?php
echo $strDisplayOrder; ?
><br
/>
187 <select name
="orderField" style
="vertical-align: middle">
188 <option value
="--nil--"></option
>
191 for ($i = 0; $i < $fields_cnt; $i++
) {
193 echo '<option value="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
197 <input type
="radio" name
="order" value
="ASC" checked
="checked" />
198 <?php
echo $strAscending; ?
> 
;
199 <input type
="radio" name
="order" value
="DESC" />
200 <?php
echo $strDescending; ?
><br
/><br
/>
204  
; 
; 
; 
;
205 <input type
="submit" name
="submit" value
="<?php echo $strGo; ?>" />
210 include('./footer.inc.php3');
215 * Selection criteria have been submitted -> do the work
219 $sql_query = 'SELECT ' . PMA_backquote(urldecode($param[0]));
224 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
228 $sql_query .= ' FROM ' . PMA_backquote($table);
231 $sql_query .= ' WHERE ' . $where;
234 $sql_query .= ' WHERE 1';
235 for ($i = 0; $i < count($fields); $i++
) {
236 if (!empty($fields) && $fields[$i] != '') {
237 if (eregi('char|blob|text|set|enum|date|time|year', $types[$i])) {
242 if (strtoupper($fields[$i]) == 'NULL' ||
strtoupper($fields[$i]) == 'NOT NULL') {
246 $sql_query .= ' AND ' . PMA_backquote(urldecode($names[$i])) . " $func[$i] $quot$fields[$i]$quot";
251 if ($orderField != '--nil--') {
252 $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
255 include('./sql.php3');