/** * Function to handle the creation or edit of an index * * @param string $db current db * @param string $table current table * @param PMA_Index $index current index * * @return void */ function PMA_handleCreateOrEditIndex($db, $table, $index) { $error = false; $sql_query = PMA_getSqlQueryForIndexCreateOrEdit($db, $table, $index, $error); // If there is a request for SQL previewing. if (isset($_REQUEST['preview_sql'])) { PMA_previewSQL($sql_query); } if (!$error) { $GLOBALS['dbi']->query($sql_query); $message = PMA_Message::success(__('Table %1$s has been altered successfully.')); $message->addParam($table); if ($GLOBALS['is_ajax_request'] == true) { $response = PMA_Response::getInstance(); $response->addJSON('message', $message); $response->addJSON('index_table', PMA_Index::getView($table, $db)); $response->addJSON('sql_query', PMA_Util::getMessage(null, $sql_query)); } else { include 'tbl_structure.php'; } exit; } else { $response = PMA_Response::getInstance(); $response->isSuccess(false); $response->addJSON('message', $error); exit; } }
/** * test success method */ public function testSuccess() { $this->object = new PMA_Message('test<&>', PMA_Message::SUCCESS); $this->assertEquals($this->object, PMA_Message::success('test<&>')); $this->assertEquals( 'Your SQL query has been executed successfully', PMA_Message::success()->getString() ); }
/** * returns HTML for error message * * @return String HTML code */ function PMA_getHtmlForErrorMessage() { $html = ''; if (isset($_SESSION['replication']['sr_action_status']) && isset($_SESSION['replication']['sr_action_info'])) { if ($_SESSION['replication']['sr_action_status'] == 'error') { $error_message = $_SESSION['replication']['sr_action_info']; $html .= PMA_Message::error($error_message)->getDisplay(); $_SESSION['replication']['sr_action_status'] = 'unknown'; } elseif ($_SESSION['replication']['sr_action_status'] == 'success') { $success_message = $_SESSION['replication']['sr_action_info']; $html .= PMA_Message::success($success_message)->getDisplay(); $_SESSION['replication']['sr_action_status'] = 'unknown'; } } return $html; }
/** * Prepares queries for adding users and * also create database and return query and message * * @param boolean $_error whether user create or not * @param string $real_sql_query SQL query for add a user * @param string $sql_query SQL query to be displayed * @param string $username username * @param string $hostname host name * @param string $dbname database name * * @return array $sql_query, $message */ function PMA_addUserAndCreateDatabase($_error, $real_sql_query, $sql_query, $username, $hostname, $dbname) { if ($_error || !empty($real_sql_query) && !$GLOBALS['dbi']->tryQuery($real_sql_query)) { $_REQUEST['createdb-1'] = $_REQUEST['createdb-2'] = $_REQUEST['createdb-3'] = null; $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } else { $message = PMA_Message::success(__('You have added a new user.')); } if (isset($_REQUEST['createdb-1'])) { // Create database with same name and grant all privileges $q = 'CREATE DATABASE IF NOT EXISTS ' . PMA_Util::backquote(PMA_Util::sqlAddSlashes($username)) . ';'; $sql_query .= $q; if (!$GLOBALS['dbi']->tryQuery($q)) { $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } /** * Reload the navigation */ $GLOBALS['reload'] = true; $GLOBALS['db'] = $username; $q = 'GRANT ALL PRIVILEGES ON ' . PMA_Util::backquote(PMA_Util::escapeMysqlWildcards(PMA_Util::sqlAddSlashes($username))) . '.* TO \'' . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\';'; $sql_query .= $q; if (!$GLOBALS['dbi']->tryQuery($q)) { $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } } if (isset($_REQUEST['createdb-2'])) { // Grant all privileges on wildcard name (username\_%) $q = 'GRANT ALL PRIVILEGES ON ' . PMA_Util::backquote(PMA_Util::sqlAddSlashes($username) . '\\_%') . '.* TO \'' . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\';'; $sql_query .= $q; if (!$GLOBALS['dbi']->tryQuery($q)) { $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } } if (isset($_REQUEST['createdb-3'])) { // Grant all privileges on the specified database to the new user $q = 'GRANT ALL PRIVILEGES ON ' . PMA_Util::backquote(PMA_Util::sqlAddSlashes($dbname)) . '.* TO \'' . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\';'; $sql_query .= $q; if (!$GLOBALS['dbi']->tryQuery($q)) { $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } } return array($sql_query, $message); }
} $odd_row = ! $odd_row; } } else { $user_form .= ' <tr class="odd">' . "\n" . ' <td colspan="6">' . "\n" . ' ' . __('No user found.') . "\n" . ' </td>' . "\n" . ' </tr>' . "\n"; } $user_form .= '</tbody>' . "\n" . '</table></fieldset></form>' . "\n"; if ($GLOBALS['is_ajax_request'] == true) { $extra_data['user_form'] = $user_form; $message = PMA_Message::success(__('User has been added.')); PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); } else { // Offer to create a new user for the current database $user_form .= '<fieldset id="fieldset_add_user">' . "\n" . '<legend>' . __('New') . '</legend>' . "\n" . ' <a href="server_privileges.php?' . $GLOBALS['url_query'] . '&adduser=1&dbname=' . htmlspecialchars($checkprivs) .'" rel="'.'checkprivs='.htmlspecialchars($checkprivs). '&'.$GLOBALS['url_query'] . '" class="'.$conditional_class.'" name="db_specific">' . "\n" . PMA_getIcon('b_usradd.png') . ' ' . __('Add user') . '</a>' . "\n" . '</fieldset>' . "\n"; echo $user_form ; } } // end if (empty($_REQUEST['adduser']) && empty($checkprivs)) ... elseif ... else ...
/** * Deletes users * (Changes / copies a user, part IV) */ if (isset($_REQUEST['delete']) || isset($_REQUEST['change_copy']) && $_REQUEST['mode'] < 4) { $queries = PMA_getDataForDeleteUsers($queries); if (empty($_REQUEST['change_copy'])) { list($sql_query, $message) = PMA_deleteUser($queries); } } /** * Changes / copies a user, part V */ if (isset($_REQUEST['change_copy'])) { $queries = PMA_getDataForQueries($queries, $queries_for_display); $message = PMA_Message::success(); $sql_query = join("\n", $queries); } /** * Reloads the privilege tables into memory */ $message_ret = PMA_updateMessageForReload(); if (isset($message_ret)) { $message = $message_ret; unset($message_ret); } /** * If we are in an Ajax request for Create User/Edit User/Revoke User/ * Flush Privileges, show $message and exit. */ if ($GLOBALS['is_ajax_request'] && empty($_REQUEST['ajax_page_request']) && !isset($_REQUEST['export']) && (!isset($_REQUEST['submit_mult']) || $_REQUEST['submit_mult'] != 'export') && (!isset($_REQUEST['initial']) || $_REQUEST['initial'] === null || $_REQUEST['initial'] === '' || isset($_REQUEST['delete']) && $_REQUEST['delete'] === 'Go') && !isset($_REQUEST['showall']) && !isset($_REQUEST['edit_user_group_dialog']) && !isset($_REQUEST['db_specific'])) {
/** * Handles editor requests for adding or editing an item * * @return void */ function PMA_RTN_handleEditor() { global $_GET, $_POST, $_REQUEST, $GLOBALS, $db, $errors; if (!empty($_REQUEST['editor_process_add']) || !empty($_REQUEST['editor_process_edit'])) { /** * Handle a request to create/edit a routine */ $sql_query = ''; $routine_query = PMA_RTN_getQueryFromRequest(); if (!count($errors)) { // set by PMA_RTN_getQueryFromRequest() // Execute the created query if (!empty($_REQUEST['editor_process_edit'])) { $isProcOrFunc = in_array($_REQUEST['item_original_type'], array('PROCEDURE', 'FUNCTION')); if (!$isProcOrFunc) { $errors[] = sprintf(__('Invalid routine type: "%s"'), htmlspecialchars($_REQUEST['item_original_type'])); } else { // Backup the old routine, in case something goes wrong $create_routine = $GLOBALS['dbi']->getDefinition($db, $_REQUEST['item_original_type'], $_REQUEST['item_original_name']); if (!defined('PMA_DRIZZLE') || !PMA_DRIZZLE) { if (isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv']) { // Backup the Old Privileges before dropping // if $_REQUEST['item_adjust_privileges'] set $privilegesBackup = array(); if (isset($_REQUEST['item_adjust_privileges']) && !empty($_REQUEST['item_adjust_privileges'])) { $privilegesBackupQuery = 'SELECT * FROM ' . PMA_Util::backquote('mysql') . '.' . PMA_Util::backquote('procs_priv') . ' where Routine_name = "' . $_REQUEST['item_original_name'] . '" AND Routine_type = "' . $_REQUEST['item_original_type'] . '";'; $privilegesBackup = $GLOBALS['dbi']->fetchResult($privilegesBackupQuery, 0); } } } $drop_routine = "DROP {$_REQUEST['item_original_type']} " . PMA_Util::backquote($_REQUEST['item_original_name']) . ";\n"; $result = $GLOBALS['dbi']->tryQuery($drop_routine); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($drop_routine)) . '<br />' . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { $result = $GLOBALS['dbi']->tryQuery($routine_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($routine_query)) . '<br />' . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); // We dropped the old routine, // but were unable to create the new one // Try to restore the backup query $result = $GLOBALS['dbi']->tryQuery($create_routine); $errors = checkResult($result, __('Sorry, we failed to restore' . ' the dropped routine.'), $create_routine, $errors); } else { // Default value $resultAdjust = false; if (!defined('PMA_DRIZZLE') || !PMA_DRIZZLE) { if (isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv']) { // Insert all the previous privileges // but with the new name and the new type foreach ($privilegesBackup as $priv) { $adjustProcPrivilege = 'INSERT INTO ' . PMA_Util::backquote('mysql') . '.' . PMA_Util::backquote('procs_priv') . ' VALUES("' . $priv[0] . '", "' . $priv[1] . '", "' . $priv[2] . '", "' . $_REQUEST['item_name'] . '", "' . $_REQUEST['item_type'] . '", "' . $priv[5] . '", "' . $priv[6] . '", "' . $priv[7] . '");'; $resultAdjust = $GLOBALS['dbi']->query($adjustProcPrivilege); } } } if ($resultAdjust) { // Flush the Privileges $flushPrivQuery = 'FLUSH PRIVILEGES;'; $GLOBALS['dbi']->query($flushPrivQuery); $message = PMA_Message::success(__('Routine %1$s has been modified. Privileges have been adjusted.')); } else { $message = PMA_Message::success(__('Routine %1$s has been modified.')); } $message->addParam(PMA_Util::backquote($_REQUEST['item_name'])); $sql_query = $drop_routine . $routine_query; } } } } else { // 'Add a new routine' mode $result = $GLOBALS['dbi']->tryQuery($routine_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($routine_query)) . '<br /><br />' . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { $message = PMA_Message::success(__('Routine %1$s has been created.')); $message->addParam(PMA_Util::backquote($_REQUEST['item_name'])); $sql_query = $routine_query; } } } if (count($errors)) { $message = PMA_Message::error(__('One or more errors have occurred while' . ' processing your request:')); $message->addString('<ul>'); foreach ($errors as $string) { $message->addString('<li>' . $string . '</li>'); } $message->addString('</ul>'); } $output = PMA_Util::getMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $response = PMA_Response::getInstance(); if ($message->isSuccess()) { $routines = $GLOBALS['dbi']->getRoutines($db, $_REQUEST['item_type'], $_REQUEST['item_name']); $routine = $routines[0]; $response->addJSON('name', htmlspecialchars(mb_strtoupper($_REQUEST['item_name']))); $response->addJSON('new_row', PMA_RTN_getRowForList($routine)); $response->addJSON('insert', !empty($routine)); $response->addJSON('message', $output); } else { $response->isSuccess(false); $response->addJSON('message', $output); } exit; } } /** * Display a form used to add/edit a routine, if necessary */ // FIXME: this must be simpler than that if (count($errors) || empty($_REQUEST['editor_process_add']) && empty($_REQUEST['editor_process_edit']) && (!empty($_REQUEST['add_item']) || !empty($_REQUEST['edit_item']) || !empty($_REQUEST['routine_addparameter']) || !empty($_REQUEST['routine_removeparameter']) || !empty($_REQUEST['routine_changetype']))) { // Handle requests to add/remove parameters and changing routine type // This is necessary when JS is disabled $operation = ''; if (!empty($_REQUEST['routine_addparameter'])) { $operation = 'add'; } else { if (!empty($_REQUEST['routine_removeparameter'])) { $operation = 'remove'; } else { if (!empty($_REQUEST['routine_changetype'])) { $operation = 'change'; } } } // Get the data for the form (if any) if (!empty($_REQUEST['add_item'])) { $title = PMA_RTE_getWord('add'); $routine = PMA_RTN_getDataFromRequest(); $mode = 'add'; } else { if (!empty($_REQUEST['edit_item'])) { $title = __("Edit routine"); if (!$operation && !empty($_REQUEST['item_name']) && empty($_REQUEST['editor_process_edit'])) { $routine = PMA_RTN_getDataFromName($_REQUEST['item_name'], $_REQUEST['item_type']); if ($routine !== false) { $routine['item_original_name'] = $routine['item_name']; $routine['item_original_type'] = $routine['item_type']; } } else { $routine = PMA_RTN_getDataFromRequest(); } $mode = 'edit'; } } if ($routine !== false) { // Show form $editor = PMA_RTN_getEditorForm($mode, $operation, $routine); if ($GLOBALS['is_ajax_request']) { $response = PMA_Response::getInstance(); $response->addJSON('message', $editor); $response->addJSON('title', $title); $response->addJSON('param_template', PMA_RTN_getParameterRow()); $response->addJSON('type', $routine['item_type']); } else { echo "\n\n<h2>{$title}</h2>\n\n{$editor}"; } exit; } else { $message = __('Error in processing request:') . ' '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_Util::backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_Util::backquote($db))); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { $response->isSuccess(false); $response->addJSON('message', $message); exit; } else { $message->display(); } } } }
/** * Move or copy a table * * @param string $db current database name * @param string $table current table name * * @return void */ function PMA_moveOrCopyTable($db, $table) { /** * Selects the database to work with */ $GLOBALS['dbi']->selectDb($db); /** * $_REQUEST['target_db'] could be empty in case we came from an input field * (when there are many databases, no drop-down) */ if (empty($_REQUEST['target_db'])) { $_REQUEST['target_db'] = $db; } /** * A target table name has been sent to this script -> do the work */ if (PMA_isValid($_REQUEST['new_name'])) { if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) { if (isset($_REQUEST['submit_move'])) { $message = PMA_Message::error(__('Can\'t move table to same one!')); } else { $message = PMA_Message::error(__('Can\'t copy table to same one!')); } } else { PMA_Table::moveCopy($db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'], $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table'); if (isset($_REQUEST['adjust_privileges']) && !empty($_REQUEST['adjust_privileges'])) { if (isset($_REQUEST['submit_move'])) { PMA_AdjustPrivileges_renameOrMoveTable($db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']); } else { PMA_AdjustPrivileges_copyTable($db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']); } if (isset($_REQUEST['submit_move'])) { $message = PMA_Message::success(__('Table %s has been moved to %s. Privileges have been ' . 'adjusted.')); } else { $message = PMA_Message::success(__('Table %s has been copied to %s. Privileges have been ' . 'adjusted.')); } } else { if (isset($_REQUEST['submit_move'])) { $message = PMA_Message::success(__('Table %s has been moved to %s.')); } else { $message = PMA_Message::success(__('Table %s has been copied to %s.')); } } $old = PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table); $message->addParam($old); $new = PMA_Util::backquote($_REQUEST['target_db']) . '.' . PMA_Util::backquote($_REQUEST['new_name']); $message->addParam($new); /* Check: Work on new table or on old table? */ if (isset($_REQUEST['submit_move']) || PMA_isValid($_REQUEST['switch_to_new'])) { } } } else { /** * No new name for the table! */ $message = PMA_Message::error(__('The table name is empty!')); } if ($GLOBALS['is_ajax_request'] == true) { $response = PMA_Response::getInstance(); $response->addJSON('message', $message); if ($message->isSuccess()) { $response->addJSON('db', $GLOBALS['db']); } else { $response->isSuccess(false); } exit; } }
/** * Displays a table of results returned by a SQL query. * This function is called by the "sql.php" script. * * @param integer the link id associated to the query which results have * to be displayed * @param array the display mode * @param array the analyzed query * * @uses $_SESSION['tmp_user_values']['pos'] * @global string $db the database name * @global string $table the table name * @global string $goto the URL to go back in case of errors * @global string $sql_query the current SQL query * @global integer $num_rows the total number of rows returned by the * SQL query * @global integer $unlim_num_rows the total number of rows returned by the * SQL query without any programmatically * appended "LIMIT" clause * @global array $fields_meta the list of fields properties * @global integer $fields_cnt the total number of fields returned by * the SQL query * @global array $vertical_display informations used with vertical display * mode * @global array $highlight_columns column names to highlight * @global array $cfgRelation the relation settings * * @access private * * @see PMA_showMessage(), PMA_setDisplayMode(), * PMA_displayTableNavigation(), PMA_displayTableHeaders(), * PMA_displayTableBody(), PMA_displayResultsOperations() */ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) { global $db, $table, $goto; global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt; global $vertical_display, $highlight_columns; global $cfgRelation; global $showtable; // why was this called here? (already called from sql.php) //PMA_displayTable_checkConfigParams(); /** * @todo move this to a central place * @todo for other future table types */ $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB'; if ($is_innodb && !isset($analyzed_sql[0]['queryflags']['union']) && !isset($analyzed_sql[0]['table_ref'][1]['table_name']) && (empty($analyzed_sql[0]['where_clause']) || $analyzed_sql[0]['where_clause'] == '1 ')) { // "j u s t b r o w s i n g" $pre_count = '~'; $after_count = PMA_showHint(PMA_sanitize($GLOBALS['strApproximateCount']), true); } else { $pre_count = ''; $after_count = ''; } // 1. ----- Prepares the work ----- // 1.1 Gets the informations about which functionalities should be // displayed $total = ''; $is_display = PMA_setDisplayMode($the_disp_mode, $total); // 1.2 Defines offsets for the next and previous pages if ($is_display['nav_bar'] == '1') { if ($_SESSION['tmp_user_values']['max_rows'] == 'all') { $pos_next = 0; $pos_prev = 0; } else { $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows']; $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows']; if ($pos_prev < 0) { $pos_prev = 0; } } } // end if // 1.3 Find the sort expression // we need $sort_expression and $sort_expression_nodirection // even if there are many table references if (!empty($analyzed_sql[0]['order_by_clause'])) { $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause'])); /** * Get rid of ASC|DESC */ preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches); $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression; $sort_direction = isset($matches[2]) ? trim($matches[2]) : ''; unset($matches); } else { $sort_expression = $sort_expression_nodirection = $sort_direction = ''; } // 1.4 Prepares display of first and last value of the sorted column if (!empty($sort_expression_nodirection)) { list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection); $sort_table = PMA_unQuote($sort_table); $sort_column = PMA_unQuote($sort_column); // find the sorted column index in row result // (this might be a multi-table query) $sorted_column_index = false; foreach ($fields_meta as $key => $meta) { if ($meta->table == $sort_table && $meta->name == $sort_column) { $sorted_column_index = $key; break; } } if ($sorted_column_index !== false) { // fetch first row of the result set $row = PMA_DBI_fetch_row($dt_result); $column_for_first_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']); // fetch last row of the result set PMA_DBI_data_seek($dt_result, $num_rows - 1); $row = PMA_DBI_fetch_row($dt_result); $column_for_last_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']); // reset to first row for the loop in PMA_displayTableBody() PMA_DBI_data_seek($dt_result, 0); // we could also use here $sort_expression_nodirection $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]'; unset($row, $column_for_first_row, $column_for_last_row); } unset($sorted_column_index, $sort_table, $sort_column); } // 2. ----- Displays the top of the page ----- // 2.1 Displays a messages with position informations if ($is_display['nav_bar'] == '1' && isset($pos_next)) { if (isset($unlim_num_rows) && $unlim_num_rows != $total) { $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows']; } else { $selectstring = ''; } $last_shown_rec = $_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total ? $total - 1 : $pos_next - 1; if (PMA_Table::isView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCountViews']) { $message = PMA_Message::notice('strViewHasAtLeast'); $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]'); $message->addParam('[/a]'); $message_view_warning = PMA_showHint($message); } else { $message_view_warning = false; } $message = PMA_Message::success('strShowingRecords'); $message->addMessage($_SESSION['tmp_user_values']['pos']); if ($message_view_warning) { $message->addMessage('...', ' - '); $message->addMessage($message_view_warning); $message->addMessage('('); } else { $message->addMessage($last_shown_rec, ' - '); $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' ('); $message->addString('strTotal'); $message->addMessage($selectstring, ''); $message->addMessage(', ', ''); } $messagge_qt = PMA_Message::notice('strQueryTime'); $messagge_qt->addParam($GLOBALS['querytime']); $message->addMessage($messagge_qt, ''); $message->addMessage(')', ''); $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', ''); PMA_showMessage($message, $sql_query, 'success'); } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success'); } // 2.3 Displays the navigation bars if (!strlen($table)) { if (isset($analyzed_sql[0]['query_type']) && $analyzed_sql[0]['query_type'] == 'SELECT') { // table does not always contain a real table name, // for example in MySQL 5.0.x, the query SHOW STATUS // returns STATUS as a table name $table = $fields_meta[0]->table; } else { $table = ''; } } if ($is_display['nav_bar'] == '1') { PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown'); echo "\n"; } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { echo "\n" . '<br /><br />' . "\n"; } // 2b ----- Get field references from Database ----- // (see the 'relation' configuration variable) // loic1, 2002-03-02: extended to php3 // initialize map $map = array(); // find tables $target = array(); if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) { foreach ($analyzed_sql[0]['table_ref'] as $table_ref_position => $table_ref) { $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name']; } } $tabs = '(\'' . join('\',\'', $target) . '\')'; if ($cfgRelation['displaywork']) { if (!strlen($table)) { $exist_rel = false; } else { $exist_rel = PMA_getForeigners($db, $table, '', 'both'); if ($exist_rel) { foreach ($exist_rel as $master_field => $rel) { $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']); $map[$master_field] = array($rel['foreign_table'], $rel['foreign_field'], $display_field, $rel['foreign_db']); } // end while } // end if } // end if } // end if // end 2b // 3. ----- Displays the results table ----- PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction); $url_query = ''; echo '<tbody>' . "\n"; $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql); // vertical output case if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') { PMA_displayVerticalTable(); } // end if unset($vertical_display); echo '</tbody>' . "\n"; ?> </table> <?php // 4. ----- Displays the link for multi-fields edit and delete if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') { $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill']; $_url_params = array('db' => $db, 'table' => $table, 'sql_query' => $sql_query, 'goto' => $goto); $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params); $_url_params['checkall'] = '1'; $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params); if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') { $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;'; $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;'; } else { $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;'; $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;'; } $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false); $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false); if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') { echo '<img class="selectallarrow" width="38" height="22"' . ' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"' . ' alt="' . $GLOBALS['strWithChecked'] . '" />'; } echo $checkall_link . "\n" . ' / ' . "\n" . $uncheckall_link . "\n" . '<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n"; PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png'); PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_delete', $delete_text, 'b_drop.png'); if ($analyzed_sql[0]['querytype'] == 'SELECT') { PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', $GLOBALS['strExport'], 'b_tblexport.png'); } echo "\n"; echo '<input type="hidden" name="sql_query"' . ' value="' . htmlspecialchars($sql_query) . '" />' . "\n"; echo '<input type="hidden" name="url_query"' . ' value="' . $GLOBALS['url_query'] . '" />' . "\n"; echo '<input type="hidden" name="clause_is_unique"' . ' value="' . $clause_is_unique . '" />' . "\n"; echo '</form>' . "\n"; } // 5. ----- Displays the navigation bar at the bottom if required ----- if ($is_display['nav_bar'] == '1') { echo '<br />' . "\n"; PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown'); } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { echo "\n" . '<br /><br />' . "\n"; } // 6. ----- Displays "Query results operations" if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { PMA_displayResultsOperations($the_disp_mode, $analyzed_sql); } }
/** * get PMA_Message for number of inserted rows * * shorthand for getting a customized message * * @param integer $rows Number of rows * * @return PMA_Message * @static */ public static function getMessageForInsertedRows($rows) { $message = PMA_Message::success(_ngettext('%1$d row inserted.', '%1$d rows inserted.', $rows)); $message->addParam($rows); return $message; }
} // Show correct message if (!empty($id_bookmark) && $action_bookmark == 2) { $message = PMA_Message::success('strBookmarkDeleted'); $display_query = $import_text; $error = FALSE; // unset error marker, it was used just to skip processing } elseif (!empty($id_bookmark) && $action_bookmark == 1) { $message = PMA_Message::notice('strShowingBookmark'); } elseif ($bookmark_created) { $special_message = '[br]' . sprintf($strBookmarkCreated, htmlspecialchars($bkm_label)); } elseif ($finished && !$error) { if ($import_type == 'query') { $message = PMA_Message::success(); } else { $message = PMA_Message::success('strImportSuccessfullyFinished'); $message->addParam($executed_queries); } } // Did we hit timeout? Tell it user. if ($timeout_passed) { $message = PMA_Message::error('strTimeoutPassed'); if ($offset == 0 || (isset($original_skip) && $original_skip == $offset)) { $message->addString('strTimeoutNothingParsed'); } } // Parse and analyze the query, for correct db and table name // in case of a query typed in the query window require_once './libraries/parse_analyze.lib.php';
/** * Handles editor requests for adding or editing an item * * @return void */ function PMA_TRI_handleEditor() { global $_REQUEST, $_POST, $errors, $db, $table; if (!empty($_REQUEST['editor_process_add']) || !empty($_REQUEST['editor_process_edit'])) { $sql_query = ''; $item_query = PMA_TRI_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 $trigger = PMA_TRI_getDataFromName($_REQUEST['item_original_name']); $create_item = $trigger['create']; $drop_item = $trigger['drop'] . ';'; $result = PMA_DBI_try_query($drop_item); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($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"'), htmlspecialchars($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 trigger.') . '<br />' . __('The backed up query was:') . "\"" . htmlspecialchars($create_item) . "\"" . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); } } else { $message = PMA_Message::success(__('Trigger %1$s has been modified.')); $message->addParam(PMA_Util::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"'), htmlspecialchars($item_query)) . '<br /><br />' . __('MySQL said: ') . PMA_DBI_getError(null); } else { $message = PMA_Message::success(__('Trigger %1$s has been created.')); $message->addParam(PMA_Util::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_Util::getMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $response = PMA_Response::getInstance(); if ($message->isSuccess()) { $items = PMA_DBI_get_triggers($db, $table, ''); $trigger = false; foreach ($items as $value) { if ($value['name'] == $_REQUEST['item_name']) { $trigger = $value; } } $insert = false; if (empty($table) || $trigger !== false && $table == $trigger['table']) { $insert = true; $response->addJSON('new_row', PMA_TRI_getRowForList($trigger)); $response->addJSON('name', htmlspecialchars(strtoupper($_REQUEST['item_name']))); } $response->addJSON('insert', $insert); $response->addJSON('message', $output); } else { $response->addJSON('message', $message); $response->isSuccess(false); } 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']))) { // Get the data for the form (if any) if (!empty($_REQUEST['add_item'])) { $title = PMA_RTE_getWord('add'); $item = PMA_TRI_getDataFromRequest(); $mode = 'add'; } else { if (!empty($_REQUEST['edit_item'])) { $title = __("Edit trigger"); if (!empty($_REQUEST['item_name']) && empty($_REQUEST['editor_process_edit'])) { $item = PMA_TRI_getDataFromName($_REQUEST['item_name']); if ($item !== false) { $item['item_original_name'] = $item['item_name']; } } else { $item = PMA_TRI_getDataFromRequest(); } $mode = 'edit'; } } if ($item !== false) { // Show form $editor = PMA_TRI_getEditorForm($mode, $item); if ($GLOBALS['is_ajax_request']) { $response = PMA_Response::getInstance(); $response->addJSON('message', $editor); $response->addJSON('title', $title); } else { echo "\n\n<h2>{$title}</h2>\n\n{$editor}"; unset($_POST); } exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_Util::backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_Util::backquote($db))); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { $response = PMA_Response::getInstance(); $response->isSuccess(false); $response->addJSON('message', $message); exit; } else { $message->display(); } } } }
if (! PMA_DBI_select_db($db)) { $common_functions->mysqlDie( PMA_DBI_getError(), 'USE ' . $common_functions->backquote($db) . ';', '', $err_url ); } $sql_query = 'ALTER TABLE ' . $common_functions->backquote($table) . ' '; $sql_query .= implode(', ', $changes) . $key_query; $sql_query .= ';'; $result = PMA_DBI_try_query($sql_query); if ($result !== false) { $message = PMA_Message::success( __('Table %1$s has been altered successfully') ); $message->addParam($table); $btnDrop = 'Fake'; /** * If comments were sent, enable relation stuff */ include_once 'libraries/transformations.lib.php'; // update field names in relation if (isset($_REQUEST['field_orig']) && is_array($_REQUEST['field_orig'])) { foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) { if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) { PMA_REL_renameField( $db, $table, $fieldcontent,
/** * Moves columns in the table's structure based on $_REQUEST * * @param string $db database name * @param string $table table name * * @return void */ function PMA_moveColumns($db, $table) { $GLOBALS['dbi']->selectDb($db); /* * load the definitions for all columns */ $columns = $GLOBALS['dbi']->getColumnsFull($db, $table); $column_names = array_keys($columns); $changes = array(); $we_dont_change_keys = array(); // move columns from first to last for ($i = 0, $l = count($_REQUEST['move_columns']); $i < $l; $i++) { $column = $_REQUEST['move_columns'][$i]; // is this column already correctly placed? if ($column_names[$i] == $column) { continue; } // it is not, let's move it to index $i $data = $columns[$column]; $extracted_columnspec = PMA_Util::extractColumnSpec($data['Type']); if (isset($data['Extra']) && $data['Extra'] == 'on update CURRENT_TIMESTAMP') { $extracted_columnspec['attribute'] = $data['Extra']; unset($data['Extra']); } $current_timestamp = false; if (($data['Type'] == 'timestamp' || $data['Type'] == 'datetime') && $data['Default'] == 'CURRENT_TIMESTAMP') { $current_timestamp = true; } $default_type = $data['Null'] === 'YES' && $data['Default'] === null ? 'NULL' : ($current_timestamp ? 'CURRENT_TIMESTAMP' : ($data['Default'] === null ? 'NONE' : 'USER_DEFINED')); $changes[] = 'CHANGE ' . PMA_Table::generateAlter($column, $column, strtoupper($extracted_columnspec['type']), $extracted_columnspec['spec_in_brackets'], $extracted_columnspec['attribute'], isset($data['Collation']) ? $data['Collation'] : '', $data['Null'] === 'YES' ? 'NULL' : 'NOT NULL', $default_type, $current_timestamp ? '' : $data['Default'], isset($data['Extra']) && $data['Extra'] !== '' ? $data['Extra'] : false, isset($data['COLUMN_COMMENT']) && $data['COLUMN_COMMENT'] !== '' ? $data['COLUMN_COMMENT'] : false, $we_dont_change_keys, $i, $i === 0 ? '-first' : $column_names[$i - 1]); // update current column_names array, first delete old position for ($j = 0, $ll = count($column_names); $j < $ll; $j++) { if ($column_names[$j] == $column) { unset($column_names[$j]); } } // insert moved column array_splice($column_names, $i, 0, $column); } $response = PMA_Response::getInstance(); if (empty($changes)) { // should never happen $response->isSuccess(false); exit; } $move_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' '; $move_query .= implode(', ', $changes); // move columns $GLOBALS['dbi']->tryQuery($move_query); $tmp_error = $GLOBALS['dbi']->getError(); if ($tmp_error) { $response->isSuccess(false); $response->addJSON('message', PMA_Message::error($tmp_error)); } else { $message = PMA_Message::success(__('The columns have been moved successfully.')); $response->addJSON('message', $message); $response->addJSON('columns', $column_names); } exit; }
$fields_meta = PMA_DBI_get_fields_meta($result); $fields_cnt = count($fields_meta); } if (empty($disp_mode)) { // see the "PMA_setDisplayMode()" function in // libraries/display_tbl.lib.php $disp_mode = 'urdr111101'; } // hide edit and delete links for information_schema if (PMA_is_system_schema($db)) { $disp_mode = 'nnnn110111'; } $message = PMA_Message::success($message); echo PMA_showMessage($message, $GLOBALS['sql_query'], 'success'); PMA_displayTable($result, $disp_mode, $analyzed_sql); exit(); } // Displays the headers if (isset($show_query)) { unset($show_query); } if (isset($printview) && $printview == '1') { include_once 'libraries/header_printview.inc.php'; } else { $GLOBALS['js_include'][] = 'functions.js'; $GLOBALS['js_include'][] = 'makegrid.js';
// unset error marker, it was used just to skip processing } elseif (!empty($id_bookmark) && $action_bookmark == 1) { $message = PMA_Message::notice(__('Showing bookmark')); } elseif ($bookmark_created) { $special_message = '[br]' . sprintf(__('Bookmark %s created'), htmlspecialchars($bkm_label)); } elseif ($finished && !$error) { if ($import_type == 'query') { $message = PMA_Message::success(); } else { if ($import_notice) { $message = PMA_Message::success('<em>' . __('Import has been successfully finished, %d queries executed.') . '</em>'); $message->addParam($executed_queries); $message->addString($import_notice); $message->addString('(' . $_FILES['import_file']['name'] . ')'); } else { $message = PMA_Message::success(__('Import has been successfully finished, %d queries executed.')); $message->addParam($executed_queries); $message->addString('(' . $_FILES['import_file']['name'] . ')'); } } } // Did we hit timeout? Tell it user. if ($timeout_passed) { $message = PMA_Message::error(__('Script timeout passed, if you want to finish import, please resubmit same file and import will resume.')); if ($offset == 0 || isset($original_skip) && $original_skip == $offset) { $message->addString(__('However on last run no data has been parsed, this usually means phpMyAdmin won\'t be able to finish this import unless you increase php time limits.')); } } // if there is any message, copy it into $_SESSION as well, so we can obtain it by AJAX call if (isset($message)) { $_SESSION['Import_message']['message'] = $message->getDisplay();
} if (!$_error && $move) { /** * cleanup pmadb stuff for this db */ require_once './libraries/relation_cleanup.lib.php'; PMA_relationsCleanupDatabase($db); // if someday the RENAME DATABASE reappears, do not DROP $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';'; $sql_query .= "\n" . $local_query; PMA_DBI_query($local_query); $message = PMA_Message::success('strRenameDatabaseOK'); $message->addParam($db); $message->addParam($newname); } elseif (!$_error) { $message = PMA_Message::success('strCopyDatabaseOK'); $message->addParam($db); $message->addParam($newname); } $reload = true; /* Change database to be used */ if (!$_error && $move) { $db = $newname; } elseif (!$_error) { if (isset($switch_to_new) && $switch_to_new == 'true') { PMA_setCookie('pma_switch_to_new', 'true'); $db = $newname; } else { PMA_setCookie('pma_switch_to_new', ''); } }
} } if ($go_sql) { // parse sql query include_once 'libraries/parse_analyze.inc.php'; if (isset($ajax_reload) && $ajax_reload['reload'] === true) { $response = PMA_Response::getInstance(); $response->addJSON('ajax_reload', $ajax_reload); } PMA_executeQueryAndSendQueryResponse($analyzed_sql_results, false, $db, $table, null, $import_text, null, $analyzed_sql_results['is_affected'], null, null, null, null, $goto, $pmaThemeImage, null, null, null, $sql_query, null, null); } else { if ($result) { // Save a Bookmark with more than one queries (if Bookmark label given). if (!empty($_POST['bkm_label']) && !empty($import_text)) { PMA_storeTheQueryAsBookmark($db, $GLOBALS['cfg']['Bookmark']['user'], $import_text, $_POST['bkm_label'], isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null); } $response = PMA_Response::getInstance(); $response->isSuccess(true); $response->addJSON('message', PMA_Message::success($msg)); $response->addJSON('sql_query', PMA_Util::getMessage($msg, $sql_query, 'success')); } else { if ($result == false) { $response = PMA_Response::getInstance(); $response->isSuccess(false); $response->addJSON('message', PMA_Message::error($msg)); } else { $active_page = $goto; include '' . $goto; } } }
/** * Function to display results when the executed query returns non empty results * * @param array $result executed query results * @param array $analyzed_sql_results analysed sql results * @param string $db current database * @param string $table current table * @param string $disp_mode display mode * @param string $message message to show * @param array $sql_data sql data * @param object $displayResultsObject Instance of DisplayResults.class * @param string $goto goto page url * @param string $pmaThemeImage uri of the theme image * @param string $sql_limit_to_append sql limit to append * @param int $unlim_num_rows unlimited number of rows * @param int $num_rows number of rows * @param string $full_sql_query full sql query * @param string $disp_query display query * @param string $disp_message display message * @param array $profiling_results profiling results * @param string $query_type query type * @param array|null $selectedTables array of table names selected from * the database structure page, for an * action like check table, optimize * table, analyze table or repair table * @param string $sql_query sql query * @param string $complete_query complete sql query * * @return void */ function PMA_sendQueryResponseForResultsReturned($result, $analyzed_sql_results, $db, $table, $disp_mode, $message, $sql_data, $displayResultsObject, $goto, $pmaThemeImage, $sql_limit_to_append, $unlim_num_rows, $num_rows, $full_sql_query, $disp_query, $disp_message, $profiling_results, $query_type, $selectedTables, $sql_query, $complete_query) { // If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here if (isset($_REQUEST['grid_edit']) && $_REQUEST['grid_edit'] == true) { PMA_sendResponseForGridEdit($result); // script has exited at this point } // Gets the list of fields properties if (isset($result) && $result) { $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); } // Should be initialized these parameters before parsing $showtable = isset($showtable) ? $showtable : null; $url_query = isset($url_query) ? $url_query : null; $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); // hide edit and delete links: // - for information_schema // - if the result set does not contain all the columns of a unique key // (unless this is an updatable view) $sele_exp_cls = $analyzed_sql_results['analyzed_sql'][0]['select_expr_clause']; $updatableView = trim($sele_exp_cls) == '*' && PMA_Table::isUpdatableView($db, $table); $has_unique = PMA_resultSetContainsUniqueKey($db, $table, $fields_meta); $just_one_table = PMA_resultSetHasJustOneTable($fields_meta); $editable = ($has_unique || $updatableView) && $just_one_table; // Displays the results in a table if (empty($disp_mode)) { // see the "PMA_setDisplayMode()" function in // libraries/DisplayResults.class.php $disp_mode = 'urdr111101'; } if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $disp_mode = 'nnnn110111'; } if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { $disp_mode = 'nnnn000000'; } if (isset($_REQUEST['table_maintenance'])) { $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); $table_maintenance_html = ''; if (isset($message)) { $message = PMA_Message::success($message); $table_maintenance_html = PMA_Util::getMessage($message, $GLOBALS['sql_query'], 'success'); } $table_maintenance_html .= PMA_getHtmlForSqlQueryResultsTable(isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto, $pmaThemeImage, $url_query, $disp_mode, $sql_limit_to_append, false, $unlim_num_rows, $num_rows, $showtable, $result, $analyzed_sql_results); if (empty($sql_data) || ($sql_data['valid_queries'] = 1)) { $response->addHTML($table_maintenance_html); exit; } } if (!isset($_REQUEST['printview']) || $_REQUEST['printview'] != '1') { $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); unset($GLOBALS['message']); //we don't need to buffer the output in getMessage here. //set a global variable and check against it in the function $GLOBALS['buffer_message'] = false; } $print_view_header_html = PMA_getHtmlForPrintViewHeader($db, $full_sql_query, $num_rows); $previous_update_query_html = PMA_getHtmlForPreviousUpdateQuery(isset($disp_query) ? $disp_query : null, $GLOBALS['cfg']['ShowSQL'], isset($sql_data) ? $sql_data : null, isset($disp_message) ? $disp_message : null); $profiling_chart_html = PMA_getHtmlForProfilingChart($disp_mode, $db, isset($profiling_results) ? $profiling_results : null); $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex($table, $db, $editable); $bookmark_created_msg = PMA_getBookmarkCreatedMessage(); $table_html = PMA_getHtmlForSqlQueryResultsTable(isset($sql_data) ? $sql_data : null, $displayResultsObject, $db, $goto, $pmaThemeImage, $url_query, $disp_mode, $sql_limit_to_append, $editable, $unlim_num_rows, $num_rows, $showtable, $result, $analyzed_sql_results); $indexes_problems_html = PMA_getHtmlForIndexesProblems(isset($query_type) ? $query_type : null, isset($selectedTables) ? $selectedTables : null, $db); $cfgBookmark = PMA_Bookmark_getParams(); if ($cfgBookmark) { $bookmark_support_html = PMA_getHtmlForBookmark($disp_mode, $cfgBookmark, $sql_query, $db, $table, isset($complete_query) ? $complete_query : $sql_query, $cfgBookmark['user']); } else { $bookmark_support_html = ''; } $print_button_html = PMA_getHtmlForPrintButton(); $html_output = isset($table_maintenance_html) ? $table_maintenance_html : ''; $html_output .= isset($print_view_header_html) ? $print_view_header_html : ''; $html_output .= PMA_getHtmlForSqlQueryResults($previous_update_query_html, $profiling_chart_html, $missing_unique_column_msg, $bookmark_created_msg, $table_html, $indexes_problems_html, $bookmark_support_html, $print_button_html); $response->addHTML($html_output); exit; }
* A target table name has been sent to this script -> do the work */ if (PMA_isValid($_REQUEST['new_name'])) { if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) { if (isset($_REQUEST['submit_move'])) { $message = PMA_Message::error(__('Can\'t move table to same one!')); } else { $message = PMA_Message::error(__('Can\'t copy table to same one!')); } $result = false; } else { $result = PMA_Table::moveCopy($db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'], $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table'); if (isset($_REQUEST['submit_move'])) { $message = PMA_Message::success(__('Table %s has been moved to %s.')); } else { $message = PMA_Message::success(__('Table %s has been copied to %s.')); } $old = PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table); $message->addParam($old); $new = PMA_Util::backquote($_REQUEST['target_db']) . '.' . PMA_Util::backquote($_REQUEST['new_name']); $message->addParam($new); /* Check: Work on new table or on old table? */ if (isset($_REQUEST['submit_move']) || PMA_isValid($_REQUEST['switch_to_new'])) { $db = $_REQUEST['target_db']; $table = $_REQUEST['new_name']; } $reload = 1; } } else { /** * No new name for the table!
// The part "SELECT `id`, `name` FROM `customers`" // is not modified by the next code segment, when exporting // the result set from a query such as // "SELECT `id`, `name` FROM `customers` WHERE id NOT IN // ( SELECT id FROM companies WHERE name LIKE '%u%')" if (!is_null($first_occurring_regex)) { $temp_sql_array = preg_split($first_occurring_regex, $sql_query); $sql_query = $temp_sql_array[0]; } unset($first_occurring_regex, $temp_sql_array); // Append the where clause using the primary key of each row if (is_array($where_clause) && count($where_clause) > 0) { $sql_query .= ' WHERE (' . implode(') OR (', $where_clause) . ')'; } if (!empty($analyzed_sql[0]['group_by_clause'])) { $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause']; } if (!empty($analyzed_sql[0]['having_clause'])) { $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause']; } if (!empty($analyzed_sql[0]['order_by_clause'])) { $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause']; } } else { // Just crop LIMIT clause $sql_query = $analyzed_sql[0]['section_before_limit'] . $analyzed_sql[0]['section_after_limit']; } echo PMA_Util::getMessage(PMA_Message::success()); } $export_type = 'table'; require_once 'libraries/display_export.inc.php';
/** * Defines the url to return to in case of error in a sql statement */ $err_url = 'main.php?' . PMA_generate_common_url(); /** * Builds and executes the db creation sql query */ $sql_query = 'CREATE DATABASE ' . PMA_backquote($new_db); if (!empty($db_collation)) { list($db_charset) = explode('_', $db_collation); if (in_array($db_charset, $mysql_charsets) && in_array($db_collation, $mysql_collations[$db_charset])) { $sql_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation); } unset($db_charset, $db_collation); } $sql_query .= ';'; $result = PMA_DBI_try_query($sql_query); if (!$result) { $message = PMA_Message::rawError(PMA_DBI_getError()); // avoid displaying the not-created db name in header or navi panel $GLOBALS['db'] = ''; $GLOBALS['table'] = ''; require_once './libraries/header.inc.php'; require_once './main.php'; } else { $message = PMA_Message::success('strDatabaseHasBeenCreated'); $message->addParam($new_db); $GLOBALS['db'] = $new_db; require_once './libraries/header.inc.php'; require_once './' . $cfg['DefaultTabDatabase']; }
/** * Set the content that needs to be shown in message * * @param string $sorted_column_message the message for sorted column * @param string $limit_clause the limit clause of analyzed query * @param integer $total the total number of rows returned by * the SQL query without any * programmatically appended LIMIT clause * @param integer $pos_next the offset for next page * @param string $pre_count the string renders before row count * @param string $after_count the string renders after row count * * @return PMA_Message $message an object of PMA_Message * * @access private * * @see getTable() */ private function _setMessageInformation($sorted_column_message, $limit_clause, $total, $pos_next, $pre_count, $after_count) { $unlim_num_rows = $this->__get('unlim_num_rows'); // To use in isset() if (!empty($limit_clause)) { $limit_data = PMA_Util::analyzeLimitClause($limit_clause); $first_shown_rec = $limit_data['start']; if ($limit_data['length'] < $total) { $last_shown_rec = $limit_data['start'] + $limit_data['length'] - 1; } else { $last_shown_rec = $limit_data['start'] + $total - 1; } } elseif ($_SESSION['tmpval']['max_rows'] == self::ALL_ROWS || $pos_next > $total) { $first_shown_rec = $_SESSION['tmpval']['pos']; $last_shown_rec = $total - 1; } else { $first_shown_rec = $_SESSION['tmpval']['pos']; $last_shown_rec = $pos_next - 1; } if (PMA_Table::isView($this->__get('db'), $this->__get('table')) && $total == $GLOBALS['cfg']['MaxExactCountViews']) { $message = PMA_Message::notice(__('This view has at least this number of rows. ' . 'Please refer to %sdocumentation%s.')); $message->addParam('[doc@cfg_MaxExactCount]'); $message->addParam('[/doc]'); $message_view_warning = PMA_Util::showHint($message); } else { $message_view_warning = false; } $message = PMA_Message::success(__('Showing rows %1s - %2s')); $message->addParam($first_shown_rec); if ($message_view_warning) { $message->addParam('... ' . $message_view_warning, false); } else { $message->addParam($last_shown_rec); } $message->addMessage('('); if (!$message_view_warning) { if (isset($unlim_num_rows) && $unlim_num_rows != $total) { $message_total = PMA_Message::notice($pre_count . __('%1$d total, %2$d in query')); $message_total->addParam($total); $message_total->addParam($unlim_num_rows); } else { $message_total = PMA_Message::notice($pre_count . __('%d total')); $message_total->addParam($total); } if (!empty($after_count)) { $message_total->addMessage($after_count); } $message->addMessage($message_total, ''); $message->addMessage(', ', ''); } $message_qt = PMA_Message::notice(__('Query took %01.4f seconds.') . ')'); $message_qt->addParam($this->__get('querytime')); $message->addMessage($message_qt, ''); if (!is_null($sorted_column_message)) { $message->addMessage($sorted_column_message, ''); } return $message; }
} // end if if ($reread_info) { // to avoid showing the old value (for example the AUTO_INCREMENT) after // a change, clear the cache PMA_Table::$cache = array(); $page_checksum = $checksum = $delay_key_write = 0; include 'libraries/tbl_info.inc.php'; } unset($reread_info); if (isset($result) && empty($message_to_show)) { // set to success by default, because result set could be empty // (for example, a table rename) $_type = 'success'; if (empty($_message)) { $_message = $result ? PMA_Message::success(__('Your SQL query has been executed successfully.')) : PMA_Message::error(__('Error')); // $result should exist, regardless of $_message $_type = $result ? 'success' : 'error'; if (isset($GLOBALS['ajax_request']) && $GLOBALS['ajax_request'] == true) { $response = PMA_Response::getInstance(); $response->isSuccess($_message->isSuccess()); $response->addJSON('message', $_message); $response->addJSON('sql_query', PMA_Util::getMessage(null, $sql_query)); exit; } } if (!empty($warning_messages)) { $_message = new PMA_Message(); $_message->addMessages($warning_messages); $_message->isError(true); if ($GLOBALS['ajax_request'] == true) {
} elseif (!$run_parts) { $GLOBALS['dbi']->selectDb($db); $result = $GLOBALS['dbi']->tryQuery($sql_query); if ($result && !empty($sql_query_views)) { $sql_query .= ' ' . $sql_query_views . ';'; $result = $GLOBALS['dbi']->tryQuery($sql_query_views); unset($sql_query_views); } if (!$result) { $message = PMA_Message::error($GLOBALS['dbi']->getError()); } } if ($query_type == 'drop_tbl' || $query_type == 'empty_tbl' || $query_type == 'row_delete') { PMA_Util::handleDisableFKCheckCleanup($default_fk_check_value); } if ($rebuild_database_list) { // avoid a problem with the database list navigator // when dropping a db from server_databases $GLOBALS['pma']->databases->build(); } } else { if (isset($submit_mult) && ($submit_mult == 'sync_unique_columns_central_list' || $submit_mult == 'delete_unique_columns_central_list' || $submit_mult == 'add_to_central_columns' || $submit_mult == 'remove_from_central_columns' || $submit_mult == 'make_consistent_with_central_list')) { if (isset($centralColsError) && $centralColsError !== true) { $message = $centralColsError; } else { $message = PMA_Message::success(__('Success!')); } } else { $message = PMA_Message::success(__('No change')); } }
echo ' (' . implode(' ', PMA_formatByteDown($each_log['File_size'], 3, 2)) . ')'; } echo '</option>'; } echo '</select> '; echo count($binary_logs) . ' ' . __('Files') . ', '; if ($full_size > 0) { echo implode(' ', PMA_formatByteDown($full_size)); } echo '</fieldset>'; echo '<fieldset class="tblFooters">'; echo '<input type="submit" value="' . __('Go') . '" />'; echo '</fieldset>'; echo '</form>'; } PMA_showMessage(PMA_Message::success()); /** * Displays the page */ ?> <table border="0" cellpadding="2" cellspacing="1"> <thead> <tr> <td colspan="6" align="center"> <?php // we do not now how much rows are in the binlog // so we can just force 'NEXT' button if ($pos > 0) { $this_url_params = $url_params; if ($pos > $GLOBALS['cfg']['MaxRows']) { $this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows'];
/** * Handles editor requests for adding or editing an item * * @return Does not return */ function PMA_RTN_handleEditor() { global $_GET, $_POST, $_REQUEST, $GLOBALS, $db, $errors; if (!empty($_REQUEST['editor_process_add']) || !empty($_REQUEST['editor_process_edit'])) { /** * Handle a request to create/edit a routine */ $sql_query = ''; $routine_query = PMA_RTN_getQueryFromRequest(); if (!count($errors)) { // set by PMA_RTN_getQueryFromRequest() // Execute the created query if (!empty($_REQUEST['editor_process_edit'])) { if (!in_array($_REQUEST['item_original_type'], array('PROCEDURE', 'FUNCTION'))) { $errors[] = sprintf(__('Invalid routine type: "%s"'), htmlspecialchars($_REQUEST['item_original_type'])); } else { // Backup the old routine, in case something goes wrong $create_routine = PMA_DBI_get_definition($db, $_REQUEST['item_original_type'], $_REQUEST['item_original_name']); $drop_routine = "DROP {$_REQUEST['item_original_type']} " . PMA_Util::backquote($_REQUEST['item_original_name']) . ";\n"; $result = PMA_DBI_try_query($drop_routine); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($drop_routine)) . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); } else { $result = PMA_DBI_try_query($routine_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($routine_query)) . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); // We dropped the old routine, but were unable to create the new one // Try to restore the backup query $result = PMA_DBI_try_query($create_routine); 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 routine.') . '<br />' . __('The backed up query was:') . "\"" . htmlspecialchars($create_routine) . "\"" . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); } } else { $message = PMA_Message::success(__('Routine %1$s has been modified.')); $message->addParam(PMA_Util::backquote($_REQUEST['item_name'])); $sql_query = $drop_routine . $routine_query; } } } } else { // 'Add a new routine' mode $result = PMA_DBI_try_query($routine_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), htmlspecialchars($routine_query)) . '<br /><br />' . __('MySQL said: ') . PMA_DBI_getError(null); } else { $message = PMA_Message::success(__('Routine %1$s has been created.')); $message->addParam(PMA_Util::backquote($_REQUEST['item_name'])); $sql_query = $routine_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_Util::getMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $response = PMA_Response::getInstance(); if ($message->isSuccess()) { $columns = "`SPECIFIC_NAME`, `ROUTINE_NAME`, `ROUTINE_TYPE`, `DTD_IDENTIFIER`, `ROUTINE_DEFINITION`"; $where = "ROUTINE_SCHEMA='" . PMA_Util::sqlAddSlashes($db) . "' " . "AND ROUTINE_NAME='" . PMA_Util::sqlAddSlashes($_REQUEST['item_name']) . "'" . "AND ROUTINE_TYPE='" . PMA_Util::sqlAddSlashes($_REQUEST['item_type']) . "'"; $routine = PMA_DBI_fetch_single_row("SELECT {$columns} FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE {$where};"); $response->addJSON('name', htmlspecialchars(strtoupper($_REQUEST['item_name']))); $response->addJSON('new_row', PMA_RTN_getRowForList($routine)); $response->addJSON('insert', !empty($routine)); $response->addJSON('message', $output); } else { $response->isSuccess(false); $response->addJSON('message', $output); } exit; } } /** * Display a form used to add/edit a routine, 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['routine_addparameter']) || !empty($_REQUEST['routine_removeparameter']) || !empty($_REQUEST['routine_changetype']))) { // Handle requests to add/remove parameters and changing routine type // This is necessary when JS is disabled $operation = ''; if (!empty($_REQUEST['routine_addparameter'])) { $operation = 'add'; } else { if (!empty($_REQUEST['routine_removeparameter'])) { $operation = 'remove'; } else { if (!empty($_REQUEST['routine_changetype'])) { $operation = 'change'; } } } // Get the data for the form (if any) if (!empty($_REQUEST['add_item'])) { $title = PMA_RTE_getWord('add'); $routine = PMA_RTN_getDataFromRequest(); $mode = 'add'; } else { if (!empty($_REQUEST['edit_item'])) { $title = __("Edit routine"); if (!$operation && !empty($_REQUEST['item_name']) && empty($_REQUEST['editor_process_edit'])) { $routine = PMA_RTN_getDataFromName($_REQUEST['item_name'], $_REQUEST['item_type']); if ($routine !== false) { $routine['item_original_name'] = $routine['item_name']; $routine['item_original_type'] = $routine['item_type']; } } else { $routine = PMA_RTN_getDataFromRequest(); } $mode = 'edit'; } } if ($routine !== false) { // Show form $editor = PMA_RTN_getEditorForm($mode, $operation, $routine); if ($GLOBALS['is_ajax_request']) { $response = PMA_Response::getInstance(); $response->addJSON('message', $editor); $response->addJSON('title', $title); $response->addJSON('param_template', PMA_RTN_getParameterRow()); $response->addJSON('type', $routine['item_type']); } else { echo "\n\n<h2>{$title}</h2>\n\n{$editor}"; } exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_Util::backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_Util::backquote($db))); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { $response->isSuccess(false); $response->addJSON('message', $message); exit; } else { $message->display(); } } } }
/** * Returns the html for binary log information. * * @param Array $url_params links parameters * * @return string */ function PMA_getLogInfo($url_params) { /** * Need to find the real end of rows? */ if (!isset($_REQUEST['pos'])) { $pos = 0; } else { /* We need this to be a integer */ $pos = (int) $_REQUEST['pos']; } $sql_query = 'SHOW BINLOG EVENTS'; if (!empty($_REQUEST['log'])) { $sql_query .= ' IN \'' . $_REQUEST['log'] . '\''; } $sql_query .= ' LIMIT ' . $pos . ', ' . (int) $GLOBALS['cfg']['MaxRows']; /** * Sends the query */ $result = $GLOBALS['dbi']->query($sql_query); /** * prepare some vars for displaying the result table */ // Gets the list of fields properties if (isset($result) && $result) { $num_rows = $GLOBALS['dbi']->numRows($result); } else { $num_rows = 0; } if (empty($_REQUEST['dontlimitchars'])) { $dontlimitchars = false; } else { $dontlimitchars = true; $url_params['dontlimitchars'] = 1; } //html output $html = PMA_Util::getMessage(PMA_Message::success(), $sql_query); $html .= '<table cellpadding="2" cellspacing="1" id="binlogTable">' . '<thead>' . '<tr>' . '<td colspan="6" class="center">'; $html .= PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars); $html .= '</td>' . '</tr>' . '<tr>' . '<th>' . __('Log name') . '</th>' . '<th>' . __('Position') . '</th>' . '<th>' . __('Event type') . '</th>' . '<th>' . __('Server ID') . '</th>' . '<th>' . __('Original position') . '</th>' . '<th>' . __('Information') . '</th>' . '</tr>' . '</thead>' . '<tbody>'; $html .= PMA_getAllLogItemInfo($result, $dontlimitchars); $html .= '</tbody>' . '</table>'; return $html; }
} // Export as SQL execution if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'execution') { foreach ($entries as $entry) { $sql_result = PMA_DBI_query("/*NOTRACK*/\n" . $entry['statement']); } $msg = PMA_Message::success($strTrackingSQLExecuted); $msg->display(); } // Export as SQL dump if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'sqldump') { $new_query = "# " . $strTrackingYouCanExecute . "\n" . "# " . $strTrackingCommentOut . "\n" . "\n" . "CREATE database IF NOT EXISTS pma_temp_db; \n" . "USE pma_temp_db; \n" . "\n"; foreach ($entries as $entry) { $new_query .= $entry['statement']; } $msg = PMA_Message::success($strTrackingSQLExported); $msg->display(); $db_temp = $db; $table_temp = $table; $db = $table = ''; $GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/sql_query_form.lib.php'; PMA_sqlQueryForm($new_query, 'sql'); $db = $db_temp; $table = $table_temp; } /* * Schema snapshot */ if (isset($_REQUEST['snapshot'])) { ?>
/** * Function to create the tracking version * * @return string HTML of the success message */ function PMA_createTrackingVersion() { $html = ''; $tracking_set = PMA_getTrackingSet(); $versionCreated = PMA_Tracker::createVersion($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'], $tracking_set, PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])); if ($versionCreated) { $msg = PMA_Message::success(sprintf(__('Version %1$s was created, tracking for %2$s is active.'), htmlspecialchars($_REQUEST['version']), htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']))); $html .= $msg->getDisplay(); } return $html; }