2.11.1.2 release
[phpmyadmin/arisferyanto.git] / libraries / export / htmlexcel.php
blobb380cd52e8e5fe5a5186632da791371f41b39e58
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used to build CSV dumps of tables
6 * @version $Id$
7 */
9 /**
12 if (isset($plugin_list)) {
13 $plugin_list['htmlexcel'] = array(
14 'text' => 'strHTMLExcel',
15 'extension' => 'xls',
16 'mime_type' => 'application/vnd.ms-excel',
17 'force_file' => true,
18 'options' => array(
19 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
20 array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
21 array('type' => 'hidden', 'name' => 'data'),
23 'options_text' => 'strOptions',
25 } else {
27 /**
28 * Outputs comment
30 * @param string Text of comment
32 * @return bool Whether it suceeded
34 function PMA_exportComment($text) {
35 return TRUE;
38 /**
39 * Outputs export footer
41 * @return bool Whether it suceeded
43 * @access public
45 function PMA_exportFooter() {
46 if (!PMA_exportOutputHandler('
47 </table>
48 </div>
49 </body>
50 </html>
51 ')) {
52 return FALSE;
54 return TRUE;
57 /**
58 * Outputs export header
60 * @return bool Whether it suceeded
62 * @access public
64 function PMA_exportHeader() {
65 global $charset, $charset_of_file;
66 if (!PMA_exportOutputHandler('
67 <html xmlns:o="urn:schemas-microsoft-com:office:office"
68 xmlns:x="urn:schemas-microsoft-com:office:excel"
69 xmlns="http://www.w3.org/TR/REC-html40">
71 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
72 <html>
73 <head>
74 <meta http-equiv="Content-type" content="text/html;charset=' . (isset($charset_of_file) ? $charset_of_file : $charset) .'" />
75 <style id="Classeur1_16681_Styles">
76 </style>
78 </head>
79 <body>
81 <div id="Classeur1_16681" align=center x:publishsource="Excel">
83 <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse">
84 ')) {
85 return FALSE;
88 return TRUE;
91 /**
92 * Outputs database header
94 * @param string Database name
96 * @return bool Whether it suceeded
98 * @access public
100 function PMA_exportDBHeader($db) {
101 return TRUE;
105 * Outputs database footer
107 * @param string Database name
109 * @return bool Whether it suceeded
111 * @access public
113 function PMA_exportDBFooter($db) {
114 return TRUE;
118 * Outputs create database database
120 * @param string Database name
122 * @return bool Whether it suceeded
124 * @access public
126 function PMA_exportDBCreate($db) {
127 return TRUE;
131 * Outputs the content of a table in CSV format
133 * @param string the database name
134 * @param string the table name
135 * @param string the end of line sequence
136 * @param string the url to go back in case of error
137 * @param string SQL query for obtaining data
139 * @return bool Whether it suceeded
141 * @access public
143 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
144 global $what;
146 // Gets the data from the database
147 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
148 $fields_cnt = PMA_DBI_num_fields($result);
150 // If required, get fields name at the first line
151 if (isset($GLOBALS[$what . '_columns'])) {
152 $schema_insert = '<tr>';
153 for ($i = 0; $i < $fields_cnt; $i++) {
154 $schema_insert .= '<td class=xl2216681 nowrap><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
155 } // end for
156 $schema_insert .= '</tr>';
157 if (!PMA_exportOutputHandler($schema_insert)) {
158 return FALSE;
160 } // end if
162 // Format the data
163 while ($row = PMA_DBI_fetch_row($result)) {
164 $schema_insert = '<tr>';
165 for ($j = 0; $j < $fields_cnt; $j++) {
166 if (!isset($row[$j]) || is_null($row[$j])) {
167 $value = $GLOBALS[$what . '_null'];
168 } elseif ($row[$j] == '0' || $row[$j] != '') {
169 $value = $row[$j];
170 } else {
171 $value = '';
173 $schema_insert .= '<td class=xl2216681 nowrap>' . htmlspecialchars($value) . '</td>';
174 } // end for
175 $schema_insert .= '</tr>';
176 if (!PMA_exportOutputHandler($schema_insert)) {
177 return FALSE;
179 } // end while
180 PMA_DBI_free_result($result);
182 return TRUE;