00001 <?php
00002
00003
00004
00018 function PMA_texEscape($string) {
00019 $escape = array('$', '%', '{', '}', '&', '#', '_', '^');
00020 $cnt_escape = count($escape);
00021 for ($k=0; $k < $cnt_escape; $k++) {
00022 $string = str_replace($escape[$k], '\\' . $escape[$k], $string);
00023 }
00024 return $string;
00025 }
00026
00034 function PMA_exportComment($text) {
00035 return PMA_exportOutputHandler('% ' . $text . $GLOBALS['crlf']);
00036 }
00037
00045 function PMA_exportFooter() {
00046 return TRUE;
00047 }
00048
00056 function PMA_exportHeader() {
00057 global $crlf;
00058 global $cfg;
00059
00060 $head = '% phpMyAdmin LaTeX Dump' . $crlf
00061 . '% version ' . PMA_VERSION . $crlf
00062 . '% http:
00063 . '%' . $crlf
00064 . '% ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
00065 if (!empty($cfg['Server']['port'])) {
00066 $head .= ':' . $cfg['Server']['port'];
00067 }
00068 $head .= $crlf
00069 . '% ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
00070 . '% ' . $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
00071 . '% ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf;
00072 return PMA_exportOutputHandler($head);
00073 }
00074
00084 function PMA_exportDBHeader($db) {
00085 global $crlf;
00086 $head = '% ' . $crlf
00087 . '% ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
00088 . '% ' . $crlf;
00089 return PMA_exportOutputHandler($head);
00090 }
00091
00101 function PMA_exportDBFooter($db) {
00102 return TRUE;
00103 }
00104
00114 function PMA_exportDBCreate($db) {
00115 return TRUE;
00116 }
00117
00131 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
00132 $result = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED);
00133
00134 $columns_cnt = PMA_DBI_num_fields($result);
00135 for ($i = 0; $i < $columns_cnt; $i++) {
00136 $columns[$i] = PMA_DBI_field_name($result, $i);
00137 }
00138 unset($i);
00139
00140 $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strData'] . ': ' . $table . $crlf . '%' . $crlf
00141 . ' \\begin{longtable}{|';
00142
00143 for ($index=0;$index<$columns_cnt;$index++) {
00144 $buffer .= 'l|';
00145 }
00146 $buffer .= '} ' . $crlf ;
00147
00148 $buffer .= ' \\hline \\endhead \\hline \\endfoot \\hline ' . $crlf;
00149 if (isset($GLOBALS['latex_caption'])) {
00150 $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_caption'])
00151 . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_data_label']) . '} \\\\';
00152 }
00153 if (!PMA_exportOutputHandler($buffer)) return FALSE;
00154
00155
00156 if (isset($GLOBALS['latex_showcolumns'])) {
00157 $buffer = '\\hline ';
00158 for ($i = 0; $i < $columns_cnt; $i++) {
00159 $buffer .= '\\multicolumn{1}{|c|}{\\textbf{' . PMA_texEscape(stripslashes($columns[$i])) . '}} & ';
00160 }
00161
00162 $buffer = substr($buffer,0,-2) . '\\\\ \\hline \hline ';
00163 if (!PMA_exportOutputHandler($buffer . ' \\endfirsthead ' . $crlf)) return FALSE;
00164 if (isset($GLOBALS['latex_caption'])) {
00165 if (!PMA_exportOutputHandler('\\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_continued_caption']) . '} \\\\ ')) return FALSE;
00166 }
00167 if (!PMA_exportOutputHandler($buffer . '\\endhead \\endfoot' . $crlf)) return FALSE;
00168 } else {
00169 if (!PMA_exportOutputHandler('\\\\ \hline')) return FALSE;
00170 }
00171
00172
00173 while ($record = PMA_DBI_fetch_assoc($result)) {
00174
00175 $buffer = '';
00176
00177 for ($i = 0; $i < $columns_cnt; $i++) {
00178 if ( isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) {
00179 $column_value = PMA_texEscape(stripslashes($record[$columns[$i]]));
00180 } else {
00181 $column_value = $GLOBALS['latex_replace_null'];
00182 }
00183
00184
00185 if ($i == ($columns_cnt - 1)) {
00186 $buffer .= $column_value;
00187 } else {
00188 $buffer .= $column_value . " & ";
00189 }
00190 }
00191 $buffer .= ' \\\\ \\hline ' . $crlf;
00192 if (!PMA_exportOutputHandler($buffer)) return FALSE;
00193 }
00194
00195 $buffer = ' \\end{longtable}' . $crlf;
00196 if (!PMA_exportOutputHandler($buffer)) return FALSE;
00197
00198 PMA_DBI_free_result($result);
00199 return TRUE;
00200
00201 }
00202
00218
00219 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
00220 {
00221 global $cfgRelation;
00222
00226 $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db);
00227 $keys_result = PMA_DBI_query($keys_query);
00228 $unique_keys = array();
00229 while ($key = PMA_DBI_fetch_assoc($keys_result)) {
00230 if ($key['Non_unique'] == 0) $unique_keys[] = $key['Column_name'];
00231 }
00232 PMA_DBI_free_result($keys_result);
00233
00237 PMA_DBI_select_db($db);
00238 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
00239 $result = PMA_DBI_query($local_query);
00240 $fields_cnt = PMA_DBI_num_rows($result);
00241
00242
00243 if ($do_relation && !empty($cfgRelation['relation'])) {
00244
00245
00246 $res_rel = PMA_getForeigners($db, $table);
00247
00248 if ($res_rel && count($res_rel) > 0) {
00249 $have_rel = TRUE;
00250 } else {
00251 $have_rel = FALSE;
00252 }
00253 }
00254 else {
00255 $have_rel = FALSE;
00256 }
00257
00261 $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf
00262 . ' \\begin{longtable}{';
00263 if (!PMA_exportOutputHandler($buffer)) return FALSE;
00264
00265 $columns_cnt = 4;
00266 $alignment = '|l|c|c|c|';
00267 if ($do_relation && $have_rel) {
00268 $columns_cnt++;
00269 $alignment .= 'l|';
00270 }
00271 if ($do_comments && $cfgRelation['commwork']) {
00272 $columns_cnt++;
00273 $alignment .= 'l|';
00274 }
00275 if ($do_mime && $cfgRelation['mimework']) {
00276 $columns_cnt++;
00277 $alignment .='l|';
00278 }
00279 $buffer = $alignment . '} ' . $crlf ;
00280
00281 $header = ' \\hline ';
00282 $header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}';
00283 if ($do_relation && $have_rel) {
00284 $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}';
00285 }
00286 if ($do_comments && $cfgRelation['commwork']) {
00287 $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}';
00288 $comments = PMA_getComments($db, $table);
00289 }
00290 if ($do_mime && $cfgRelation['mimework']) {
00291 $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
00292 $mime_map = PMA_getMIME($db, $table, true);
00293 }
00294
00295 $local_buffer = PMA_texEscape($table);
00296
00297
00298 if (isset($GLOBALS['latex_caption'])) {
00299 $buffer .= ' \\caption{'. str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption'])
00300 . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label'])
00301 . '} \\\\' . $crlf;
00302 }
00303 $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
00304
00305 if (isset($GLOBALS['latex_caption'])) {
00306 $buffer .= ' \\caption{'. str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption'])
00307 . '} \\\\ ' . $crlf;
00308 }
00309 $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ';
00310
00311 if (!PMA_exportOutputHandler($buffer)) return FALSE;
00312
00313 while ($row = PMA_DBI_fetch_assoc($result)) {
00314
00315 $type = $row['Type'];
00316
00317
00318 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp = array())) {
00319 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
00320 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
00321 $type_nowrap = '';
00322
00323 $binary = 0;
00324 $unsigned = 0;
00325 $zerofill = 0;
00326 } else {
00327 $type_nowrap = ' nowrap="nowrap"';
00328 $type = eregi_replace('BINARY', '', $type);
00329 $type = eregi_replace('ZEROFILL', '', $type);
00330 $type = eregi_replace('UNSIGNED', '', $type);
00331 if (empty($type)) {
00332 $type = ' ';
00333 }
00334
00335 $binary = eregi('BINARY', $row['Type'], $test = array());
00336 $unsigned = eregi('UNSIGNED', $row['Type'], $test = array());
00337 $zerofill = eregi('ZEROFILL', $row['Type'], $test = array());
00338 }
00339 $strAttribute = ' ';
00340 if ($binary) {
00341 $strAttribute = 'BINARY';
00342 }
00343 if ($unsigned) {
00344 $strAttribute = 'UNSIGNED';
00345 }
00346 if ($zerofill) {
00347 $strAttribute = 'UNSIGNED ZEROFILL';
00348 }
00349 if (!isset($row['Default'])) {
00350 if ($row['Null'] != '') {
00351 $row['Default'] = 'NULL';
00352 }
00353 } else {
00354 $row['Default'] = $row['Default'];
00355 }
00356
00357 $field_name = $row['Field'];
00358
00359 $local_buffer = $field_name . "\000" . $type . "\000" . (($row['Null'] == '') ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "\000" . (isset($row['Default']) ? $row['Default'] : '');
00360
00361 if ($do_relation && $have_rel) {
00362 $local_buffer .= "\000";
00363 if (isset($res_rel[$field_name])) {
00364 $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')';
00365 }
00366 }
00367 if ($do_comments && $cfgRelation['commwork']) {
00368 $local_buffer .= "\000";
00369 if (isset($comments[$field_name])) {
00370 $local_buffer .= $comments[$field_name];
00371 }
00372 }
00373 if ($do_mime && $cfgRelation['mimework']) {
00374 $local_buffer .= "\000";
00375 if (isset($mime_map[$field_name])) {
00376 $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
00377 }
00378 }
00379 $local_buffer = PMA_texEscape($local_buffer);
00380 if ($row['Key']=='PRI') {
00381 $pos=strpos($local_buffer, "\000");
00382 $local_buffer = '\\textit{' . substr($local_buffer,0,$pos) . '}' . substr($local_buffer,$pos);
00383 }
00384 if (in_array($field_name, $unique_keys)) {
00385 $pos=strpos($local_buffer, "\000");
00386 $local_buffer = '\\textbf{' . substr($local_buffer,0,$pos) . '}' . substr($local_buffer,$pos);
00387 }
00388 $buffer = str_replace("\000", ' & ', $local_buffer);
00389 $buffer .= ' \\\\ \\hline ' . $crlf;
00390
00391 if (!PMA_exportOutputHandler($buffer)) return FALSE;
00392 }
00393 PMA_DBI_free_result($result);
00394
00395 $buffer = ' \\end{longtable}' . $crlf;
00396 return PMA_exportOutputHandler($buffer);
00397 }
00398 ?>