ExportPdf.class.php 6.8 KB

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