Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / libraries / export / htmlexcel.php
blob47ddc36b81186ba250c3a0be92de9d8be4a1dd0a
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 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
15 if (isset($plugin_list)) {
16 $plugin_list['htmlexcel'] = array(
17 'text' => 'strHTMLExcel',
18 'extension' => 'xls',
19 'mime_type' => 'application/vnd.ms-excel',
20 'force_file' => true,
21 'options' => array(
22 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
23 array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
24 array('type' => 'hidden', 'name' => 'data'),
26 'options_text' => 'strOptions',
28 } else {
30 /**
31 * Outputs comment
33 * @param string Text of comment
35 * @return bool Whether it suceeded
37 function PMA_exportComment($text) {
38 return TRUE;
41 /**
42 * Outputs export footer
44 * @return bool Whether it suceeded
46 * @access public
48 function PMA_exportFooter() {
49 if (!PMA_exportOutputHandler('
50 </table>
51 </div>
52 </body>
53 </html>
54 ')) {
55 return FALSE;
57 return TRUE;
60 /**
61 * Outputs export header
63 * @return bool Whether it suceeded
65 * @access public
67 function PMA_exportHeader() {
68 global $charset, $charset_of_file;
69 if (!PMA_exportOutputHandler('
70 <html xmlns:o="urn:schemas-microsoft-com:office:office"
71 xmlns:x="urn:schemas-microsoft-com:office:excel"
72 xmlns="http://www.w3.org/TR/REC-html40">
74 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
75 <html>
76 <head>
77 <meta http-equiv="Content-type" content="text/html;charset=' . (isset($charset_of_file) ? $charset_of_file : $charset) .'" />
78 <style id="Classeur1_16681_Styles">
79 </style>
81 </head>
82 <body>
84 <div id="Classeur1_16681" align=center x:publishsource="Excel">
86 <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse">
87 ')) {
88 return FALSE;
91 return TRUE;
94 /**
95 * Outputs database header
97 * @param string Database name
99 * @return bool Whether it suceeded
101 * @access public
103 function PMA_exportDBHeader($db) {
104 return TRUE;
108 * Outputs database footer
110 * @param string Database name
112 * @return bool Whether it suceeded
114 * @access public
116 function PMA_exportDBFooter($db) {
117 return TRUE;
121 * Outputs create database database
123 * @param string Database name
125 * @return bool Whether it suceeded
127 * @access public
129 function PMA_exportDBCreate($db) {
130 return TRUE;
134 * Outputs the content of a table in CSV format
136 * @param string the database name
137 * @param string the table name
138 * @param string the end of line sequence
139 * @param string the url to go back in case of error
140 * @param string SQL query for obtaining data
142 * @return bool Whether it suceeded
144 * @access public
146 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
147 global $what;
149 // Gets the data from the database
150 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
151 $fields_cnt = PMA_DBI_num_fields($result);
153 // If required, get fields name at the first line
154 if (isset($GLOBALS[$what . '_columns'])) {
155 $schema_insert = '<tr>';
156 for ($i = 0; $i < $fields_cnt; $i++) {
157 $schema_insert .= '<td class=xl2216681 nowrap><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
158 } // end for
159 $schema_insert .= '</tr>';
160 if (!PMA_exportOutputHandler($schema_insert)) {
161 return FALSE;
163 } // end if
165 $fields_meta = PMA_DBI_get_fields_meta($result);
167 // Format the data
168 while ($row = PMA_DBI_fetch_row($result)) {
169 $schema_insert = '<tr>';
170 for ($j = 0; $j < $fields_cnt; $j++) {
171 if (!isset($row[$j]) || is_null($row[$j])) {
172 $value = $GLOBALS[$what . '_null'];
173 } elseif ($row[$j] == '0' || $row[$j] != '') {
174 $value = $row[$j];
175 } else {
176 $value = '';
178 $schema_insert .= '<td class=xl2216681 nowrap';
179 if ('1' == $fields_meta[$j]->numeric) {
180 $schema_insert .= ' x:num ';
182 $schema_insert .= '>' . htmlspecialchars($value) . '</td>';
183 } // end for
184 $schema_insert .= '</tr>';
185 if (!PMA_exportOutputHandler($schema_insert)) {
186 return FALSE;
188 } // end while
189 PMA_DBI_free_result($result);
191 return TRUE;