ExportOdt.php 29 KB

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