Documentation TYPO3 par Ameos |
00001 <?php 00002 /* $Id: csv.php,v 2.7 2004/04/14 13:48:41 nijel Exp $ */ 00003 // vim: expandtab sw=4 ts=4 sts=4: 00004 00016 function PMA_exportComment($text) { 00017 return TRUE; 00018 } 00019 00027 function PMA_exportFooter() { 00028 return TRUE; 00029 } 00030 00038 function PMA_exportHeader() { 00039 global $what; 00040 global $add_character; 00041 global $separator; 00042 global $enclosed; 00043 global $escaped; 00044 00045 // Here we just prepare some values for export 00046 if ($what == 'excel') { 00047 $add_character = "\015\012"; 00048 $separator = isset($GLOBALS['excel_edition']) && $GLOBALS['excel_edition'] == 'mac' ? ';' : ','; 00049 $enclosed = '"'; 00050 $escaped = '"'; 00051 if (isset($GLOBALS['showexcelnames']) && $GLOBALS['showexcelnames'] == 'yes') { 00052 $GLOBALS['showcsvnames'] = 'yes'; 00053 } 00054 } else { 00055 if (empty($add_character)) { 00056 $add_character = $GLOBALS['crlf']; 00057 } else { 00058 $add_character = str_replace('\\r', "\015", $add_character); 00059 $add_character = str_replace('\\n', "\012", $add_character); 00060 $add_character = str_replace('\\t', "\011", $add_character); 00061 } // end if 00062 $separator = str_replace('\\t', "\011", $separator); 00063 } 00064 return TRUE; 00065 } 00066 00076 function PMA_exportDBHeader($db) { 00077 return TRUE; 00078 } 00079 00089 function PMA_exportDBFooter($db) { 00090 return TRUE; 00091 } 00092 00102 function PMA_exportDBCreate($db) { 00103 return TRUE; 00104 } 00105 00119 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { 00120 global $what; 00121 global $add_character; 00122 global $separator; 00123 global $enclosed; 00124 global $escaped; 00125 00126 // Gets the data from the database 00127 $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); 00128 $fields_cnt = PMA_DBI_num_fields($result); 00129 00130 // If required, get fields name at the first line 00131 if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') { 00132 $schema_insert = ''; 00133 for ($i = 0; $i < $fields_cnt; $i++) { 00134 if ($enclosed == '') { 00135 $schema_insert .= stripslashes(PMA_DBI_field_name($result, $i)); 00136 } else { 00137 $schema_insert .= $enclosed 00138 . str_replace($enclosed, $escaped . $enclosed, stripslashes(PMA_DBI_field_name($result, $i))) 00139 . $enclosed; 00140 } 00141 $schema_insert .= $separator; 00142 } // end for 00143 $schema_insert =trim(substr($schema_insert, 0, -1)); 00144 if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE; 00145 } // end if 00146 00147 // Format the data 00148 while ($row = PMA_DBI_fetch_row($result)) { 00149 $schema_insert = ''; 00150 for ($j = 0; $j < $fields_cnt; $j++) { 00151 if (!isset($row[$j]) || is_null($row[$j])) { 00152 $schema_insert .= $GLOBALS[$what . '_replace_null']; 00153 } 00154 else if ($row[$j] == '0' || $row[$j] != '') { 00155 // loic1 : always enclose fields 00156 if ($what == 'excel') { 00157 $row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]); 00158 } 00159 if ($enclosed == '') { 00160 $schema_insert .= $row[$j]; 00161 } else { 00162 $schema_insert .= $enclosed 00163 . str_replace($enclosed, $escaped . $enclosed, $row[$j]) 00164 . $enclosed; 00165 } 00166 } 00167 else { 00168 $schema_insert .= ''; 00169 } 00170 if ($j < $fields_cnt-1) { 00171 $schema_insert .= $separator; 00172 } 00173 } // end for 00174 if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE; 00175 } // end while 00176 PMA_DBI_free_result($result); 00177 00178 return TRUE; 00179 } // end of the 'PMA_getTableCsv()' function 00180 ?>