2.11.1.2 release
[phpmyadmin/arisferyanto.git] / libraries / export / xml.php
blob9f3da10219e2b07b97168f01a9725c8d6020f1b8
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used to build XML dumps of tables
6 * @version $Id$
7 */
9 /**
12 if (strlen($GLOBALS['db'])) { /* Can't do server export */
14 if (isset($plugin_list)) {
15 $plugin_list['xml'] = array(
16 'text' => 'strXML',
17 'extension' => 'xml',
18 'mime_type' => 'text/xml',
19 'options' => array(
20 array('type' => 'hidden', 'name' => 'data'),
22 'options_text' => 'strOptions',
24 } else {
26 /**
27 * Outputs comment
29 * @param string Text of comment
31 * @return bool Whether it suceeded
33 function PMA_exportComment($text) {
34 return PMA_exportOutputHandler('<!-- ' . $text . ' -->' . $GLOBALS['crlf']);
37 /**
38 * Outputs export footer
40 * @return bool Whether it suceeded
42 * @access public
44 function PMA_exportFooter() {
45 return TRUE;
48 /**
49 * Outputs export header
51 * @return bool Whether it suceeded
53 * @access public
55 function PMA_exportHeader() {
56 global $crlf;
57 global $cfg;
59 if ($GLOBALS['output_charset_conversion']) {
60 $charset = $GLOBALS['charset_of_file'];
61 } else {
62 $charset = $GLOBALS['charset'];
65 $head = '<?xml version="1.0" encoding="' . $charset . '" ?>' . $crlf
66 . '<!--' . $crlf
67 . '-' . $crlf
68 . '- phpMyAdmin XML Dump' . $crlf
69 . '- version ' . PMA_VERSION . $crlf
70 . '- http://www.phpmyadmin.net' . $crlf
71 . '-' . $crlf
72 . '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
73 if (!empty($cfg['Server']['port'])) {
74 $head .= ':' . $cfg['Server']['port'];
76 $head .= $crlf
77 . '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
78 . '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
79 . '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf
80 . '-->' . $crlf . $crlf;
81 return PMA_exportOutputHandler($head);
84 /**
85 * Outputs database header
87 * @param string Database name
89 * @return bool Whether it suceeded
91 * @access public
93 function PMA_exportDBHeader($db) {
94 global $crlf;
95 $head = '<!--' . $crlf
96 . '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
97 . '-->' . $crlf
98 . '<' . $db . '>' . $crlf;
99 return PMA_exportOutputHandler($head);
103 * Outputs database footer
105 * @param string Database name
107 * @return bool Whether it suceeded
109 * @access public
111 function PMA_exportDBFooter($db) {
112 global $crlf;
113 return PMA_exportOutputHandler('</' . $db . '>' . $crlf);
117 * Outputs create database database
119 * @param string Database name
121 * @return bool Whether it suceeded
123 * @access public
125 function PMA_exportDBCreate($db) {
126 return TRUE;
131 * Outputs the content of a table
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 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
146 $columns_cnt = PMA_DBI_num_fields($result);
147 for ($i = 0; $i < $columns_cnt; $i++) {
148 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
150 unset($i);
152 $buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
153 if (!PMA_exportOutputHandler($buffer)) {
154 return FALSE;
157 while ($record = PMA_DBI_fetch_row($result)) {
158 $buffer = ' <' . $table . '>' . $crlf;
159 for ($i = 0; $i < $columns_cnt; $i++) {
160 if (isset($record[$i]) && !is_null($record[$i])) {
161 $buffer .= ' <' . $columns[$i] . '>' . htmlspecialchars($record[$i])
162 . '</' . $columns[$i] . '>' . $crlf;
165 $buffer .= ' </' . $table . '>' . $crlf;
167 if (!PMA_exportOutputHandler($buffer)) {
168 return FALSE;
171 PMA_DBI_free_result($result);
173 return TRUE;
174 } // end of the 'PMA_getTableXML()' function