00001 <?php
00002
00003
00004
00016 function PMA_exportComment($text) {
00017 return TRUE;
00018 }
00019
00027 function PMA_exportFooter() {
00028 return PMA_exportOutputHandler('</body></html>');
00029 }
00030
00038 function PMA_exportHeader() {
00039 global $charset, $charset_of_file;
00040 return PMA_exportOutputHandler('<html xmlns:o="urn:schemas-microsoft-com:office:office"
00041 xmlns:x="urn:schemas-microsoft-com:office:word"
00042 xmlns="http://www.w3.org/TR/REC-html40">
00043
00044 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
00045 <html>
00046 <head>
00047 <meta http-equiv="Content-type" content="text/html;charset=' . ( isset($charset_of_file) ? $charset_of_file : $charset ) .'" />
00048 </head>
00049 <body>');
00050 }
00051
00061 function PMA_exportDBHeader($db) {
00062 return PMA_exportOutputHandler('<h1>' . $GLOBALS['strDatabase'] . ' ' . $db . '</h1>');
00063 }
00064
00074 function PMA_exportDBFooter($db) {
00075 return TRUE;
00076 }
00077
00087 function PMA_exportDBCreate($db) {
00088 return TRUE;
00089 }
00090
00104 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
00105 global $what;
00106
00107 if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strDumpingData'] . ' ' .$table . '</h2>')) return FALSE;
00108 if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) return FALSE;
00109
00110
00111 $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED);
00112 $fields_cnt = PMA_DBI_num_fields($result);
00113
00114
00115 if (isset($GLOBALS[$what . '_shownames']) && $GLOBALS[$what . '_shownames'] == 'yes') {
00116 $schema_insert = '<tr class="print-category">';
00117 for ($i = 0; $i < $fields_cnt; $i++) {
00118 $schema_insert .= '<td class="print"><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
00119 }
00120 $schema_insert .= '</tr>';
00121 if (!PMA_exportOutputHandler($schema_insert)) return FALSE;
00122 }
00123
00124
00125 while ($row = PMA_DBI_fetch_row($result)) {
00126 $schema_insert = '<tr class="print-category">';
00127 for ($j = 0; $j < $fields_cnt; $j++) {
00128 if (!isset($row[$j]) || is_null($row[$j])) {
00129 $value = $GLOBALS[$what . '_replace_null'];
00130 } else if ($row[$j] == '0' || $row[$j] != '') {
00131 $value = $row[$j];
00132 } else {
00133 $value = '';
00134 }
00135 $schema_insert .= '<td class="print">' . htmlspecialchars($value) . '</td>';
00136 }
00137 $schema_insert .= '</tr>';
00138 if (!PMA_exportOutputHandler($schema_insert)) return FALSE;
00139 }
00140 PMA_DBI_free_result($result);
00141 if (!PMA_exportOutputHandler('</table>')) return FALSE;
00142
00143 return TRUE;
00144 }
00145
00146 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
00147 {
00148 global $cfgRelation;
00149
00150 if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strTableStructure'] . ' ' .$table . '</h2>')) return FALSE;
00151
00155 $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db);
00156 $keys_result = PMA_DBI_query($keys_query);
00157 $unique_keys = array();
00158 while ($key = PMA_DBI_fetch_assoc($keys_result)) {
00159 if ($key['Non_unique'] == 0) $unique_keys[] = $key['Column_name'];
00160 }
00161 PMA_DBI_free_result($keys_result);
00162
00166 PMA_DBI_select_db($db);
00167 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
00168 $result = PMA_DBI_query($local_query);
00169 $fields_cnt = PMA_DBI_num_rows($result);
00170
00171
00172 if ($do_relation && !empty($cfgRelation['relation'])) {
00173
00174
00175 $res_rel = PMA_getForeigners($db, $table);
00176
00177 if ($res_rel && count($res_rel) > 0) {
00178 $have_rel = TRUE;
00179 } else {
00180 $have_rel = FALSE;
00181 }
00182 }
00183 else {
00184 $have_rel = FALSE;
00185 }
00186
00190 if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) return FALSE;
00191
00192 $columns_cnt = 4;
00193 if ($do_relation && $have_rel) {
00194 $columns_cnt++;
00195 }
00196 if ($do_comments && $cfgRelation['commwork']) {
00197 $columns_cnt++;
00198 }
00199 if ($do_mime && $cfgRelation['mimework']) {
00200 $columns_cnt++;
00201 }
00202
00203 $schema_insert = '<tr class="print-category">';
00204 $schema_insert .= '<th class="print">' . htmlspecialchars($GLOBALS['strField']) . '</th>';
00205 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strType']) . '</b></td>';
00206 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strNull']) . '</b></td>';
00207 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strDefault']) . '</b></td>';
00208 if ($do_relation && $have_rel) {
00209 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strLinksTo']) . '</b></td>';
00210 }
00211 if ($do_comments && $cfgRelation['commwork']) {
00212 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strComments']) . '</b></td>';
00213 $comments = PMA_getComments($db, $table);
00214 }
00215 if ($do_mime && $cfgRelation['mimework']) {
00216 $schema_insert .= '<td class="print"><b>' . htmlspecialchars('MIME') . '</b></td>';
00217 $mime_map = PMA_getMIME($db, $table, true);
00218 }
00219 $schema_insert .= '</tr>';
00220
00221 if (!PMA_exportOutputHandler($schema_insert)) return FALSE;
00222
00223 while ($row = PMA_DBI_fetch_assoc($result)) {
00224
00225 $schema_insert = '<tr class="print-category">';
00226 $type = $row['Type'];
00227
00228
00229 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp = array())) {
00230 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
00231 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
00232 $type_nowrap = '';
00233
00234 $binary = 0;
00235 $unsigned = 0;
00236 $zerofill = 0;
00237 } else {
00238 $type_nowrap = ' nowrap="nowrap"';
00239 $type = eregi_replace('BINARY', '', $type);
00240 $type = eregi_replace('ZEROFILL', '', $type);
00241 $type = eregi_replace('UNSIGNED', '', $type);
00242 if (empty($type)) {
00243 $type = ' ';
00244 }
00245
00246 $binary = eregi('BINARY', $row['Type'], $test = array());
00247 $unsigned = eregi('UNSIGNED', $row['Type'], $test = array());
00248 $zerofill = eregi('ZEROFILL', $row['Type'], $test = array());
00249 }
00250 $strAttribute = ' ';
00251 if ($binary) {
00252 $strAttribute = 'BINARY';
00253 }
00254 if ($unsigned) {
00255 $strAttribute = 'UNSIGNED';
00256 }
00257 if ($zerofill) {
00258 $strAttribute = 'UNSIGNED ZEROFILL';
00259 }
00260 if (!isset($row['Default'])) {
00261 if ($row['Null'] != '') {
00262 $row['Default'] = 'NULL';
00263 }
00264 } else {
00265 $row['Default'] = $row['Default'];
00266 }
00267
00268 $fmt_pre = '';
00269 $fmt_post = '';
00270 if (in_array($row['Field'], $unique_keys)) {
00271 $fmt_pre = '<b>' . $fmt_pre;
00272 $fmt_post = $fmt_post . '</b>';
00273 }
00274 if ($row['Key']=='PRI') {
00275 $fmt_pre = '<i>' . $fmt_pre;
00276 $fmt_post = $fmt_post . '</i>';
00277 }
00278 $schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($row['Field']) . $fmt_post . '</td>';
00279 $schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>';
00280 $schema_insert .= '<td class="print">' . htmlspecialchars($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . '</td>';
00281 $schema_insert .= '<td class="print">' . htmlspecialchars(isset($row['Default']) ? $row['Default'] : '') . '</td>';
00282
00283 $field_name = $row['Field'];
00284
00285 if ($do_relation && $have_rel) {
00286 $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>';
00287 }
00288 if ($do_comments && $cfgRelation['commwork']) {
00289 $schema_insert .= '<td class="print">' . ( isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>';
00290 }
00291 if ($do_mime && $cfgRelation['mimework']) {
00292 $schema_insert .= '<td class="print">' . ( isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>';
00293 }
00294
00295 $schema_insert .= '</tr>';
00296
00297 if (!PMA_exportOutputHandler($schema_insert)) return FALSE;
00298 }
00299 PMA_DBI_free_result($result);
00300
00301 return PMA_exportOutputHandler('</table>');
00302 }
00303 ?>