array('ENABLE',
'DISABLE',
'DISABLE ON SLAVE'),
'display' => array('ENABLED',
'DISABLED',
'SLAVESIDE_DISABLED')
);
$event_type = array('RECURRING',
'ONE TIME');
$event_interval = array('YEAR',
'QUARTER',
'MONTH',
'DAY',
'HOUR',
'MINUTE',
'WEEK',
'SECOND',
'YEAR_MONTH',
'DAY_HOUR',
'DAY_MINUTE',
'DAY_SECOND',
'HOUR_MINUTE',
'HOUR_SECOND',
'MINUTE_SECOND');
}
/**
* This function is defined in: rte_routines.lib.php, rte_triggers.lib.php and
* rte_events.lib.php. It is used to retreive some language strings that are
* used in functionalities that are common to routines, triggers and events.
*
* @param string $index The index of the string to get
*
* @return string The requested string or an empty string, if not available
*/
function PMA_RTE_getWord($index)
{
$words = array(
'add' => __('Add event'),
'docu' => 'EVENTS',
'export' => __('Export of event %s'),
'human' => __('event'),
'no_create' => __('You do not have the necessary privileges to create a new event'),
'not_found' => __('No event with name %1$s found in database %2$s'),
'nothing' => __('There are no events to display.'),
'title' => __('Events'),
);
return isset($words[$index]) ? $words[$index] : '';
} // end PMA_RTE_getWord()
/**
* Main function for the events functionality
*/
function PMA_RTE_main()
{
global $db;
PMA_EVN_setGlobals();
/**
* Process all requests
*/
PMA_EVN_handleEditor();
PMA_EVN_handleExport();
/**
* Display a list of available events
*/
$columns = "`EVENT_NAME`, `EVENT_TYPE`, `STATUS`";
$where = "EVENT_SCHEMA='" . PMA_sqlAddSlashes($db) . "'";
$query = "SELECT $columns FROM `INFORMATION_SCHEMA`.`EVENTS` "
. "WHERE $where ORDER BY `EVENT_NAME` ASC;";
$items = PMA_DBI_fetch_result($query);
echo PMA_RTE_getList('event', $items);
/**
* Display a link for adding a new event, if
* the user has the privileges and a link to
* toggle the state of the event scheduler.
*/
echo PMA_EVN_getFooterLinks();
} // end PMA_RTE_main()
/**
* Handles editor requests for adding or editing an item
*/
function PMA_EVN_handleEditor()
{
global $_REQUEST, $_POST, $errors, $db, $table;
if (! empty($_REQUEST['editor_process_add'])
|| ! empty($_REQUEST['editor_process_edit'])
) {
$sql_query = '';
$item_query = PMA_EVN_getQueryFromRequest();
if (! count($errors)) { // set by PMA_RTN_getQueryFromRequest()
// Execute the created query
if (! empty($_REQUEST['editor_process_edit'])) {
// Backup the old trigger, in case something goes wrong
$create_item = PMA_DBI_get_definition(
$db,
'EVENT',
$_REQUEST['item_original_name']
);
$drop_item = "DROP EVENT " . PMA_backquote($_REQUEST['item_original_name']) . ";\n";
$result = PMA_DBI_try_query($drop_item);
if (! $result) {
$errors[] = sprintf(__('The following query has failed: "%s"'), $drop_item) . '
'
. __('MySQL said: ') . PMA_DBI_getError(null);
} else {
$result = PMA_DBI_try_query($item_query);
if (! $result) {
$errors[] = sprintf(__('The following query has failed: "%s"'), $item_query) . '
'
. __('MySQL said: ') . PMA_DBI_getError(null);
// We dropped the old item, but were unable to create the new one
// Try to restore the backup query
$result = PMA_DBI_try_query($create_item);
if (! $result) {
// OMG, this is really bad! We dropped the query, failed to create a new one
// and now even the backup query does not execute!
// This should not happen, but we better handle this just in case.
$errors[] = __('Sorry, we failed to restore the dropped event.') . '
'
. __('The backed up query was:') . "\"$create_item\"" . '
'
. __('MySQL said: ') . PMA_DBI_getError(null);
}
} else {
$message = PMA_Message::success(__('Event %1$s has been modified.'));
$message->addParam(PMA_backquote($_REQUEST['item_name']));
$sql_query = $drop_item . $item_query;
}
}
} else {
// 'Add a new item' mode
$result = PMA_DBI_try_query($item_query);
if (! $result) {
$errors[] = sprintf(__('The following query has failed: "%s"'), $item_query) . '
'
. __('MySQL said: ') . PMA_DBI_getError(null);
} else {
$message = PMA_Message::success(__('Event %1$s has been created.'));
$message->addParam(PMA_backquote($_REQUEST['item_name']));
$sql_query = $item_query;
}
}
}
if (count($errors)) {
$message = PMA_Message::error(__('One or more errors have occured while processing your request:'));
$message->addString('