Fixed bugs in show error message ine multi row change in table structure
[phpmyadmin/madhuracj.git] / libraries / db_events.inc.php
blob4aa68a82546de93abb397dba7327da0c4080f949
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 $events = PMA_DBI_fetch_result('SELECT EVENT_NAME, EVENT_TYPE FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \'' . PMA_sqlAddslashes($db,true) . '\';');
13 $conditional_class_add = '';
14 $conditional_class_drop = '';
15 $conditional_class_export = '';
16 if ($GLOBALS['cfg']['AjaxEnable']) {
17 $conditional_class_add = 'class="add_event_anchor"';
18 $conditional_class_drop = 'class="drop_event_anchor"';
19 $conditional_class_export = 'class="export_event_anchor"';
22 /**
23 * Display the export for a event. This is for when JS is disabled.
25 if (! empty($_GET['exportevent']) && ! empty($_GET['eventname'])) {
26 $event_name = htmlspecialchars(PMA_backquote($_GET['eventname']));
27 if ($create_event = PMA_DBI_get_definition($db, 'EVENT', $_GET['eventname'])) {
28 $create_event = '<textarea cols="40" rows="15" style="width: 100%;">' . $create_event . '</textarea>';
29 if (! empty($_REQUEST['ajax_request'])) {
30 $extra_data = array('title' => sprintf(__('Export of event %s'), $event_name));
31 PMA_ajaxResponse($create_event, true, $extra_data);
32 } else {
33 echo '<fieldset>' . "\n"
34 . ' <legend>' . sprintf(__('Export of event "%s"'), $event_name) . '</legend>' . "\n"
35 . $create_event
36 . '</fieldset>';
38 } else {
39 $response = __('Error in Processing Request') . ' : '
40 . sprintf(__('No event with name %s found in database %s'),
41 $event_name, htmlspecialchars(PMA_backquote($db)));
42 $response = PMA_message::error($response);
43 if (! empty($_REQUEST['ajax_request'])) {
44 PMA_ajaxResponse($response, false);
45 } else {
46 $response->display();
51 /**
52 * Display a list of available events
54 echo "\n\n<span id='js_query_display'></span>\n\n";
55 echo '<fieldset>' . "\n";
56 echo ' <legend>' . __('Events') . '</legend>' . "\n";
57 if (! $events) {
58 echo __('There are no events to display.');
59 } else {
60 echo '<div class="hide" id="nothing2display">' . __('There are no events to display.') . '</div>';
61 echo '<table class="data">';
62 echo sprintf('<tr>
63 <th>%s</th>
64 <th colspan="3">%s</th>
65 <th>%s</th>
66 </tr>',
67 __('Name'),
68 __('Action'),
69 __('Type'));
70 $ct=0;
71 $delimiter = '//';
72 foreach ($events as $event) {
74 // information_schema (at least in MySQL 5.1.22) does not return
75 // the full CREATE EVENT statement in a way that could be useful for us
76 // so we rely on PMA_DBI_get_definition() which uses SHOW CREATE EVENT
78 $create_event = PMA_DBI_get_definition($db, 'EVENT', $event['EVENT_NAME']);
79 $definition = 'DROP EVENT IF EXISTS ' . PMA_backquote($event['EVENT_NAME'])
80 . $delimiter . "\n" . $create_event . "\n";
82 $sqlDrop = 'DROP EVENT ' . PMA_backquote($event['EVENT_NAME']);
83 echo sprintf('<tr class="%s">
84 <td><span class="drop_sql" style="display:none;">%s</span><strong>%s</strong></td>
85 <td>%s</td>
86 <td><div class="create_sql" style="display: none;">%s</div>%s</td>
87 <td>%s</td>
88 <td>%s</td>
89 </tr>',
90 ($ct%2 == 0) ? 'even' : 'odd',
91 $sqlDrop,
92 $event['EVENT_NAME'],
93 ! empty($definition) ? PMA_linkOrButton('db_sql.php?' . $url_query . '&amp;sql_query=' . urlencode($definition) . '&amp;show_query=1&amp;db_query_force=1&amp;delimiter=' . urlencode($delimiter), $titles['Edit']) : '&nbsp;',
94 $create_event,
95 '<a ' . $conditional_class_export . ' href="db_events.php?' . $url_query
96 . '&amp;exportevent=1'
97 . '&amp;eventname=' . urlencode($event['EVENT_NAME'])
98 . '">' . $titles['Export'] . '</a>',
99 '<a ' . $conditional_class_drop . ' href="sql.php?' . $url_query . '&amp;sql_query=' . urlencode($sqlDrop) . '" >' . $titles['Drop'] . '</a>',
100 $event['EVENT_TYPE']);
101 $ct++;
103 echo '</table>';
105 echo '</fieldset>' . "\n";
108 * If there has been a request to change the state
109 * of the event scheduler, process it now.
111 if (! empty($_GET['toggle_scheduler'])) {
112 $new_scheduler_state = $_GET['toggle_scheduler'];
113 if ($new_scheduler_state === 'ON' || $new_scheduler_state === 'OFF') {
114 PMA_DBI_query("SET GLOBAL event_scheduler='$new_scheduler_state'");
119 * Prepare to show the event scheduler fieldset, if necessary
121 $tableStart = '';
122 $schedulerFieldset = '';
123 $es_state = PMA_DBI_fetch_value("SHOW GLOBAL VARIABLES LIKE 'event_scheduler'", 0, 1);
124 if ($es_state === 'ON' || $es_state === 'OFF') {
125 $es_change = ($es_state == 'ON') ? 'OFF' : 'ON';
126 $tableStart = '<table style="width: 100%;"><tr><td style="width: 50%;">';
127 $schedulerFieldset = '</td><td><fieldset style="margin: 1em 0;">' . "\n"
128 . PMA_getIcon('b_events.png')
129 . ($es_state === 'ON' ? __('The event scheduler is enabled') : __('The event scheduler is disabled')) . ':'
130 . ' <a href="db_events.php?' . $url_query . '&amp;toggle_scheduler=' . $es_change . '">'
131 . ($es_change === 'ON' ? __('Turn it on') : __('Turn it off'))
132 . '</a>' . "\n"
133 . '</fieldset></td></tr></table>' . "\n";
137 * Display the form for adding a new event
139 echo $tableStart . '<fieldset style="margin: 1em 0;">' . "\n"
140 . ' <a href="db_events.php?' . $url_query . '&amp;addevent=1" ' . $conditional_class_add . '>' . "\n"
141 . PMA_getIcon('b_event_add.png') . __('Add an event') . '</a>' . "\n"
142 . '</fieldset>' . "\n";
145 * Display the state of the event scheduler
146 * and offer an option to toggle it.
148 echo $schedulerFieldset;