Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Dropped PMA_ajaxResponse()

  • Loading branch information...
commit a16e723048940f87b4be4b4097d16c4376826f2c 1 parent 1871e82
Rouslan Placella roccivic authored
Showing with 328 additions and 308 deletions.
  1. +12 −16 db_create.php
  2. +9 −6 db_operations.php
  3. +2 −1  db_tables_search.php
  4. +5 −4 db_tracking.php
  5. +5 −3 gis_data_editor.php
  6. +12 −6 import.php
  7. +1 −4 js/functions.js
  8. +5 −4 js/gis_data_editor.js
  9. +7 −3 js/sql.js
  10. +1 −4 js/tbl_zoom_plot_jqplot.js
  11. +1 −1  libraries/auth/cookie.auth.lib.php
  12. +5 −24 libraries/common.lib.php
  13. +5 −2 libraries/db_common.inc.php
  14. +15 −10 libraries/rte/rte_events.lib.php
  15. +8 −3 libraries/rte/rte_export.lib.php
  16. +38 −28 libraries/rte/rte_routines.lib.php
  17. +21 −12 libraries/rte/rte_triggers.lib.php
  18. +5 −4 navigation.php
  19. +5 −10 prefs_manage.php
  20. +4 −1 server_databases.php
  21. +13 −4 server_privileges.php
  22. +32 −14 sql.php
  23. +5 −3 tbl_addfield.php
  24. +18 −12 tbl_alter.php
  25. +20 −17 tbl_create.php
  26. +15 −11 tbl_indexes.php
  27. +14 −9 tbl_move_copy.php
  28. +11 −5 tbl_operations.php
  29. +6 −1 tbl_replace.php
  30. +13 −12 tbl_zoom_select.php
  31. +0 −71 test/libraries/common/PMA_ajaxResponse_test.php
  32. +15 −3 view_create.php
