Documentation TYPO3 par Ameos

tbl_query_box.php

00001 <?php
00002 /* $Id: tbl_query_box.php,v 2.4 2003/12/13 13:15:38 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 // Check parameters
00006 
00007 require_once('./libraries/common.lib.php');
00008 require_once('./libraries/bookmark.lib.php');
00009 
00010 if (!($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full'))) {
00011     PMA_checkParameters(array('db','table','url_query'));
00012 }
00013 
00017 if (isset($show_query) && $show_query == '1') {
00018     // This script has been called by read_dump.php
00019     if (isset($sql_query_cpy)) {
00020         $query_to_display = $sql_query_cpy;
00021     }
00022     // Other cases
00023     else {
00024         $query_to_display = $sql_query;
00025     }
00026 } else {
00027     $query_to_display     = '';
00028 }
00029 unset($sql_query);
00030 
00034 $fields_cnt = 0;
00035 if (isset($db) && isset($table) && $table != '' && $db != '') {
00036     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
00037     $result      = @PMA_mysql_query($local_query);
00038     if (!$result) {
00039         PMA_mysqlDie('', $local_query, '', $err_url);
00040     }
00041     else {
00042         $fields_cnt        = mysql_num_rows($result);
00043         while ($row = PMA_mysql_fetch_array($result)) {
00044             $fields_list[] = $row['Field'];
00045         } // end while
00046         mysql_free_result($result);
00047     }
00048 }
00049 
00053 // loic1: defines wether file upload is available or not
00054 // ($is_upload now defined in common.lib.php)
00055 
00056 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full')) {
00057     $locking   = 'onKeyPress="document.sqlform.elements[\'LockFromUpdate\'].checked = true;"';
00058 } else {
00059     $locking   = '';
00060 }
00061 
00062 $auto_sel  = ($cfg['TextareaAutoSelect']
00063                // 2003-02-05 rabus: This causes big trouble with Opera 7 for
00064                // Windows, so let's disable it there...
00065                && !(PMA_USR_OS == 'Win' && PMA_USR_BROWSER_AGENT == 'OPERA' && PMA_USR_BROWSER_VER >= 7))
00066            ? "\n" . '             onfocus="if (typeof(document.layers) == \'undefined\' || typeof(textarea_selected) == \'undefined\') {textarea_selected = 1; document.sqlform.elements[\'sql_query\'].select();}"'
00067            : '';
00068 $auto_sel .= ' ' . $locking;
00069 
00070 // garvin: If non-JS query window is embedded, display a list of databases to choose from.
00071 //         Apart from that, a non-js query window sucks badly.
00072 
00073 if ($cfg['QueryFrame'] && (!$cfg['QueryFrameJS'] && !$db || ($cfg['QueryFrameJS'] && !$db))) {
00077     if ($server > 0) {
00078         PMA_availableDatabases(); // this function is defined in "common.lib.php"
00079     } else {
00080         $num_dbs = 0;
00081     }
00082 
00083     if ($num_dbs > 0) {
00084         $queryframe_db_list = '<select size=1 name="db">';
00085         for ($i = 0; $i < $num_dbs; $i++) {
00086             $t_db = $dblist[$i];
00087             $queryframe_db_list .= '<option value="' . htmlspecialchars($t_db) . '">' . htmlspecialchars($t_db) . '</option>';
00088         }
00089         $queryframe_db_list .= '</select>';
00090     } else {
00091         $queryframe_db_list = '';
00092     }
00093 } else {
00094     $queryframe_db_list = '';
00095 }
00096 
00097 $form_items = 0;
00098 
00099 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow) {
00100 ?>
00101         <script type="text/javascript">
00102         <!--
00103         document.writeln('<form method="post" target="phpmain' +  <?php echo ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) ? 'opener.' : '');?>parent.frames.queryframe.document.hashform.hash.value + '" action="read_dump.php"<?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?> onsubmit="return checkSqlQuery(this)" name="sqlform">');
00104         //-->
00105         </script>
00106         <noscript>
00107             <form method="post" target="phpmain<?php echo md5($cfg['PmaAbsoluteUri']); ?>" action="read_dump.php"<?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?> name="sqlform">
00108         </noscript>
00109 <?php
00110 } else {
00111 ?>
00112         <form method="post" action="read_dump.php"<?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?> onsubmit="return checkSqlQuery(this)" name="sqlform">
00113 <?php
00114 }
00115 ?>
00116             <input type="hidden" name="is_js_confirmed" value="0" />
00117             <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
00118             <input type="hidden" name="pos" value="0" />
00119             <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
00120             <input type="hidden" name="zero_rows" value="<?php echo $strSuccess; ?>" />
00121             <input type="hidden" name="prev_sql_query" value="<?php echo ((!empty($query_to_display)) ? urlencode($query_to_display) : ''); ?>" />
00122 <?php
00123 if (!isset($is_inside_querywindow) ||
00124     (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full'))) {
00125 ?>
00126     <!-- Query box and bookmark support -->
00127 <?php
00128 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
00129 ?>
00130     <input type="hidden" name="focus_querywindow" value="true" />
00131 <?php
00132 }
00133 ?>
00134     <a name="querybox"></a>
00135             <table cellpadding="1" cellspacing="1">
00136                 <tr>
00137                     <td>
00138                         <?php echo sprintf($strRunSQLQuery,  htmlspecialchars($db)) . $queryframe_db_list . (isset($is_inside_querywindow) ? '<br />' : ' ') . PMA_showMySQLDocu('Reference', 'SELECT'); ?>
00139                         <br />
00140                         <textarea name="sql_query" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? ceil($cfg['TextareaCols'] * 1.25) : $cfg['TextareaCols'] * 2); ?>" wrap="virtual" dir="<?php echo $text_dir; ?>"<?php echo $auto_sel; ?>>
00141 <?php
00142 if (!empty($query_to_display)) {
00143     echo htmlspecialchars($query_to_display);
00144 } elseif (isset($table)) {
00145     echo htmlspecialchars(str_replace('%d', PMA_backquote($db), str_replace('%t', PMA_backquote($table), $cfg['DefaultQueryTable'])));
00146 } else {
00147     echo htmlspecialchars(str_replace('%d', PMA_backquote($db), $cfg['DefaultQueryDatabase']));
00148 }
00149 ?></textarea>
00150                     </td>
00151                         <?php if (isset($table) && $fields_cnt > 0) { ?>
00152                     <td align="center" valign="top"><?php echo (isset($is_inside_querywindow) ? '<br />' : '') . $strFields; ?>:<br />
00153                             <select name="dummy" size="4" multiple>
00154                        <?php
00155                            echo "\n";
00156                            for ($i = 0 ; $i < $fields_cnt; $i++) {
00157                                echo '                '
00158                                     . '<option value="' . PMA_backquote(htmlspecialchars($fields_list[$i])) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
00159                            }
00160                        ?>
00161                             </select><br /><br />
00162                             <input type="button" name="insert" value="<?php echo($strInsert); ?>" onclick="insertValueQuery()" />
00163                     </td>
00164                         <?php
00165                         }
00166                         ?>
00167                 </tr>
00168             </table>
00169             <input type="checkbox" name="show_query" value="1" id="checkbox_show_query" checked="checked" />&nbsp;
00170                 <label for="checkbox_show_query"><?php echo $strShowThisQuery; ?></label><br />
00171             <?php
00172             if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
00173             ?>
00174             <script type="text/javascript">
00175                 document.writeln('<input type="checkbox" name="LockFromUpdate" value="1" id="checkbox_lock" />&nbsp;');
00176                 document.writeln('    <label for="checkbox_lock"><?php echo $strQueryWindowLock; ?></label><br />');
00177             </script>
00178             <?php
00179             }
00180 
00181             $form_items++;
00182             ?>
00183             </div>
00184 <?php
00185 } else {
00186 ?>
00187             <input type="hidden" name="sql_query" value="" />
00188             <input type="hidden" name="show_query" value="1" />
00189 <?php
00190 }
00191 
00192 // loic1: displays import dump feature only if file upload available
00193 if ($is_upload && (!isset($is_inside_querywindow) ||
00194     (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full')))) {
00195     $form_items++;
00196     echo '            ' . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') || !isset($is_inside_querywindow) ? '<i>' . $strOr . '</i>' : '') . ' ' . $strLocationTextfile . '&nbsp;:<br />' . "\n";
00197     ?>
00198             <div style="margin-bottom: 5px">
00199             <input type="file" name="sql_file" class="textfield" />&nbsp;<?php echo PMA_displayMaximumUploadSize($max_upload_size);?><br />
00200     <?php
00201     // some browsers should respect this :)
00202     echo '        ' . PMA_generateHiddenMaxFileSize($max_upload_size) . "\n";
00203 
00204     if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
00205     ?>
00206             <input type="hidden" name="focus_querywindow" value="true" />
00207     <?php
00208     }
00209 
00210     $is_gzip = ($cfg['GZipDump'] && @function_exists('gzopen'));
00211     $is_bzip = ($cfg['BZipDump'] && @function_exists('bzdecompress'));
00212     if ($is_bzip || $is_gzip) {
00213         echo '        ' . $strCompression . ':' . "\n"
00214            . '            <input type="radio" id="radio_sql_file_compression_auto" name="sql_file_compression" value="" checked="checked" />' . "\n"
00215            . '            <label for="radio_sql_file_compression_auto">' . $strAutodetect . '</label>&nbsp;&nbsp;&nbsp;' . "\n"
00216            . '            <input type="radio" id="radio_sql_file_compression_plain" name="sql_file_compression" value="text/plain" />' . "\n"
00217            . '            <label for="radio_sql_file_compression_plain">' . $strNone . '</label>&nbsp;&nbsp;&nbsp;' . "\n";
00218         if ($is_gzip) {
00219             echo '            <input type="radio" id="radio_sql_file_compression_gzip" name="sql_file_compression" value="application/x-gzip" />' . "\n"
00220                . '            <label for="radio_sql_file_compression_gzip">' . $strGzip . '</label>&nbsp;&nbsp;&nbsp;' . "\n";
00221         }
00222         if ($is_bzip) {
00223             echo '            <input type="radio" id="radio_sql_file_compression_bzip" name="sql_file_compression" value="application/x-bzip" />' . "\n"
00224                . '            <label for="radio_sql_file_compression_bzip">' . $strBzip . '</label>&nbsp;&nbsp;&nbsp;' . "\n";
00225         }
00226     } else {
00227         echo '        <input type="hidden" name="sql_file_compression" value="text/plain" />' . "\n";
00228     }
00229     ?>
00230             </div>
00231     <?php
00232 } // end if
00233 echo "\n";
00234 
00235 // web-server upload directory
00236 $is_upload_dir = false;
00237 if (!empty($cfg['UploadDir']) && !isset($is_inside_querywindow) ||
00238     (!empty($cfg['UploadDir']) && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full'))) {
00239 
00240     if (substr($cfg['UploadDir'], -1) != '/') {
00241         $cfg['UploadDir'] .= '/';
00242     }
00243     if ($handle = @opendir($cfg['UploadDir'])) {
00244         if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
00245         ?>
00246             <input type="hidden" name="focus_querywindow" value="true" />
00247         <?php
00248         }
00249 
00250         $is_first = 0;
00251         while ($file = @readdir($handle)) {
00252             if (is_file($cfg['UploadDir'] . $file) && PMA_checkFileExtensions($file, '.sql')) {
00253                 if ($is_first == 0) {
00254                     $is_upload_dir = true;
00255                     echo "\n";
00256                     echo '    ' . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') || !isset($is_inside_querywindow) ? '<i>' . $strOr . '</i>' : '') . ' ' . $strWebServerUploadDirectory . '&nbsp;:<br />' . "\n";
00257                     echo '    <div style="margin-bottom: 5px">' . "\n";
00258                     echo '        <select size="1" name="sql_localfile">' . "\n";
00259                     echo '            <option value="" selected="selected"></option>' . "\n";
00260                     $form_items++;
00261                 } // end if (is_first)
00262                 echo '            <option value="' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</option>' . "\n";
00263                 $is_first++;
00264             } // end if (is_file)
00265         } // end while
00266         if ($is_first > 0) {
00267             echo '        </select>' . "\n"
00268                  . '    </div>' . "\n\n";
00269         } // end if (isfirst > 0)
00270         @closedir($handle);
00271     } else {
00272         echo '    <div style="margin-bottom: 5px">' . "\n";
00273         echo '        <font color="red">' . $strError . '</font><br />' . "\n";
00274         echo '        ' . $strWebServerUploadDirectoryError . "\n";
00275         echo '    </div>' . "\n";
00276     }
00277 } // end if (web-server upload directory)
00278 echo "\n";
00279 
00280 // Encoding setting form appended by Y.Kawada
00281 if (function_exists('PMA_set_enc_form')) {
00282     echo PMA_set_enc_form('            ');
00283     $form_items++;
00284 }
00285 
00286 // Charset conversion options
00287 if (($is_upload || $is_upload_dir) &&
00288         (!isset($is_inside_querywindow) ||
00289          (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full')))
00290         && isset($db) && $db != ''){
00291     if ($cfg['AllowAnywhereRecoding'] && $allow_recoding) {
00292         $form_items++;
00293         echo '    <div style="margin-bottom: 5px">' . "\n";
00294         $temp_charset = reset($cfg['AvailableCharsets']);
00295         echo $strCharsetOfFile . "\n"
00296              . '    <select name="charset_of_file" size="1">' . "\n"
00297              . '            <option value="' . $temp_charset . '"';
00298         if ($temp_charset == $charset) {
00299             echo ' selected="selected"';
00300         }
00301         echo '>' . $temp_charset . '</option>' . "\n";
00302         while ($temp_charset = next($cfg['AvailableCharsets'])) {
00303             echo '            <option value="' . $temp_charset . '"';
00304             if ($temp_charset == $charset) {
00305                 echo ' selected="selected"';
00306             }
00307             echo '>' . $temp_charset . '</option>' . "\n";
00308         }
00309         echo '        </select><br />' . "\n" . '    ';
00310         echo '    </div>' . "\n";
00311     } // end if (recoding)
00312 }
00313 
00314 // Bookmark Support
00315 $bookmark_go = FALSE;
00316 if (!isset($is_inside_querywindow) ||
00317     (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full'))) {
00318     if ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table']) {
00319         if (($bookmark_list = PMA_listBookmarks($db, $cfg['Bookmark'])) && count($bookmark_list) > 0) {
00320             $form_items++;
00321             echo "            " . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') || !isset($is_inside_querywindow) ? "<i>$strOr</i>" : '') . " $strBookmarkQuery&nbsp;:<br />\n";
00322 
00323             if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
00324             ?>
00325                 <input type="hidden" name="focus_querywindow" value="true" />
00326             <?php
00327             }
00328 
00329             echo '            <div style="margin-bottom: 5px">' . "\n";
00330             echo '            <select name="id_bookmark" style="vertical-align: middle">' . "\n";
00331             echo '                <option value=""></option>' . "\n";
00332             foreach($bookmark_list AS $key => $value) {
00333                 echo '                <option value="' . $value . '">' . htmlspecialchars($key) . '</option>' . "\n";
00334             }
00335             echo '            </select>' . "<br />\n";
00336             echo '            ' . $strVar . ' (<a href="./Documentation.html#faqbookmark" target="documentation">' . $strDocu . '</a>): <input type="text" name="bookmark_variable" class="textfield" size="10" />' . "\n";
00337             echo '            <input type="radio" name="action_bookmark" value="0" id="radio_bookmark0" checked="checked" style="vertical-align: middle" /><label for="radio_bookmark0">' . $strSubmit . '</label>' . "\n";
00338             echo '            &nbsp;<input type="radio" name="action_bookmark" value="1" id="radio_bookmark1" style="vertical-align: middle" /><label for="radio_bookmark1">' . $strBookmarkView . '</label>' . "\n";
00339             echo '            &nbsp;<input type="radio" name="action_bookmark" value="2" id="radio_bookmark2" style="vertical-align: middle" /><label for="radio_bookmark2">' . $strDelete . '</label>' . "\n";
00340             echo '            <br />' . "\n";
00341             echo '            </div>' . "\n";
00342             $bookmark_go = TRUE;
00343         }
00344     }
00345 }
00346 
00347 if (!isset($is_inside_querywindow) || (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && (($querydisplay_tab == 'files') || $querydisplay_tab == 'sql' || $querydisplay_tab == 'full' || ($querydisplay_tab == 'history' && $bookmark_go)))) {
00348     if ($form_items > 0) {
00349 ?>
00350             <table border="0">
00351                 <tr>
00352                     <td valign="top">
00353                         <input type="submit" name="SQL" value="<?php echo $strGo; ?>" />
00354                     </td>
00355 <?php
00356         if ( $cfg['Bookmark']['db']
00357           && $cfg['Bookmark']['table']
00358           && (!isset($is_inside_querywindow)
00359             || (  isset($is_inside_querywindow)
00360                && $is_inside_querywindow == TRUE
00361                && isset($querydisplay_tab)
00362                //&& $querydisplay_tab != 'history'))) {
00363                && $querydisplay_tab == 'sql'))) {
00364 ?>
00365                     <td valign="top">
00366                         <input type="submit" name="SQLbookmark" value="<?php echo $strGo . ' &amp; ' . $strBookmarkThis; ?>" />
00367                     </td>
00368 
00369                     <td>
00370                         <fieldset>
00371                             <legend><?php echo $strBookmarkOptions; ?></legend>
00372                                 <?php echo $strBookmarkLabel; ?>: <input type="text" name="bkm_label" value="" /><br />
00373                                 <input type="checkbox" name="bkm_all_users" id="id_bkm_all_users" value="true" /><label for="id_bkm_all_users"><?php echo $strBookmarkAllUsers; ?></label>
00374                         </fieldset>
00375                     </td>
00376 <?php
00377         }
00378 ?>
00379                 </tr>
00380             </table>
00381 <?php
00382         } else {
00383             // TODO: Add a more complete warning that no items (like for file import) where found.
00384             //       (After 2.5.2 release!)
00385             echo $strWebServerUploadDirectoryError;
00386         }
00387 }
00388 ?>
00389 </form>
00390 <?php
00391 if (!isset($is_inside_querywindow) ||
00392     (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full')) && isset($db) && $db != '') {
00393 
00394     // loic1: displays import dump feature only if file upload available
00395     $ldi_target = 'ldi_table.php?' . $url_query . (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? '&amp;focus_querywindow=true' : '');
00396 
00397     if ($is_upload && isset($db) && isset($table)) {
00398         ?>
00399         <!-- Insert a text file -->
00400         <br /><br />
00401         <li>
00402             <?php
00403             if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
00404             ?>
00405 
00406             <script type="text/javascript">
00407                 document.writeln('<div style="margin-bottom: 10px"><a href="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? '#' : $ldi_target); ?>" <?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? 'onclick="opener.parent.frames.phpmain\' + opener.parent.frames.queryframe.document.hashform.hash.value + \'.location.href = \\\'' . $ldi_target . '\\\'; return false;"' : ''); ?>><?php echo addslashes($strInsertTextfiles); ?></a></div>');
00408             </script>
00409 
00410             <?php
00411             } else {
00412             ?>
00413 
00414             <script type="text/javascript">
00415                 document.writeln('<div style="margin-bottom: 10px"><a href="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? '#' : $ldi_target); ?>" <?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? 'onclick="opener.parent.frames.phpmain' . md5($cfg['PmaAbsoluteUri']) . '.location.href = \\\'' . $ldi_target . '\\\'; return false;"' : ''); ?>><?php echo addslashes($strInsertTextfiles); ?></a></div>');
00416             </script>
00417 
00418             <?php
00419             }
00420             ?>
00421 
00422             <noscript>
00423                <div style="margin-bottom: 10px"><a href="<?php echo $ldi_target; ?>"><?php echo $strInsertTextfiles; ?></a></div>
00424             </noscript>
00425         </li>
00426         <?php
00427     }
00428 }
00429 echo "\n";
00430 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6