PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/phpMyAdmin_old/libraries/export/htmlword.php

https://bitbucket.org/steve_delbar/iepsm-projet-de-d-veloppement-internet-2013
PHP | 301 lines | 186 code | 32 blank | 83 comment | 64 complexity | 2b157d0ab7ca725f08af1ada704fb97f MD5 | raw file
  1. <?php
  2. /* $Id: htmlword.php,v 1.2 2005/03/06 14:54:15 nijel Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. /**
  5. * Set of functions used to build CSV dumps of tables
  6. */
  7. /**
  8. * Outputs comment
  9. *
  10. * @param string Text of comment
  11. *
  12. * @return bool Whether it suceeded
  13. */
  14. function PMA_exportComment($text) {
  15. return TRUE;
  16. }
  17. /**
  18. * Outputs export footer
  19. *
  20. * @return bool Whether it suceeded
  21. *
  22. * @access public
  23. */
  24. function PMA_exportFooter() {
  25. return PMA_exportOutputHandler('</body></html>');
  26. }
  27. /**
  28. * Outputs export header
  29. *
  30. * @return bool Whether it suceeded
  31. *
  32. * @access public
  33. */
  34. function PMA_exportHeader() {
  35. global $charset, $charset_of_file;
  36. return PMA_exportOutputHandler('<html xmlns:o="urn:schemas-microsoft-com:office:office"
  37. xmlns:x="urn:schemas-microsoft-com:office:word"
  38. xmlns="http://www.w3.org/TR/REC-html40">
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  40. <html>
  41. <head>
  42. <meta http-equiv="Content-type" content="text/html;charset=' . ( isset($charset_of_file) ? $charset_of_file : $charset ) .'" />
  43. </head>
  44. <body>');
  45. }
  46. /**
  47. * Outputs database header
  48. *
  49. * @param string Database name
  50. *
  51. * @return bool Whether it suceeded
  52. *
  53. * @access public
  54. */
  55. function PMA_exportDBHeader($db) {
  56. return PMA_exportOutputHandler('<h1>' . $GLOBALS['strDatabase'] . ' ' . $db . '</h1>');
  57. }
  58. /**
  59. * Outputs database footer
  60. *
  61. * @param string Database name
  62. *
  63. * @return bool Whether it suceeded
  64. *
  65. * @access public
  66. */
  67. function PMA_exportDBFooter($db) {
  68. return TRUE;
  69. }
  70. /**
  71. * Outputs create database database
  72. *
  73. * @param string Database name
  74. *
  75. * @return bool Whether it suceeded
  76. *
  77. * @access public
  78. */
  79. function PMA_exportDBCreate($db) {
  80. return TRUE;
  81. }
  82. /**
  83. * Outputs the content of a table in CSV format
  84. *
  85. * @param string the database name
  86. * @param string the table name
  87. * @param string the end of line sequence
  88. * @param string the url to go back in case of error
  89. * @param string SQL query for obtaining data
  90. *
  91. * @return bool Whether it suceeded
  92. *
  93. * @access public
  94. */
  95. function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
  96. global $what;
  97. if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strDumpingData'] . ' ' .$table . '</h2>')) return FALSE;
  98. if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) return FALSE;
  99. // Gets the data from the database
  100. $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED);
  101. $fields_cnt = PMA_DBI_num_fields($result);
  102. // If required, get fields name at the first line
  103. if (isset($GLOBALS[$what . '_shownames']) && $GLOBALS[$what . '_shownames'] == 'yes') {
  104. $schema_insert = '<tr class="print-category">';
  105. for ($i = 0; $i < $fields_cnt; $i++) {
  106. $schema_insert .= '<td class="print"><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
  107. } // end for
  108. $schema_insert .= '</tr>';
  109. if (!PMA_exportOutputHandler($schema_insert)) return FALSE;
  110. } // end if
  111. // Format the data
  112. while ($row = PMA_DBI_fetch_row($result)) {
  113. $schema_insert = '<tr class="print-category">';
  114. for ($j = 0; $j < $fields_cnt; $j++) {
  115. if (!isset($row[$j]) || is_null($row[$j])) {
  116. $value = $GLOBALS[$what . '_replace_null'];
  117. } else if ($row[$j] == '0' || $row[$j] != '') {
  118. $value = $row[$j];
  119. } else {
  120. $value = '';
  121. }
  122. $schema_insert .= '<td class="print">' . htmlspecialchars($value) . '</td>';
  123. } // end for
  124. $schema_insert .= '</tr>';
  125. if (!PMA_exportOutputHandler($schema_insert)) return FALSE;
  126. } // end while
  127. PMA_DBI_free_result($result);
  128. if (!PMA_exportOutputHandler('</table>')) return FALSE;
  129. return TRUE;
  130. }
  131. function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
  132. {
  133. global $cfgRelation;
  134. if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strTableStructure'] . ' ' .$table . '</h2>')) return FALSE;
  135. /**
  136. * Get the unique keys in the table
  137. */
  138. $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db);
  139. $keys_result = PMA_DBI_query($keys_query);
  140. $unique_keys = array();
  141. while ($key = PMA_DBI_fetch_assoc($keys_result)) {
  142. if ($key['Non_unique'] == 0) $unique_keys[] = $key['Column_name'];
  143. }
  144. PMA_DBI_free_result($keys_result);
  145. /**
  146. * Gets fields properties
  147. */
  148. PMA_DBI_select_db($db);
  149. $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
  150. $result = PMA_DBI_query($local_query);
  151. $fields_cnt = PMA_DBI_num_rows($result);
  152. // Check if we can use Relations (Mike Beck)
  153. if ($do_relation && !empty($cfgRelation['relation'])) {
  154. // Find which tables are related with the current one and write it in
  155. // an array
  156. $res_rel = PMA_getForeigners($db, $table);
  157. if ($res_rel && count($res_rel) > 0) {
  158. $have_rel = TRUE;
  159. } else {
  160. $have_rel = FALSE;
  161. }
  162. }
  163. else {
  164. $have_rel = FALSE;
  165. } // end if
  166. /**
  167. * Displays the table structure
  168. */
  169. if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) return FALSE;
  170. $columns_cnt = 4;
  171. if ($do_relation && $have_rel) {
  172. $columns_cnt++;
  173. }
  174. if ($do_comments && $cfgRelation['commwork']) {
  175. $columns_cnt++;
  176. }
  177. if ($do_mime && $cfgRelation['mimework']) {
  178. $columns_cnt++;
  179. }
  180. $schema_insert = '<tr class="print-category">';
  181. $schema_insert .= '<th class="print">' . htmlspecialchars($GLOBALS['strField']) . '</th>';
  182. $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strType']) . '</b></td>';
  183. $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strNull']) . '</b></td>';
  184. $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strDefault']) . '</b></td>';
  185. if ($do_relation && $have_rel) {
  186. $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strLinksTo']) . '</b></td>';
  187. }
  188. if ($do_comments && $cfgRelation['commwork']) {
  189. $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strComments']) . '</b></td>';
  190. $comments = PMA_getComments($db, $table);
  191. }
  192. if ($do_mime && $cfgRelation['mimework']) {
  193. $schema_insert .= '<td class="print"><b>' . htmlspecialchars('MIME') . '</b></td>';
  194. $mime_map = PMA_getMIME($db, $table, true);
  195. }
  196. $schema_insert .= '</tr>';
  197. if (!PMA_exportOutputHandler($schema_insert)) return FALSE;
  198. while ($row = PMA_DBI_fetch_assoc($result)) {
  199. $schema_insert = '<tr class="print-category">';
  200. $type = $row['Type'];
  201. // reformat mysql query output - staybyte - 9. June 2001
  202. // loic1: set or enum types: slashes single quotes inside options
  203. if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
  204. $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
  205. $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  206. $type_nowrap = '';
  207. $binary = 0;
  208. $unsigned = 0;
  209. $zerofill = 0;
  210. } else {
  211. $type_nowrap = ' nowrap="nowrap"';
  212. $type = eregi_replace('BINARY', '', $type);
  213. $type = eregi_replace('ZEROFILL', '', $type);
  214. $type = eregi_replace('UNSIGNED', '', $type);
  215. if (empty($type)) {
  216. $type = '&nbsp;';
  217. }
  218. $binary = eregi('BINARY', $row['Type'], $test);
  219. $unsigned = eregi('UNSIGNED', $row['Type'], $test);
  220. $zerofill = eregi('ZEROFILL', $row['Type'], $test);
  221. }
  222. $strAttribute = '&nbsp;';
  223. if ($binary) {
  224. $strAttribute = 'BINARY';
  225. }
  226. if ($unsigned) {
  227. $strAttribute = 'UNSIGNED';
  228. }
  229. if ($zerofill) {
  230. $strAttribute = 'UNSIGNED ZEROFILL';
  231. }
  232. if (!isset($row['Default'])) {
  233. if ($row['Null'] != '') {
  234. $row['Default'] = 'NULL';
  235. }
  236. } else {
  237. $row['Default'] = $row['Default'];
  238. }
  239. $fmt_pre = '';
  240. $fmt_post = '';
  241. if (in_array($row['Field'], $unique_keys)) {
  242. $fmt_pre = '<b>' . $fmt_pre;
  243. $fmt_post = $fmt_post . '</b>';
  244. }
  245. if ($row['Key']=='PRI') {
  246. $fmt_pre = '<i>' . $fmt_pre;
  247. $fmt_post = $fmt_post . '</i>';
  248. }
  249. $schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($row['Field']) . $fmt_post . '</td>';
  250. $schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>';
  251. $schema_insert .= '<td class="print">' . htmlspecialchars($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . '</td>';
  252. $schema_insert .= '<td class="print">' . htmlspecialchars(isset($row['Default']) ? $row['Default'] : '') . '</td>';
  253. if ($do_relation && $have_rel) {
  254. $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>';
  255. }
  256. if ($do_comments && $cfgRelation['commwork']) {
  257. $schema_insert .= '<td class="print">' . ( isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>';
  258. }
  259. if ($do_mime && $cfgRelation['mimework']) {
  260. $schema_insert .= '<td class="print">' . ( isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>';
  261. }
  262. $schema_insert .= '</tr>';
  263. if (!PMA_exportOutputHandler($schema_insert)) return FALSE;
  264. } // end while
  265. PMA_DBI_free_result($result);
  266. return PMA_exportOutputHandler('</table>');
  267. }
  268. ?>