/** * Test for getMessage * * @return void */ function testShowMessageNotAjax() { global $cfg; $cfg['Server']['DisableIS'] = false; $GLOBALS['table'] = 'tbl'; $GLOBALS['db'] = 'db'; $GLOBALS['sql_query'] = "SELECT * FROM tblPatient "; $this->expectOutputString( "<div class=\"result_query\" align=\"\"> <div class=\"notice\">msg</div><code class=\"sql\"><span class=\"syntax\"><span class=\"inner_sql\"><a href=\"./url.php?url=http%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.0%2Fen%2Fselect.html&server=server&lang=en\" target=\"mysql_doc\"><span class=\"syntax_alpha syntax_alpha_reservedWord\">SELECT</span></a> <span class=\"syntax_punct\">*</span> <br /><span class=\"syntax_alpha syntax_alpha_reservedWord\">FROM</span> <span class=\"syntax_alpha syntax_alpha_identifier\">tblPatient</span></span></span></code><div class=\"tools\"><form action=\"sql.php\" method=\"post\"><input type=\"hidden\" name=\"db\" value=\"db\" /><input type=\"hidden\" name=\"table\" value=\"tbl\" /><input type=\"hidden\" name=\"server\" value=\"server\" /><input type=\"hidden\" name=\"lang\" value=\"en\" /><input type=\"hidden\" name=\"token\" value=\"647a62ad301bf9025e3b13bc7caa02cb\" /><input type=\"hidden\" name=\"sql_query\" value=\"SELECT * FROM tblPatient \" /></form><script type=\"text/javascript\"> //<![CDATA[ $('.tools form').last().after('[<a href=\"#\" title=\"Inline edit of this query\" class=\"inline_edit_sql\">Inline</a>]'); //]]> </script> [ <a href=\"tbl_sql.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&server=server&lang=en#querybox\" >Edit</a> ] [ <a href=\"import.php?db=db&table=tbl&sql_query=EXPLAIN+SELECT+%2A+FROM+tblPatient+&server=server&lang=en\" >Explain SQL</a> ] [ <a href=\"import.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&show_as_php=1&server=server&lang=en\" >Create PHP code</a> ] [ <a href=\"import.php?db=db&table=tbl&sql_query=SELECT+%2A+FROM+tblPatient+&show_query=1&server=server&lang=en\" >Refresh</a> ]</div></div>" ); echo PMA\libraries\Util::getMessage("msg"); //$this->assertEquals("", PMA\libraries\Util::getMessage("msg")); $this->assertTrue(true); }
/** * Show message for empty result or set the unique_condition * * @param array $rows MySQL returned rows * @param string $key_id ID in current key * @param array $where_clause_array array of where clauses * @param string $local_query query performed * @param array $result MySQL result handle * * @return boolean $has_unique_condition */ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, $where_clause_array, $local_query, $result) { $has_unique_condition = false; // No row returned if (!$rows[$key_id]) { unset($rows[$key_id], $where_clause_array[$key_id]); PMA\libraries\Response::getInstance()->addHtml(PMA\libraries\Util::getMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query)); /** * @todo not sure what should be done at this point, but we must not * exit if we want the message to be displayed */ } else { // end if (no row returned) $meta = $GLOBALS['dbi']->getFieldsMeta($result[$key_id]); list($unique_condition, $tmp_clause_is_unique) = PMA\libraries\Util::getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true, false, null); if (!empty($unique_condition)) { $has_unique_condition = true; } unset($unique_condition, $tmp_clause_is_unique); } return $has_unique_condition; }
/** * Function to display results when the executed query returns non empty results * * @param object $result executed query results * @param array $analyzed_sql_results analysed sql results * @param string $db current database * @param string $table current table * @param string $message message to show * @param array $sql_data sql data * @param DisplayResults $displayResultsObject Instance of DisplayResults * @param string $pmaThemeImage uri of the theme image * @param int $unlim_num_rows unlimited number of rows * @param int $num_rows number of rows * @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 string html */ function PMA_getQueryResponseForResultsReturned($result, $analyzed_sql_results, $db, $table, $message, $sql_data, $displayResultsObject, $pmaThemeImage, $unlim_num_rows, $num_rows, $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\libraries\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) $updatableView = false; $statement = $analyzed_sql_results['statement']; if ($statement instanceof SqlParser\Statements\SelectStatement) { if (!empty($statement->expr)) { if ($statement->expr[0]->expr === '*') { $_table = new Table($table, $db); $updatableView = $_table->isUpdatableView(); } } } $has_unique = PMA_resultSetContainsUniqueKey($db, $table, $fields_meta); $just_one_table = PMA_resultSetHasJustOneTable($fields_meta); $editable = ($has_unique || $GLOBALS['cfg']['RowActionLinksWithoutUnique'] || $updatableView) && $just_one_table; $displayParts = array('edit_lnk' => $displayResultsObject::UPDATE_ROW, 'del_lnk' => $displayResultsObject::DELETE_ROW, 'sort_lnk' => '1', 'nav_bar' => '1', 'bkm_form' => '1', 'text_btn' => '0', 'pview_lnk' => '1'); if (!empty($table) && ($GLOBALS['dbi']->isSystemSchema($db) || !$editable)) { $displayParts = array('edit_lnk' => $displayResultsObject::NO_EDIT_OR_DELETE, 'del_lnk' => $displayResultsObject::NO_EDIT_OR_DELETE, 'sort_lnk' => '1', 'nav_bar' => '1', 'bkm_form' => '1', 'text_btn' => '1', 'pview_lnk' => '1'); } if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { $displayParts = array('edit_lnk' => $displayResultsObject::NO_EDIT_OR_DELETE, 'del_lnk' => $displayResultsObject::NO_EDIT_OR_DELETE, 'sort_lnk' => '0', 'nav_bar' => '0', 'bkm_form' => '0', 'text_btn' => '0', 'pview_lnk' => '0'); } if (isset($_REQUEST['table_maintenance'])) { $scripts->addFile('makegrid.js'); $scripts->addFile('sql.js'); $table_maintenance_html = ''; if (isset($message)) { $message = Message::success($message); $table_maintenance_html = PMA\libraries\Util::getMessage($message, $GLOBALS['sql_query'], 'success'); } $table_maintenance_html .= PMA_getHtmlForSqlQueryResultsTable($displayResultsObject, $pmaThemeImage, $url_query, $displayParts, 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; } $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($url_query, $db, isset($profiling_results) ? $profiling_results : array()); $missing_unique_column_msg = PMA_getMessageIfMissingColumnIndex($table, $db, $editable, $has_unique); $bookmark_created_msg = PMA_getBookmarkCreatedMessage(); $table_html = PMA_getHtmlForSqlQueryResultsTable($displayResultsObject, $pmaThemeImage, $url_query, $displayParts, $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($displayParts, $cfgBookmark, $sql_query, $db, $table, isset($complete_query) ? $complete_query : $sql_query, $cfgBookmark['user']); } else { $bookmark_support_html = ''; } $html_output = isset($table_maintenance_html) ? $table_maintenance_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); return $html_output; }
$pma_transformation_data = $systemDb->getExistingTransformationData($GLOBALS['db']); if ($pma_transformation_data !== false) { // SQL for store new transformation details of VIEW $new_transformations_sql = $systemDb->getNewTransformationDataSql($pma_transformation_data, $column_map, $_REQUEST['view']['name'], $GLOBALS['db']); // Store new transformations if ($new_transformations_sql != '') { $GLOBALS['dbi']->tryQuery($new_transformations_sql); } } unset($pma_transformation_data); if (!isset($_REQUEST['ajax_dialog'])) { $message = PMA\libraries\Message::success(); include 'tbl_structure.php'; } else { $response = PMA\libraries\Response::getInstance(); $response->addJSON('message', PMA\libraries\Util::getMessage(PMA\libraries\Message::success(), $sql_query)); $response->setRequestStatus(true); } exit; } // prefill values if not already filled from former submission $view = array('operation' => 'create', 'or_replace' => '', 'algorithm' => '', 'definer' => '', 'sql_security' => '', 'name' => '', 'column_names' => '', 'as' => $sql_query, 'with' => ''); if (PMA_isValid($_REQUEST['view'], 'array')) { $view = array_merge($view, $_REQUEST['view']); } $url_params['db'] = $GLOBALS['db']; $url_params['reload'] = 1; /** * Displays the page */ $htmlString = '<!-- CREATE VIEW options -->' . '<div id="div_view_options">' . '<form method="post" action="view_create.php">' . PMA_URL_getHiddenInputs($url_params) . '<fieldset>' . '<legend>' . (isset($_REQUEST['ajax_dialog']) ? __('Details') : ($view['operation'] == 'create' ? __('Create view') : __('Edit view'))) . '</legend>' . '<table class="rte_table">';
/** * Display the page * * @param string $message Message * @param string $sql_query SQL query * * @return void */ function PMA_changePassDisplayPage($message, $sql_query) { echo '<h1>', __('Change password'), '</h1>', "\n\n"; echo PMA\libraries\Util::getMessage($message, $sql_query, 'success'); echo '<a href="index.php', PMA_URL_getCommon(), ' target="_parent">', "\n", '<strong>', __('Back'), '</strong></a>'; exit; }
*/ $db_url_params['db'] = $_POST['new_db']; $is_superuser = $GLOBALS['dbi']->isSuperuser(); $column_order = PMA_getColumnOrder(); $url_query = PMA_URL_getCommon(array('db' => $_POST['new_db'])); /** * String that will contain the output HTML * @name $new_db_string */ $new_db_string = '<tr>'; if (empty($db_collation_for_ajax)) { $db_collation_for_ajax = PMA_getServerCollation(); } // $dbstats comes from the create table dialog if (!empty($dbstats)) { $current = array('SCHEMA_NAME' => $_POST['new_db'], 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax, 'SCHEMA_TABLES' => '0', 'SCHEMA_TABLE_ROWS' => '0', 'SCHEMA_DATA_LENGTH' => '0', 'SCHEMA_MAX_DATA_LENGTH' => '0', 'SCHEMA_INDEX_LENGTH' => '0', 'SCHEMA_LENGTH' => '0', 'SCHEMA_DATA_FREE' => '0'); } else { $current = array('SCHEMA_NAME' => $_POST['new_db'], 'DEFAULT_COLLATION_NAME' => $db_collation_for_ajax); } list($column_order, $generated_html) = PMA_buildHtmlForDb($current, $is_superuser, $url_query, $column_order, $replication_types, $GLOBALS['replication_info']); $new_db_string .= $generated_html; $new_db_string .= '</tr>'; $response = PMA\libraries\Response::getInstance(); $response->addJSON('message', $message); $response->addJSON('new_db_string', $new_db_string); $response->addJSON('sql_query', PMA\libraries\Util::getMessage(null, $sql_query, 'success')); $response->addJSON('url_query', PMA\libraries\Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . $url_query . '&db=' . urlencode($current['SCHEMA_NAME'])); } else { include_once '' . $cfg['DefaultTabDatabase']; } }
exit; } if ($GLOBALS['PMA_Config']->isGitRevision()) { if (isset($_REQUEST['git_revision']) && $GLOBALS['is_ajax_request'] == true) { PMA_printGitRevision(); exit; } echo '<div id="is_git_revision"></div>'; } // Handles some variables that may have been sent by the calling script $GLOBALS['db'] = ''; $GLOBALS['table'] = ''; $show_query = '1'; // Any message to display? if (!empty($message)) { echo PMA\libraries\Util::getMessage($message); unset($message); } $common_url_query = PMA_URL_getCommon(); $mysql_cur_user_and_host = ''; // when $server > 0, a server has been chosen so we can display // all MySQL-related information if ($server > 0) { include 'libraries/server_common.inc.php'; // Use the verbose name of the server instead of the hostname // if a value is set $server_info = ''; if (!empty($cfg['Server']['verbose'])) { $server_info .= htmlspecialchars($cfg['Server']['verbose']); if ($GLOBALS['cfg']['ShowServerInfo']) { $server_info .= ' (';
/** * Function to get html for schema snapshot * * @param string $url_query url query * * @return string */ function PMA_getHtmlForSchemaSnapshot($url_query) { $html = '<h3>' . __('Structure snapshot') . ' [<a href="tbl_tracking.php' . $url_query . '">' . __('Close') . '</a>]</h3>'; $data = Tracker::getTrackedData($_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']); // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements $drop_create_statements = $data['ddlog'][0]['statement']; if (mb_strstr($data['ddlog'][0]['statement'], 'DROP TABLE') || mb_strstr($data['ddlog'][0]['statement'], 'DROP VIEW')) { $drop_create_statements .= $data['ddlog'][1]['statement']; } // Print SQL code $html .= PMA\libraries\Util::getMessage(sprintf(__('Version %s snapshot (SQL code)'), htmlspecialchars($_REQUEST['version'])), $drop_create_statements); // Unserialize snapshot $temp = unserialize($data['schema_snapshot']); $columns = $temp['COLUMNS']; $indexes = $temp['INDEXES']; $html .= PMA_getHtmlForColumns($columns); if (count($indexes) > 0) { $html .= PMA_getHtmlForIndexes($indexes); } // endif $html .= '<br /><hr /><br />'; return $html; }
// Checking if the WHERE clause has to be replaced. if (!empty($where_clause) && is_array($where_clause)) { $replaces[] = array('WHERE', 'WHERE (' . implode(') OR (', $where_clause) . ')'); } // Preparing to remove the LIMIT clause. $replaces[] = array('LIMIT', ''); // Replacing the clauses. $sql_query = SqlParser\Utils\Query::replaceClauses($parser->statements[0], $parser->list, $replaces); // Removing the aliases by finding the alias followed by a dot. $tokens = SqlParser\Lexer::getTokens($sql_query); foreach ($aliases as $alias => $table) { $tokens = SqlParser\Utils\Tokens::replaceTokens($tokens, array(array('value_str' => $alias), array('type' => SqlParser\Token::TYPE_OPERATOR, 'value_str' => '.')), array(new SqlParser\Token($table), new SqlParser\Token('.', SqlParser\Token::TYPE_OPERATOR))); } $sql_query = SqlParser\TokensList::build($tokens); } echo PMA\libraries\Util::getMessage(PMA\libraries\Message::success()); } require_once 'libraries/display_export.lib.php'; if (!isset($sql_query)) { $sql_query = ''; } if (!isset($num_tables)) { $num_tables = 0; } if (!isset($unlim_num_rows)) { $unlim_num_rows = 0; } if (!isset($multi_values)) { $multi_values = ''; } $response = Response::getInstance();
/** * 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 = $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 trigger.'), $create_item, $errors); } else { $message = PMA\libraries\Message::success(__('Trigger %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(__('Trigger %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->addHtml('<ul>'); foreach ($errors as $string) { $message->addHtml('<li>' . $string . '</li>'); } $message->addHtml('</ul>'); } $output = PMA\libraries\Util::getMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $response = PMA\libraries\Response::getInstance(); if ($message->isSuccess()) { $items = $GLOBALS['dbi']->getTriggers($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(mb_strtoupper($_REQUEST['item_name']))); } $response->addJSON('insert', $insert); $response->addJSON('message', $output); } else { $response->addJSON('message', $message); $response->setRequestStatus(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'; } } PMA_RTE_sendEditor('TRI', $mode, $item, $title, $db); } }
/** * 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); } }
$column_name = $transformation['column_name']; foreach ($transformation_types as $type) { $file = PMA_securePath($transformation[$type]); $extra_data = PMA_transformEditedValues($db, $table, $transformation, $edited_values, $file, $column_name, $extra_data, $type); } } // end of loop for each $mime_map } // Need to check the inline edited value can be truncated by MySQL // without informing while saving $column_name = $_REQUEST['fields_name']['multi_edit'][0][0]; PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData($db, $table, $column_name, $extra_data); /**Get the total row count of the table*/ $_table = new Table($_REQUEST['table'], $_REQUEST['db']); $extra_data['row_count'] = $_table->countRecords(); $extra_data['sql_query'] = PMA\libraries\Util::getMessage($message, $GLOBALS['display_query']); $response = PMA\libraries\Response::getInstance(); $response->setRequestStatus($message->isSuccess()); $response->addJSON('message', $message); $response->addJSON($extra_data); exit; } if (!empty($return_to_sql_query)) { $disp_query = $GLOBALS['sql_query']; $disp_message = $message; unset($message); $GLOBALS['sql_query'] = $return_to_sql_query; } $scripts->addFile('tbl_change.js'); $active_page = $goto_include; /**
} // Need to check the inline edited value can be truncated by MySQL // without informing while saving $column_name = $_REQUEST['fields_name']['multi_edit'][0][0]; PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData( $db, $table, $column_name, $extra_data ); /**Get the total row count of the table*/ $_table = new Table($_REQUEST['table'], $_REQUEST['db']); $extra_data['row_count'] = $_table->countRecords(); $extra_data['sql_query'] = PMA\libraries\Util::getMessage($message, $GLOBALS['display_query']); $response->setRequestStatus($message->isSuccess()); $response->addJSON('message', $message); $response->addJSON($extra_data); exit; } if (! empty($return_to_sql_query)) { $disp_query = $GLOBALS['sql_query']; $disp_message = $message; unset($message); $GLOBALS['sql_query'] = $return_to_sql_query; } $scripts->addFile('tbl_change.js');
$_REQUEST['field_transformation_options'][$fieldindex], $_REQUEST['field_input_transformation'][$fieldindex], $_REQUEST['field_input_transformation_options'][$fieldindex] ); } } } // Go back to the structure sub-page $message = PMA\libraries\Message::success( __('Table %1$s has been altered successfully.') ); $message->addParam($table); $response->addJSON( 'message', PMA\libraries\Util::getMessage($message, $sql_query, 'success') ); exit; } else { $error_message_html = PMA\libraries\Util::mysqlDie( '', '', false, $err_url, false ); $response->addHTML($error_message_html); $response->setRequestStatus(false); exit; } } // end do alter table
$data = Tracker::getTrackedData($_REQUEST['db'], '', '1'); // No tables present and no log exist if ($num_tables == 0 && count($data['ddlog']) == 0) { echo '<p>', __('No tables found in database.'), '</p>', "\n"; if (empty($db_is_system_schema)) { echo PMA_getHtmlForCreateTable($db); } exit; } // --------------------------------------------------------------------------- $cfgRelation = PMA_getRelationsParam(); // Prepare statement to get HEAD version $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' . PMA\libraries\Util::backquote($cfgRelation['db']) . '.' . PMA\libraries\Util::backquote($cfgRelation['tracking']) . ' WHERE db_name = \'' . PMA\libraries\Util::sqlAddSlashes($_REQUEST['db']) . '\' ' . ' GROUP BY table_name' . ' ORDER BY table_name ASC'; $all_tables_result = PMA_queryAsControlUser($all_tables_query); // If a HEAD version exists if (is_object($all_tables_result) && $GLOBALS['dbi']->numRows($all_tables_result) > 0) { PMA_displayTrackedTables($GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage, $text_dir, $cfgRelation); } $untracked_tables = PMA_getUntrackedTables($GLOBALS['db']); // If untracked tables exist if (count($untracked_tables) > 0) { PMA_displayUntrackedTables($GLOBALS['db'], $untracked_tables, $url_query, $pmaThemeImage, $text_dir); } // If available print out database log if (count($data['ddlog']) > 0) { $log = ''; foreach ($data['ddlog'] as $entry) { $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n" . $entry['statement'] . "\n"; } echo PMA\libraries\Util::getMessage(__('Database Log'), $log); }
if (isset($result)) { // set to success by default, because result set could be empty // (for example, a table rename) $_type = 'success'; if (empty($_message)) { $_message = $result ? __('Your SQL query has been executed successfully.') : __('Error'); // $result should exist, regardless of $_message $_type = $result ? 'success' : 'error'; } if (!empty($warning_messages)) { $_message = new PMA\libraries\Message(); $_message->addMessages($warning_messages); $_message->isError(true); unset($warning_messages); } echo PMA\libraries\Util::getMessage($_message, $sql_query, $_type); unset($_message, $_type); } $url_params['goto'] = 'view_operations.php'; $url_params['back'] = 'view_operations.php'; /** * Displays the page */ ?> <!-- Table operations --> <div class="operations_half_width"> <form method="post" action="view_operations.php"> <?php echo PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); ?> <input type="hidden" name="reload" value="1" />
$_message->isError(true); if (isset($GLOBALS['ajax_request']) && $GLOBALS['ajax_request'] == true) { $response = PMA\libraries\Response::getInstance(); $response->setRequestStatus(false); $response->addJSON('message', $_message); if (!empty($sql_query)) { $response->addJSON('sql_query', PMA\libraries\Util::getMessage(null, $sql_query)); } exit; } unset($warning_messages); } if (empty($sql_query)) { $response->addHTML($_message->getDisplay()); } else { $response->addHTML(PMA\libraries\Util::getMessage($_message, $sql_query)); } unset($_message); } $url_params['goto'] = $url_params['back'] = 'tbl_operations.php'; /** * Get columns names */ $columns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $GLOBALS['table']); /** * Displays the page */ $response->addHTML('<div id="boxContainer" data-box-width="300">'); /** * Order the table */
$cfgRelation = PMA_getRelationsParam(); /** * Check if comments were updated * (must be done before displaying the menu tabs) */ if (isset($_REQUEST['comment'])) { PMA_setDbComment($GLOBALS['db'], $_REQUEST['comment']); } require 'libraries/db_common.inc.php'; $url_query .= '&goto=db_operations.php'; // Gets the database structure $sub_part = '_structure'; list($tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats, $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos) = PMA\libraries\Util::getDbInfo($db, isset($sub_part) ? $sub_part : ''); echo "\n"; if (isset($message)) { echo PMA\libraries\Util::getMessage($message, $sql_query); unset($message); } $_REQUEST['db_collation'] = PMA_getDbCollation($GLOBALS['db']); $is_information_schema = $GLOBALS['dbi']->isSystemSchema($GLOBALS['db']); $response->addHTML('<div id="boxContainer" data-box-width="300">'); if (!$is_information_schema) { if ($cfgRelation['commwork']) { /** * database comment */ $response->addHTML(PMA_getHtmlForDatabaseComment($GLOBALS['db'])); } $response->addHTML('<div class="operations_half_width">'); $response->addHTML(PMA_getHtmlForCreateTable($db)); $response->addHTML('</div>');
list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url); if ($result === true) { // If comments were sent, enable relation stuff include_once 'libraries/transformations.lib.php'; // Update comment table for mime types [MIME] if (isset($_REQUEST['field_mimetype']) && is_array($_REQUEST['field_mimetype']) && $cfg['BrowseMIME']) { foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) { if (isset($_REQUEST['field_name'][$fieldindex]) && mb_strlen($_REQUEST['field_name'][$fieldindex])) { PMA_setMIME($db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype, $_REQUEST['field_transformation'][$fieldindex], $_REQUEST['field_transformation_options'][$fieldindex], $_REQUEST['field_input_transformation'][$fieldindex], $_REQUEST['field_input_transformation_options'][$fieldindex]); } } } // Go back to the structure sub-page $message = PMA\libraries\Message::success(__('Table %1$s has been altered successfully.')); $message->addParam($table); $response->addJSON('message', PMA\libraries\Util::getMessage($message, $sql_query, 'success')); exit; } else { $error_message_html = PMA\libraries\Util::mysqlDie('', '', false, $err_url, false); $response->addHTML($error_message_html); $response->setRequestStatus(false); exit; } } // end do alter table /** * Displays the form used to define the new field */ if ($abort == false) { /** * Gets tables information
/** * Displays the links */ if (isset($_REQUEST['viewing_mode']) && $_REQUEST['viewing_mode'] == 'db') { $GLOBALS['db'] = $_REQUEST['db'] = $_REQUEST['checkprivsdb']; $url_query .= '&goto=db_operations.php'; // Gets the database structure $sub_part = '_structure'; ob_start(); list($tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats, $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos) = PMA\libraries\Util::getDbInfo($db, isset($sub_part) ? $sub_part : ''); $content = ob_get_contents(); ob_end_clean(); $response->addHTML($content . "\n"); } else { if (!empty($GLOBALS['message'])) { $response->addHTML(PMA\libraries\Util::getMessage($GLOBALS['message'])); unset($GLOBALS['message']); } } /** * Displays the page */ $response->addHTML(PMA_getHtmlForUserGroupDialog(isset($username) ? $username : null, $cfgRelation['menuswork'])); // export user definition if (isset($_REQUEST['export']) || isset($_REQUEST['submit_mult']) && $_REQUEST['submit_mult'] == 'export') { list($title, $export) = PMA_getListForExportUserDefinition(isset($username) ? $username : null, isset($hostname) ? $hostname : null); unset($username, $hostname, $grants, $one_grant); $response = PMA\libraries\Response::getInstance(); if ($GLOBALS['is_ajax_request']) { $response->addJSON('message', $export); $response->addJSON('title', $title);
/** * Test for PMA_getExtraDataForAjaxBehavior * * @return void */ public function testPMAGetExtraDataForAjaxBehavior() { $password = "******"; $sql_query = "pma_sql_query"; $username = "******"; $hostname = "pma_hostname"; $GLOBALS['dbname'] = "pma_dbname"; $_REQUEST['adduser_submit'] = "adduser_submit"; $_REQUEST['change_copy'] = "change_copy"; $_REQUEST['validate_username'] = "******"; $_REQUEST['username'] = "******"; $_POST['update_privs'] = "update_privs"; //PMA_getExtraDataForAjaxBehavior $extra_data = PMA_getExtraDataForAjaxBehavior($password, $sql_query, $hostname, $username); //user_exists $this->assertEquals(false, $extra_data['user_exists']); //db_wildcard_privs $this->assertEquals(true, $extra_data['db_wildcard_privs']); //user_exists $this->assertEquals(false, $extra_data['db_specific_privs']); //new_user_initial $this->assertEquals('P', $extra_data['new_user_initial']); //sql_query $this->assertEquals(PMA\libraries\Util::getMessage(null, $sql_query), $extra_data['sql_query']); //new_user_string $this->assertContains(htmlspecialchars($hostname), $extra_data['new_user_string']); $this->assertContains(htmlspecialchars($username), $extra_data['new_user_string']); //new_privileges $this->assertContains(join(', ', PMA_extractPrivInfo(null, true)), $extra_data['new_privileges']); }
// Store new transformations if ($new_transformations_sql != '') { $GLOBALS['dbi']->tryQuery($new_transformations_sql); } } unset($pma_transformation_data); if (! isset($_REQUEST['ajax_dialog'])) { $message = PMA\libraries\Message::success(); include 'tbl_structure.php'; } else { $response->addJSON( 'message', PMA\libraries\Util::getMessage( PMA\libraries\Message::success(), $sql_query ) ); $response->setRequestStatus(true); } exit; } // prefill values if not already filled from former submission $view = array( 'operation' => 'create', 'or_replace' => '', 'algorithm' => '', 'definer' => '', 'sql_security' => '',