ExportOdt.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Set of functions used to build OpenDocument Text dumps of tables
  5. *
  6. * @package PhpMyAdmin-Export
  7. * @subpackage ODT
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /* Get the export interface */
  13. require_once 'libraries/plugins/ExportPlugin.class.php';
  14. $GLOBALS['odt_buffer'] = '';
  15. require_once 'libraries/opendocument.lib.php';
  16. /**
  17. * Handles the export for the ODT class
  18. *
  19. * @package PhpMyAdmin-Export
  20. * @subpackage ODT
  21. */
  22. class ExportOdt extends ExportPlugin
  23. {
  24. /**
  25. * Constructor
  26. */
  27. public function __construct()
  28. {
  29. $this->setProperties();
  30. }
  31. /**
  32. * Sets the export ODT properties
  33. *
  34. * @return void
  35. */
  36. protected function setProperties()
  37. {
  38. global $plugin_param;
  39. $hide_structure = false;
  40. if ($plugin_param['export_type'] == 'table'
  41. && ! $plugin_param['single_table']
  42. ) {
  43. $hide_structure = true;
  44. }
  45. $props = 'libraries/properties/';
  46. include_once "$props/plugins/ExportPluginProperties.class.php";
  47. include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
  48. include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
  49. include_once "$props/options/items/TextPropertyItem.class.php";
  50. include_once "$props/options/items/BoolPropertyItem.class.php";
  51. include_once "$props/options/items/HiddenPropertyItem.class.php";
  52. include_once "$props/options/items/RadioPropertyItem.class.php";
  53. $exportPluginProperties = new ExportPluginProperties();
  54. $exportPluginProperties->setText('OpenDocument Text');
  55. $exportPluginProperties->setExtension('odt');
  56. $exportPluginProperties->setMimeType(
  57. 'application/vnd.oasis.opendocument.text'
  58. );
  59. $exportPluginProperties->setForceFile(true);
  60. $exportPluginProperties->setOptionsText(__('Options'));
  61. // create the root group that will be the options field for
  62. // $exportPluginProperties
  63. // this will be shown as "Format specific options"
  64. $exportSpecificOptions = new OptionsPropertyRootGroup();
  65. $exportSpecificOptions->setName("Format Specific Options");
  66. // what to dump (structure/data/both) main group
  67. $dumpWhat = new OptionsPropertyMainGroup();
  68. $dumpWhat->setName("general_opts");
  69. $dumpWhat->setText(__('Dump table'));
  70. // create primary items and add them to the group
  71. $leaf = new RadioPropertyItem();
  72. $leaf->setName("structure_or_data");
  73. $leaf->setValues(
  74. array(
  75. 'structure' => __('structure'),
  76. 'data' => __('data'),
  77. 'structure_and_data' => __('structure and data')
  78. )
  79. );
  80. $dumpWhat->addProperty($leaf);
  81. // add the main group to the root group
  82. $exportSpecificOptions->addProperty($dumpWhat);
  83. // structure options main group
  84. if (! $hide_structure) {
  85. $structureOptions = new OptionsPropertyMainGroup();
  86. $structureOptions->setName("structure");
  87. $structureOptions->setText(__('Object creation options'));
  88. $structureOptions->setForce('data');
  89. // create primary items and add them to the group
  90. if (! empty($GLOBALS['cfgRelation']['relation'])) {
  91. $leaf = new BoolPropertyItem();
  92. $leaf->setName("relation");
  93. $leaf->setText(__('Display foreign key relationships'));
  94. $structureOptions->addProperty($leaf);
  95. }
  96. $leaf = new BoolPropertyItem();
  97. $leaf->setName("comments");
  98. $leaf->setText(__('Display comments'));
  99. $structureOptions->addProperty($leaf);
  100. if (! empty($GLOBALS['cfgRelation']['mimework'])) {
  101. $leaf = new BoolPropertyItem();
  102. $leaf->setName("mime");
  103. $leaf->setText(__('Display MIME types'));
  104. $structureOptions->addProperty($leaf);
  105. }
  106. // add the main group to the root group
  107. $exportSpecificOptions->addProperty($structureOptions);
  108. }
  109. // data options main group
  110. $dataOptions = new OptionsPropertyMainGroup();
  111. $dataOptions->setName("data");
  112. $dataOptions->setText(__('Data dump options'));
  113. $dataOptions->setForce('structure');
  114. // create primary items and add them to the group
  115. $leaf = new BoolPropertyItem();
  116. $leaf->setName("columns");
  117. $leaf->setText(__('Put columns names in the first row'));
  118. $dataOptions->addProperty($leaf);
  119. $leaf = new TextPropertyItem();
  120. $leaf->setName('null');
  121. $leaf->setText(__('Replace NULL with:'));
  122. $dataOptions->addProperty($leaf);
  123. // add the main group to the root group
  124. $exportSpecificOptions->addProperty($dataOptions);
  125. // set the options for the export plugin property item
  126. $exportPluginProperties->setOptions($exportSpecificOptions);
  127. $this->properties = $exportPluginProperties;
  128. }
  129. /**
  130. * This method is called when any PluginManager to which the observer
  131. * is attached calls PluginManager::notify()
  132. *
  133. * @param SplSubject $subject The PluginManager notifying the observer
  134. * of an update.
  135. *
  136. * @return void
  137. */
  138. public function update (SplSubject $subject)
  139. {
  140. }
  141. /**
  142. * Outputs export header
  143. *
  144. * @return bool Whether it succeeded
  145. */
  146. public function exportHeader ()
  147. {
  148. $GLOBALS['odt_buffer'] .= '<?xml version="1.0" encoding="utf-8"?' . '>'
  149. . '<office:document-content '
  150. . $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
  151. . '<office:body>'
  152. . '<office:text>';
  153. return true;
  154. }
  155. /**
  156. * Outputs export footer
  157. *
  158. * @return bool Whether it succeeded
  159. */
  160. public function exportFooter ()
  161. {
  162. $GLOBALS['odt_buffer'] .= '</office:text>'
  163. . '</office:body>'
  164. . '</office:document-content>';
  165. if (! PMA_exportOutputHandler(
  166. PMA_createOpenDocument(
  167. 'application/vnd.oasis.opendocument.text',
  168. $GLOBALS['odt_buffer']
  169. )
  170. )) {
  171. return false;
  172. }
  173. return true;
  174. }
  175. /**
  176. * Outputs database header
  177. *
  178. * @param string $db Database name
  179. *
  180. * @return bool Whether it succeeded
  181. */
  182. public function exportDBHeader ($db)
  183. {
  184. $GLOBALS['odt_buffer'] .=
  185. '<text:h text:outline-level="1" text:style-name="Heading_1"'
  186. . ' text:is-list-header="true">'
  187. . __('Database') . ' ' . htmlspecialchars($db)
  188. . '</text:h>';
  189. return true;
  190. }
  191. /**
  192. * Outputs database footer
  193. *
  194. * @param string $db Database name
  195. *
  196. * @return bool Whether it succeeded
  197. */
  198. public function exportDBFooter ($db)
  199. {
  200. return true;
  201. }
  202. /**
  203. * Outputs CREATE DATABASE statement
  204. *
  205. * @param string $db Database name
  206. *
  207. * @return bool Whether it succeeded
  208. */
  209. public function exportDBCreate($db)
  210. {
  211. return true;
  212. }
  213. /**
  214. * Outputs the content of a table in NHibernate format
  215. *
  216. * @param string $db database name
  217. * @param string $table table name
  218. * @param string $crlf the end of line sequence
  219. * @param string $error_url the url to go back in case of error
  220. * @param string $sql_query SQL query for obtaining data
  221. *
  222. * @return bool Whether it succeeded
  223. */
  224. public function exportData($db, $table, $crlf, $error_url, $sql_query)
  225. {
  226. global $what;
  227. // Gets the data from the database
  228. $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
  229. $fields_cnt = PMA_DBI_num_fields($result);
  230. $fields_meta = PMA_DBI_get_fields_meta($result);
  231. $field_flags = array();
  232. for ($j = 0; $j < $fields_cnt; $j++) {
  233. $field_flags[$j] = PMA_DBI_field_flags($result, $j);
  234. }
  235. $GLOBALS['odt_buffer'] .=
  236. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  237. . ' text:is-list-header="true">'
  238. . __('Dumping data for table') . ' ' . htmlspecialchars($table)
  239. . '</text:h>'
  240. . '<table:table'
  241. . ' table:name="' . htmlspecialchars($table) . '_structure">'
  242. . '<table:table-column'
  243. . ' table:number-columns-repeated="' . $fields_cnt . '"/>';
  244. // If required, get fields name at the first line
  245. if (isset($GLOBALS[$what . '_columns'])) {
  246. $GLOBALS['odt_buffer'] .= '<table:table-row>';
  247. for ($i = 0; $i < $fields_cnt; $i++) {
  248. $GLOBALS['odt_buffer'] .=
  249. '<table:table-cell office:value-type="string">'
  250. . '<text:p>'
  251. . htmlspecialchars(
  252. stripslashes(PMA_DBI_field_name($result, $i))
  253. )
  254. . '</text:p>'
  255. . '</table:table-cell>';
  256. } // end for
  257. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  258. } // end if
  259. // Format the data
  260. while ($row = PMA_DBI_fetch_row($result)) {
  261. $GLOBALS['odt_buffer'] .= '<table:table-row>';
  262. for ($j = 0; $j < $fields_cnt; $j++) {
  263. if (! isset($row[$j]) || is_null($row[$j])) {
  264. $GLOBALS['odt_buffer'] .=
  265. '<table:table-cell office:value-type="string">'
  266. . '<text:p>'
  267. . htmlspecialchars($GLOBALS[$what . '_null'])
  268. . '</text:p>'
  269. . '</table:table-cell>';
  270. } elseif (stristr($field_flags[$j], 'BINARY')
  271. && $fields_meta[$j]->blob
  272. ) {
  273. // ignore BLOB
  274. $GLOBALS['odt_buffer'] .=
  275. '<table:table-cell office:value-type="string">'
  276. . '<text:p></text:p>'
  277. . '</table:table-cell>';
  278. } elseif ($fields_meta[$j]->numeric
  279. && $fields_meta[$j]->type != 'timestamp'
  280. && ! $fields_meta[$j]->blob
  281. ) {
  282. $GLOBALS['odt_buffer'] .=
  283. '<table:table-cell office:value-type="float"'
  284. . ' office:value="' . $row[$j] . '" >'
  285. . '<text:p>'
  286. . htmlspecialchars($row[$j])
  287. . '</text:p>'
  288. . '</table:table-cell>';
  289. } else {
  290. $GLOBALS['odt_buffer'] .=
  291. '<table:table-cell office:value-type="string">'
  292. . '<text:p>'
  293. . htmlspecialchars($row[$j])
  294. . '</text:p>'
  295. . '</table:table-cell>';
  296. }
  297. } // end for
  298. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  299. } // end while
  300. PMA_DBI_free_result($result);
  301. $GLOBALS['odt_buffer'] .= '</table:table>';
  302. return true;
  303. }
  304. /**
  305. * Returns a stand-in CREATE definition to resolve view dependencies
  306. *
  307. * @param string $db the database name
  308. * @param string $view the view name
  309. * @param string $crlf the end of line sequence
  310. *
  311. * @return bool true
  312. */
  313. public function getTableDefStandIn($db, $view, $crlf)
  314. {
  315. /**
  316. * Gets fields properties
  317. */
  318. PMA_DBI_select_db($db);
  319. /**
  320. * Displays the table structure
  321. */
  322. $GLOBALS['odt_buffer'] .=
  323. '<table:table table:name="'
  324. . htmlspecialchars($view) . '_data">';
  325. $columns_cnt = 4;
  326. $GLOBALS['odt_buffer'] .=
  327. '<table:table-column'
  328. . ' table:number-columns-repeated="' . $columns_cnt . '"/>';
  329. /* Header */
  330. $GLOBALS['odt_buffer'] .= '<table:table-row>'
  331. . '<table:table-cell office:value-type="string">'
  332. . '<text:p>' . __('Column') . '</text:p>'
  333. . '</table:table-cell>'
  334. . '<table:table-cell office:value-type="string">'
  335. . '<text:p>' . __('Type') . '</text:p>'
  336. . '</table:table-cell>'
  337. . '<table:table-cell office:value-type="string">'
  338. . '<text:p>' . __('Null') . '</text:p>'
  339. . '</table:table-cell>'
  340. . '<table:table-cell office:value-type="string">'
  341. . '<text:p>' . __('Default') . '</text:p>'
  342. . '</table:table-cell>'
  343. . '</table:table-row>';
  344. $columns = PMA_DBI_get_columns($db, $view);
  345. foreach ($columns as $column) {
  346. $GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column);
  347. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  348. } // end foreach
  349. $GLOBALS['odt_buffer'] .= '</table:table>';
  350. return true;
  351. }
  352. /**
  353. * Returns $table's CREATE definition
  354. *
  355. * @param string $db the database name
  356. * @param string $table the table name
  357. * @param string $crlf the end of line sequence
  358. * @param string $error_url the url to go back in case of error
  359. * @param bool $do_relation whether to include relation comments
  360. * @param bool $do_comments whether to include the pmadb-style column
  361. * comments as comments in the structure;
  362. * this is deprecated but the parameter is
  363. * left here because export.php calls
  364. * PMA_exportStructure() also for other
  365. * @param bool $do_mime whether to include mime comments
  366. * @param bool $show_dates whether to include creation/update/check dates
  367. * @param bool $add_semicolon whether to add semicolon and end-of-line at
  368. * the end
  369. * @param bool $view whether we're handling a view
  370. *
  371. * @return bool true
  372. */
  373. public function getTableDef(
  374. $db,
  375. $table,
  376. $crlf,
  377. $error_url,
  378. $do_relation,
  379. $do_comments,
  380. $do_mime,
  381. $show_dates = false,
  382. $add_semicolon = true,
  383. $view = false
  384. ) {
  385. global $cfgRelation;
  386. /**
  387. * Gets fields properties
  388. */
  389. PMA_DBI_select_db($db);
  390. // Check if we can use Relations
  391. if ($do_relation && ! empty($cfgRelation['relation'])) {
  392. // Find which tables are related with the current one and write it in
  393. // an array
  394. $res_rel = PMA_getForeigners($db, $table);
  395. if ($res_rel && count($res_rel) > 0) {
  396. $have_rel = true;
  397. } else {
  398. $have_rel = false;
  399. }
  400. } else {
  401. $have_rel = false;
  402. } // end if
  403. /**
  404. * Displays the table structure
  405. */
  406. $GLOBALS['odt_buffer'] .= '<table:table table:name="'
  407. . htmlspecialchars($table) . '_structure">';
  408. $columns_cnt = 4;
  409. if ($do_relation && $have_rel) {
  410. $columns_cnt++;
  411. }
  412. if ($do_comments) {
  413. $columns_cnt++;
  414. }
  415. if ($do_mime && $cfgRelation['mimework']) {
  416. $columns_cnt++;
  417. }
  418. $GLOBALS['odt_buffer'] .= '<table:table-column'
  419. . ' table:number-columns-repeated="' . $columns_cnt . '"/>';
  420. /* Header */
  421. $GLOBALS['odt_buffer'] .= '<table:table-row>'
  422. . '<table:table-cell office:value-type="string">'
  423. . '<text:p>' . __('Column') . '</text:p>'
  424. . '</table:table-cell>'
  425. . '<table:table-cell office:value-type="string">'
  426. . '<text:p>' . __('Type') . '</text:p>'
  427. . '</table:table-cell>'
  428. . '<table:table-cell office:value-type="string">'
  429. . '<text:p>' . __('Null') . '</text:p>'
  430. . '</table:table-cell>'
  431. . '<table:table-cell office:value-type="string">'
  432. . '<text:p>' . __('Default') . '</text:p>'
  433. . '</table:table-cell>';
  434. if ($do_relation && $have_rel) {
  435. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  436. . '<text:p>' . __('Links to') . '</text:p>'
  437. . '</table:table-cell>';
  438. }
  439. if ($do_comments) {
  440. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  441. . '<text:p>' . __('Comments') . '</text:p>'
  442. . '</table:table-cell>';
  443. $comments = PMA_getComments($db, $table);
  444. }
  445. if ($do_mime && $cfgRelation['mimework']) {
  446. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  447. . '<text:p>' . __('MIME type') . '</text:p>'
  448. . '</table:table-cell>';
  449. $mime_map = PMA_getMIME($db, $table, true);
  450. }
  451. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  452. $columns = PMA_DBI_get_columns($db, $table);
  453. foreach ($columns as $column) {
  454. $field_name = $column['Field'];
  455. $GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column);
  456. if ($do_relation && $have_rel) {
  457. if (isset($res_rel[$field_name])) {
  458. $GLOBALS['odt_buffer'] .=
  459. '<table:table-cell office:value-type="string">'
  460. . '<text:p>'
  461. . htmlspecialchars(
  462. $res_rel[$field_name]['foreign_table']
  463. . ' (' . $res_rel[$field_name]['foreign_field'] . ')'
  464. )
  465. . '</text:p>'
  466. . '</table:table-cell>';
  467. }
  468. }
  469. if ($do_comments) {
  470. if (isset($comments[$field_name])) {
  471. $GLOBALS['odt_buffer'] .=
  472. '<table:table-cell office:value-type="string">'
  473. . '<text:p>'
  474. . htmlspecialchars($comments[$field_name])
  475. . '</text:p>'
  476. . '</table:table-cell>';
  477. } else {
  478. $GLOBALS['odt_buffer'] .=
  479. '<table:table-cell office:value-type="string">'
  480. . '<text:p></text:p>'
  481. . '</table:table-cell>';
  482. }
  483. }
  484. if ($do_mime && $cfgRelation['mimework']) {
  485. if (isset($mime_map[$field_name])) {
  486. $GLOBALS['odt_buffer'] .=
  487. '<table:table-cell office:value-type="string">'
  488. . '<text:p>'
  489. . htmlspecialchars(
  490. str_replace('_', '/', $mime_map[$field_name]['mimetype'])
  491. )
  492. . '</text:p>'
  493. . '</table:table-cell>';
  494. } else {
  495. $GLOBALS['odt_buffer'] .=
  496. '<table:table-cell office:value-type="string">'
  497. . '<text:p></text:p>'
  498. . '</table:table-cell>';
  499. }
  500. }
  501. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  502. } // end foreach
  503. $GLOBALS['odt_buffer'] .= '</table:table>';
  504. return true;
  505. } // end of the '$this->getTableDef()' function
  506. /**
  507. * Outputs triggers
  508. *
  509. * @param string $db database name
  510. * @param string $table table name
  511. *
  512. * @return bool true
  513. */
  514. protected function getTriggers($db, $table)
  515. {
  516. $GLOBALS['odt_buffer'] .= '<table:table'
  517. . ' table:name="' . htmlspecialchars($table) . '_triggers">'
  518. . '<table:table-column'
  519. . ' table:number-columns-repeated="4"/>'
  520. . '<table:table-row>'
  521. . '<table:table-cell office:value-type="string">'
  522. . '<text:p>' . __('Name') . '</text:p>'
  523. . '</table:table-cell>'
  524. . '<table:table-cell office:value-type="string">'
  525. . '<text:p>' . __('Time') . '</text:p>'
  526. . '</table:table-cell>'
  527. . '<table:table-cell office:value-type="string">'
  528. . '<text:p>' . __('Event') . '</text:p>'
  529. . '</table:table-cell>'
  530. . '<table:table-cell office:value-type="string">'
  531. . '<text:p>' . __('Definition') . '</text:p>'
  532. . '</table:table-cell>'
  533. . '</table:table-row>';
  534. $triggers = PMA_DBI_get_triggers($db, $table);
  535. foreach ($triggers as $trigger) {
  536. $GLOBALS['odt_buffer'] .= '<table:table-row>';
  537. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  538. . '<text:p>'
  539. . htmlspecialchars($trigger['name'])
  540. . '</text:p>'
  541. . '</table:table-cell>';
  542. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  543. . '<text:p>'
  544. . htmlspecialchars($trigger['action_timing'])
  545. . '</text:p>'
  546. . '</table:table-cell>';
  547. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  548. . '<text:p>'
  549. . htmlspecialchars($trigger['event_manipulation'])
  550. . '</text:p>'
  551. . '</table:table-cell>';
  552. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  553. . '<text:p>'
  554. . htmlspecialchars($trigger['definition'])
  555. . '</text:p>'
  556. . '</table:table-cell>';
  557. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  558. }
  559. $GLOBALS['odt_buffer'] .= '</table:table>';
  560. return true;
  561. }
  562. /**
  563. * Outputs table's structure
  564. *
  565. * @param string $db database name
  566. * @param string $table table name
  567. * @param string $crlf the end of line sequence
  568. * @param string $error_url the url to go back in case of error
  569. * @param string $export_mode 'create_table', 'triggers', 'create_view',
  570. * 'stand_in'
  571. * @param string $export_type 'server', 'database', 'table'
  572. * @param bool $do_relation whether to include relation comments
  573. * @param bool $do_comments whether to include the pmadb-style column
  574. * comments as comments in the structure;
  575. * this is deprecated but the parameter is
  576. * left here because export.php calls
  577. * PMA_exportStructure() also for other
  578. * @param bool $do_mime whether to include mime comments
  579. * @param bool $dates whether to include creation/update/check dates
  580. *
  581. * @return bool Whether it succeeded
  582. */
  583. public function exportStructure(
  584. $db,
  585. $table,
  586. $crlf,
  587. $error_url,
  588. $export_mode,
  589. $export_type,
  590. $do_relation = false,
  591. $do_comments = false,
  592. $do_mime = false,
  593. $dates = false
  594. ) {
  595. switch($export_mode) {
  596. case 'create_table':
  597. $GLOBALS['odt_buffer'] .=
  598. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  599. . ' text:is-list-header="true">'
  600. . __('Table structure for table') . ' ' .
  601. htmlspecialchars($table)
  602. . '</text:h>';
  603. $this->getTableDef(
  604. $db, $table, $crlf, $error_url, $do_relation, $do_comments,
  605. $do_mime, $dates
  606. );
  607. break;
  608. case 'triggers':
  609. $triggers = PMA_DBI_get_triggers($db, $table);
  610. if ($triggers) {
  611. $GLOBALS['odt_buffer'] .=
  612. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  613. . ' text:is-list-header="true">'
  614. . __('Triggers') . ' '
  615. . htmlspecialchars($table)
  616. . '</text:h>';
  617. $this->getTriggers($db, $table);
  618. }
  619. break;
  620. case 'create_view':
  621. $GLOBALS['odt_buffer'] .=
  622. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  623. . ' text:is-list-header="true">'
  624. . __('Structure for view') . ' '
  625. . htmlspecialchars($table)
  626. . '</text:h>';
  627. $this->getTableDef(
  628. $db, $table, $crlf, $error_url, $do_relation, $do_comments,
  629. $do_mime, $dates, true, true
  630. );
  631. break;
  632. case 'stand_in':
  633. $GLOBALS['odt_buffer'] .=
  634. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  635. . ' text:is-list-header="true">'
  636. . __('Stand-in structure for view') . ' '
  637. . htmlspecialchars($table)
  638. . '</text:h>';
  639. // export a stand-in definition to resolve view dependencies
  640. $this->getTableDefStandIn($db, $table, $crlf);
  641. } // end switch
  642. return true;
  643. } // end of the '$this->exportStructure' function
  644. /**
  645. * Formats the definition for one column
  646. *
  647. * @param array $column info about this column
  648. *
  649. * @return string Formatted column definition
  650. */
  651. protected function formatOneColumnDefinition($column)
  652. {
  653. $field_name = $column['Field'];
  654. $definition = '<table:table-row>';
  655. $definition .= '<table:table-cell office:value-type="string">'
  656. . '<text:p>' . htmlspecialchars($field_name) . '</text:p>'
  657. . '</table:table-cell>';
  658. $extracted_columnspec
  659. = PMA_Util::extractColumnSpec($column['Type']);
  660. $type = htmlspecialchars($extracted_columnspec['print_type']);
  661. if (empty($type)) {
  662. $type = '&nbsp;';
  663. }
  664. $definition .= '<table:table-cell office:value-type="string">'
  665. . '<text:p>' . htmlspecialchars($type) . '</text:p>'
  666. . '</table:table-cell>';
  667. if (! isset($column['Default'])) {
  668. if ($column['Null'] != 'NO') {
  669. $column['Default'] = 'NULL';
  670. } else {
  671. $column['Default'] = '';
  672. }
  673. } else {
  674. $column['Default'] = $column['Default'];
  675. }
  676. $definition .= '<table:table-cell office:value-type="string">'
  677. . '<text:p>'
  678. . (($column['Null'] == '' || $column['Null'] == 'NO')
  679. ? __('No')
  680. : __('Yes'))
  681. . '</text:p>'
  682. . '</table:table-cell>';
  683. $definition .= '<table:table-cell office:value-type="string">'
  684. . '<text:p>' . htmlspecialchars($column['Default']) . '</text:p>'
  685. . '</table:table-cell>';
  686. return $definition;
  687. }
  688. }
  689. ?>