[ Index ] |
|
Code source de phpMyAdmin 2.10.3 |
1 <?php 2 /* $Id: latex.php 9805 2006-12-26 16:10:47Z lem9 $ */ 3 // vim: expandtab sw=4 ts=4 sts=4: 4 5 /** 6 * Set of functions used to build dumps of tables 7 */ 8 9 if (isset($plugin_list)) { 10 $hide_structure = false; 11 if ($plugin_param['export_type'] == 'table' && !$plugin_param['single_table']) { 12 $hide_structure = true; 13 } 14 $plugin_list['latex'] = array( 15 'text' => 'strLaTeX', 16 'extension' => 'tex', 17 'mime_type' => 'application/x-tex', 18 'options' => array( 19 array('type' => 'bool', 'name' => 'caption', 'text' => 'strLatexIncludeCaption'), 20 ), 21 'options_text' => 'strLaTeXOptions', 22 ); 23 /* Structure options */ 24 if (!$hide_structure) { 25 $plugin_list['latex']['options'][] = 26 array('type' => 'bgroup', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data'); 27 $plugin_list['latex']['options'][] = 28 array('type' => 'text', 'name' => 'structure_caption', 'text' => 'strLatexCaption'); 29 $plugin_list['latex']['options'][] = 30 array('type' => 'text', 'name' => 'structure_continued_caption', 'text' => 'strLatexContinuedCaption'); 31 $plugin_list['latex']['options'][] = 32 array('type' => 'text', 'name' => 'structure_label', 'text' => 'strLatexLabel'); 33 if (!empty($GLOBALS['cfgRelation']['relation'])) { 34 $plugin_list['latex']['options'][] = 35 array('type' => 'bool', 'name' => 'relation', 'text' => 'strRelations'); 36 } 37 if (!empty($GLOBALS['cfgRelation']['commwork']) || PMA_MYSQL_INT_VERSION >= 40100) { 38 $plugin_list['latex']['options'][] = 39 array('type' => 'bool', 'name' => 'comments', 'text' => 'strComments'); 40 } 41 if (!empty($GLOBALS['cfgRelation']['mimework'])) { 42 $plugin_list['latex']['options'][] = 43 array('type' => 'bool', 'name' => 'mime', 'text' => 'strMIME_MIMEtype'); 44 } 45 $plugin_list['latex']['options'][] = 46 array('type' => 'egroup'); 47 } 48 /* Data */ 49 $plugin_list['latex']['options'][] = 50 array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure'); 51 $plugin_list['latex']['options'][] = 52 array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'); 53 $plugin_list['latex']['options'][] = 54 array('type' => 'text', 'name' => 'data_caption', 'text' => 'strLatexCaption'); 55 $plugin_list['latex']['options'][] = 56 array('type' => 'text', 'name' => 'data_continued_caption', 'text' => 'strLatexContinuedCaption'); 57 $plugin_list['latex']['options'][] = 58 array('type' => 'text', 'name' => 'data_label', 'text' => 'strLatexLabel'); 59 $plugin_list['latex']['options'][] = 60 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'); 61 $plugin_list['latex']['options'][] = 62 array('type' => 'egroup'); 63 } else { 64 65 /** 66 * Escapes some special characters for use in TeX/LaTeX 67 * 68 * @param string the string to convert 69 * 70 * @return string the converted string with escape codes 71 * 72 * @access private 73 */ 74 function PMA_texEscape($string) { 75 $escape = array('$', '%', '{', '}', '&', '#', '_', '^'); 76 $cnt_escape = count($escape); 77 for ($k=0; $k < $cnt_escape; $k++) { 78 $string = str_replace($escape[$k], '\\' . $escape[$k], $string); 79 } 80 return $string; 81 } 82 83 /** 84 * Outputs comment 85 * 86 * @param string Text of comment 87 * 88 * @return bool Whether it suceeded 89 */ 90 function PMA_exportComment($text) { 91 return PMA_exportOutputHandler('% ' . $text . $GLOBALS['crlf']); 92 } 93 94 /** 95 * Outputs export footer 96 * 97 * @return bool Whether it suceeded 98 * 99 * @access public 100 */ 101 function PMA_exportFooter() { 102 return TRUE; 103 } 104 105 /** 106 * Outputs export header 107 * 108 * @return bool Whether it suceeded 109 * 110 * @access public 111 */ 112 function PMA_exportHeader() { 113 global $crlf; 114 global $cfg; 115 116 $head = '% phpMyAdmin LaTeX Dump' . $crlf 117 . '% version ' . PMA_VERSION . $crlf 118 . '% http://www.phpmyadmin.net' . $crlf 119 . '%' . $crlf 120 . '% ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host']; 121 if (!empty($cfg['Server']['port'])) { 122 $head .= ':' . $cfg['Server']['port']; 123 } 124 $head .= $crlf 125 . '% ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf 126 . '% ' . $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 127 . '% ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf; 128 return PMA_exportOutputHandler($head); 129 } 130 131 /** 132 * Outputs database header 133 * 134 * @param string Database name 135 * 136 * @return bool Whether it suceeded 137 * 138 * @access public 139 */ 140 function PMA_exportDBHeader($db) { 141 global $crlf; 142 $head = '% ' . $crlf 143 . '% ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf 144 . '% ' . $crlf; 145 return PMA_exportOutputHandler($head); 146 } 147 148 /** 149 * Outputs database footer 150 * 151 * @param string Database name 152 * 153 * @return bool Whether it suceeded 154 * 155 * @access public 156 */ 157 function PMA_exportDBFooter($db) { 158 return TRUE; 159 } 160 161 /** 162 * Outputs create database database 163 * 164 * @param string Database name 165 * 166 * @return bool Whether it suceeded 167 * 168 * @access public 169 */ 170 function PMA_exportDBCreate($db) { 171 return TRUE; 172 } 173 174 /** 175 * Outputs the content of a table in LaTeX table/sideways table environment 176 * 177 * @param string the database name 178 * @param string the table name 179 * @param string the end of line sequence 180 * @param string the url to go back in case of error 181 * @param string SQL query for obtaining data 182 * 183 * @return bool Whether it suceeded 184 * 185 * @access public 186 */ 187 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { 188 $result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); 189 190 $columns_cnt = PMA_DBI_num_fields($result); 191 for ($i = 0; $i < $columns_cnt; $i++) { 192 $columns[$i] = PMA_DBI_field_name($result, $i); 193 } 194 unset($i); 195 196 $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strData'] . ': ' . $table . $crlf . '%' . $crlf 197 . ' \\begin{longtable}{|'; 198 199 for ($index=0;$index<$columns_cnt;$index++) { 200 $buffer .= 'l|'; 201 } 202 $buffer .= '} ' . $crlf ; 203 204 $buffer .= ' \\hline \\endhead \\hline \\endfoot \\hline ' . $crlf; 205 if (isset($GLOBALS['latex_caption'])) { 206 $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_caption']) 207 . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_data_label']) . '} \\\\'; 208 } 209 if (!PMA_exportOutputHandler($buffer)) { 210 return FALSE; 211 } 212 213 // show column names 214 if (isset($GLOBALS['latex_columns'])) { 215 $buffer = '\\hline '; 216 for ($i = 0; $i < $columns_cnt; $i++) { 217 $buffer .= '\\multicolumn{1}{|c|}{\\textbf{' . PMA_texEscape(stripslashes($columns[$i])) . '}} & '; 218 } 219 220 $buffer = substr($buffer, 0, -2) . '\\\\ \\hline \hline '; 221 if (!PMA_exportOutputHandler($buffer . ' \\endfirsthead ' . $crlf)) { 222 return FALSE; 223 } 224 if (isset($GLOBALS['latex_caption'])) { 225 if (!PMA_exportOutputHandler('\\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_continued_caption']) . '} \\\\ ')) return FALSE; 226 } 227 if (!PMA_exportOutputHandler($buffer . '\\endhead \\endfoot' . $crlf)) { 228 return FALSE; 229 } 230 } else { 231 if (!PMA_exportOutputHandler('\\\\ \hline')) { 232 return FALSE; 233 } 234 } 235 236 // print the whole table 237 while ($record = PMA_DBI_fetch_assoc($result)) { 238 239 $buffer = ''; 240 // print each row 241 for ($i = 0; $i < $columns_cnt; $i++) { 242 if ( isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) { 243 $column_value = PMA_texEscape(stripslashes($record[$columns[$i]])); 244 } else { 245 $column_value = $GLOBALS['latex_null']; 246 } 247 248 // last column ... no need for & character 249 if ($i == ($columns_cnt - 1)) { 250 $buffer .= $column_value; 251 } else { 252 $buffer .= $column_value . " & "; 253 } 254 } 255 $buffer .= ' \\\\ \\hline ' . $crlf; 256 if (!PMA_exportOutputHandler($buffer)) { 257 return FALSE; 258 } 259 } 260 261 $buffer = ' \\end{longtable}' . $crlf; 262 if (!PMA_exportOutputHandler($buffer)) { 263 return FALSE; 264 } 265 266 PMA_DBI_free_result($result); 267 return TRUE; 268 269 } // end getTableLaTeX 270 271 /** 272 * Returns $table's structure as LaTeX 273 * 274 * @param string the database name 275 * @param string the table name 276 * @param string the end of line sequence 277 * @param string the url to go back in case of error 278 * @param boolean whether to include relation comments 279 * @param boolean whether to include column comments 280 * @param boolean whether to include mime comments 281 * @param string future feature: support view dependencies 282 * 283 * @return bool Whether it suceeded 284 * 285 * @access public 286 */ 287 // @@@ $strTableStructure 288 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy) 289 { 290 global $cfgRelation; 291 292 /** 293 * Get the unique keys in the table 294 */ 295 $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db); 296 $keys_result = PMA_DBI_query($keys_query); 297 $unique_keys = array(); 298 while ($key = PMA_DBI_fetch_assoc($keys_result)) { 299 if ($key['Non_unique'] == 0) { 300 $unique_keys[] = $key['Column_name']; 301 } 302 } 303 PMA_DBI_free_result($keys_result); 304 305 /** 306 * Gets fields properties 307 */ 308 PMA_DBI_select_db($db); 309 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); 310 $result = PMA_DBI_query($local_query); 311 $fields_cnt = PMA_DBI_num_rows($result); 312 313 // Check if we can use Relations (Mike Beck) 314 if ($do_relation && !empty($cfgRelation['relation'])) { 315 // Find which tables are related with the current one and write it in 316 // an array 317 $res_rel = PMA_getForeigners($db, $table); 318 319 if ($res_rel && count($res_rel) > 0) { 320 $have_rel = TRUE; 321 } else { 322 $have_rel = FALSE; 323 } 324 } else { 325 $have_rel = FALSE; 326 } // end if 327 328 /** 329 * Displays the table structure 330 */ 331 $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf 332 . ' \\begin{longtable}{'; 333 if (!PMA_exportOutputHandler($buffer)) { 334 return FALSE; 335 } 336 337 $columns_cnt = 4; 338 $alignment = '|l|c|c|c|'; 339 if ($do_relation && $have_rel) { 340 $columns_cnt++; 341 $alignment .= 'l|'; 342 } 343 if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) { 344 $columns_cnt++; 345 $alignment .= 'l|'; 346 } 347 if ($do_mime && $cfgRelation['mimework']) { 348 $columns_cnt++; 349 $alignment .='l|'; 350 } 351 $buffer = $alignment . '} ' . $crlf ; 352 353 $header = ' \\hline '; 354 $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'] . '}}'; 355 if ($do_relation && $have_rel) { 356 $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}'; 357 } 358 if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) { 359 $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}'; 360 $comments = PMA_getComments($db, $table); 361 } 362 if ($do_mime && $cfgRelation['mimework']) { 363 $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; 364 $mime_map = PMA_getMIME($db, $table, true); 365 } 366 367 $local_buffer = PMA_texEscape($table); 368 369 // Table caption for first page and label 370 if (isset($GLOBALS['latex_caption'])) { 371 $buffer .= ' \\caption{'. str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption']) 372 . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label']) 373 . '} \\\\' . $crlf; 374 } 375 $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf; 376 // Table caption on next pages 377 if (isset($GLOBALS['latex_caption'])) { 378 $buffer .= ' \\caption{'. str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption']) 379 . '} \\\\ ' . $crlf; 380 } 381 $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf; 382 383 if (!PMA_exportOutputHandler($buffer)) { 384 return FALSE; 385 } 386 387 while ($row = PMA_DBI_fetch_assoc($result)) { 388 389 $type = $row['Type']; 390 // reformat mysql query output - staybyte - 9. June 2001 391 // loic1: set or enum types: slashes single quotes inside options 392 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) { 393 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1); 394 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; 395 $type_nowrap = ''; 396 397 $binary = 0; 398 $unsigned = 0; 399 $zerofill = 0; 400 } else { 401 $type_nowrap = ' nowrap="nowrap"'; 402 $type = eregi_replace('BINARY', '', $type); 403 $type = eregi_replace('ZEROFILL', '', $type); 404 $type = eregi_replace('UNSIGNED', '', $type); 405 if (empty($type)) { 406 $type = ' '; 407 } 408 409 $binary = eregi('BINARY', $row['Type']); 410 $unsigned = eregi('UNSIGNED', $row['Type']); 411 $zerofill = eregi('ZEROFILL', $row['Type']); 412 } 413 if (!isset($row['Default'])) { 414 if ($row['Null'] != '') { 415 $row['Default'] = 'NULL'; 416 } 417 } else { 418 $row['Default'] = $row['Default']; 419 } 420 421 $field_name = $row['Field']; 422 423 $local_buffer = $field_name . "\000" . $type . "\000" . (($row['Null'] == '') ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "\000" . (isset($row['Default']) ? $row['Default'] : ''); 424 425 if ($do_relation && $have_rel) { 426 $local_buffer .= "\000"; 427 if (isset($res_rel[$field_name])) { 428 $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')'; 429 } 430 } 431 if ($do_comments && $cfgRelation['commwork']) { 432 $local_buffer .= "\000"; 433 if (isset($comments[$field_name])) { 434 $local_buffer .= $comments[$field_name]; 435 } 436 } 437 if ($do_mime && $cfgRelation['mimework']) { 438 $local_buffer .= "\000"; 439 if (isset($mime_map[$field_name])) { 440 $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']); 441 } 442 } 443 $local_buffer = PMA_texEscape($local_buffer); 444 if ($row['Key']=='PRI') { 445 $pos=strpos($local_buffer, "\000"); 446 $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); 447 } 448 if (in_array($field_name, $unique_keys)) { 449 $pos=strpos($local_buffer, "\000"); 450 $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); 451 } 452 $buffer = str_replace("\000", ' & ', $local_buffer); 453 $buffer .= ' \\\\ \\hline ' . $crlf; 454 455 if (!PMA_exportOutputHandler($buffer)) { 456 return FALSE; 457 } 458 } // end while 459 PMA_DBI_free_result($result); 460 461 $buffer = ' \\end{longtable}' . $crlf; 462 return PMA_exportOutputHandler($buffer); 463 } // end of the 'PMA_exportStructure' function 464 465 } // end else 466 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 15:18:20 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |