~ubuntu-branches/ubuntu/lucid/phpmyadmin/lucid

« back to all changes in this revision

Viewing changes to libraries/export/htmlexcel.php

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-03-08 15:25:00 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100308152500-6e8hmuqc5co39de5
Tags: 4:3.3.0-1
* New upstream version.
* Rediff debian/patches.
* Fix permissions on mediawiki export extension.

Show diffs side-by-side

added added

removed removed

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