28 db_create.php
View
@@ -61,12 +61,15 @@
$GLOBALS['table'] = '';
/**
- * If in an Ajax request, just display the message with {@link PMA_ajaxResponse}
+ * If in an Ajax request, just display the message with {@link PMA_Response}
*/
if ($GLOBALS['is_ajax_request'] == true) {
- PMA_ajaxResponse($message, false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $message);
+ } else {
+ include_once 'main.php';
}
- include_once 'main.php';
} else {
$message = PMA_Message::success(__('Database %1$s has been created.'));
$message->addParam($new_db);
@@ -76,14 +79,6 @@
* If in an Ajax request, build the output and send it
*/
if ($GLOBALS['is_ajax_request'] == true) {
-
- /**
- * String containing the SQL Query formatted in pretty HTML
- * @global array $GLOBALS['extra_data']
- * @name $extra_data
- */
- $extra_data['sql_query'] = PMA_getMessage(null, $sql_query, 'success');
-
//Construct the html for the new database, so that it can be appended to
// the list of databases on server_databases.php
@@ -137,11 +132,12 @@
$new_db_string .= '</tr>';
- $extra_data['new_db_string'] = $new_db_string;
-
- PMA_ajaxResponse($message, true, $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $message);
+ $response->addJSON('new_db_string', $new_db_string);
+ $response->addJSON('sql_query', PMA_getMessage(null, $sql_query, 'success'));
+ } else {
+ include_once '' . $cfg['DefaultTabDatabase'];
}
-
- include_once '' . $cfg['DefaultTabDatabase'];
}
?>
15 db_operations.php
View
@@ -340,13 +340,16 @@
/**
* Database has been successfully renamed/moved. If in an Ajax request,
- * generate the output with {@link PMA_ajaxResponse} and exit
+ * generate the output with {@link PMA_Response} and exit
*/
- if ( $GLOBALS['is_ajax_request'] == true) {
- $extra_data['newname'] = $newname;
- $extra_data['sql_query'] = PMA_getMessage(null, $sql_query);
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
- };
+ if ($GLOBALS['is_ajax_request'] == true) {
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ $response->addJSON('newname', $newname);
+ $response->addJSON('sql_query', PMA_getMessage(null, $sql_query));
+ exit;
+ }
}
3  db_tables_search.php
View
@@ -63,5 +63,6 @@
}
}
-PMA_ajaxResponse('', true, array('tables' => $tables_response));
+$response = PMA_Response::getInstance();
+$response->addJSON('tables', $tables_response);
?>
9 db_tracking.php
View
@@ -20,8 +20,8 @@
*/
if ($GLOBALS['is_ajax_request'] != true) {
include 'libraries/db_common.inc.php';
+ $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
}
-$url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
// Get the database structure
$sub_part = '_structure';
@@ -34,11 +34,12 @@
/**
* If in an Ajax request, generate the success message and use
- * {@link PMA_ajaxResponse()} to send the output
+ * {@link PMA_Response()} to send the output
*/
if ($GLOBALS['is_ajax_request'] == true) {
- $message = PMA_Message::success();
- PMA_ajaxResponse($message, true);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', PMA_Message::success());
+ exit;
}
}
8 gis_data_editor.php
View
@@ -62,7 +62,9 @@
'visualization' => $visualization,
'openLayers' => $open_layers,
);
- PMA_ajaxResponse(null, true, $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->addJSON($extra_data);
+ exit;
}
ob_start();
@@ -311,7 +313,7 @@
</form>
<?php
-$extra_data['gis_editor'] = ob_get_contents();
-PMA_ajaxResponse(null, ob_end_clean(), $extra_data);
+PMA_Response::getInstance()->addJSON('gis_editor', ob_get_contents());
+ob_end_clean();
?>
18 import.php
View
@@ -221,10 +221,13 @@
case 1: // bookmarked query that have to be displayed
$import_text = PMA_Bookmark_get($db, $id_bookmark);
if ($GLOBALS['is_ajax_request'] == true) {
- $extra_data['sql_query'] = $import_text;
- $extra_data['action_bookmark'] = $action_bookmark;
$message = PMA_Message::success(__('Showing bookmark'));
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ $response->addJSON('sql_query', $import_text);
+ $response->addJSON('action_bookmark', $action_bookmark);
+ exit;
} else {
$run_query = false;
}
@@ -234,9 +237,12 @@
PMA_Bookmark_delete($db, $id_bookmark);
if ($GLOBALS['is_ajax_request'] == true) {
$message = PMA_Message::success(__('The bookmark has been deleted.'));
- $extra_data['action_bookmark'] = $action_bookmark;
- $extra_data['id_bookmark'] = $id_bookmark;
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ $response->addJSON('action_bookmark', $action_bookmark);
+ $response->addJSON('id_bookmark', $id_bookmark);
+ exit;
} else {
$run_query = false;
$error = true; // this is kind of hack to skip processing the query
5 js/functions.js
View
@@ -2417,10 +2417,7 @@ $(function() {
window.parent.frame_navigation.location.reload();
}
} else {
- var $temp_div = $("<div id='temp_div'></div>");
- $temp_div.html(data.error);
- var $error = $temp_div.find("code").addClass("error");
- PMA_ajaxShowMessage($error, false);
+ PMA_ajaxShowMessage(data.error, false);
}
}); // end $.post()
}
9 js/gis_data_editor.js
View
@@ -142,7 +142,8 @@ function loadGISEditor(value, field, type, input_name, token) {
'type' : type,
'input_name' : input_name,
'get_gis_editor' : true,
- 'token' : token
+ 'token' : token,
+ 'ajax_request': true
}, function(data) {
if (data.success == true) {
$gis_editor.html(data.gis_editor);
@@ -190,7 +191,7 @@ function insertDataAndClose() {
var $form = $('form#gis_data_editor_form');
var input_name = $form.find("input[name='input_name']").val();
- $.post('gis_data_editor.php', $form.serialize() + "&generate=true", function(data) {
+ $.post('gis_data_editor.php', $form.serialize() + "&generate=true&ajax_request=true", function(data) {
if(data.success == true) {
$("input[name='" + input_name + "']").val(data.result);
} else {
@@ -226,7 +227,7 @@ $(function() {
*/
$('#gis_editor').find("input[type='text']").live('change', function() {
var $form = $('form#gis_data_editor_form');
- $.post('gis_data_editor.php', $form.serialize() + "&generate=true", function(data) {
+ $.post('gis_data_editor.php', $form.serialize() + "&generate=true&ajax_request=true", function(data) {
if(data.success == true) {
$('#gis_data_textarea').val(data.result);
$('#placeholder').empty().removeClass('hasSVG').html(data.visualization);
@@ -246,7 +247,7 @@ $(function() {
var $gis_editor = $("#gis_editor");
var $form = $('form#gis_data_editor_form');
- $.post('gis_data_editor.php', $form.serialize() + "&get_gis_editor=true", function(data) {
+ $.post('gis_data_editor.php', $form.serialize() + "&get_gis_editor=true&ajax_request=true", function(data) {
if(data.success == true) {
$gis_editor.html(data.gis_editor);
initGISEditorVisualization();
10 js/sql.js
View
@@ -227,11 +227,15 @@ $(function() {
$sqlqueryresults.show().trigger('makegrid');
$('#togglequerybox').show();
PMA_init_slider();
- if( $('#sqlqueryform input[name="retain_query_box"]').is(':checked') != true ) {
- if ($("#togglequerybox").siblings(":visible").length > 0) {
- $("#togglequerybox").trigger('click');
+
+ if (typeof data.action_bookmark == 'undefined') {
+ if( $('#sqlqueryform input[name="retain_query_box"]').is(':checked') != true ) {
+ if ($("#togglequerybox").siblings(":visible").length > 0) {
+ $("#togglequerybox").trigger('click');
+ }
}
}
+
// this happens if a USE command was typed
if (typeof data.reload != 'undefined') {
// Unbind the submit event before reloading. See bug #3295529
5 js/tbl_zoom_plot_jqplot.js
View
@@ -12,10 +12,7 @@
** Display Help/Info
**/
function displayHelp() {
- var msgbox = PMA_ajaxShowMessage(PMA_messages['strDisplayHelp'], 10000);
- msgbox.click(function() {
- PMA_ajaxRemoveMessage(msgbox);
- });
+ PMA_ajaxShowMessage(PMA_messages['strDisplayHelp'], 10000);
}
/**
2  libraries/auth/cookie.auth.lib.php
View
@@ -136,7 +136,7 @@ function PMA_auth()
if (! empty($conn_error)) {
$response->addJSON('message', $conn_error);
} else {
- $response->addJSON('message', __('Session expired'));
+ $response->addJSON('message', PMA_Message::error(__('Your session has expired. Please login again.')));
}
exit;
}
29 libraries/common.lib.php
View
@@ -679,10 +679,13 @@ function PMA_mysqlDie(
/**
* If in an Ajax request
* - avoid displaying a Back link
- * - use PMA_ajaxResponse() to transmit the message and exit
+ * - use PMA_Response() to transmit the message and exit
*/
if ($GLOBALS['is_ajax_request'] == true) {
- PMA_ajaxResponse($error_msg, false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $error_msg);
+ exit;
}
if (! empty($back_url)) {
if (strstr($back_url, '?')) {
@@ -3245,28 +3248,6 @@ function PMA_expandUserString($string, $escape = null, $updates = array())
}
/**
- * function that generates a json output for an ajax request and ends script
- * execution
- *
- * @param PMA_Message|string $message message string containing the
- * html of the message
- * @param bool $success success whether the ajax request
- * was successfull
- * @param array $extra_data extra data optional - any other data
- * as part of the json request
- *
- * @return void
- */
-function PMA_ajaxResponse($message, $success = true, $extra_data = array())
-{
- $response = PMA_Response::getInstance();
- $response->isSuccess($success);
- $response->addJSON('message', $message);
- $response->addJSON($extra_data);
- exit;
-}
-
-/**
* Display the form used to browse anywhere on the local server for a file to
* import
*
7 libraries/db_common.inc.php
View
@@ -72,8 +72,11 @@
* other pages, we might have to move this to a different location.
*/
if ( $GLOBALS['is_ajax_request'] == true) {
- PMA_ajaxResponse($message, $message->isSuccess());
- };
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ exit;
+ }
}
/**
25 libraries/rte/rte_events.lib.php
View
@@ -148,21 +148,22 @@ function PMA_EVN_handleEditor()
$output = PMA_getMessage($message, $sql_query);
if ($GLOBALS['is_ajax_request']) {
- $extra_data = array();
+ $response = PMA_Response::getInstance();
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;
+ $response->addJSON('name', htmlspecialchars(strtoupper($_REQUEST['item_name'])));
+ $response->addJSON('new_row', PMA_EVN_getRowForList($event));
+ $response->addJSON('insert', ! empty($event));
+ $response->addJSON('message', $output);
} else {
- $response = $message;
+ $response->isSuccess(false);
+ $response->addJSON('message', $message);
}
- PMA_ajaxResponse($response, $message->isSuccess(), $extra_data);
+ exit;
}
}
/**
@@ -200,8 +201,9 @@ function PMA_EVN_handleEditor()
// 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);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $editor);
+ $response->addJSON('title', $title);
} else {
echo "\n\n<h2>$title</h2>\n\n$editor";
unset($_POST);
@@ -216,7 +218,10 @@ function PMA_EVN_handleEditor()
);
$message = PMA_message::error($message);
if ($GLOBALS['is_ajax_request']) {
- PMA_ajaxResponse($message, false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $message);
+ exit;
} else {
$message->display();
}
11 libraries/rte/rte_export.lib.php
View
@@ -26,8 +26,10 @@ function PMA_RTE_handleExport($item_name, $export_data)
. 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);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $export_data);
+ $response->addJSON('title', $title);
+ exit;
} else {
echo "<fieldset>\n"
. "<legend>$title</legend>\n"
@@ -40,7 +42,10 @@ function PMA_RTE_handleExport($item_name, $export_data)
. sprintf(PMA_RTE_getWord('not_found'), $item_name, $_db);
$response = PMA_message::error($response);
if ($GLOBALS['is_ajax_request'] == true) {
- PMA_ajaxResponse($response, false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $response);
+ exit;
} else {
$response->display();
}
66 libraries/rte/rte_routines.lib.php
View
@@ -301,21 +301,22 @@ function PMA_RTN_handleEditor()
$output = PMA_getMessage($message, $sql_query);
if ($GLOBALS['is_ajax_request']) {
- $extra_data = array();
+ $response = PMA_Response::getInstance();
if ($message->isSuccess()) {
$columns = "`SPECIFIC_NAME`, `ROUTINE_NAME`, `ROUTINE_TYPE`, `DTD_IDENTIFIER`, `ROUTINE_DEFINITION`";
$where = "ROUTINE_SCHEMA='" . PMA_sqlAddSlashes($db) . "' "
. "AND ROUTINE_NAME='" . PMA_sqlAddSlashes($_REQUEST['item_name']) . "'"
. "AND ROUTINE_TYPE='" . PMA_sqlAddSlashes($_REQUEST['item_type']) . "'";
$routine = PMA_DBI_fetch_single_row("SELECT $columns FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE $where;");
- $extra_data['name'] = htmlspecialchars(strtoupper($_REQUEST['item_name']));
- $extra_data['new_row'] = PMA_RTN_getRowForList($routine);
- $extra_data['insert'] = ! empty($routine);
- $response = $output;
+ $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 = $message;
+ $response->isSuccess(false);
+ $response->addJSON('message', $output);
}
- PMA_ajaxResponse($response, $message->isSuccess(), $extra_data);
+ exit;
}
}
@@ -359,13 +360,14 @@ function PMA_RTN_handleEditor()
// Show form
$editor = PMA_RTN_getEditorForm($mode, $operation, $routine);
if ($GLOBALS['is_ajax_request']) {
- $template = PMA_RTN_getParameterRow();
- $extra_data = array('title' => $title,
- 'param_template' => $template,
- 'type' => $routine['item_type']);
- PMA_ajaxResponse($editor, true, $extra_data);
+ $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";
}
- echo "\n\n<h2>$title</h2>\n\n$editor";
exit;
} else {
$message = __('Error in processing request') . ' : ';
@@ -376,7 +378,9 @@ function PMA_RTN_handleEditor()
);
$message = PMA_message::error($message);
if ($GLOBALS['is_ajax_request']) {
- PMA_ajaxResponse($message, false);
+ $response->isSuccess(false);
+ $response->addJSON('message', $message);
+ exit;
} else {
$message->display();
}
@@ -1267,12 +1271,11 @@ function PMA_RTN_handleExecute()
}
// Print/send output
if ($GLOBALS['is_ajax_request']) {
- $extra_data = array('dialog' => false);
- PMA_ajaxResponse(
- $message->getDisplay() . $output,
- $message->isSuccess(),
- $extra_data
- );
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message->getDisplay() . $output);
+ $response->addJSON('dialog', false);
+ exit;
} else {
echo $message->getDisplay() . $output;
if ($message->isError()) {
@@ -1292,7 +1295,10 @@ function PMA_RTN_handleExecute()
);
$message = PMA_message::error($message);
if ($GLOBALS['is_ajax_request']) {
- PMA_ajaxResponse($message, $message->isSuccess());
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $message);
+ exit;
} else {
echo $message->getDisplay();
unset($_POST);
@@ -1306,18 +1312,18 @@ function PMA_RTN_handleExecute()
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(
+ $title = __("Execute routine") . " " . PMA_backquote(
htmlentities($_GET['item_name'], ENT_QUOTES)
);
- PMA_ajaxResponse($form, true, $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $form);
+ $response->addJSON('title', $title);
+ $response->addJSON('dialog', true);
} else {
echo "\n\n<h2>" . __("Execute routine") . "</h2>\n\n";
echo $form;
- exit;
}
+ exit;
} else if (($GLOBALS['is_ajax_request'] == true)) {
$message = __('Error in processing request') . ' : ';
$message .= sprintf(
@@ -1326,7 +1332,11 @@ function PMA_RTN_handleExecute()
htmlspecialchars(PMA_backquote($db))
);
$message = PMA_message::error($message);
- PMA_ajaxResponse($message, false);
+
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $message);
+ exit;
}
}
}
33 libraries/rte/rte_triggers.lib.php
View
@@ -121,7 +121,7 @@ function PMA_TRI_handleEditor()
$output = PMA_getMessage($message, $sql_query);
if ($GLOBALS['is_ajax_request']) {
- $extra_data = array();
+ $response = PMA_Response::getInstance();
if ($message->isSuccess()) {
$items = PMA_DBI_get_triggers($db, $table, '');
$trigger = false;
@@ -130,19 +130,24 @@ function PMA_TRI_handleEditor()
$trigger = $value;
}
}
- $extra_data['insert'] = false;
+ $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'])
+ $insert = true;
+ $response->addJSON('new_row', PMA_TRI_getRowForList($trigger));
+ $response->addJSON(
+ 'name',
+ htmlspecialchars(
+ strtoupper($_REQUEST['item_name'])
+ )
);
}
- $response = $output;
+ $response->addJSON('insert', $insert);
+ $response->addJSON('message', $output);
} else {
- $response = $message;
+ $response->addJSON('message', $message);
+ $response->isSuccess(false);
}
- PMA_ajaxResponse($response, $message->isSuccess(), $extra_data);
+ exit;
}
}
@@ -175,8 +180,9 @@ function PMA_TRI_handleEditor()
// Show form
$editor = PMA_TRI_getEditorForm($mode, $item);
if ($GLOBALS['is_ajax_request']) {
- $extra_data = array('title' => $title);
- PMA_ajaxResponse($editor, true, $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $editor);
+ $response->addJSON('title', $title);
} else {
echo "\n\n<h2>$title</h2>\n\n$editor";
unset($_POST);
@@ -191,7 +197,10 @@ function PMA_TRI_handleEditor()
);
$message = PMA_message::error($message);
if ($GLOBALS['is_ajax_request']) {
- PMA_ajaxResponse($message, false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $message);
+ exit;
} else {
$message->display();
}
9 navigation.php
View
@@ -29,11 +29,12 @@ function PMA_exitNavigationFrame()
* 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())
+ $response = PMA_Response::getInstance();
+ $response->addJSON(
+ 'options',
+ PMA_RecentTable::getInstance()->getHtmlSelectOption()
);
+ exit;
}
// keep the offset of the db list in session before closing it
15 prefs_manage.php
View
@@ -28,18 +28,13 @@
PMA_downloadHeader($filename, 'application/json');
$settings = PMA_load_userprefs();
echo json_encode($settings['config_data']);
- return;
+ exit;
} else if (isset($_POST['submit_get_json'])) {
$settings = PMA_load_userprefs();
- PMA_ajaxResponse(
- '',
- true,
- array(
- 'prefs' => json_encode($settings['config_data']),
- 'mtime' => $settings['mtime']
- )
- );
- return;
+ $response = PMA_Response::getInstance();
+ $response->addJSON('prefs', json_encode($settings['config_data']));
+ $response->addJSON('mtime', $settings['mtime']);
+ exit;
} else if (isset($_POST['submit_import'])) {
// load from JSON file
$json = '';
5 server_databases.php
View
@@ -117,7 +117,10 @@
}
}
if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message) {
- PMA_ajaxResponse($message, $message->isSuccess());
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ exit;
}
}
17 server_privileges.php
View
@@ -1643,7 +1643,11 @@ function PMA_getGrants($user, $host)
}
if ($message instanceof PMA_Message) {
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ $response->addJSON($extra_data);
+ exit;
}
}
@@ -1705,7 +1709,10 @@ function PMA_getGrants($user, $host)
$response .= '</textarea>';
unset($username, $hostname, $grants, $one_grant);
if ($GLOBALS['is_ajax_request']) {
- PMA_ajaxResponse($response, 1, array('title' => $title));
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $response);
+ $response->addJSON('title', $title);
+ exit;
} else {
echo "<h2>$title</h2>$response";
}
@@ -2568,9 +2575,11 @@ function PMA_getGrants($user, $host)
. '</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);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $message);
+ $response->addJSON('user_form', $user_form);
+ exit;
} else {
// Offer to create a new user for the current database
$user_form .= '<fieldset id="fieldset_add_user">' . "\n"
46 sql.php
View
@@ -146,8 +146,9 @@
$dropdown = '<select>' . $dropdown . '</select>';
}
- $extra_data['dropdown'] = $dropdown;
- PMA_ajaxResponse(null, true, $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('dropdown', $dropdown);
+ exit;
}
/**
@@ -173,8 +174,9 @@
$dropdown = '<select>' . $dropdown . '</select>';
- $extra_data['dropdown'] = $dropdown;
- PMA_ajaxResponse(null, true, $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('dropdown', $dropdown);
+ exit;
}
/**
@@ -201,8 +203,9 @@
$select_size = (sizeof($values) > 10) ? 10 : sizeof($values);
$select = '<select multiple="multiple" size="' . $select_size . '">' . $select . '</select>';
- $extra_data['select'] = $select;
- PMA_ajaxResponse(null, true, $extra_data);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('select', $select);
+ exit;
}
/**
@@ -220,7 +223,10 @@
$_REQUEST['table_create_time']
);
if (gettype($retval) != 'boolean') {
- PMA_ajaxResponse($retval->getString(), false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $retval->getString());
+ exit;
}
}
@@ -232,11 +238,16 @@
$_REQUEST['table_create_time']
);
if (gettype($retval) != 'boolean') {
- PMA_ajaxResponse($retval->getString(), false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $retval->getString());
+ exit;
}
}
- PMA_ajaxResponse(null, ($retval == true));
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($retval == true);
+ exit;
}
// Default to browse if no query set and we have table
@@ -572,7 +583,10 @@
$message = PMA_Message::rawError($error);
if ($GLOBALS['is_ajax_request'] == true) {
- PMA_ajaxResponse($message, false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $message);
+ exit;
}
/**
@@ -820,7 +834,11 @@
$extra_data['reload'] = 1;
$extra_data['db'] = $GLOBALS['db'];
}
- PMA_ajaxResponse($message, $message->isSuccess(), (isset($extra_data) ? $extra_data : array()));
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ $response->addJSON(isset($extra_data) ? $extra_data : array());
+ exit;
}
if ($is_gotofile) {
@@ -863,9 +881,9 @@
// 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);
+ $response = PMA_Response::getInstance();
+ $response->addJSON('value', $row[0]);
+ exit;
}
if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['table_maintenance'])) {
8 tbl_addfield.php
View
@@ -188,9 +188,11 @@
$message = PMA_Message::success(__('Table %1$s has been altered successfully'));
$message->addParam($table);
- if ( $GLOBALS['is_ajax_request'] == true) {
- $extra_data['sql_query'] = PMA_getMessage(null, $sql_query);
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
+ if ($GLOBALS['is_ajax_request'] == true) {
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $message);
+ $response->addJSON('sql_query', PMA_getMessage(null, $sql_query));
+ exit;
}
$active_page = 'tbl_structure.php';
30 tbl_alter.php
View
@@ -113,8 +113,10 @@
// insert moved column
array_splice($column_names, $i, 0, $column);
}
+ $response = PMA_Response::getInstance();
if (empty($changes)) { // should never happen
- PMA_ajaxResponse('', true);
+ $response->isSuccess(false);
+ exit;
}
$move_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ';
$move_query .= implode(', ', $changes);
@@ -122,15 +124,16 @@
$result = PMA_DBI_try_query($move_query);
$tmp_error = PMA_DBI_getError();
if ($tmp_error) {
- PMA_ajaxResponse(PMA_Message::error($tmp_error), false);
+ $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);
}
- PMA_ajaxResponse(
- PMA_Message::success(__('The columns have been moved successfully.')),
- true,
- array(
- 'columns' => $column_names
- )
- );
+ exit;
}
/**
@@ -249,9 +252,12 @@
}
}
- if ( $_REQUEST['ajax_request'] == true) {
- $extra_data['sql_query'] = PMA_getMessage(null, $sql_query);
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
+ if ($_REQUEST['ajax_request'] == true) {
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ $response->addJSON('sql_query', PMA_getMessage(null, $sql_query));
+ exit;
}
$active_page = 'tbl_structure.php';
37 tbl_create.php
View
@@ -320,29 +320,31 @@
$new_table_string .= '</tr>' . "\n";
- $extra_data['new_table_string'] = $new_table_string;
-
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
- }
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $message);
+ $response->addJSON('new_table_string', $new_table_string);
+ } else {
- $display_query = $sql_query;
- $sql_query = '';
+ $display_query = $sql_query;
+ $sql_query = '';
- // read table info on this newly created table, in case
- // the next page is Structure
- $reread_info = true;
- include 'libraries/tbl_info.inc.php';
+ // read table info on this newly created table, in case
+ // the next page is Structure
+ $reread_info = true;
+ include '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') {
- include 'tbl_structure.php';
- } else {
- include '' . $cfg['DefaultTabTable'];
+ // do not switch to sql.php - as there is no row to be displayed on a new table
+ if ($cfg['DefaultTabTable'] === 'sql.php') {
+ include 'tbl_structure.php';
+ } else {
+ include '' . $cfg['DefaultTabTable'];
+ }
}
- exit;
} else {
if ($GLOBALS['is_ajax_request'] == true) {
- PMA_ajaxResponse(PMA_DBI_getError(), false);
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', PMA_DBI_getError());
} else {
PMA_mysqlDie('', '', '', $err_url, false);
// An error happened while inserting/updating a table definition.
@@ -352,6 +354,7 @@
$regenerate = true;
}
}
+ exit;
} // end do create table
/**
26 tbl_indexes.php
View
@@ -105,21 +105,25 @@
'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_getMessage(null, $sql_query);
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
+ 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_getMessage(null, $sql_query));
+ } else {
+ $active_page = 'tbl_structure.php';
+ include 'tbl_structure.php';
}
-
- $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);
+ if ($GLOBALS['is_ajax_request'] == true) {
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $error);
+ exit;
+ } else {
+ $error->display();
}
- $error->display();
}
} // end builds the new index
23 tbl_move_copy.php
View
@@ -64,16 +64,9 @@
/* 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'];
+ $db = $_REQUEST['target_db'];
+ $table = $_REQUEST['new_name'];
}
-
- if ( $_REQUEST['ajax_request'] == true) {
- $extra_data['sql_query'] = PMA_getMessage(null, $sql_query);
- $extra_data['db'] = $GLOBALS['db'];
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
- }
-
$reload = 1;
}
} else {
@@ -84,6 +77,18 @@
$result = false;
}
+if ($GLOBALS['is_ajax_request'] == true) {
+ $response = PMA_Response::getInstance();
+ $response->addJSON('message', $message);
+ if ($message->isSuccess()) {
+ $response->addJSON('db', $GLOBALS['db']);
+ $response->addJSON('sql_query', PMA_getMessage(null, $sql_query));
+ } else {
+ $response->isSuccess(false);
+ }
+ exit;
+}
+
/**
* Back to the calling script
*/
16 tbl_operations.php
View
@@ -231,17 +231,23 @@
$_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 (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
- $extra_data['sql_query'] = PMA_getMessage(null, $sql_query);
- PMA_ajaxResponse($_message, $_message->isSuccess(), $extra_data);
+ if ($GLOBALS['ajax_request'] == true) {
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($_message->isSuccess());
+ $response->addJSON('message', $_message);
+ $response->addJSON('sql_query', PMA_getMessage(null, $sql_query));
+ exit;
}
}
if (! empty($warning_messages)) {
$_message = new PMA_Message;
$_message->addMessages($warning_messages);
$_message->isError(true);
- if ( $_REQUEST['ajax_request'] == true) {
- PMA_ajaxResponse($_message, false);
+ if ($GLOBALS['ajax_request'] == true) {
+ $response = PMA_Response::getInstance();
+ $response->isSuccess(false);
+ $response->addJSON('message', $_message);
+ exit;
}
unset($warning_messages);
}
7 tbl_replace.php
View
@@ -421,7 +421,12 @@
/**Get the total row count of the table*/
$extra_data['row_count'] = PMA_Table::countRecords($_REQUEST['db'], $_REQUEST['table']);
$extra_data['sql_query'] = PMA_getMessage($message, $GLOBALS['display_query']);
- PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
+
+ $response = PMA_Response::getInstance();
+ $response->isSuccess($message->isSuccess());
+ $response->addJSON('message', $message);
+ $response->addJSON($extra_data);
+ exit;
}
if (isset($return_to_sql_query)) {
25 tbl_zoom_select.php
View
@@ -72,7 +72,8 @@
}
$extra_data['row_info'] = $row;
}
- PMA_ajaxResponse(null, true, $extra_data);
+ PMA_Response::getInstance()->addJSON($extra_data);
+ exit;
}
/**
@@ -82,14 +83,14 @@
*/
if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
- $extra_data = array();
+ $response = PMA_Response::getInstance();
$field = $_REQUEST['field'];
if ($field == 'pma_null') {
- $extra_data['field_type'] = '';
- $extra_data['field_collation'] = '';
- $extra_data['field_operators'] = '';
- $extra_data['field_value'] = '';
- PMA_ajaxResponse(null, true, $extra_data);
+ $response->addJSON('field_type', '');
+ $response->addJSON('field_collation', '');
+ $response->addJSON('field_operators', '');
+ $response->addJSON('field_value', '');
+ exit;
}
// Gets the list and number of fields
list($columnNames, $columnTypes, $columnCollations, $columnNullFlags)
@@ -100,11 +101,11 @@
$db, $table, $columnNames, $columnTypes, $columnCollations,
$columnNullFlags, $foreigners, $_REQUEST['it'], $key
);
- $extra_data['field_type'] = $properties['type'];
- $extra_data['field_collation'] = $properties['collation'];
- $extra_data['field_operators'] = $properties['func'];
- $extra_data['field_value'] = $properties['value'];
- PMA_ajaxResponse(null, true, $extra_data);
+ $response->addJSON('field_type', $properties['type']);
+ $response->addJSON('field_collation', $properties['collation']);
+ $response->addJSON('field_operators', $properties['func']);
+ $response->addJSON('field_value', $properties['value']);
+ exit;
}
$titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values'));
71 test/libraries/common/PMA_ajaxResponse_test.php
View
@@ -1,71 +0,0 @@
-<?php
-/* vim: set expandtab sw=4 ts=4 sts=4: */
-/**
- * Test for PMA_ajaxResponse from common.lib.php
- *
- * @package PhpMyAdmin-test
- * @group common.lib-tests
- */
-
-/*
- * Include to test.
- */
-require_once 'libraries/common.lib.php';
-require_once 'libraries/Message.class.php';
-
-class PMA_ajaxResponse_test extends PHPUnit_Framework_TestCase
-{
- function testAjaxResponseText()
- {
- $message = 'text';
-
- $this->expectOutputString('{"success":true,"message":"' . $message . '"}');
- PMA_ajaxResponse($message);
- }
-
- function testAjaxResponseTextWithExtra()
- {
- $message = 'text';
- $exra = array('str_val' => 'te\x/t"1', 'int_val' => 10);
-
- $this->expectOutputString('{"success":true,"message":"' . $message . '","str_val":"te\\\\x\/t\"1","int_val":10}');
- PMA_ajaxResponse($message, true, $exra);
- }
-
- function testAjaxResponseTextError()
- {
- $message = 'error_text';
-
- $this->expectOutputString('{"success":false,"error":"' . $message . '"}');
- PMA_ajaxResponse($message, false);
- }
-
- function testAjaxResponseMessage()
- {
- $message = new PMA_Message("Message Text", 1);
-
- $this->expectOutputString('{"success":true,"message":"<div class=\"success\">Message Text<\/div>"}');
- PMA_ajaxResponse($message);
- }
-
- function testAjaxResponseMessageWithExtra()
- {
-
- $message = new PMA_Message("Message Text", 1);
- $exra = array('str_val' => 'te\x/t"1', 'int_val' => 10);
-
- $this->expectOutputString('{"success":true,"message":"<div class=\"success\">Message Text<\/div>","str_val":"te\\\\x\/t\"1","int_val":10}');
- PMA_ajaxResponse($message, true, $exra);
- }
-
- 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);
- }
-
-}
18 view_create.php
View
@@ -66,15 +66,27 @@
if ($GLOBALS['is_ajax_request'] != true) {
$message = PMA_Message::success();
include './' . $cfg['DefaultTabDatabase'];
- exit();
} else {
- PMA_ajaxResponse(PMA_getMessage(PMA_Message::success(), $sql_query), 1);
+ $response = PMA_Response::getInstance();
+ $response->addJSON(
+ 'message',
+ PMA_getMessage(PMA_Message::success(), $sql_query)
+ );
}
+ exit;
} 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);
+ $response = PMA_Response::getInstance();
+ $response->addJSON(
+ 'message',
+ PMA_Message::error(
+ "<i>$sql_query</i><br /><br />" . PMA_DBI_getError()
+ )
+ );
+ $response->isSuccess(false);
+ exit;
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.