~hexmode/+junk/main

« back to all changes in this revision

Viewing changes to install-files/apps/phpmyadmin2.10.1/libraries/export/ods.php

  • Committer: Mark A. Hershberger
  • Date: 2008-01-05 19:38:56 UTC
  • Revision ID: hershberger@spawn-xp-20080105193856-6rnzgwa4nehue3qj
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* $Id: ods.php 9000 2006-04-28 10:46:13Z nijel $ */
 
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
if (isset($plugin_list)) {
 
10
    $plugin_list['ods'] = array(
 
11
        'text' => 'strOpenDocumentSpreadsheet',
 
12
        'extension' => 'ods',
 
13
        'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
 
14
        'force_file' => true,
 
15
        'options' => array(
 
16
            array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
 
17
            array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
 
18
            array('type' => 'hidden', 'name' => 'data'),
 
19
            ),
 
20
        'options_text' => 'strOpenDocumentSpreadsheetOptions',
 
21
        );
 
22
} else {
 
23
 
 
24
$GLOBALS['ods_buffer'] = '';
 
25
require_once('./libraries/opendocument.lib.php');
 
26
 
 
27
/**
 
28
 * Outputs comment
 
29
 *
 
30
 * @param   string      Text of comment
 
31
 *
 
32
 * @return  bool        Whether it suceeded
 
33
 */
 
34
function PMA_exportComment($text) {
 
35
    return TRUE;
 
36
}
 
37
 
 
38
/**
 
39
 * Outputs export footer
 
40
 *
 
41
 * @return  bool        Whether it suceeded
 
42
 *
 
43
 * @access  public
 
44
 */
 
45
function PMA_exportFooter() {
 
46
    $GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
 
47
        . '</office:body>'
 
48
        . '</office:document-content>';
 
49
    if (!PMA_exportOutputHandler(PMA_createOpenDocument('application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer']))) {
 
50
        return FALSE;
 
51
    }
 
52
    return TRUE;
 
53
}
 
54
 
 
55
/**
 
56
 * Outputs export header
 
57
 *
 
58
 * @return  bool        Whether it suceeded
 
59
 *
 
60
 * @access  public
 
61
 */
 
62
function PMA_exportHeader() {
 
63
    $GLOBALS['ods_buffer'] .= '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?' . '>'
 
64
        . '<office:document-content '. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
 
65
        . '<office:body>'
 
66
        . '<office:spreadsheet>';
 
67
    return TRUE;
 
68
}
 
69
 
 
70
/**
 
71
 * Outputs database header
 
72
 *
 
73
 * @param   string      Database name
 
74
 *
 
75
 * @return  bool        Whether it suceeded
 
76
 *
 
77
 * @access  public
 
78
 */
 
79
function PMA_exportDBHeader($db) {
 
80
    return TRUE;
 
81
}
 
82
 
 
83
/**
 
84
 * Outputs database footer
 
85
 *
 
86
 * @param   string      Database name
 
87
 *
 
88
 * @return  bool        Whether it suceeded
 
89
 *
 
90
 * @access  public
 
91
 */
 
92
function PMA_exportDBFooter($db) {
 
93
    return TRUE;
 
94
}
 
95
 
 
96
/**
 
97
 * Outputs create database database
 
98
 *
 
99
 * @param   string      Database name
 
100
 *
 
101
 * @return  bool        Whether it suceeded
 
102
 *
 
103
 * @access  public
 
104
 */
 
105
function PMA_exportDBCreate($db) {
 
106
    return TRUE;
 
107
}
 
108
 
 
109
/**
 
110
 * Outputs the content of a table in CSV format
 
111
 *
 
112
 * @param   string      the database name
 
113
 * @param   string      the table name
 
114
 * @param   string      the end of line sequence
 
115
 * @param   string      the url to go back in case of error
 
116
 * @param   string      SQL query for obtaining data
 
117
 *
 
118
 * @return  bool        Whether it suceeded
 
119
 *
 
120
 * @access  public
 
121
 */
 
122
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
 
123
    global $what;
 
124
 
 
125
    // Gets the data from the database
 
126
    $result      = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
 
127
    $fields_cnt  = PMA_DBI_num_fields($result);
 
128
    $fields_meta = PMA_DBI_get_fields_meta($result);
 
129
    $field_flags = array();
 
130
    for ($j = 0; $j < $fields_cnt; $j++) {
 
131
        $field_flags[$j] = PMA_DBI_field_flags($result, $j);
 
132
    }
 
133
 
 
134
    $GLOBALS['ods_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '">';
 
135
 
 
136
    // If required, get fields name at the first line
 
137
    if (isset($GLOBALS[$what . '_columns'])) {
 
138
        $GLOBALS['ods_buffer'] .= '<table:table-row>';
 
139
        for ($i = 0; $i < $fields_cnt; $i++) {
 
140
            $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
 
141
                . '<text:p>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</text:p>'
 
142
                . '</table:table-cell>';
 
143
        } // end for
 
144
        $GLOBALS['ods_buffer'] .= '</table:table-row>';
 
145
    } // end if
 
146
 
 
147
    // Format the data
 
148
    while ($row = PMA_DBI_fetch_row($result)) {
 
149
        $GLOBALS['ods_buffer'] .= '<table:table-row>';
 
150
        for ($j = 0; $j < $fields_cnt; $j++) {
 
151
            if (!isset($row[$j]) || is_null($row[$j])) {
 
152
                $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
 
153
                    . '<text:p>' . htmlspecialchars($GLOBALS[$what . '_null']) . '</text:p>'
 
154
                    . '</table:table-cell>';
 
155
            // ignore binary field
 
156
            // Note: with mysqli, under MySQL 4.1.3, we get the flag
 
157
            // "binary" for those field types (I don't know why)
 
158
            } elseif (stristr($field_flags[$j], 'BINARY')
 
159
                    && isset($GLOBALS['sql_hex_for_binary'])
 
160
                    && $fields_meta[$j]->type != 'datetime'
 
161
                    && $fields_meta[$j]->type != 'date'
 
162
                    && $fields_meta[$j]->type != 'time'
 
163
                    && $fields_meta[$j]->type != 'timestamp'
 
164
                   ) {
 
165
                $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
 
166
                    . '<text:p></text:p>'
 
167
                    . '</table:table-cell>';
 
168
            } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && ! $fields_meta[$j]->blob) {
 
169
                $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="float" office:value="' . $row[$j] . '" >'
 
170
                    . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
 
171
                    . '</table:table-cell>';
 
172
            } else {
 
173
                $GLOBALS['ods_buffer'] .= '<table:table-cell office:value-type="string">'
 
174
                    . '<text:p>' . htmlspecialchars($row[$j]) . '</text:p>'
 
175
                    . '</table:table-cell>';
 
176
            }
 
177
        } // end for
 
178
        $GLOBALS['ods_buffer'] .= '</table:table-row>';
 
179
    } // end while
 
180
    PMA_DBI_free_result($result);
 
181
 
 
182
    $GLOBALS['ods_buffer'] .= '</table:table>';
 
183
 
 
184
    return TRUE;
 
185
}
 
186
 
 
187
}
 
188
?>