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 = $GLOBALS['dbi']->query(
  229. $sql_query, null, PMA_DatabaseInterface::QUERY_UNBUFFERED
  230. );
  231. $fields_cnt = $GLOBALS['dbi']->numFields($result);
  232. $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
  233. $field_flags = array();
  234. for ($j = 0; $j < $fields_cnt; $j++) {
  235. $field_flags[$j] = $GLOBALS['dbi']->fieldFlags($result, $j);
  236. }
  237. $GLOBALS['odt_buffer'] .=
  238. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  239. . ' text:is-list-header="true">'
  240. . __('Dumping data for table') . ' ' . htmlspecialchars($table)
  241. . '</text:h>'
  242. . '<table:table'
  243. . ' table:name="' . htmlspecialchars($table) . '_structure">'
  244. . '<table:table-column'
  245. . ' table:number-columns-repeated="' . $fields_cnt . '"/>';
  246. // If required, get fields name at the first line
  247. if (isset($GLOBALS[$what . '_columns'])) {
  248. $GLOBALS['odt_buffer'] .= '<table:table-row>';
  249. for ($i = 0; $i < $fields_cnt; $i++) {
  250. $GLOBALS['odt_buffer'] .=
  251. '<table:table-cell office:value-type="string">'
  252. . '<text:p>'
  253. . htmlspecialchars(
  254. stripslashes($GLOBALS['dbi']->fieldName($result, $i))
  255. )
  256. . '</text:p>'
  257. . '</table:table-cell>';
  258. } // end for
  259. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  260. } // end if
  261. // Format the data
  262. while ($row = $GLOBALS['dbi']->fetchRow($result)) {
  263. $GLOBALS['odt_buffer'] .= '<table:table-row>';
  264. for ($j = 0; $j < $fields_cnt; $j++) {
  265. if (! isset($row[$j]) || is_null($row[$j])) {
  266. $GLOBALS['odt_buffer'] .=
  267. '<table:table-cell office:value-type="string">'
  268. . '<text:p>'
  269. . htmlspecialchars($GLOBALS[$what . '_null'])
  270. . '</text:p>'
  271. . '</table:table-cell>';
  272. } elseif (stristr($field_flags[$j], 'BINARY')
  273. && $fields_meta[$j]->blob
  274. ) {
  275. // ignore BLOB
  276. $GLOBALS['odt_buffer'] .=
  277. '<table:table-cell office:value-type="string">'
  278. . '<text:p></text:p>'
  279. . '</table:table-cell>';
  280. } elseif ($fields_meta[$j]->numeric
  281. && $fields_meta[$j]->type != 'timestamp'
  282. && ! $fields_meta[$j]->blob
  283. ) {
  284. $GLOBALS['odt_buffer'] .=
  285. '<table:table-cell office:value-type="float"'
  286. . ' office:value="' . $row[$j] . '" >'
  287. . '<text:p>'
  288. . htmlspecialchars($row[$j])
  289. . '</text:p>'
  290. . '</table:table-cell>';
  291. } else {
  292. $GLOBALS['odt_buffer'] .=
  293. '<table:table-cell office:value-type="string">'
  294. . '<text:p>'
  295. . htmlspecialchars($row[$j])
  296. . '</text:p>'
  297. . '</table:table-cell>';
  298. }
  299. } // end for
  300. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  301. } // end while
  302. $GLOBALS['dbi']->freeResult($result);
  303. $GLOBALS['odt_buffer'] .= '</table:table>';
  304. return true;
  305. }
  306. /**
  307. * Returns a stand-in CREATE definition to resolve view dependencies
  308. *
  309. * @param string $db the database name
  310. * @param string $view the view name
  311. * @param string $crlf the end of line sequence
  312. *
  313. * @return bool true
  314. */
  315. public function getTableDefStandIn($db, $view, $crlf)
  316. {
  317. /**
  318. * Gets fields properties
  319. */
  320. $GLOBALS['dbi']->selectDb($db);
  321. /**
  322. * Displays the table structure
  323. */
  324. $GLOBALS['odt_buffer'] .=
  325. '<table:table table:name="'
  326. . htmlspecialchars($view) . '_data">';
  327. $columns_cnt = 4;
  328. $GLOBALS['odt_buffer'] .=
  329. '<table:table-column'
  330. . ' table:number-columns-repeated="' . $columns_cnt . '"/>';
  331. /* Header */
  332. $GLOBALS['odt_buffer'] .= '<table:table-row>'
  333. . '<table:table-cell office:value-type="string">'
  334. . '<text:p>' . __('Column') . '</text:p>'
  335. . '</table:table-cell>'
  336. . '<table:table-cell office:value-type="string">'
  337. . '<text:p>' . __('Type') . '</text:p>'
  338. . '</table:table-cell>'
  339. . '<table:table-cell office:value-type="string">'
  340. . '<text:p>' . __('Null') . '</text:p>'
  341. . '</table:table-cell>'
  342. . '<table:table-cell office:value-type="string">'
  343. . '<text:p>' . __('Default') . '</text:p>'
  344. . '</table:table-cell>'
  345. . '</table:table-row>';
  346. $columns = $GLOBALS['dbi']->getColumns($db, $view);
  347. foreach ($columns as $column) {
  348. $GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column);
  349. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  350. } // end foreach
  351. $GLOBALS['odt_buffer'] .= '</table:table>';
  352. return true;
  353. }
  354. /**
  355. * Returns $table's CREATE definition
  356. *
  357. * @param string $db the database name
  358. * @param string $table the table name
  359. * @param string $crlf the end of line sequence
  360. * @param string $error_url the url to go back in case of error
  361. * @param bool $do_relation whether to include relation comments
  362. * @param bool $do_comments whether to include the pmadb-style column
  363. * comments as comments in the structure;
  364. * this is deprecated but the parameter is
  365. * left here because export.php calls
  366. * PMA_exportStructure() also for other
  367. * @param bool $do_mime whether to include mime comments
  368. * @param bool $show_dates whether to include creation/update/check dates
  369. * @param bool $add_semicolon whether to add semicolon and end-of-line at
  370. * the end
  371. * @param bool $view whether we're handling a view
  372. *
  373. * @return bool true
  374. */
  375. public function getTableDef(
  376. $db,
  377. $table,
  378. $crlf,
  379. $error_url,
  380. $do_relation,
  381. $do_comments,
  382. $do_mime,
  383. $show_dates = false,
  384. $add_semicolon = true,
  385. $view = false
  386. ) {
  387. global $cfgRelation;
  388. /**
  389. * Gets fields properties
  390. */
  391. $GLOBALS['dbi']->selectDb($db);
  392. // Check if we can use Relations
  393. if ($do_relation && ! empty($cfgRelation['relation'])) {
  394. // Find which tables are related with the current one and write it in
  395. // an array
  396. $res_rel = PMA_getForeigners($db, $table);
  397. if ($res_rel && count($res_rel) > 0) {
  398. $have_rel = true;
  399. } else {
  400. $have_rel = false;
  401. }
  402. } else {
  403. $have_rel = false;
  404. } // end if
  405. /**
  406. * Displays the table structure
  407. */
  408. $GLOBALS['odt_buffer'] .= '<table:table table:name="'
  409. . htmlspecialchars($table) . '_structure">';
  410. $columns_cnt = 4;
  411. if ($do_relation && $have_rel) {
  412. $columns_cnt++;
  413. }
  414. if ($do_comments) {
  415. $columns_cnt++;
  416. }
  417. if ($do_mime && $cfgRelation['mimework']) {
  418. $columns_cnt++;
  419. }
  420. $GLOBALS['odt_buffer'] .= '<table:table-column'
  421. . ' table:number-columns-repeated="' . $columns_cnt . '"/>';
  422. /* Header */
  423. $GLOBALS['odt_buffer'] .= '<table:table-row>'
  424. . '<table:table-cell office:value-type="string">'
  425. . '<text:p>' . __('Column') . '</text:p>'
  426. . '</table:table-cell>'
  427. . '<table:table-cell office:value-type="string">'
  428. . '<text:p>' . __('Type') . '</text:p>'
  429. . '</table:table-cell>'
  430. . '<table:table-cell office:value-type="string">'
  431. . '<text:p>' . __('Null') . '</text:p>'
  432. . '</table:table-cell>'
  433. . '<table:table-cell office:value-type="string">'
  434. . '<text:p>' . __('Default') . '</text:p>'
  435. . '</table:table-cell>';
  436. if ($do_relation && $have_rel) {
  437. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  438. . '<text:p>' . __('Links to') . '</text:p>'
  439. . '</table:table-cell>';
  440. }
  441. if ($do_comments) {
  442. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  443. . '<text:p>' . __('Comments') . '</text:p>'
  444. . '</table:table-cell>';
  445. $comments = PMA_getComments($db, $table);
  446. }
  447. if ($do_mime && $cfgRelation['mimework']) {
  448. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  449. . '<text:p>' . __('MIME type') . '</text:p>'
  450. . '</table:table-cell>';
  451. $mime_map = PMA_getMIME($db, $table, true);
  452. }
  453. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  454. $columns = $GLOBALS['dbi']->getColumns($db, $table);
  455. foreach ($columns as $column) {
  456. $field_name = $column['Field'];
  457. $GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column);
  458. if ($do_relation && $have_rel) {
  459. if (isset($res_rel[$field_name])) {
  460. $GLOBALS['odt_buffer'] .=
  461. '<table:table-cell office:value-type="string">'
  462. . '<text:p>'
  463. . htmlspecialchars(
  464. $res_rel[$field_name]['foreign_table']
  465. . ' (' . $res_rel[$field_name]['foreign_field'] . ')'
  466. )
  467. . '</text:p>'
  468. . '</table:table-cell>';
  469. }
  470. }
  471. if ($do_comments) {
  472. if (isset($comments[$field_name])) {
  473. $GLOBALS['odt_buffer'] .=
  474. '<table:table-cell office:value-type="string">'
  475. . '<text:p>'
  476. . htmlspecialchars($comments[$field_name])
  477. . '</text:p>'
  478. . '</table:table-cell>';
  479. } else {
  480. $GLOBALS['odt_buffer'] .=
  481. '<table:table-cell office:value-type="string">'
  482. . '<text:p></text:p>'
  483. . '</table:table-cell>';
  484. }
  485. }
  486. if ($do_mime && $cfgRelation['mimework']) {
  487. if (isset($mime_map[$field_name])) {
  488. $GLOBALS['odt_buffer'] .=
  489. '<table:table-cell office:value-type="string">'
  490. . '<text:p>'
  491. . htmlspecialchars(
  492. str_replace('_', '/', $mime_map[$field_name]['mimetype'])
  493. )
  494. . '</text:p>'
  495. . '</table:table-cell>';
  496. } else {
  497. $GLOBALS['odt_buffer'] .=
  498. '<table:table-cell office:value-type="string">'
  499. . '<text:p></text:p>'
  500. . '</table:table-cell>';
  501. }
  502. }
  503. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  504. } // end foreach
  505. $GLOBALS['odt_buffer'] .= '</table:table>';
  506. return true;
  507. } // end of the '$this->getTableDef()' function
  508. /**
  509. * Outputs triggers
  510. *
  511. * @param string $db database name
  512. * @param string $table table name
  513. *
  514. * @return bool true
  515. */
  516. protected function getTriggers($db, $table)
  517. {
  518. $GLOBALS['odt_buffer'] .= '<table:table'
  519. . ' table:name="' . htmlspecialchars($table) . '_triggers">'
  520. . '<table:table-column'
  521. . ' table:number-columns-repeated="4"/>'
  522. . '<table:table-row>'
  523. . '<table:table-cell office:value-type="string">'
  524. . '<text:p>' . __('Name') . '</text:p>'
  525. . '</table:table-cell>'
  526. . '<table:table-cell office:value-type="string">'
  527. . '<text:p>' . __('Time') . '</text:p>'
  528. . '</table:table-cell>'
  529. . '<table:table-cell office:value-type="string">'
  530. . '<text:p>' . __('Event') . '</text:p>'
  531. . '</table:table-cell>'
  532. . '<table:table-cell office:value-type="string">'
  533. . '<text:p>' . __('Definition') . '</text:p>'
  534. . '</table:table-cell>'
  535. . '</table:table-row>';
  536. $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
  537. foreach ($triggers as $trigger) {
  538. $GLOBALS['odt_buffer'] .= '<table:table-row>';
  539. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  540. . '<text:p>'
  541. . htmlspecialchars($trigger['name'])
  542. . '</text:p>'
  543. . '</table:table-cell>';
  544. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  545. . '<text:p>'
  546. . htmlspecialchars($trigger['action_timing'])
  547. . '</text:p>'
  548. . '</table:table-cell>';
  549. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  550. . '<text:p>'
  551. . htmlspecialchars($trigger['event_manipulation'])
  552. . '</text:p>'
  553. . '</table:table-cell>';
  554. $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
  555. . '<text:p>'
  556. . htmlspecialchars($trigger['definition'])
  557. . '</text:p>'
  558. . '</table:table-cell>';
  559. $GLOBALS['odt_buffer'] .= '</table:table-row>';
  560. }
  561. $GLOBALS['odt_buffer'] .= '</table:table>';
  562. return true;
  563. }
  564. /**
  565. * Outputs table's structure
  566. *
  567. * @param string $db database name
  568. * @param string $table table name
  569. * @param string $crlf the end of line sequence
  570. * @param string $error_url the url to go back in case of error
  571. * @param string $export_mode 'create_table', 'triggers', 'create_view',
  572. * 'stand_in'
  573. * @param string $export_type 'server', 'database', 'table'
  574. * @param bool $do_relation whether to include relation comments
  575. * @param bool $do_comments whether to include the pmadb-style column
  576. * comments as comments in the structure;
  577. * this is deprecated but the parameter is
  578. * left here because export.php calls
  579. * PMA_exportStructure() also for other
  580. * @param bool $do_mime whether to include mime comments
  581. * @param bool $dates whether to include creation/update/check dates
  582. *
  583. * @return bool Whether it succeeded
  584. */
  585. public function exportStructure(
  586. $db,
  587. $table,
  588. $crlf,
  589. $error_url,
  590. $export_mode,
  591. $export_type,
  592. $do_relation = false,
  593. $do_comments = false,
  594. $do_mime = false,
  595. $dates = false
  596. ) {
  597. switch($export_mode) {
  598. case 'create_table':
  599. $GLOBALS['odt_buffer'] .=
  600. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  601. . ' text:is-list-header="true">'
  602. . __('Table structure for table') . ' ' .
  603. htmlspecialchars($table)
  604. . '</text:h>';
  605. $this->getTableDef(
  606. $db, $table, $crlf, $error_url, $do_relation, $do_comments,
  607. $do_mime, $dates
  608. );
  609. break;
  610. case 'triggers':
  611. $triggers = $GLOBALS['dbi']->getTriggers($db, $table);
  612. if ($triggers) {
  613. $GLOBALS['odt_buffer'] .=
  614. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  615. . ' text:is-list-header="true">'
  616. . __('Triggers') . ' '
  617. . htmlspecialchars($table)
  618. . '</text:h>';
  619. $this->getTriggers($db, $table);
  620. }
  621. break;
  622. case 'create_view':
  623. $GLOBALS['odt_buffer'] .=
  624. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  625. . ' text:is-list-header="true">'
  626. . __('Structure for view') . ' '
  627. . htmlspecialchars($table)
  628. . '</text:h>';
  629. $this->getTableDef(
  630. $db, $table, $crlf, $error_url, $do_relation, $do_comments,
  631. $do_mime, $dates, true, true
  632. );
  633. break;
  634. case 'stand_in':
  635. $GLOBALS['odt_buffer'] .=
  636. '<text:h text:outline-level="2" text:style-name="Heading_2"'
  637. . ' text:is-list-header="true">'
  638. . __('Stand-in structure for view') . ' '
  639. . htmlspecialchars($table)
  640. . '</text:h>';
  641. // export a stand-in definition to resolve view dependencies
  642. $this->getTableDefStandIn($db, $table, $crlf);
  643. } // end switch
  644. return true;
  645. } // end of the '$this->exportStructure' function
  646. /**
  647. * Formats the definition for one column
  648. *
  649. * @param array $column info about this column
  650. *
  651. * @return string Formatted column definition
  652. */
  653. protected function formatOneColumnDefinition($column)
  654. {
  655. $field_name = $column['Field'];
  656. $definition = '<table:table-row>';
  657. $definition .= '<table:table-cell office:value-type="string">'
  658. . '<text:p>' . htmlspecialchars($field_name) . '</text:p>'
  659. . '</table:table-cell>';
  660. $extracted_columnspec
  661. = PMA_Util::extractColumnSpec($column['Type']);
  662. $type = htmlspecialchars($extracted_columnspec['print_type']);
  663. if (empty($type)) {
  664. $type = '&nbsp;';
  665. }
  666. $definition .= '<table:table-cell office:value-type="string">'
  667. . '<text:p>' . htmlspecialchars($type) . '</text:p>'
  668. . '</table:table-cell>';
  669. if (! isset($column['Default'])) {
  670. if ($column['Null'] != 'NO') {
  671. $column['Default'] = 'NULL';
  672. } else {
  673. $column['Default'] = '';
  674. }
  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. ?>