function testAjaxResponseMessageError() { $message = new PMA_Message("Error Message Text", 1); // TODO: class for output div should be "error" $this->expectOutputString('{"success":false,"error":"<div class=\\"success\\">Error Message Text<\\/div>"}'); PMA_ajaxResponse($message, false); }
/** * Prints details about the current Git commit revision */ function PMA_printGitRevision() { if (!$GLOBALS['PMA_Config']->get('PMA_VERSION_GIT')) { PMA_ajaxResponse('', false); } // load revision data from repo $GLOBALS['PMA_Config']->checkGitRevision(); // if using a remote commit fast-forwarded, link to Github $commit_hash = substr($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH'), 0, 7); $commit_hash = '<strong title="' . htmlspecialchars($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_MESSAGE')) . '">' . $commit_hash . '</strong>'; if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTECOMMIT')) { $commit_hash = '<a href="' . PMA_linkURL('https://github.com/phpmyadmin/phpmyadmin/commit/' . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITHASH')) . '" target="_blank">' . $commit_hash . '</a>'; } $branch = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH'); if ($GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_ISREMOTEBRANCH')) { $branch = '<a href="' . PMA_linkURL('https://github.com/phpmyadmin/phpmyadmin/tree/' . $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_BRANCH')) . '" target="_blank">' . $branch . '</a>'; } if ($branch !== false) { $branch = sprintf(__('%1$s from %2$s branch'), $commit_hash, $branch); } else { $branch = $commit_hash . ' (' . __('no branch') . ')'; } ob_start(); $committer = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_COMMITTER'); $author = $GLOBALS['PMA_Config']->get('PMA_VERSION_GIT_AUTHOR'); PMA_printListItem(__('Git revision') . ': ' . $branch . ',<br /> ' . sprintf(__('committed on %1$s by %2$s'), PMA_localisedDate(strtotime($committer['date'])), '<a href="' . PMA_linkURL('mailto:' . $committer['email']) . '">' . htmlspecialchars($committer['name']) . '</a>') . ($author != $committer ? ', <br />' . sprintf(__('authored on %1$s by %2$s'), PMA_localisedDate(strtotime($author['date'])), '<a href="' . PMA_linkURL('mailto:' . $author['email']) . '">' . htmlspecialchars($author['name']) . '</a>') : ''), 'li_pma_version_git', null, null, null); $item = ob_get_contents(); ob_end_clean(); PMA_ajaxResponse($item, true); }
/** * Send the message as an ajax request * * @param array $change_password_message * @param string $sql_query * * @return void */ function PMA_getChangePassMessage($change_password_message, $sql_query = '') { if ($GLOBALS['is_ajax_request'] == true) { /** * If in an Ajax request, we don't need to show the rest of the page */ if ($change_password_message['error']) { PMA_ajaxResponse($change_password_message['msg'], false); } else { $extra_data['sql_query'] = PMA_showMessage($change_password_message['msg'], $sql_query, 'success'); PMA_ajaxResponse($change_password_message['msg'], true, $extra_data); } } }
/** * This function is called from one of the other functions in this file * and it completes the handling of the export functionality. * * @param string $item_name The name of the item that we are exporting * @param string $export_data The SQL query to create the requested item */ function PMA_RTE_handleExport($item_name, $export_data) { global $db; $item_name = htmlspecialchars(PMA_backquote($_GET['item_name'])); if ($export_data !== false) { $export_data = '<textarea cols="40" rows="15" style="width: 100%;">' . htmlspecialchars(trim($export_data)) . '</textarea>'; $title = sprintf(PMA_RTE_getWord('export'), $item_name); if ($GLOBALS['is_ajax_request'] == true) { $extra_data = array('title' => $title); PMA_ajaxResponse($export_data, true, $extra_data); } else { echo "<fieldset>\n" . "<legend>{$title}</legend>\n" . $export_data . "</fieldset>\n"; } } else { $_db = htmlspecialchars(PMA_backquote($db)); $response = __('Error in Processing Request') . ' : ' . sprintf(PMA_RTE_getWord('not_found'), $item_name, $_db); $response = PMA_message::error($response); if ($GLOBALS['is_ajax_request'] == true) { PMA_ajaxResponse($response, false); } else { $response->display(); } } }
/** * Handles editor requests for adding or editing an item */ function PMA_EVN_handleEditor() { global $_REQUEST, $_POST, $errors, $db; if (!empty($_REQUEST['editor_process_add']) || !empty($_REQUEST['editor_process_edit'])) { $sql_query = ''; $item_query = PMA_EVN_getQueryFromRequest(); if (!count($errors)) { // set by PMA_RTN_getQueryFromRequest() // Execute the created query if (!empty($_REQUEST['editor_process_edit'])) { // Backup the old trigger, in case something goes wrong $create_item = PMA_DBI_get_definition($db, 'EVENT', $_REQUEST['item_original_name']); $drop_item = "DROP EVENT " . PMA_backquote($_REQUEST['item_original_name']) . ";\n"; $result = PMA_DBI_try_query($drop_item); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), $drop_item) . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); } else { $result = PMA_DBI_try_query($item_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), $item_query) . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); // We dropped the old item, but were unable to create the new one // Try to restore the backup query $result = PMA_DBI_try_query($create_item); if (!$result) { // OMG, this is really bad! We dropped the query, failed to create a new one // and now even the backup query does not execute! // This should not happen, but we better handle this just in case. $errors[] = __('Sorry, we failed to restore the dropped event.') . '<br />' . __('The backed up query was:') . "\"{$create_item}\"" . '<br />' . __('MySQL said: ') . PMA_DBI_getError(null); } } else { $message = PMA_Message::success(__('Event %1$s has been modified.')); $message->addParam(PMA_backquote($_REQUEST['item_name'])); $sql_query = $drop_item . $item_query; } } } else { // 'Add a new item' mode $result = PMA_DBI_try_query($item_query); if (!$result) { $errors[] = sprintf(__('The following query has failed: "%s"'), $item_query) . '<br /><br />' . __('MySQL said: ') . PMA_DBI_getError(null); } else { $message = PMA_Message::success(__('Event %1$s has been created.')); $message->addParam(PMA_backquote($_REQUEST['item_name'])); $sql_query = $item_query; } } } if (count($errors)) { $message = PMA_Message::error(__('<b>One or more errors have occured while processing your request:</b>')); $message->addString('<ul>'); foreach ($errors as $string) { $message->addString('<li>' . $string . '</li>'); } $message->addString('</ul>'); } $output = PMA_showMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $extra_data = array(); if ($message->isSuccess()) { $columns = "`EVENT_NAME`, `EVENT_TYPE`, `STATUS`"; $where = "EVENT_SCHEMA='" . PMA_sqlAddSlashes($db) . "' " . "AND EVENT_NAME='" . PMA_sqlAddSlashes($_REQUEST['item_name']) . "'"; $query = "SELECT {$columns} FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE {$where};"; $event = PMA_DBI_fetch_single_row($query); $extra_data['name'] = htmlspecialchars(strtoupper($_REQUEST['item_name'])); $extra_data['new_row'] = PMA_EVN_getRowForList($event); $extra_data['insert'] = !empty($event); $response = $output; } else { $response = $message; } PMA_ajaxResponse($response, $message->isSuccess(), $extra_data); } } /** * Display a form used to add/edit a trigger, if necessary */ if (count($errors) || empty($_REQUEST['editor_process_add']) && empty($_REQUEST['editor_process_edit']) && (!empty($_REQUEST['add_item']) || !empty($_REQUEST['edit_item']) || !empty($_REQUEST['item_changetype']))) { // FIXME: this must be simpler than that $operation = ''; if (!empty($_REQUEST['item_changetype'])) { $operation = 'change'; } // Get the data for the form (if any) if (!empty($_REQUEST['add_item'])) { $title = PMA_RTE_getWord('add'); $item = PMA_EVN_getDataFromRequest(); $mode = 'add'; } else { if (!empty($_REQUEST['edit_item'])) { $title = __("Edit event"); if (!empty($_REQUEST['item_name']) && empty($_REQUEST['editor_process_edit']) && empty($_REQUEST['item_changetype'])) { $item = PMA_EVN_getDataFromName($_REQUEST['item_name']); if ($item !== false) { $item['item_original_name'] = $item['item_name']; } } else { $item = PMA_EVN_getDataFromRequest(); } $mode = 'edit'; } } if ($item !== false) { // Show form $editor = PMA_EVN_getEditorForm($mode, $operation, $item); if ($GLOBALS['is_ajax_request']) { $extra_data = array('title' => $title); PMA_ajaxResponse($editor, true, $extra_data); } else { echo "\n\n<h2>{$title}</h2>\n\n{$editor}"; unset($_POST); include './libraries/footer.inc.php'; } // exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_backquote($db))); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { PMA_ajaxResponse($message, false); } else { $message->display(); } } } }
$result = @PMA_DBI_try_query($local_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, false, $err_url); // Changes password cookie if required // Duration = till the browser is closed for password (we don't want this to be saved) if ($cfg['Server']['auth_type'] == 'cookie') { $GLOBALS['PMA_Config']->setCookie('pmaPass-' . $server, PMA_blowfish_encrypt($password, $GLOBALS['cfg']['blowfish_secret'])); } // end if // For http auth. mode, the "back" link will also enforce new // authentication if ($cfg['Server']['auth_type'] == 'http') { $_url_params['old_usr'] = '******'; } $message = PMA_Message::success(__('The profile has been updated.')); if ($GLOBALS['is_ajax_request'] == true) { $extra_data['sql_query'] = PMA_showMessage($message, $sql_query, 'success'); PMA_ajaxResponse($message, true, $extra_data); } // Displays the page require_once './libraries/header.inc.php'; echo '<h1>' . __('Change password') . '</h1>' . "\n\n"; PMA_showMessage($message, $sql_query, 'success'); ?> <a href="index.php<?php echo PMA_generate_common_url($_url_params); ?> " target="_parent"> <strong><?php echo __('Back'); ?> </strong></a> <?php
} $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php'; // Get the database structure $sub_part = '_structure'; require './libraries/db_info.inc.php'; // Work to do? // (here, do not use $_REQUEST['db] as it can be crafted) if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) { PMA_Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']); /** * If in an Ajax request, generate the success message and use * {@link PMA_ajaxResponse()} to send the output */ if ($GLOBALS['is_ajax_request'] == true) { $message = PMA_Message::success(); PMA_ajaxResponse($message, true); } } // Get tracked data about the database $data = PMA_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_information_schema)) { require './libraries/display_create_table.lib.php'; } // Display the footer require './libraries/footer.inc.php'; exit; } // ---------------------------------------------------------------------------
// avoid a redirect loop when last record was deleted if (0 == $num_rows && 'sql.php' == $cfg['DefaultTabTable']) { $goto = str_replace('sql.php', 'tbl_structure.php', $goto); } PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&', '&', $goto) . '&message=' . urlencode($message)); } // end else exit; } else { //If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here and exit if ($GLOBALS['inline_edit'] == true && $GLOBALS['cfg']['AjaxEnable']) { $row = PMA_DBI_fetch_row($result); $extra_data = array(); $extra_data['value'] = $row[0]; PMA_ajaxResponse(NULL, true, $extra_data); } // Displays the headers if (isset($show_query)) { unset($show_query); } if (isset($printview) && $printview == '1') { require_once './libraries/header_printview.inc.php'; } else { $GLOBALS['js_include'][] = 'functions.js'; $GLOBALS['js_include'][] = 'sql.js'; unset($message); if (!$GLOBALS['is_ajax_request'] || !$GLOBALS['cfg']['AjaxEnable']) { if (strlen($table)) { require './libraries/tbl_common.php'; $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php';
$_type = 'success'; if (empty($_message)) { $_message = $result ? $message = 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 ( $_REQUEST['ajax_request'] == true) { $extra_data['sql_query'] = PMA_showMessage(null, $sql_query); PMA_ajaxResponse($_message, $_message->isSuccess(), $extra_data); } } if (! empty($warning_messages)) { $_message = new PMA_Message; $_message->addMessages($warning_messages); $_message->isError(true); if ( $_REQUEST['ajax_request'] == true) { PMA_ajaxResponse($_message, false); } unset($warning_messages); } PMA_showMessage($_message, $sql_query, $_type); unset($_message, $_type); } $url_params['goto'] = 'tbl_operations.php'; $url_params['back'] = 'tbl_operations.php'; /** * Get columns names */ $columns = PMA_DBI_get_columns($GLOBALS['db'], $GLOBALS['table']);
/** * Displays a MySQL error message in the right frame. * * @param string $error_message the error message * @param string $the_query the sql query that failed * @param bool $is_modify_link whether to show a "modify" link or not * @param string $back_url the "back" link url (full path is not required) * @param bool $exit EXIT the page? * * @global string the curent table * @global string the current db * * @access public */ function PMA_mysqlDie($error_message = '', $the_query = '', $is_modify_link = true, $back_url = '', $exit = true) { global $table, $db; /** * start http output, display html headers */ include_once './libraries/header.inc.php'; $error_msg_output = ''; if (!$error_message) { $error_message = PMA_DBI_getError(); } if (!$the_query && !empty($GLOBALS['sql_query'])) { $the_query = $GLOBALS['sql_query']; } // --- Added to solve bug #641765 if (!function_exists('PMA_SQP_isError') || PMA_SQP_isError()) { $formatted_sql = htmlspecialchars($the_query); } elseif (empty($the_query) || trim($the_query) == '') { $formatted_sql = ''; } else { if (strlen($the_query) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) { $formatted_sql = htmlspecialchars(substr($the_query, 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]'; } else { $formatted_sql = PMA_formatSql(PMA_SQP_parse($the_query), $the_query); } } // --- $error_msg_output .= "\n" . '<!-- PMA-SQL-ERROR -->' . "\n"; $error_msg_output .= ' <div class="error"><h1>' . __('Error') . '</h1>' . "\n"; // if the config password is wrong, or the MySQL server does not // respond, do not show the query that would reveal the // username/password if (!empty($the_query) && !strstr($the_query, 'connect')) { // --- Added to solve bug #641765 if (function_exists('PMA_SQP_isError') && PMA_SQP_isError()) { $error_msg_output .= PMA_SQP_getErrorString() . "\n"; $error_msg_output .= '<br />' . "\n"; } // --- // modified to show the help on sql errors $error_msg_output .= ' <p><strong>' . __('SQL query') . ':</strong>' . "\n"; if (strstr(strtolower($formatted_sql), 'select')) { // please show me help to the error on select $error_msg_output .= PMA_showMySQLDocu('SQL-Syntax', 'SELECT'); } if ($is_modify_link) { $_url_params = array('sql_query' => $the_query, 'show_query' => 1); if (strlen($table)) { $_url_params['db'] = $db; $_url_params['table'] = $table; $doedit_goto = '<a href="tbl_sql.php' . PMA_generate_common_url($_url_params) . '">'; } elseif (strlen($db)) { $_url_params['db'] = $db; $doedit_goto = '<a href="db_sql.php' . PMA_generate_common_url($_url_params) . '">'; } else { $doedit_goto = '<a href="server_sql.php' . PMA_generate_common_url($_url_params) . '">'; } $error_msg_output .= $doedit_goto . PMA_getIcon('b_edit.png', __('Edit')) . '</a>'; } // end if $error_msg_output .= ' </p>' . "\n" . ' <p>' . "\n" . ' ' . $formatted_sql . "\n" . ' </p>' . "\n"; } // end if if (!empty($error_message)) { $error_message = preg_replace("@((\r\n)|(\r)|(\n)){3,}@", "\n\n", $error_message); } // modified to show the help on error-returns // (now error-messages-server) $error_msg_output .= '<p>' . "\n" . ' <strong>' . __('MySQL said: ') . '</strong>' . PMA_showMySQLDocu('Error-messages-server', 'Error-messages-server') . "\n" . '</p>' . "\n"; // The error message will be displayed within a CODE segment. // To preserve original formatting, but allow wordwrapping, // we do a couple of replacements // Replace all non-single blanks with their HTML-counterpart $error_message = str_replace(' ', ' ', $error_message); // Replace TAB-characters with their HTML-counterpart $error_message = str_replace("\t", ' ', $error_message); // Replace linebreaks $error_message = nl2br($error_message); $error_msg_output .= '<code>' . "\n" . $error_message . "\n" . '</code><br />' . "\n"; $error_msg_output .= '</div>'; $_SESSION['Import_message']['message'] = $error_msg_output; if ($exit) { /** * If in an Ajax request * - avoid displaying a Back link * - use PMA_ajaxResponse() to transmit the message and exit */ if ($GLOBALS['is_ajax_request'] == true) { PMA_ajaxResponse($error_msg_output, false); } if (!empty($back_url)) { if (strstr($back_url, '?')) { $back_url .= '&no_history=true'; } else { $back_url .= '?no_history=true'; } $_SESSION['Import_message']['go_back_url'] = $back_url; $error_msg_output .= '<fieldset class="tblFooters">'; $error_msg_output .= '[ <a href="' . $back_url . '">' . __('Back') . '</a> ]'; $error_msg_output .= '</fieldset>' . "\n\n"; } echo $error_msg_output; /** * display footer and exit */ include './libraries/footer.inc.php'; } else { echo $error_msg_output; } }
if (0 == $num_rows && 'sql.php' == $cfg['DefaultTabTable']) { $goto = str_replace('sql.php', 'tbl_structure.php', $goto); } PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&', '&', $goto) . '&message=' . urlencode($message)); } // end else exit(); // end no rows returned } else { // At least one row is returned -> displays a table with results //If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here and exit if ($GLOBALS['grid_edit'] == true && $GLOBALS['cfg']['AjaxEnable']) { $row = PMA_DBI_fetch_row($result); $extra_data = array(); $extra_data['value'] = $row[0]; PMA_ajaxResponse(null, true, $extra_data); } if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['table_maintenance'])) { $GLOBALS['js_include'][] = 'functions.js'; $GLOBALS['js_include'][] = 'makegrid.js'; $GLOBALS['js_include'][] = 'sql.js'; // Gets the list of fields properties if (isset($result) && $result) { $fields_meta = PMA_DBI_get_fields_meta($result); $fields_cnt = count($fields_meta); } if (empty($disp_mode)) { // see the "PMA_setDisplayMode()" function in
} } if (PMA_DBI_try_query($sql_query)) { if ($GLOBALS['is_ajax_request'] != true) { $message = PMA_Message::success(); include './' . $cfg['DefaultTabDatabase']; exit(); } else { PMA_ajaxResponse(PMA_showMessage(PMA_Message::success(), $sql_query), 1); } } else { if ($GLOBALS['is_ajax_request'] != true) { $message = PMA_Message::rawError(PMA_DBI_getError()); } else { PMA_ajaxResponse(PMA_Message::error("<i>$sql_query</i><br /><br />" . PMA_DBI_getError()), 0); } } } // prefill values if not already filled from former submission $view = array( 'or_replace' => '', 'algorithm' => '', 'name' => '', 'column_names' => '', 'as' => $sql_query, 'with' => array(), ); if (PMA_isValid($_REQUEST['view'], 'array')) {
* finish and cleanup navigation.php script execution, only to be used in navigation.php * * @access private */ function PMA_exitNavigationFrame() { echo '</body></html>'; exit; } require_once './libraries/common.lib.php'; require_once './libraries/RecentTable.class.php'; /** * Check if it is an ajax request to reload the recent tables list. */ if ($GLOBALS['is_ajax_request'] && $_REQUEST['recent_table']) { PMA_ajaxResponse('', true, array('options' => PMA_RecentTable::getInstance()->getHtmlSelectOption())); } // keep the offset of the db list in session before closing it if (!isset($_SESSION['tmp_user_values']['navi_limit_offset'])) { $_SESSION['tmp_user_values']['navi_limit_offset'] = 0; } if (!isset($_SESSION['tmp_user_values']['table_limit_offset']) || $_SESSION['tmp_user_values']['table_limit_offset_db'] != $db) { $_SESSION['tmp_user_values']['table_limit_offset'] = 0; $_SESSION['tmp_user_values']['table_limit_offset_db'] = $db; } if (isset($_REQUEST['pos'])) { if (isset($_REQUEST['tpos'])) { $_SESSION['tmp_user_values']['table_limit_offset'] = (int) $_REQUEST['pos']; } else { $_SESSION['tmp_user_values']['navi_limit_offset'] = (int) $_REQUEST['pos']; }
* DB search optimisation * * @package PhpMyAdmin */ require_once 'libraries/common.inc.php'; require_once 'libraries/common.lib.php'; $db = $_GET['db']; $table_term = $_GET['table']; $common_url_query = PMA_generate_common_url($GLOBALS['db']); $tables_full = PMA_getTableList($db); $tables_response = array(); foreach ($tables_full as $key => $table) { if (strpos($key, $table_term) !== false) { $link = '<li class="ajax_table"><a class="tableicon" title="' . htmlspecialchars($link_title) . ': ' . htmlspecialchars($table['Comment']) . ' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . __('Rows') . ')"' . ' id="quick_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"' . ' href="' . $GLOBALS['cfg']['LeftDefaultTabTable'] . '?' . $common_url_query . '&table=' . urlencode($table['Name']) . '&goto=' . $GLOBALS['cfg']['LeftDefaultTabTable'] . '" >'; $attr = array('id' => 'icon_' . htmlspecialchars($table_db . '.' . $table['Name'])); if (PMA_Table::isView($table_db, $table['Name'])) { $link .= PMA_getImage('s_views.png', htmlspecialchars($link_title), $attr); } else { $link .= PMA_getImage('b_browse.png', htmlspecialchars($link_title), $attr); } $link .= '</a>'; // link for the table name itself $href = $GLOBALS['cfg']['DefaultTabTable'] . '?' . $common_url_query . '&table=' . urlencode($table['Name']) . '&pos=0'; $link .= '<a href="' . $href . '" title="' . htmlspecialchars(PMA_getTitleForTarget($GLOBALS['cfg']['DefaultTabTable']) . ': ' . $table['Comment'] . ' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . __('Rows') . ')') . '" id="' . htmlspecialchars($table_db . '.' . $table['Name']) . '">' . str_replace(' ', ' ', htmlspecialchars($table['disp_name'])) . '</a>'; $link .= '</li>' . "\n"; $table['line'] = $link; $tables_response[] = $table; } } PMA_ajaxResponse('', true, array('tables' => $tables_response));
$display_query = $sql_query; $sql_query = ''; // read table info on this newly created table, in case // the next page is Structure $reread_info = true; require './libraries/tbl_info.inc.php'; // do not switch to sql.php - as there is no row to be displayed on a new table if ($cfg['DefaultTabTable'] === 'sql.php') { require './tbl_structure.php'; } else { require './' . $cfg['DefaultTabTable']; } exit; } else { if ($GLOBALS['is_ajax_request'] == true) { PMA_ajaxResponse(PMA_DBI_getError(), false); } else { PMA_mysqlDie('', '', '', $err_url, false); // An error happened while inserting/updating a table definition. // to prevent total loss of that data, we embed the form once again. // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php $num_fields = $_REQUEST['orig_num_fields']; $regenerate = true; } } } // end do create table /** * Displays the form used to define the structure of the table */ // This div is used to show the content(eg: create table form with more columns) fetched with AJAX subsequently.
<div id="gis_data_output"> <h3><?php echo __('Output'); ?> </h3> <p><?php echo __('Chose "GeomFromText" from the "Function" column and paste the below string into the "Value" field'); ?> </p> <textarea id="gis_data_textarea" cols="95" rows="5"> <?php echo $result; ?> </textarea> </div> </div> </form> <?php // If the call is to get the whole content, get the content in the buffer and make and AJAX response. if (isset($_REQUEST['get_gis_editor']) && $_REQUEST['get_gis_editor'] == true) { $extra_data['gis_editor'] = ob_get_contents(); PMA_ajaxResponse(null, ob_end_clean(), $extra_data); } ?> </body> <?php /** * Displays the footer */ require 'libraries/footer.inc.php';
/** * Handles editor requests for adding or editing an item */ 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_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_backquote($_REQUEST['item_name'])); $sql_query = $item_query; } } } if (count($errors)) { $message = PMA_Message::error(__('<b>One or more errors have occured while processing your request:</b>')); $message->addString('<ul>'); foreach ($errors as $string) { $message->addString('<li>' . $string . '</li>'); } $message->addString('</ul>'); } $output = PMA_showMessage($message, $sql_query); if ($GLOBALS['is_ajax_request']) { $extra_data = array(); if ($message->isSuccess()) { $items = PMA_DBI_get_triggers($db, $table, ''); $trigger = false; foreach ($items as $value) { if ($value['name'] == $_REQUEST['item_name']) { $trigger = $value; } } $extra_data['insert'] = false; if (empty($table) || $trigger !== false && $table == $trigger['table']) { $extra_data['insert'] = true; $extra_data['new_row'] = PMA_TRI_getRowForList($trigger); $extra_data['name'] = htmlspecialchars(strtoupper($_REQUEST['item_name'])); } $response = $output; } else { $response = $message; } PMA_ajaxResponse($response, $message->isSuccess(), $extra_data); } } /** * Display a form used to add/edit a trigger, if necessary */ if (count($errors) || empty($_REQUEST['editor_process_add']) && empty($_REQUEST['editor_process_edit']) && (!empty($_REQUEST['add_item']) || !empty($_REQUEST['edit_item']))) { // 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']) { $extra_data = array('title' => $title); PMA_ajaxResponse($editor, true, $extra_data); } else { echo "\n\n<h2>{$title}</h2>\n\n{$editor}"; unset($_POST); include './libraries/footer.inc.php'; } // exit; } else { $message = __('Error in processing request') . ' : '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_backquote($db))); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { PMA_ajaxResponse($message, false); } else { $message->display(); } } } }
/** * Handles requests for executing a routine */ function PMA_RTN_handleExecute() { global $_GET, $_POST, $_REQUEST, $GLOBALS, $db, $cfg; /** * Handle all user requests other than the default of listing routines */ if (!empty($_REQUEST['execute_routine']) && !empty($_REQUEST['item_name'])) { // Build the queries $routine = PMA_RTN_getDataFromName($_REQUEST['item_name'], $_REQUEST['item_type'], false); if ($routine !== false) { $queries = array(); $end_query = array(); $args = array(); for ($i = 0; $i < $routine['item_num_params']; $i++) { if (isset($_REQUEST['params'][$routine['item_param_name'][$i]])) { $value = $_REQUEST['params'][$routine['item_param_name'][$i]]; if (is_array($value)) { // is SET type $value = implode(',', $value); } $value = PMA_sqlAddSlashes($value); if (!empty($_REQUEST['funcs'][$routine['item_param_name'][$i]]) && in_array($_REQUEST['funcs'][$routine['item_param_name'][$i]], $cfg['Functions'])) { $queries[] = "SET @p{$i}={$_REQUEST['funcs'][$routine['item_param_name'][$i]]}('{$value}');\n"; } else { $queries[] = "SET @p{$i}='{$value}';\n"; } $args[] = "@p{$i}"; } else { $args[] = "@p{$i}"; } if ($routine['item_type'] == 'PROCEDURE') { if ($routine['item_param_dir'][$i] == 'OUT' || $routine['item_param_dir'][$i] == 'INOUT') { $end_query[] = "@p{$i} AS " . PMA_backquote($routine['item_param_name'][$i]); } } } if ($routine['item_type'] == 'PROCEDURE') { $queries[] = "CALL " . PMA_backquote($routine['item_name']) . "(" . implode(', ', $args) . ");\n"; if (count($end_query)) { $queries[] = "SELECT " . implode(', ', $end_query) . ";\n"; } } else { $queries[] = "SELECT " . PMA_backquote($routine['item_name']) . "(" . implode(', ', $args) . ") " . "AS " . PMA_backquote($routine['item_name']) . ";\n"; } // Execute the queries $affected = 0; $result = null; $outcome = true; foreach ($queries as $query) { $resource = PMA_DBI_try_query($query); if ($resource === false) { $outcome = false; break; } while (true) { if (!PMA_DBI_more_results()) { break; } PMA_DBI_next_result(); } if (substr($query, 0, 6) == 'SELECT') { $result = $resource; } else { if (substr($query, 0, 4) == 'CALL') { $result = $resource ? $resource : $result; $affected = PMA_DBI_affected_rows() - PMA_DBI_num_rows($resource); } } } // Generate output if ($outcome) { $message = __('Your SQL query has been executed successfully'); if ($routine['item_type'] == 'PROCEDURE') { $message .= '<br />'; $message .= sprintf(_ngettext('%d row affected by the last statement inside the procedure', '%d rows affected by the last statement inside the procedure', $affected), $affected); } $message = PMA_message::success($message); // Pass the SQL queries through the "pretty printer" $output = '<code class="sql" style="margin-bottom: 1em;">'; $output .= PMA_SQP_formatHtml(PMA_SQP_parse(implode($queries))); $output .= '</code>'; // Display results if ($result) { $output .= "<fieldset><legend>"; $output .= sprintf(__('Execution results of routine %s'), PMA_backquote(htmlspecialchars($routine['item_name']))); $output .= "</legend>"; $output .= "<table><tr>"; foreach (PMA_DBI_get_fields_meta($result) as $key => $field) { $output .= "<th>"; $output .= htmlspecialchars($field->name); $output .= "</th>"; } $output .= "</tr>"; // Stored routines can only ever return ONE ROW. $data = PMA_DBI_fetch_single_row($result); foreach ($data as $key => $value) { if ($value === null) { $value = '<i>NULL</i>'; } else { $value = htmlspecialchars($value); } $output .= "<td class='odd'>" . $value . "</td>"; } $output .= "</table></fieldset>"; } else { $notice = __('MySQL returned an empty result set (i.e. zero rows).'); $output .= PMA_message::notice($notice)->getDisplay(); } } else { $output = ''; $message = PMA_message::error(sprintf(__('The following query has failed: "%s"'), $query) . '<br /><br />' . __('MySQL said: ') . PMA_DBI_getError(null)); } // Print/send output if ($GLOBALS['is_ajax_request']) { $extra_data = array('dialog' => false); PMA_ajaxResponse($message->getDisplay() . $output, $message->isSuccess(), $extra_data); } else { echo $message->getDisplay() . $output; if ($message->isError()) { // At least one query has failed, so shouldn't // execute any more queries, so we quit. exit; } unset($_POST); // Now deliberately fall through to displaying the routines list } } else { $message = __('Error in processing request') . ' : '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_backquote($db))); $message = PMA_message::error($message); if ($GLOBALS['is_ajax_request']) { PMA_ajaxResponse($message, $message->isSuccess()); } else { echo $message->getDisplay(); unset($_POST); } } } else { if (!empty($_GET['execute_dialog']) && !empty($_GET['item_name'])) { /** * Display the execute form for a routine. */ $routine = PMA_RTN_getDataFromName($_GET['item_name'], $_GET['item_type'], true); if ($routine !== false) { $form = PMA_RTN_getExecuteForm($routine); if ($GLOBALS['is_ajax_request'] == true) { $extra_data = array(); $extra_data['dialog'] = true; $extra_data['title'] = __("Execute routine") . " "; $extra_data['title'] .= PMA_backquote(htmlentities($_GET['item_name'], ENT_QUOTES)); PMA_ajaxResponse($form, true, $extra_data); } else { echo "\n\n<h2>" . __("Execute routine") . "</h2>\n\n"; echo $form; include './libraries/footer.inc.php'; // exit; } } else { if ($GLOBALS['is_ajax_request'] == true) { $message = __('Error in processing request') . ' : '; $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_backquote($db))); $message = PMA_message::error($message); PMA_ajaxResponse($message, false); } } } } }
foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) { if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) { PMA_REL_renameField($db, $table, $fieldcontent, $_REQUEST['field_name'][$fieldindex]); } } } // update mime types 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]) && strlen($_REQUEST['field_name'][$fieldindex])) { PMA_setMIME($db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype, $_REQUEST['field_transformation'][$fieldindex], $_REQUEST['field_transformation_options'][$fieldindex]); } } } if ($GLOBALS['is_ajax_request'] == true) { PMA_ajaxResponse($message, $message->isSuccess()); } $active_page = 'tbl_structure.php'; require './tbl_structure.php'; } else { PMA_mysqlDie('', '', '', $err_url, false); // An error happened while inserting/updating a table definition. // to prevent total loss of that data, we embed the form once again. // The variable $regenerate will be used to restore data in libraries/tbl_properties.inc.php if (isset($_REQUEST['orig_field'])) { $_REQUEST['field'] = $_REQUEST['orig_field']; } $regenerate = true; } } /**
$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 ... /**
$message = PMA_Message::success(__('Table %1$s has been altered successfully')); $message->addParam($table); if ( $GLOBALS['is_ajax_request'] == true) { $extra_data['index_table'] = PMA_Index::getView($table, $db); $extra_data['sql_query'] = PMA_showMessage(null, $sql_query); PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); } $active_page = 'tbl_structure.php'; include 'tbl_structure.php'; exit; } else { if ( $GLOBALS['is_ajax_request'] == true) { $extra_data['error'] = $error; PMA_ajaxResponse($error, false); } $error->display(); } } // end builds the new index /** * Display the form to edit/create an index */ // Displays headers (if needed) $GLOBALS['js_include'][] = 'indexes.js'; require_once 'libraries/tbl_info.inc.php'; if ($GLOBALS['is_ajax_request'] != true) { include_once 'libraries/tbl_links.inc.php';