Documentation TYPO3 par Ameos |
00001 <?php 00002 /* $Id: csv.php,v 2.1 2003/11/20 16:31:51 garvinhicking Exp $ */ 00003 // vim: expandtab sw=4 ts=4 sts=4: 00004 00016 function PMA_exportComment($text) { 00017 return TRUE; 00018 } 00019 00027 function PMA_exportHeader() { 00028 global $what; 00029 global $add_character; 00030 global $separator; 00031 global $enclosed; 00032 global $escaped; 00033 00034 // Here we just prepare some values for export 00035 if ($what == 'excel') { 00036 $add_character = "\015\012"; 00037 $separator = isset($GLOBALS['excel_edition']) && $GLOBALS['excel_edition'] == 'mac' ? ';' : ','; 00038 $enclosed = '"'; 00039 $escaped = '"'; 00040 if (isset($GLOBALS['showexcelnames']) && $GLOBALS['showexcelnames'] == 'yes') { 00041 $GLOBALS['showcsvnames'] = 'yes'; 00042 } 00043 } else { 00044 if (empty($add_character)) { 00045 $add_character = $GLOBALS['crlf']; 00046 } else { 00047 $add_character = str_replace('\\r', "\015", $add_character); 00048 $add_character = str_replace('\\n', "\012", $add_character); 00049 $add_character = str_replace('\\t', "\011", $add_character); 00050 } // end if 00051 $separator = str_replace('\\t', "\011", $separator); 00052 } 00053 return TRUE; 00054 } 00055 00065 function PMA_exportDBHeader($db) { 00066 return TRUE; 00067 } 00068 00078 function PMA_exportDBFooter($db) { 00079 return TRUE; 00080 } 00081 00091 function PMA_exportDBCreate($db) { 00092 return TRUE; 00093 } 00094 00108 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { 00109 global $what; 00110 global $add_character; 00111 global $separator; 00112 global $enclosed; 00113 global $escaped; 00114 00115 // Gets the data from the database 00116 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url); 00117 $fields_cnt = mysql_num_fields($result); 00118 00119 // If required, get fields name at the first line 00120 if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') { 00121 $schema_insert = ''; 00122 for ($i = 0; $i < $fields_cnt; $i++) { 00123 if ($enclosed == '') { 00124 $schema_insert .= stripslashes(mysql_field_name($result, $i)); 00125 } else { 00126 $schema_insert .= $enclosed 00127 . str_replace($enclosed, $escaped . $enclosed, stripslashes(mysql_field_name($result, $i))) 00128 . $enclosed; 00129 } 00130 $schema_insert .= $separator; 00131 } // end for 00132 $schema_insert =trim(substr($schema_insert, 0, -1)); 00133 if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE; 00134 } // end if 00135 00136 // Format the data 00137 while ($row = PMA_mysql_fetch_row($result)) { 00138 $schema_insert = ''; 00139 for ($j = 0; $j < $fields_cnt; $j++) { 00140 if (!isset($row[$j])) { 00141 $schema_insert .= $GLOBALS[$what . '_replace_null']; 00142 } 00143 else if ($row[$j] == '0' || $row[$j] != '') { 00144 $row[$j] = stripslashes($row[$j]); 00145 // loic1 : always enclose fields 00146 if ($what == 'excel') { 00147 $row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]); 00148 } 00149 if ($enclosed == '') { 00150 $schema_insert .= $row[$j]; 00151 } else { 00152 $schema_insert .= $enclosed 00153 . str_replace($enclosed, $escaped . $enclosed, $row[$j]) 00154 . $enclosed; 00155 } 00156 } 00157 else { 00158 $schema_insert .= ''; 00159 } 00160 if ($j < $fields_cnt-1) { 00161 $schema_insert .= $separator; 00162 } 00163 } // end for 00164 if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE; 00165 } // end while 00166 mysql_free_result($result); 00167 00168 return TRUE; 00169 } // end of the 'PMA_getTableCsv()' function 00170 ?>