/Quản lý website bán phụ tùng oto PHP/phpMyAdmin1/libraries/export/xls.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien · PHP · 195 lines · 103 code · 21 blank · 71 comment · 22 complexity · 4ca0ea689da8214050a7fd5993c2e098 MD5 · raw file

  1. <?php
  2. /* $Id: xls.php 8964 2006-04-26 19:16:52Z nijel $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. // Check if we have native MS Excel export using PEAR class Spreadsheet_Excel_Writer
  5. if (!empty($GLOBALS['cfg']['TempDir'])) {
  6. @include_once('Spreadsheet/Excel/Writer.php');
  7. if (class_exists('Spreadsheet_Excel_Writer')) {
  8. $xls = TRUE;
  9. } else {
  10. $xls = FALSE;
  11. }
  12. } else {
  13. $xls = FALSE;
  14. }
  15. if ($xls) {
  16. if (isset($plugin_list)) {
  17. $plugin_list['xls'] = array(
  18. 'text' => 'strStrucNativeExcel',
  19. 'extension' => 'xls',
  20. 'mime_type' => 'application/vnd.ms-excel',
  21. 'force_file' => true,
  22. 'options' => array(
  23. array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
  24. array('type' => 'text', 'name' => 'columns', 'text' => 'strPutColNames'),
  25. array('type' => 'hidden', 'name' => 'data'),
  26. ),
  27. 'options_text' => 'strStrucNativeExcelOptions',
  28. );
  29. } else {
  30. /**
  31. * Set of functions used to build MS Excel dumps of tables
  32. */
  33. /**
  34. * Outputs comment
  35. *
  36. * @param string Text of comment
  37. *
  38. * @return bool Whether it suceeded
  39. */
  40. function PMA_exportComment($text)
  41. {
  42. return TRUE;
  43. }
  44. /**
  45. * Outputs export footer
  46. *
  47. * @return bool Whether it suceeded
  48. *
  49. * @access public
  50. */
  51. function PMA_exportFooter()
  52. {
  53. global $workbook;
  54. global $tmp_filename;
  55. $res = $workbook->close();
  56. if (PEAR::isError($res)) {
  57. echo $res->getMessage();
  58. return FALSE;
  59. }
  60. if (!PMA_exportOutputHandler(file_get_contents($tmp_filename))) {
  61. return FALSE;
  62. }
  63. unlink($tmp_filename);
  64. return TRUE;
  65. }
  66. /**
  67. * Outputs export header
  68. *
  69. * @return bool Whether it suceeded
  70. *
  71. * @access public
  72. */
  73. function PMA_exportHeader()
  74. {
  75. global $workbook;
  76. global $tmp_filename;
  77. if (empty($GLOBALS['cfg']['TempDir'])) {
  78. return FALSE;
  79. }
  80. $tmp_filename = tempnam(realpath($GLOBALS['cfg']['TempDir']), 'pma_xls_');
  81. $workbook = new Spreadsheet_Excel_Writer($tmp_filename);
  82. return TRUE;
  83. }
  84. /**
  85. * Outputs database header
  86. *
  87. * @param string Database name
  88. *
  89. * @return bool Whether it suceeded
  90. *
  91. * @access public
  92. */
  93. function PMA_exportDBHeader($db)
  94. {
  95. return TRUE;
  96. }
  97. /**
  98. * Outputs database footer
  99. *
  100. * @param string Database name
  101. *
  102. * @return bool Whether it suceeded
  103. *
  104. * @access public
  105. */
  106. function PMA_exportDBFooter($db)
  107. {
  108. return TRUE;
  109. }
  110. /**
  111. * Outputs create database database
  112. *
  113. * @param string Database name
  114. *
  115. * @return bool Whether it suceeded
  116. *
  117. * @access public
  118. */
  119. function PMA_exportDBCreate($db)
  120. {
  121. return TRUE;
  122. }
  123. /**
  124. * Outputs the content of a table in CSV format
  125. *
  126. * @param string the database name
  127. * @param string the table name
  128. * @param string the end of line sequence
  129. * @param string the url to go back in case of error
  130. * @param string SQL query for obtaining data
  131. *
  132. * @return bool Whether it suceeded
  133. *
  134. * @access public
  135. */
  136. function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
  137. {
  138. global $what;
  139. global $workbook;
  140. $worksheet =& $workbook->addWorksheet($table);
  141. $workbook->setTempDir(realpath($GLOBALS['cfg']['TempDir']));
  142. // Gets the data from the database
  143. $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
  144. $fields_cnt = PMA_DBI_num_fields($result);
  145. $col = 0;
  146. // If required, get fields name at the first line
  147. if (isset($GLOBALS['xls_columns']) && $GLOBALS['xls_columns'] == 'yes') {
  148. $schema_insert = '';
  149. for ($i = 0; $i < $fields_cnt; $i++) {
  150. $worksheet->write(0, $i, stripslashes(PMA_DBI_field_name($result, $i)));
  151. } // end for
  152. $col++;
  153. } // end if
  154. // Format the data
  155. while ($row = PMA_DBI_fetch_row($result)) {
  156. $schema_insert = '';
  157. for ($j = 0; $j < $fields_cnt; $j++) {
  158. if (!isset($row[$j]) || is_null($row[$j])) {
  159. $worksheet->write($col, $j, $GLOBALS['xls_null']);
  160. } elseif ($row[$j] == '0' || $row[$j] != '') {
  161. // FIXME: we should somehow handle character set here!
  162. $worksheet->write($col, $j, $row[$j]);
  163. } else {
  164. $worksheet->write($col, $j, '');
  165. }
  166. } // end for
  167. $col++;
  168. } // end while
  169. PMA_DBI_free_result($result);
  170. return TRUE;
  171. }
  172. }
  173. }
  174. ?>