Documentation TYPO3 par Ameos

tbl_select.php

00001 <?php
00002 /* $Id: tbl_select.php,v 2.3 2003/12/30 12:22:51 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 
00009 require_once('./libraries/grab_globals.lib.php');
00010 require_once('./libraries/common.lib.php');
00011 require_once('./libraries/relation.lib.php'); // foreign keys
00012 
00013 if ($cfg['PropertiesIconic'] == true) {
00014     // We need to copy the value or else the == 'both' check will always return true
00015     $propicon = (string)$cfg['PropertiesIconic'];
00016 
00017     if ($propicon == 'both') {
00018         $iconic_spacer = '<nobr>';
00019     } else {
00020         $iconic_spacer = '';
00021     }
00022 
00023     $titles['Browse']     = $iconic_spacer . '<img width="12" height="13" src="images/button_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
00024 
00025     if ($propicon == 'both') {
00026         $titles['Browse']        .= '&nbsp;' . $strBrowseForeignValues . '</nobr>';
00027     }
00028 } else {
00029     $titles['Browse']        = $strBrowseForeignValues;
00030 }
00031 
00038 $numfunctions  = array('=', '>', '>=', '<', '<=', '!=', 'LIKE');
00039 $textfunctions = array('LIKE', '=', '!=');
00040 
00044 if (!isset($param) || $param[0] == '') {
00045     // Gets some core libraries
00046     require('./tbl_properties_common.php');
00047     //$err_url   = 'tbl_select.php' . $err_url;
00048     $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
00049     require('./tbl_properties_table_info.php');
00050 
00051     if (!isset($goto)) {
00052         $goto = $cfg['DefaultTabTable'];
00053     }
00054     // Defines the url to return to in case of error in the next sql statement
00055     $err_url   = $goto . '?' . PMA_generate_common_url($db, $table);
00056 
00057     // Gets the list and number of fields
00058     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
00059     $result      = @PMA_mysql_query($local_query);
00060     if (!$result) {
00061         PMA_mysqlDie('', $local_query, '', $err_url);
00062     }
00063     else {
00064         $fields_cnt        = mysql_num_rows($result);
00065         while ($row = PMA_mysql_fetch_array($result)) {
00066             $fields_list[] = $row['Field'];
00067             $type          = $row['Type'];
00068             // reformat mysql query output - staybyte - 9. June 2001
00069             $shorttype     = substr($type, 0, 3);
00070             if ($shorttype == 'set' || $shorttype == 'enu') {
00071                 $type      = str_replace(',', ', ', $type);
00072             } else {
00073                 $type          = preg_replace('@BINARY@i', '', $type);
00074                 $type          = preg_replace('@ZEROFILL@i', '', $type);
00075                 $type          = preg_replace('@UNSIGNED@i', '', $type);
00076             }
00077             if (empty($type)) {
00078                 $type      = '&nbsp;';
00079             }
00080             $fields_type[] = $type;
00081         } // end while
00082         mysql_free_result($result);
00083 
00084         // <markus@noga.de>
00085         // retrieve keys into foreign fields, if any
00086         $cfgRelation = PMA_getRelationsParam();
00087         // check also foreigners even if relwork is FALSE (to get
00088         // foreign keys from innodb)
00089         //$foreigners  = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
00090         $foreigners  = PMA_getForeigners($db, $table);
00091         ?>
00092 <form method="post" action="tbl_select.php" name="insertForm">
00093     <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
00094     <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
00095     <input type="hidden" name="back" value="tbl_select.php" />
00096     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
00097     <?php echo $strSelectFields; ?>&nbsp;:<br />
00098     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
00099     <select name="param[]" size="<?php echo ($fields_cnt < 10) ? $fields_cnt : 10; ?>" multiple="multiple">
00100         <?php
00101         echo "\n";
00102         // Displays the list of the fields
00103         for ($i = 0 ; $i < $fields_cnt; $i++) {
00104             echo '        <option value="' . htmlspecialchars($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
00105         }
00106         ?>
00107     </select><br />
00108     <ul>
00109         <li>
00110             <div style="margin-bottom: 10px">
00111             <?php echo $strLimitNumRows . "\n"; ?>
00112             <input type="text" size="4" name="session_max_rows" value="<?php echo $cfg['MaxRows']; ?>" class="textfield" />
00113             </div>
00114         </li>
00115         <li>
00116             <?php echo $strAddSearchConditions; ?><br />
00117             <input type="text" name="where" class="textfield" />&nbsp;
00118             <?php echo PMA_showMySQLDocu('Reference', 'Functions') . "\n"; ?>
00119             <br /><br />
00120             <?php echo '<i>' . $strOr . '</i> ' . $strDoAQuery; ?><br />
00121             <table border="<?php echo $cfg['Border']; ?>">
00122             <tr>
00123                 <th><?php echo $strField; ?></th>
00124                 <th><?php echo $strType; ?></th>
00125                 <th><?php echo $strFunction; ?></th>
00126                 <th><?php echo $strValue; ?></th>
00127             </tr>
00128         <?php
00129         for ($i = 0; $i < $fields_cnt; $i++) {
00130             echo "\n";
00131             $bgcolor   = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
00132             ?>
00133             <tr>
00134                 <td bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($fields_list[$i]); ?></td>
00135                 <td bgcolor="<?php echo $bgcolor; ?>"><?php echo $fields_type[$i]; ?></td>
00136                 <td bgcolor="<?php echo $bgcolor; ?>">
00137                     <select name="func[]">
00138             <?php
00139             if (preg_match('@char|blob|text|set|enum@i', $fields_type[$i])) {
00140                 foreach($textfunctions AS $k => $fc) {
00141                     echo "\n" . '                        '
00142                          . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
00143                 } // end while
00144             } else {
00145                 foreach($numfunctions AS $k => $fc) {
00146                     echo "\n" . '                        '
00147                          . '<option value="' .  htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>';
00148                 } // end while
00149             } // end if... else...
00150             echo "\n";
00151             ?>
00152                     </select>
00153                 </td>
00154                 <td bgcolor="<?php echo $bgcolor; ?>">
00155             <?php
00156             // <markus@noga.de>
00157             $field = $fields_list[$i];
00158 
00159             // do not use require_once here
00160             require('./libraries/get_foreign.lib.php');
00161 
00162             echo "\n";
00163             // we got a bug report: in some cases, even if $disp is true,
00164             // there are no rows, so we add a fetch_array
00165 
00166             if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp && @PMA_mysql_fetch_array($disp)) {
00167                 // f o r e i g n    k e y s
00168                 echo '                    <select name="fields[]">' . "\n";
00169                 // go back to first row
00170                 mysql_data_seek($disp,0);
00171                 echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100);
00172                 echo '                    </select>' . "\n";
00173             } else if (isset($foreign_link) && $foreign_link == true) {
00174             ?>
00175             <input type="text"   name="fields[]" id="field_<?php echo md5($field); ?>[]" class="textfield" />
00176             <script type="text/javascript" language="javascript">
00177                 document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&amp;field=<?php echo urlencode($field); ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
00178             </script>
00179             <?php
00180             } else if (substr($fields_type[$i], 0, 3)=='enu'){
00181                 // e n u m s
00182                 $enum_value=explode(', ', str_replace("'", '', substr($fields_type[$i], 5, -1)));
00183                 echo '                    <select name="fields[]">' . "\n";
00184                 echo '                        <option value=""></option>' . "\n";
00185                 $cnt_enum_value = count($enum_value);
00186                 for ($j=0; $j<$cnt_enum_value;$j++){
00187                     echo '                        <option value="' . $enum_value[$j] . '">' . $enum_value[$j] . '</option>';
00188                 } // end for
00189                 echo '                    </select>' . "\n";
00190             } else {
00191                 // o t h e r   c a s e s
00192                 echo '                    <input type="text" name="fields[]" size="40" class="textfield" />' .  "\n";
00193             }
00194 
00195             ?>
00196                     <input type="hidden" name="names[]" value="<?php echo htmlspecialchars($fields_list[$i]); ?>" />
00197                     <input type="hidden" name="types[]" value="<?php echo $fields_type[$i]; ?>" />
00198                 </td>
00199             </tr>
00200             <?php
00201         } // end for
00202         echo "\n";
00203         ?>
00204             </table><br />
00205         </li>
00206         <li>
00207             <?php echo $strDisplayOrder; ?><br />
00208             <select name="orderField" style="vertical-align: middle">
00209                 <option value="--nil--"></option>
00210         <?php
00211         echo "\n";
00212         for ($i = 0; $i < $fields_cnt; $i++) {
00213             echo '                ';
00214             echo '<option value="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
00215         } // end for
00216         ?>
00217             </select>
00218             <input type="radio" name="order" value="ASC" checked="checked" />
00219             <?php echo $strAscending; ?>&nbsp;
00220             <input type="radio" name="order" value="DESC" />
00221             <?php echo $strDescending; ?><br /><br />
00222         </li>
00223     </ul>
00224 
00225     &nbsp;&nbsp;&nbsp;&nbsp;
00226     <input type="hidden" name="max_number_of_fields" value="<?php echo $fields_cnt; ?>" />
00227     <input type="submit" name="submit" value="<?php echo $strGo; ?>" />
00228 </form>
00229         <?php
00230     } // end if
00231     require_once('./footer.inc.php');
00232 }
00233 
00234 
00238 else {
00239     // Builds the query
00240 
00241     $sql_query = 'SELECT ';
00242 
00243     // if all fields were selected to display, we do a SELECT *
00244     // (more efficient and this helps prevent a problem in IE
00245     // if one of the rows is edited and we come back to the Select results)
00246 
00247     if (count($param) == $max_number_of_fields) {
00248         $sql_query .= '* ';
00249     } else {
00250 
00251         $sql_query .= PMA_backquote(urldecode($param[0]));
00252         $i         = 0;
00253         $c         = count($param);
00254         while ($i < $c) {
00255             if ($i > 0) {
00256                 $sql_query .= ',' . PMA_backquote(urldecode($param[$i]));
00257             }
00258             $i++;
00259         }
00260     } // end if
00261 
00262     $sql_query .= ' FROM ' . PMA_backquote($table);
00263     // The where clause
00264     if ($where != '') {
00265         $sql_query .= ' WHERE ' . $where;
00266     }
00267     else {
00268         $sql_query .= ' WHERE 1';
00269         $cnt_fields = count($fields);
00270         for ($i = 0; $i < $cnt_fields; $i++) {
00271             if (!empty($fields) && $fields[$i] != '') {
00272                 if (preg_match('@char|blob|text|set|enum|date|time|year@i', $types[$i])) {
00273                     $quot     = '\'';
00274                 } else {
00275                     $quot     = '';
00276                 }
00277                 if (strtoupper($fields[$i]) == 'NULL' || strtoupper($fields[$i]) == 'NOT NULL') {
00278                     $quot     = '';
00279                     $func[$i] = 'IS';
00280                 }
00281                 //$sql_query    .= ' AND ' . PMA_backquote(urldecode($names[$i])) . " $func[$i] $quot$fields[$i]$quot";
00282 
00283                 $sql_query    .= ' AND ' . PMA_backquote(urldecode($names[$i])) . ' ' . $func[$i] . ' ' . $quot . PMA_sqlAddslashes($fields[$i]) . $quot;
00284 
00285             } // end if
00286         } // end for
00287     } // end if
00288 
00289     if ($orderField != '--nil--') {
00290         $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order;
00291     } // end if
00292 
00293     include('./sql.php');
00294 }
00295 
00296 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6