Rev Author Line No. Line
250 kaklik 1 <?php
2 /* $Id: htmlexcel.php,v 1.2.2.1 2006/03/16 13:30:39 nijel Exp $ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4  
5 /**
6 * Set of functions used to build CSV dumps of tables
7 */
8  
9 /**
10 * Outputs comment
11 *
12 * @param string Text of comment
13 *
14 * @return bool Whether it suceeded
15 */
16 function PMA_exportComment($text) {
17 return TRUE;
18 }
19  
20 /**
21 * Outputs export footer
22 *
23 * @return bool Whether it suceeded
24 *
25 * @access public
26 */
27 function PMA_exportFooter() {
28 if (!PMA_exportOutputHandler('
29 </table>
30 </div>
31 </body>
32 </html>
33 ')) {
34 return FALSE;
35 }
36 return TRUE;
37 }
38  
39 /**
40 * Outputs export header
41 *
42 * @return bool Whether it suceeded
43 *
44 * @access public
45 */
46 function PMA_exportHeader() {
47 global $charset, $charset_of_file;
48 if (!PMA_exportOutputHandler('
49 <html xmlns:o="urn:schemas-microsoft-com:office:office"
50 xmlns:x="urn:schemas-microsoft-com:office:excel"
51 xmlns="http://www.w3.org/TR/REC-html40">
52  
53 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
54 <html>
55 <head>
56 <meta http-equiv="Content-type" content="text/html;charset=<?php echo isset($charset_of_file) ? $charset_of_file : $charset; ?>" />
57 <style id="Classeur1_16681_Styles">
58 </style>
59  
60 </head>
61 <body>
62  
63 <div id="Classeur1_16681" align=center x:publishsource="Excel">
64  
65 <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse">
66 ')) {
67 return FALSE;
68 }
69  
70 return TRUE;
71 }
72  
73 /**
74 * Outputs database header
75 *
76 * @param string Database name
77 *
78 * @return bool Whether it suceeded
79 *
80 * @access public
81 */
82 function PMA_exportDBHeader($db) {
83 return TRUE;
84 }
85  
86 /**
87 * Outputs database footer
88 *
89 * @param string Database name
90 *
91 * @return bool Whether it suceeded
92 *
93 * @access public
94 */
95 function PMA_exportDBFooter($db) {
96 return TRUE;
97 }
98  
99 /**
100 * Outputs create database database
101 *
102 * @param string Database name
103 *
104 * @return bool Whether it suceeded
105 *
106 * @access public
107 */
108 function PMA_exportDBCreate($db) {
109 return TRUE;
110 }
111  
112 /**
113 * Outputs the content of a table in CSV format
114 *
115 * @param string the database name
116 * @param string the table name
117 * @param string the end of line sequence
118 * @param string the url to go back in case of error
119 * @param string SQL query for obtaining data
120 *
121 * @return bool Whether it suceeded
122 *
123 * @access public
124 */
125 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
126 global $what;
127  
128 // Gets the data from the database
129 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
130 $fields_cnt = PMA_DBI_num_fields($result);
131  
132 // If required, get fields name at the first line
133 if (isset($GLOBALS[$what . '_shownames']) && $GLOBALS[$what . '_shownames'] == 'yes') {
134 $schema_insert = '<tr>';
135 for ($i = 0; $i < $fields_cnt; $i++) {
136 $schema_insert .= '<td class=xl2216681 nowrap><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
137 } // end for
138 $schema_insert .= '</tr>';
139 if (!PMA_exportOutputHandler($schema_insert)) {
140 return FALSE;
141 }
142 } // end if
143  
144 // Format the data
145 while ($row = PMA_DBI_fetch_row($result)) {
146 $schema_insert = '<tr>';
147 for ($j = 0; $j < $fields_cnt; $j++) {
148 if (!isset($row[$j]) || is_null($row[$j])) {
149 $value = $GLOBALS[$what . '_replace_null'];
150 } elseif ($row[$j] == '0' || $row[$j] != '') {
151 $value = $row[$j];
152 } else {
153 $value = '';
154 }
155 $schema_insert .= '<td class=xl2216681 nowrap>' . htmlspecialchars($value) . '</td>';
156 } // end for
157 $schema_insert .= '</tr>';
158 if (!PMA_exportOutputHandler($schema_insert)) {
159 return FALSE;
160 }
161 } // end while
162 PMA_DBI_free_result($result);
163  
164 return TRUE;
165 }
166 ?>