PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/manage/phpmyadminlite/libraries/export/htmlword.php

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