Sort file list on import tab, prepare generic framework to be used elsewhere (RFE #1303145).

This commit is contained in:
Michal Čihař
2005-09-27 18:57:58 +00:00
parent 600d2bb8bc
commit 22ddb6cee2
3 changed files with 69 additions and 25 deletions

View File

@@ -26,6 +26,9 @@ $Source$
* lang/*: Add missing messages, remove duplicates and no longer used.
* libraries/sql_query_form.lib.php: Do not use strOr, drop file upload
from normal SQL dialogs.
* libraries/display_import.lib.php, libraries/file_listing.php: Sort file
list on import tab, prepare generic framework to be used elsewhere (RFE
#1303145).
2005-09-26 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* libraries/database_interface.lib.php: fixed bug in PMA_DBI_fetch_*()

View File

@@ -2,6 +2,8 @@
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
require_once('./libraries/file_listing.php');
/* Scan for plugins */
$import_list = array();
$plugins_dir = './libraries/import/';
@@ -156,35 +158,22 @@ if (!empty($cfg['UploadDir'])) {
if (!empty($compressions)) $compressions .= '|';
$compressions .= 'zip';
}
if ($handle = @opendir($cfg['UploadDir'])) {
$is_first = 0;
while ($file = @readdir($handle)) {
if (is_file($cfg['UploadDir'] . $file) && eregi('\.(' . $extensions . ')(\.(' .$compressions . '))?$', $file)) {
if ($is_first == 0) {
$is_upload_dir = true;
echo "<br />\n";
echo ' <i>' . $strOr . '</i><br/><label for="select_local_import_file">' . $strWebServerUploadDirectory . '</label>&nbsp;: ' . "\n";
echo ' <select style="margin: 5px" size="1" name="local_import_file" onchange="match_file(this.value)" id="select_local_import_file">' . "\n";
echo ' <option value=""></option>' . "\n";
} // end if (is_first)
echo ' <option value="' . htmlspecialchars($file) . '"';
if (isset($timeout_passed) && $timeout_passed && isset($local_import_file) && $local_import_file == $file) {
echo ' selected="selected"';
}
echo '>' . htmlspecialchars($file) . '</option>' . "\n";
$is_first++;
} // end if (is_file)
} // end while
if ($is_first > 0) {
echo ' </select>' . "\n";
} // end if (isfirst > 0)
@closedir($handle);
} else {
$matcher = '@\.(' . $extensions . ')(\.(' .$compressions . '))?$@';
$files = PMA_getFileSelectOptions($cfg['UploadDir'], $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ? $local_import_file : '');
if ($files === FALSE) {
echo ' <div style="margin-bottom: 5px">' . "\n";
echo ' <font color="red">' . $strError . '</font><br />' . "\n";
echo ' ' . $strWebServerUploadDirectoryError . "\n";
echo ' </div>' . "\n";
} elseif (!empty($files)) {
echo "<br />\n";
echo ' <i>' . $strOr . '</i><br/><label for="select_local_import_file">' . $strWebServerUploadDirectory . '</label>&nbsp;: ' . "\n";
echo ' <select style="margin: 5px" size="1" name="local_import_file" onchange="match_file(this.value)" id="select_local_import_file">' . "\n";
echo ' <option value=""></option>' . "\n";
echo $files;
echo ' </select>' . "\n";
}
} // end if (web-server upload directory)

View File

@@ -0,0 +1,52 @@
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
// Functions for listing directories
/**
* Returns array of filtered file names
*
* @param string directory to list
* @param string regullar expression to match files
* @returns array sorted file list on success, FALSE on failure
*/
function PMA_getDirContent($dir, $expression) {
if ($handle = @opendir($dir)) {
$result = array();
if (substr($dir, -1) != '/') {
$dir .= '/';
}
while ($file = @readdir($handle)) {
if (is_file($dir . $file) && preg_match($expression, $file)) {
$result[] = $file;
}
}
@closedir($handle);
asort($result);
return $result;
} else {
return FALSE;
}
}
/**
* Returns options of filtered file names
*
* @param string directory to list
* @param string regullar expression to match files
* @param string currently active choice
* @returns array sorted file list on success, FALSE on failure
*/
function PMA_getFileSelectOptions($dir, $extensions, $active = '') {
$list = PMA_getDirContent($dir, $extensions);
if ($list === FALSE) return FALSE;
$result = '';
foreach($list as $key => $val) {
$result .= '<option value="'. htmlspecialchars($val) . '"';
if ($val == $active) {
$result .= ' selected="selected"';
}
$result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
}
return $result;
}