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
|
* Documentation.html: added a FAQ entry about upload errors
|
||||||
|
|
||||||
2001-07-12 Lo<4C>c Chapeaux <lolo@phpheaven.net>
|
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
|
* tbl_properties.php3: fixed an IE5.0 display bug and an other one with
|
||||||
Mozilla.
|
Mozilla.
|
||||||
* lib.inc.php3, line 969: fixed a wrong comparaison.
|
* 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']);
|
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.
|
* Output the content of a table in CSV format
|
||||||
// $handler must accept one parameter ($sql_insert);
|
*
|
||||||
|
* @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)
|
function get_table_csv($db, $table, $sep, $handler)
|
||||||
{
|
{
|
||||||
$result = mysql_query("SELECT * FROM ".db_name($db)."." .
|
// Handles the separator character
|
||||||
tbl_name($table)) or mysql_die();
|
if (empty($sep)) {
|
||||||
$i = 0;
|
$sep = ';';
|
||||||
while($row = mysql_fetch_row($result))
|
}
|
||||||
{
|
else {
|
||||||
@set_time_limit(60); // HaRa
|
if (get_magic_quotes_gpc()) {
|
||||||
$schema_insert = "";
|
$sep = stripslashes($sep);
|
||||||
for($j=0; $j<mysql_num_fields($result);$j++)
|
}
|
||||||
{
|
$sep = str_replace('\\t', "\011", $sep);
|
||||||
if(!isset($row[$j]))
|
}
|
||||||
$schema_insert .= "NULL".$sep;
|
|
||||||
elseif ($row[$j] != "")
|
// Gets the data from the database
|
||||||
$schema_insert .= "$row[$j]".$sep;
|
$result = mysql_query('SELECT * FROM ' . db_name($db) . '.' . tbl_name($table)) or mysql_die();
|
||||||
else
|
|
||||||
$schema_insert .= "".$sep;
|
// Format the data
|
||||||
}
|
$i = 0;
|
||||||
$schema_insert = str_replace($sep."$", "", $schema_insert);
|
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));
|
$handler(trim($schema_insert));
|
||||||
++$i;
|
++$i;
|
||||||
}
|
} // end while
|
||||||
return (true);
|
|
||||||
}
|
return true;
|
||||||
|
} // end of the 'get_table_csv()' function
|
||||||
|
|
||||||
|
|
||||||
function show_docu($link) {
|
function show_docu($link) {
|
||||||
global $cfgManualBase, $strDocu;
|
global $cfgManualBase, $strDocu;
|
||||||
|
@@ -63,15 +63,33 @@ function my_handler($sql_insert)
|
|||||||
|
|
||||||
function my_csvhandler($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;
|
// Handles the EOL character
|
||||||
global $tmp_buffer;
|
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))
|
// Result will be displays on screen
|
||||||
$tmp_buffer.= htmlspecialchars($sql_insert . $add_character . $crlf);
|
if (empty($asfile)) {
|
||||||
else
|
$tmp_buffer .= htmlspecialchars($sql_insert) . $add_character;
|
||||||
$tmp_buffer.= $sql_insert . $add_character . $crlf;
|
}
|
||||||
|
// Result will be save in a file
|
||||||
|
else {
|
||||||
|
$tmp_buffer .= $sql_insert . $add_character;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$dump_buffer="";
|
$dump_buffer="";
|
||||||
|
@@ -607,9 +607,9 @@ echo "\n";
|
|||||||
<input type="radio" name="what" value="csv" />
|
<input type="radio" name="what" value="csv" />
|
||||||
<?php echo $strStrucCSV;?> ->
|
<?php echo $strStrucCSV;?> ->
|
||||||
<?php echo $strFields . ' '. $strTerminatedBy; ?>
|
<?php echo $strFields . ' '. $strTerminatedBy; ?>
|
||||||
<input type="text" name="separator" size="1" value=";" />
|
<input type="text" name="separator" size="1" value=";" />
|
||||||
<?php echo $strLines . ' '. $strTerminatedBy; ?>
|
<?php echo $strLines . ' '. $strTerminatedBy; ?>
|
||||||
<input type="text" name="add_character" size="1" value="" />
|
<input type="text" name="add_character" size="2" value="\n" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
Reference in New Issue
Block a user