Fixed some inconsistencies in the cvs export feature
This commit is contained in:
@@ -9,6 +9,9 @@ $Source$
|
||||
* Documentation.html: added a FAQ entry about upload errors
|
||||
|
||||
2001-07-12 Lo<4C>c Chapeaux <lolo@phpheaven.net>
|
||||
* tbl_dump.php3, lines 64-93; lib.inc.php3, lines 722-774;
|
||||
tbl_properties.php3, line 612: fixed some inconsistencies in the
|
||||
csv export feature.
|
||||
* tbl_properties.php3: fixed an IE5.0 display bug and an other one with
|
||||
Mozilla.
|
||||
* lib.inc.php3, line 969: fixed a wrong comparaison.
|
||||
|
75
lib.inc.php3
75
lib.inc.php3
@@ -718,34 +718,61 @@ function count_records($db, $table)
|
||||
echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
|
||||
}
|
||||
|
||||
// Get the content of $table as a CSV output.
|
||||
// $sep contains the separation string.
|
||||
// After every row, a custom callback function $handler gets called.
|
||||
// $handler must accept one parameter ($sql_insert);
|
||||
|
||||
/**
|
||||
* Output the content of a table in CSV format
|
||||
*
|
||||
* @param string the database name
|
||||
* @param string the table name
|
||||
* @param string the separation string
|
||||
* @param string the handler (function) to call. It must accept one parameter
|
||||
* ($sql_insert)
|
||||
*
|
||||
* @return boolean always true
|
||||
*/
|
||||
function get_table_csv($db, $table, $sep, $handler)
|
||||
{
|
||||
$result = mysql_query("SELECT * FROM ".db_name($db)."." .
|
||||
tbl_name($table)) or mysql_die();
|
||||
$i = 0;
|
||||
while($row = mysql_fetch_row($result))
|
||||
{
|
||||
@set_time_limit(60); // HaRa
|
||||
$schema_insert = "";
|
||||
for($j=0; $j<mysql_num_fields($result);$j++)
|
||||
{
|
||||
if(!isset($row[$j]))
|
||||
$schema_insert .= "NULL".$sep;
|
||||
elseif ($row[$j] != "")
|
||||
$schema_insert .= "$row[$j]".$sep;
|
||||
else
|
||||
$schema_insert .= "".$sep;
|
||||
}
|
||||
$schema_insert = str_replace($sep."$", "", $schema_insert);
|
||||
// Handles the separator character
|
||||
if (empty($sep)) {
|
||||
$sep = ';';
|
||||
}
|
||||
else {
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$sep = stripslashes($sep);
|
||||
}
|
||||
$sep = str_replace('\\t', "\011", $sep);
|
||||
}
|
||||
|
||||
// Gets the data from the database
|
||||
$result = mysql_query('SELECT * FROM ' . db_name($db) . '.' . tbl_name($table)) or mysql_die();
|
||||
|
||||
// Format the data
|
||||
$i = 0;
|
||||
while ($row = mysql_fetch_row($result)) {
|
||||
@set_time_limit(60);
|
||||
$schema_insert = '';
|
||||
$fields_cnt = mysql_num_fields($result);
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
if (!isset($row[$j])) {
|
||||
$schema_insert .= 'NULL';
|
||||
}
|
||||
else if ($row[$j] != '') {
|
||||
$schema_insert .= $row[$j];
|
||||
}
|
||||
else {
|
||||
$schema_insert .= '';
|
||||
}
|
||||
if ($j < $fields_cnt-1) {
|
||||
$schema_insert .= $sep;
|
||||
}
|
||||
} // end for
|
||||
$handler(trim($schema_insert));
|
||||
++$i;
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
} // end while
|
||||
|
||||
return true;
|
||||
} // end of the 'get_table_csv()' function
|
||||
|
||||
|
||||
function show_docu($link) {
|
||||
global $cfgManualBase, $strDocu;
|
||||
|
@@ -63,15 +63,33 @@ function my_handler($sql_insert)
|
||||
|
||||
function my_csvhandler($sql_insert)
|
||||
{
|
||||
// 2001-05-07, Lem9: added $add_character
|
||||
// 2001-05-07, Lem9: added $add_character
|
||||
// 2001-07-12, loic1: $crlf should be used only if there is no EOL
|
||||
// character defined by the user
|
||||
global $crlf, $add_character, $asfile;
|
||||
global $tmp_buffer;
|
||||
|
||||
global $crlf, $add_character, $asfile;
|
||||
global $tmp_buffer;
|
||||
// Handles the EOL character
|
||||
if (empty($add_character)) {
|
||||
$add_character = $crlf;
|
||||
}
|
||||
else {
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$add_character = stripslashes($add_character);
|
||||
}
|
||||
$add_character = str_replace('\\r', "\015", $add_character);
|
||||
$add_character = str_replace('\\n', "\012", $add_character);
|
||||
$add_character = str_replace('\\t', "\011", $add_character);
|
||||
}
|
||||
|
||||
if(empty($asfile))
|
||||
$tmp_buffer.= htmlspecialchars($sql_insert . $add_character . $crlf);
|
||||
else
|
||||
$tmp_buffer.= $sql_insert . $add_character . $crlf;
|
||||
// Result will be displays on screen
|
||||
if (empty($asfile)) {
|
||||
$tmp_buffer .= htmlspecialchars($sql_insert) . $add_character;
|
||||
}
|
||||
// Result will be save in a file
|
||||
else {
|
||||
$tmp_buffer .= $sql_insert . $add_character;
|
||||
}
|
||||
}
|
||||
|
||||
$dump_buffer="";
|
||||
|
@@ -607,9 +607,9 @@ echo "\n";
|
||||
<input type="radio" name="what" value="csv" />
|
||||
<?php echo $strStrucCSV;?> ->
|
||||
<?php echo $strFields . ' '. $strTerminatedBy; ?>
|
||||
<input type="text" name="separator" size="1" value=";" />
|
||||
<input type="text" name="separator" size="1" value=";" />
|
||||
<?php echo $strLines . ' '. $strTerminatedBy; ?>
|
||||
<input type="text" name="add_character" size="1" value="" />
|
||||
<input type="text" name="add_character" size="2" value="\n" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
Reference in New Issue
Block a user