Merge remote-tracking branch 'origin/master'
[phpmyadmin/madhuracj.git] / libraries / rte / rte_export.lib.php
blob8cac214ce68ddce62222052daf6e030f40bad765
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Common functions for the export functionality for Routines, Triggers and Events.
6 * @package phpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * This function is called from one of the other functions in this file
14 * and it completes the handling of the export functionality.
16 * @param string $item_name The name of the item that we are exporting
17 * @param string $export_data The SQL query to create the requested item
19 function PMA_RTE_handleExport($item_name, $export_data)
21 global $db, $table;
23 $item_name = htmlspecialchars(PMA_backquote($_GET['item_name']));
24 if ($export_data !== false) {
25 $export_data = '<textarea cols="40" rows="15" style="width: 100%;">'
26 . htmlspecialchars(trim($export_data)) . '</textarea>';
27 $title = sprintf(PMA_RTE_getWord('export'), $item_name);
28 if ($GLOBALS['is_ajax_request'] == true) {
29 $extra_data = array('title' => $title);
30 PMA_ajaxResponse($export_data, true, $extra_data);
31 } else {
32 echo "<fieldset>\n"
33 . "<legend>$title</legend>\n"
34 . $export_data
35 . "</fieldset>\n";
37 } else {
38 $_db = htmlspecialchars(PMA_backquote($db));
39 $response = __('Error in Processing Request') . ' : '
40 . sprintf(PMA_RTE_getWord('not_found'), $item_name, $_db);
41 $response = PMA_message::error($response);
42 if ($GLOBALS['is_ajax_request'] == true) {
43 PMA_ajaxResponse($response, false);
44 } else {
45 $response->display();
48 } // end PMA_RTE_handleExport()
50 /**
51 * If necessary, prepares event information and passes
52 * it to PMA_RTE_handleExport() for the actual export.
54 function PMA_EVN_handleExport()
56 global $_GET, $db;
58 if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) {
59 $item_name = $_GET['item_name'];
60 $export_data = PMA_DBI_get_definition($db, 'EVENT', $item_name);
61 PMA_RTE_handleExport($item_name, $export_data);
63 } // end PMA_EVN_handleExport()
65 /**
66 * If necessary, prepares routine information and passes
67 * it to PMA_RTE_handleExport() for the actual export.
69 function PMA_RTN_handleExport()
71 global $_GET, $db;
73 if ( ! empty($_GET['export_item'])
74 && ! empty($_GET['item_name'])
75 && ! empty($_GET['item_type'])
76 ) {
77 if ($_GET['item_type'] == 'FUNCTION' || $_GET['item_type'] == 'PROCEDURE') {
78 $export_data = PMA_DBI_get_definition(
79 $db,
80 $_GET['item_type'],
81 $_GET['item_name']);
82 PMA_RTE_handleExport($_GET['item_name'], $export_data);
85 } // end PMA_RTN_handleExport()
87 /**
88 * If necessary, prepares trigger information and passes
89 * it to PMA_RTE_handleExport() for the actual export.
91 function PMA_TRI_handleExport()
93 global $_GET, $db, $table;
95 if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) {
96 $item_name = $_GET['item_name'];
97 $triggers = PMA_DBI_get_triggers($db, $table, '');
98 $export_data = false;
99 foreach ($triggers as $trigger) {
100 if ($trigger['name'] === $item_name) {
101 $export_data = $trigger['create'];
102 break;
105 PMA_RTE_handleExport($item_name, $export_data);
107 } // end PMA_TRI_handleExport()