/** * Creates a list of items containing the relevant * information and some action links. * * @param string $type One of ['routine'|'trigger'|'event'] * @param array $items An array of items * * @return string HTML code of the list of items */ function PMA_RTE_getList($type, $items) { global $table; /** * Conditional classes switch the list on or off */ $class1 = 'hide'; $class2 = ''; if (!$items) { $class1 = ''; $class2 = ' hide'; } /** * Generate output */ $retval = "<!-- LIST OF " . PMA_RTE_getWord('docu') . " START -->\n"; $retval .= "<fieldset>\n"; $retval .= " <legend>\n"; $retval .= " " . PMA_RTE_getWord('title') . "\n"; $retval .= " " . PMA_showMySQLDocu('SQL-Syntax', PMA_RTE_getWord('docu')) . "\n"; $retval .= " </legend>\n"; $retval .= " <div class='{$class1}' id='nothing2display'>\n"; $retval .= " " . PMA_RTE_getWord('nothing') . "\n"; $retval .= " </div>\n"; $retval .= " <table class='data{$class2}'>\n"; $retval .= " <!-- TABLE HEADERS -->\n"; $retval .= " <tr>\n"; switch ($type) { case 'routine': $retval .= " <th>" . __('Name') . "</th>\n"; $retval .= " <th colspan='4'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Type') . "</th>\n"; $retval .= " <th>" . __('Returns') . "</th>\n"; break; case 'trigger': $retval .= " <th>" . __('Name') . "</th>\n"; if (empty($table)) { $retval .= " <th>" . __('Table') . "</th>\n"; } $retval .= " <th colspan='3'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Time') . "</th>\n"; $retval .= " <th>" . __('Event') . "</th>\n"; break; case 'event': $retval .= " <th>" . __('Name') . "</th>\n"; $retval .= " <th>" . __('Status') . "</th>\n"; $retval .= " <th colspan='3'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Type') . "</th>\n"; break; default: break; } $retval .= " </tr>\n"; $retval .= " <!-- TABLE DATA -->\n"; $ct = 0; foreach ($items as $item) { $rowclass = $ct % 2 == 0 ? 'odd' : 'even'; if ($GLOBALS['is_ajax_request']) { $rowclass .= ' ajaxInsert hide'; } // Get each row from the correct function switch ($type) { case 'routine': $retval .= PMA_RTN_getRowForList($item, $rowclass); break; case 'trigger': $retval .= PMA_TRI_getRowForList($item, $rowclass); break; case 'event': $retval .= PMA_EVN_getRowForList($item, $rowclass); break; default: break; } $ct++; } $retval .= " </table>\n"; $retval .= "</fieldset>\n"; $retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n"; return $retval; }
/** * Creates a list of items containing the relevant * information and some action links. * * @param string $type One of ['routine'|'trigger'|'event'] * @param array $items An array of items * * @return string HTML code of the list of items */ function PMA_RTE_getList($type, $items) { global $table; /** * Conditional classes switch the list on or off */ $class1 = 'hide'; $class2 = ''; if (!$items) { $class1 = ''; $class2 = ' hide'; } /** * Generate output */ $retval = "<!-- LIST OF " . PMA_RTE_getWord('docu') . " START -->\n"; $retval .= '<form id="rteListForm" class="ajax" action="'; switch ($type) { case 'routine': $retval .= 'db_routines.php'; break; case 'trigger': if (!empty($table)) { $retval .= 'tbl_triggers.php'; } else { $retval .= 'db_triggers.php'; } break; case 'event': $retval .= 'db_events.php'; break; default: break; } $retval .= '">'; $retval .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); $retval .= "<fieldset>\n"; $retval .= " <legend>\n"; $retval .= " " . PMA_RTE_getWord('title') . "\n"; $retval .= " " . PMA_Util::showMySQLDocu(PMA_RTE_getWord('docu')) . "\n"; $retval .= " </legend>\n"; $retval .= " <div class='{$class1}' id='nothing2display'>\n"; $retval .= " " . PMA_RTE_getWord('nothing') . "\n"; $retval .= " </div>\n"; $retval .= " <table class='data{$class2}'>\n"; $retval .= " <!-- TABLE HEADERS -->\n"; $retval .= " <tr>\n"; // th cells with a colspan need corresponding td cells, according to W3C switch ($type) { case 'routine': $retval .= " <th></th>\n"; $retval .= " <th>" . __('Name') . "</th>\n"; $retval .= " <th colspan='4'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Type') . "</th>\n"; $retval .= " <th>" . __('Returns') . "</th>\n"; $retval .= " </tr>\n"; $retval .= " <tr style='display: none'>\n"; // see comment above for ($i = 0; $i < 7; $i++) { $retval .= " <td></td>\n"; } break; case 'trigger': $retval .= " <th></th>\n"; $retval .= " <th>" . __('Name') . "</th>\n"; if (empty($table)) { $retval .= " <th>" . __('Table') . "</th>\n"; } $retval .= " <th colspan='3'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Time') . "</th>\n"; $retval .= " <th>" . __('Event') . "</th>\n"; $retval .= " </tr>\n"; $retval .= " <tr style='display: none'>\n"; // see comment above for ($i = 0; $i < (empty($table) ? 7 : 6); $i++) { $retval .= " <td></td>\n"; } break; case 'event': $retval .= " <th></th>\n"; $retval .= " <th>" . __('Name') . "</th>\n"; $retval .= " <th>" . __('Status') . "</th>\n"; $retval .= " <th colspan='3'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Type') . "</th>\n"; $retval .= " </tr>\n"; $retval .= " <tr style='display: none'>\n"; // see comment above for ($i = 0; $i < 6; $i++) { $retval .= " <td></td>\n"; } break; default: break; } $retval .= " </tr>\n"; $retval .= " <!-- TABLE DATA -->\n"; $count = 0; foreach ($items as $item) { $rowclass = $count % 2 == 0 ? 'odd' : 'even'; if ($GLOBALS['is_ajax_request'] && empty($_REQUEST['ajax_page_request'])) { $rowclass .= ' ajaxInsert hide'; } // Get each row from the correct function switch ($type) { case 'routine': $retval .= PMA_RTN_getRowForList($item, $rowclass); break; case 'trigger': $retval .= PMA_TRI_getRowForList($item, $rowclass); break; case 'event': $retval .= PMA_EVN_getRowForList($item, $rowclass); break; default: break; } $count++; } $retval .= " </table>\n"; if (count($items)) { $retval .= '<div class="withSelected">'; $retval .= PMA_Util::getWithSelected($GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], 'rteListForm'); $retval .= PMA_Util::getButtonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', __('Export'), 'b_export.png', 'export'); $retval .= PMA_Util::getButtonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop'); $retval .= '</div>'; } $retval .= "</fieldset>\n"; $retval .= "</form>\n"; $retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n"; return $retval; }
/** * Handles editor requests for adding or editing an item */ function PMA_EVN_handleEditor() { global $_REQUEST, $_POST, $errors, $db; 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) . '<br />' . __('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) . '<br />' . __('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.') . '<br />' . __('The backed up query was:') . "\"{$create_item}\"" . '<br />' . __('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) . '<br /><br />' . __('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(__('<b>One or more errors have occured while processing your request:</b>')); $message->addString('<ul>'); foreach ($errors as $string) { $message->addString('<li>' . $string . '</li>'); } $message->addString('</ul>'); } $output = PMA_showMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $extra_data = array(); if ($message->isSuccess()) { $columns = "`EVENT_NAME`, `EVENT_TYPE`, `STATUS`"; $where = "EVENT_SCHEMA='" . PMA_sqlAddSlashes($db) . "' " . "AND EVENT_NAME='" . PMA_sqlAddSlashes($_REQUEST['item_name']) . "'"; $query = "SELECT {$columns} FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE {$where};"; $event = PMA_DBI_fetch_single_row($query); $extra_data['name'] = htmlspecialchars(strtoupper($_REQUEST['item_name'])); $extra_data['new_row'] = PMA_EVN_getRowForList($event); $extra_data['insert'] = !empty($event); $response = $output; } else { $response = $message; } PMA_ajaxResponse($response, $message->isSuccess(), $extra_data); } } /** * Display a form used to add/edit a trigger, if necessary */ if (count($errors) || empty($_REQUEST['editor_process_add']) && empty($_REQUEST['editor_process_edit']) && (!empty($_REQUEST['add_item']) || !empty($_REQUEST['edit_item']) || !empty($_REQUEST['item_changetype']))) { // FIXME: this must be simpler than that $operation = ''; if (!empty($_REQUEST['item_changetype'])) { $operation = 'change'; } // Get the data for the form (if any) if (!empty($_REQUEST['add_item'])) { $title = PMA_RTE_getWord('add'); $item = PMA_EVN_getDataFromRequest(); $mode = 'add'; } else { if (!empty($_REQUEST['edit_item'])) { $title = __("Edit event"); if (!empty($_REQUEST['item_name']) && empty($_REQUEST['editor_process_edit']) && empty($_REQUEST['item_changetype'])) { $item = PMA_EVN_getDataFromName($_REQUEST['item_name']); if ($item !== false) { $item['item_original_name'] = $item['item_name']; } } else { $item = PMA_EVN_getDataFromRequest(); } $mode = 'edit'; } } if ($item !== false) { // Show form $editor = PMA_EVN_getEditorForm($mode, $operation, $item); if ($GLOBALS['is_ajax_request']) { $extra_data = array('title' => $title); PMA_ajaxResponse($editor, true, $extra_data); } else { echo "\n\n<h2>{$title}</h2>\n\n{$editor}"; unset($_POST); include './libraries/footer.inc.php'; } // exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_backquote($db))); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { PMA_ajaxResponse($message, false); } else { $message->display(); } } } }
/** * Creates a list of items containing the relevant * information and some action links. * * @param string $type One of ['routine'|'trigger'|'event'] * @param array $items An array of items * * @return string HTML code of the list of items */ function PMA_RTE_getList($type, $items) { global $table; /** * Conditional classes switch the list on or off */ $class1 = 'hide'; $class2 = ''; if (!$items) { $class1 = ''; $class2 = ' hide'; } /** * Generate output */ $retval = "<!-- LIST OF " . PMA_RTE_getWord('docu') . " START -->\n"; $retval .= "<fieldset>\n"; $retval .= " <legend>\n"; $retval .= " " . PMA_RTE_getWord('title') . "\n"; $retval .= " " . PMA_Util::showMySQLDocu(PMA_RTE_getWord('docu')) . "\n"; $retval .= " </legend>\n"; $retval .= " <div class='{$class1}' id='nothing2display'>\n"; $retval .= " " . PMA_RTE_getWord('nothing') . "\n"; $retval .= " </div>\n"; $retval .= " <table class='data{$class2}'>\n"; $retval .= " <!-- TABLE HEADERS -->\n"; $retval .= " <tr>\n"; // th cells with a colspan need corresponding td cells, according to W3C switch ($type) { case 'routine': $retval .= " <th>" . __('Name') . "</th>\n"; $retval .= " <th colspan='4'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Type') . "</th>\n"; $retval .= " <th>" . __('Returns') . "</th>\n"; $retval .= " </tr>\n"; $retval .= " <tr style='display: none'>\n"; // see comment above for ($i = 0; $i < 7; $i++) { $retval .= " <td></td>\n"; } break; case 'trigger': $retval .= " <th>" . __('Name') . "</th>\n"; if (empty($table)) { $retval .= " <th>" . __('Table') . "</th>\n"; } $retval .= " <th colspan='3'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Time') . "</th>\n"; $retval .= " <th>" . __('Event') . "</th>\n"; $retval .= " </tr>\n"; $retval .= " <tr style='display: none'>\n"; // see comment above for ($i = 0; $i < (empty($table) ? 7 : 6); $i++) { $retval .= " <td></td>\n"; } break; case 'event': $retval .= " <th>" . __('Name') . "</th>\n"; $retval .= " <th>" . __('Status') . "</th>\n"; $retval .= " <th colspan='3'>" . __('Action') . "</th>\n"; $retval .= " <th>" . __('Type') . "</th>\n"; $retval .= " </tr>\n"; $retval .= " <tr style='display: none'>\n"; // see comment above for ($i = 0; $i < 6; $i++) { $retval .= " <td></td>\n"; } break; default: break; } $retval .= " </tr>\n"; $retval .= " <!-- TABLE DATA -->\n"; $count = 0; foreach ($items as $item) { $rowclass = $count % 2 == 0 ? 'odd' : 'even'; if ($GLOBALS['is_ajax_request'] && empty($_REQUEST['ajax_page_request'])) { $rowclass .= ' ajaxInsert hide'; } // Get each row from the correct function switch ($type) { case 'routine': $retval .= PMA_RTN_getRowForList($item, $rowclass); break; case 'trigger': $retval .= PMA_TRI_getRowForList($item, $rowclass); break; case 'event': $retval .= PMA_EVN_getRowForList($item, $rowclass); break; default: break; } $count++; } $retval .= " </table>\n"; $retval .= "</fieldset>\n"; $retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n"; return $retval; }
/** * Handles editor requests for adding or editing an item * * @return void */ function PMA_EVN_handleEditor() { global $_REQUEST, $_POST, $errors, $db; 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 = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $_REQUEST['item_original_name']); $drop_item = "DROP EVENT " . PMA\libraries\Util::backquote($_REQUEST['item_original_name']) . ";\n"; $result = $GLOBALS['dbi']->tryQuery($drop_item); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($drop_item)) . '<br />' . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { $result = $GLOBALS['dbi']->tryQuery($item_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($item_query)) . '<br />' . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); // We dropped the old item, but were unable to create // the new one. Try to restore the backup query $result = $GLOBALS['dbi']->tryQuery($create_item); $errors = checkResult($result, __('Sorry, we failed to restore the dropped event.'), $create_item, $errors); } else { $message = PMA\libraries\Message::success(__('Event %1$s has been modified.')); $message->addParam(PMA\libraries\Util::backquote($_REQUEST['item_name'])); $sql_query = $drop_item . $item_query; } } } else { // 'Add a new item' mode $result = $GLOBALS['dbi']->tryQuery($item_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($item_query)) . '<br /><br />' . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { $message = PMA\libraries\Message::success(__('Event %1$s has been created.')); $message->addParam(PMA\libraries\Util::backquote($_REQUEST['item_name'])); $sql_query = $item_query; } } } if (count($errors)) { $message = PMA\libraries\Message::error('<b>' . __('One or more errors have occurred while processing your request:') . '</b>'); $message->addString('<ul>'); foreach ($errors as $string) { $message->addString('<li>' . $string . '</li>'); } $message->addString('</ul>'); } $output = PMA\libraries\Util::getMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $response = PMA\libraries\Response::getInstance(); if ($message->isSuccess()) { $events = $GLOBALS['dbi']->getEvents($db, $_REQUEST['item_name']); $event = $events[0]; $response->addJSON('name', htmlspecialchars(mb_strtoupper($_REQUEST['item_name']))); $response->addJSON('new_row', PMA_EVN_getRowForList($event)); $response->addJSON('insert', !empty($event)); $response->addJSON('message', $output); } else { $response->setRequestStatus(false); $response->addJSON('message', $message); } exit; } } /** * Display a form used to add/edit a trigger, if necessary */ if (count($errors) || empty($_REQUEST['editor_process_add']) && empty($_REQUEST['editor_process_edit']) && (!empty($_REQUEST['add_item']) || !empty($_REQUEST['edit_item']) || !empty($_REQUEST['item_changetype']))) { // FIXME: this must be simpler than that $operation = ''; if (!empty($_REQUEST['item_changetype'])) { $operation = 'change'; } // Get the data for the form (if any) if (!empty($_REQUEST['add_item'])) { $title = PMA_RTE_getWord('add'); $item = PMA_EVN_getDataFromRequest(); $mode = 'add'; } else { if (!empty($_REQUEST['edit_item'])) { $title = __("Edit event"); if (!empty($_REQUEST['item_name']) && empty($_REQUEST['editor_process_edit']) && empty($_REQUEST['item_changetype'])) { $item = PMA_EVN_getDataFromName($_REQUEST['item_name']); if ($item !== false) { $item['item_original_name'] = $item['item_name']; } } else { $item = PMA_EVN_getDataFromRequest(); } $mode = 'edit'; } } PMA_RTE_sendEditor('EVN', $mode, $item, $title, $db, $operation); } }