ExportPdf.class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Produce a PDF report (export) from a query
  5. *
  6. * @package PhpMyAdmin-Export
  7. * @subpackage PDF
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /**
  13. * Skip the plugin if TCPDF is not available.
  14. */
  15. if (! file_exists(TCPDF_INC)) {
  16. $GLOBALS['skip_import'] = true;
  17. return;
  18. }
  19. /* Get the export interface */
  20. require_once 'libraries/plugins/ExportPlugin.class.php';
  21. /* Get the PMA_ExportPdf class */
  22. require_once 'libraries/plugins/export/PMA_ExportPdf.class.php';
  23. /**
  24. * Handles the export for the PDF class
  25. *
  26. * @package PhpMyAdmin-Export
  27. * @subpackage PDF
  28. */
  29. class ExportPdf extends ExportPlugin
  30. {
  31. /**
  32. * PMA_ExportPdf instance
  33. *
  34. * @var PMA_ExportPdf
  35. */
  36. private $_pdf;
  37. /**
  38. * PDF Report Title
  39. *
  40. * @var string
  41. */
  42. private $_pdfReportTitle;
  43. /**
  44. * Constructor
  45. */
  46. public function __construct()
  47. {
  48. // initialize the specific export PDF variables
  49. $this->initSpecificVariables();
  50. $this->setProperties();
  51. }
  52. /**
  53. * Initialize the local variables that are used for export PDF
  54. *
  55. * @return void
  56. */
  57. protected function initSpecificVariables()
  58. {
  59. $this->_setPdfReportTitle("");
  60. $this->_setPdf(new PMA_ExportPdf('L', 'pt', 'A3'));
  61. }
  62. /**
  63. * Sets the export PDF properties
  64. *
  65. * @return void
  66. */
  67. protected function setProperties()
  68. {
  69. $props = 'libraries/properties/';
  70. include_once "$props/plugins/ExportPluginProperties.class.php";
  71. include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
  72. include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
  73. include_once "$props/options/items/MessageOnlyPropertyItem.class.php";
  74. include_once "$props/options/items/TextPropertyItem.class.php";
  75. include_once "$props/options/items/HiddenPropertyItem.class.php";
  76. $exportPluginProperties = new ExportPluginProperties();
  77. $exportPluginProperties->setText('PDF');
  78. $exportPluginProperties->setExtension('pdf');
  79. $exportPluginProperties->setMimeType('application/pdf');
  80. $exportPluginProperties->setForceFile(true);
  81. $exportPluginProperties->setOptionsText(__('Options'));
  82. // create the root group that will be the options field for
  83. // $exportPluginProperties
  84. // this will be shown as "Format specific options"
  85. $exportSpecificOptions = new OptionsPropertyRootGroup();
  86. $exportSpecificOptions->setName("Format Specific Options");
  87. // general options main group
  88. $generalOptions = new OptionsPropertyMainGroup();
  89. $generalOptions->setName("general_opts");
  90. // create primary items and add them to the group
  91. $leaf = new MessageOnlyPropertyItem();
  92. $leaf->setName("explanation");
  93. $leaf->setText(
  94. __('(Generates a report containing the data of a single table)')
  95. );
  96. $generalOptions->addProperty($leaf);
  97. $leaf = new TextPropertyItem();
  98. $leaf->setName("report_title");
  99. $leaf->setText(__('Report title:'));
  100. $generalOptions->addProperty($leaf);
  101. $leaf = new HiddenPropertyItem();
  102. $leaf->setName("structure_or_data");
  103. $generalOptions->addProperty($leaf);
  104. // add the main group to the root group
  105. $exportSpecificOptions->addProperty($generalOptions);
  106. // set the options for the export plugin property item
  107. $exportPluginProperties->setOptions($exportSpecificOptions);
  108. $this->properties = $exportPluginProperties;
  109. }
  110. /**
  111. * This method is called when any PluginManager to which the observer
  112. * is attached calls PluginManager::notify()
  113. *
  114. * @param SplSubject $subject The PluginManager notifying the observer
  115. * of an update.
  116. *
  117. * @return void
  118. */
  119. public function update (SplSubject $subject)
  120. {
  121. }
  122. /**
  123. * Outputs export header
  124. *
  125. * @return bool Whether it succeeded
  126. */
  127. public function exportHeader ()
  128. {
  129. $pdf_report_title = $this->_getPdfReportTitle();
  130. $pdf = $this->_getPdf();
  131. $pdf->Open();
  132. $attr = array('titleFontSize' => 18, 'titleText' => $pdf_report_title);
  133. $pdf->setAttributes($attr);
  134. $pdf->setTopMargin(30);
  135. return true;
  136. }
  137. /**
  138. * Outputs export footer
  139. *
  140. * @return bool Whether it succeeded
  141. */
  142. public function exportFooter ()
  143. {
  144. $pdf = $this->_getPdf();
  145. // instead of $pdf->Output():
  146. if (! PMA_exportOutputHandler($pdf->getPDFData())) {
  147. return false;
  148. }
  149. return true;
  150. }
  151. /**
  152. * Outputs database header
  153. *
  154. * @param string $db Database name
  155. *
  156. * @return bool Whether it succeeded
  157. */
  158. public function exportDBHeader ($db)
  159. {
  160. return true;
  161. }
  162. /**
  163. * Outputs database footer
  164. *
  165. * @param string $db Database name
  166. *
  167. * @return bool Whether it succeeded
  168. */
  169. public function exportDBFooter ($db)
  170. {
  171. return true;
  172. }
  173. /**
  174. * Outputs CREATE DATABASE statement
  175. *
  176. * @param string $db Database name
  177. *
  178. * @return bool Whether it succeeded
  179. */
  180. public function exportDBCreate($db)
  181. {
  182. return true;
  183. }
  184. /**
  185. * Outputs the content of a table in NHibernate format
  186. *
  187. * @param string $db database name
  188. * @param string $table table name
  189. * @param string $crlf the end of line sequence
  190. * @param string $error_url the url to go back in case of error
  191. * @param string $sql_query SQL query for obtaining data
  192. *
  193. * @return bool Whether it succeeded
  194. */
  195. public function exportData($db, $table, $crlf, $error_url, $sql_query)
  196. {
  197. $pdf = $this->_getPdf();
  198. $attr = array('currentDb' => $db, 'currentTable' => $table);
  199. $pdf->setAttributes($attr);
  200. $pdf->mysqlReport($sql_query);
  201. return true;
  202. } // end of the 'PMA_exportData()' function
  203. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  204. /**
  205. * Gets the PMA_ExportPdf instance
  206. *
  207. * @return PMA_ExportPdf
  208. */
  209. private function _getPdf()
  210. {
  211. return $this->_pdf;
  212. }
  213. /**
  214. * Instantiates the PMA_ExportPdf class
  215. *
  216. * @param string $pdf PMA_ExportPdf instance
  217. *
  218. * @return void
  219. */
  220. private function _setPdf($pdf)
  221. {
  222. $this->_pdf = $pdf;
  223. }
  224. /**
  225. * Gets the PDF report title
  226. *
  227. * @return string
  228. */
  229. private function _getPdfReportTitle()
  230. {
  231. return $this->_pdfReportTitle;
  232. }
  233. /**
  234. * Sets the PDF report title
  235. *
  236. * @param string $pdfReportTitle PDF report title
  237. *
  238. * @return void
  239. */
  240. private function _setPdfReportTitle($pdfReportTitle)
  241. {
  242. $this->_pdfReportTitle = $pdfReportTitle;
  243. }
  244. }
  245. ?>