make use of PMA_Message

This commit is contained in:
Sebastian Mendel
2007-10-16 12:14:19 +00:00
parent 86acb749a4
commit 107fc46ad9
14 changed files with 103 additions and 91 deletions

View File

@@ -35,14 +35,18 @@ $sql_query .= ';';
$result = PMA_DBI_try_query($sql_query);
if (! $result) {
$message = PMA_DBI_getError();
$message = PMA_Message::rawError(PMA_DBI_getError());
// avoid displaying the not-created db name in header or navi panel
$GLOBALS['db'] = '';
$GLOBALS['table'] = '';
require_once './libraries/header.inc.php';
require_once './main.php';
} else {
$message = $strDatabase . ' ' . htmlspecialchars($db) . ' ' . $strHasBeenCreated;
$message = PMA_Message::success();
$message->setMessage($strDatabase . ' ' . htmlspecialchars($db) . ' ' . $strHasBeenCreated);
//$message = PMA_Message::success('strDatabaseHasBeenCreated');
//$message->addParam($db);
require_once './libraries/header.inc.php';
require_once './' . $cfg['DefaultTabDatabase'];
}

View File

@@ -58,7 +58,7 @@ if (empty($_REQUEST['asfile'])) {
// Does export require to be into file?
if (isset($export_list[$type]['force_file']) && ! $asfile) {
$message = new PMA_Message('strExportMustBeFile', PMA_Message::ERROR);
$message = PMA_Message::error('strExportMustBeFile');
$GLOBALS['js_include'][] = 'functions.js';
require_once './libraries/header.inc.php';
if ($export_type == 'server') {
@@ -300,16 +300,16 @@ if ($save_on_server) {
$save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
unset($message);
if (file_exists($save_filename) && empty($onserverover)) {
$message = new PMA_Message('strFileAlreadyExists', PMA_Message::ERROR, $save_filename);
$GLOBALS['show_error_header'] = true;
$message = PMA_Message::error('strFileAlreadyExists');
$message->addParam($save_filename);
} else {
if (is_file($save_filename) && !is_writable($save_filename)) {
$message = new PMA_Message('strNoPermission', PMA_Message::ERROR, $save_filename);
$GLOBALS['show_error_header'] = true;
$message = PMA_Message::error('strNoPermission');
$message->addParam($save_filename);
} else {
if (!$file_handle = @fopen($save_filename, 'w')) {
$message = new PMA_Message('strNoPermission', PMA_Message::ERROR, $save_filename);
$GLOBALS['show_error_header'] = true;
$message = PMA_Message::error('strNoPermission');
$message->addParam($save_filename);
}
}
}
@@ -360,7 +360,7 @@ if (!$save_on_server) {
if ($export_type == 'database') {
$num_tables = count($tables);
if ($num_tables == 0) {
$message = new PMA_Message('strNoTablesFound', PMA_Message::ERROR);
$message = PMA_Message::error('strNoTablesFound');
$GLOBALS['js_include'][] = 'functions.js';
require_once './libraries/header.inc.php';
$active_page = 'db_export.php';

View File

@@ -251,8 +251,7 @@ if ($import_file != 'none' && !$error) {
// Handle file compression
$compression = PMA_detectCompression($import_file);
if ($compression === FALSE) {
$message = $strFileCouldNotBeRead;
$show_error_header = TRUE;
$message = PMA_Message::error('strFileCouldNotBeRead');
$error = TRUE;
} else {
switch ($compression) {
@@ -260,8 +259,8 @@ if ($import_file != 'none' && !$error) {
if ($cfg['BZipDump'] && @function_exists('bzopen')) {
$import_handle = @bzopen($import_file, 'r');
} else {
$message = sprintf($strUnsupportedCompressionDetected, $compression);
$show_error_header = TRUE;
$message = PMA_Message::error('strUnsupportedCompressionDetected');
$message->addParam($compression);
$error = TRUE;
}
break;
@@ -269,8 +268,8 @@ if ($import_file != 'none' && !$error) {
if ($cfg['GZipDump'] && @function_exists('gzopen')) {
$import_handle = @gzopen($import_file, 'r');
} else {
$message = sprintf($strUnsupportedCompressionDetected, $compression);
$show_error_header = TRUE;
$message = PMA_Message::error('strUnsupportedCompressionDetected');
$message->addParam($compression);
$error = TRUE;
}
break;
@@ -280,12 +279,10 @@ if ($import_file != 'none' && !$error) {
$import_handle = new SimpleUnzip();
$import_handle->ReadFile($import_file);
if ($import_handle->Count() == 0) {
$message = $strNoFilesFoundInZip;
$show_error_header = TRUE;
$message = PMA_Message::error('strNoFilesFoundInZip');
$error = TRUE;
} elseif ($import_handle->GetError(0) != 0) {
$message = $strErrorInZipFile . ' ' . $import_handle->GetErrorMsg(0);
$show_error_header = TRUE;
$message = PMA_Message::rawError($strErrorInZipFile . ' ' . $import_handle->GetErrorMsg(0));
$error = TRUE;
} else {
$import_text = $import_handle->GetData(0);
@@ -293,8 +290,8 @@ if ($import_file != 'none' && !$error) {
// We don't need to store it further
$import_handle = '';
} else {
$message = sprintf($strUnsupportedCompressionDetected, $compression);
$show_error_header = TRUE;
$message = PMA_Message::error('strUnsupportedCompressionDetected');
$message->addParam($compression);
$error = TRUE;
}
break;
@@ -302,21 +299,19 @@ if ($import_file != 'none' && !$error) {
$import_handle = @fopen($import_file, 'r');
break;
default:
$message = sprintf($strUnsupportedCompressionDetected, $compression);
$show_error_header = TRUE;
$message = PMA_Message::error('strUnsupportedCompressionDetected');
$message->addParam($compression);
$error = TRUE;
break;
}
}
if (!$error && $import_handle === FALSE) {
$message = $strFileCouldNotBeRead;
$show_error_header = TRUE;
$message = PMA_Message::error('strFileCouldNotBeRead');
$error = TRUE;
}
} elseif (!$error) {
if (!isset($import_text) || empty($import_text)) {
$message = $strNoDataReceived;
$show_error_header = TRUE;
$message = PMA_Message::error('strNoDataReceived');
$error = TRUE;
}
}
@@ -349,8 +344,7 @@ if (!$error) {
// Check for file existance
if (!file_exists('./libraries/import/' . $format . '.php')) {
$error = TRUE;
$message = $strCanNotLoadImportPlugins;
$show_error_header = TRUE;
$message = PMA_Message::error('strCanNotLoadImportPlugins');
} else {
// Do the real import
$plugin_param = $import_type;
@@ -371,26 +365,27 @@ if ($reset_charset) {
// Show correct message
if (!empty($id_bookmark) && $action_bookmark == 2) {
$message = $strBookmarkDeleted;
$message = PMA_Message::success('strBookmarkDeleted');
$display_query = $import_text;
$error = FALSE; // unset error marker, it was used just to skip processing
} elseif (!empty($id_bookmark) && $action_bookmark == 1) {
$message = $strShowingBookmark;
$message = PMA_Message::notice('strShowingBookmark');
} elseif ($bookmark_created) {
$special_message = '[br]' . sprintf($strBookmarkCreated, htmlspecialchars($bkm_label));
} elseif ($finished && !$error) {
if ($import_type == 'query') {
$message = $strSuccess;
$message = PMA_Message::success();
} else {
$message = sprintf($strImportSuccessfullyFinished, $executed_queries);
$message = PMA_Message::success('strImportSuccessfullyFinished');
$message->addParam($executed_queries);
}
}
// Did we hit timeout? Tell it user.
if ($timeout_passed) {
$message = $strTimeoutPassed;
$message = PMA_Message::error('strTimeoutPassed');
if ($offset == 0 || (isset($original_skip) && $original_skip == $offset)) {
$message .= ' ' . $strTimeoutNothingParsed;
$message->addString('strTimeoutNothingParsed');
}
}

View File

@@ -47,7 +47,7 @@ if (isset($_REQUEST['drop_selected_dbs_x'])) {
if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
&& ($is_superuser || $cfg['AllowUserDropDatabase'])) {
if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
$message = $strNoDatabasesSelected;
$message = PMA_Message::error('strNoDatabasesSelected');
} else {
$action = 'server_databases.php';
$submit_mult = 'drop_db' ;
@@ -58,7 +58,7 @@ if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
require './libraries/mult_submits.inc.php';
unset($action, $submit_mult, $err_url, $selected_db);
if (empty($message)) {
$message = new PMA_Message('strDatabasesDropped');
$message = PMA_Message::success('strDatabasesDropped');
if ($mult_btn == $strYes) {
$message->addParam(count($selected));
} else {

View File

@@ -70,8 +70,7 @@ if (!$is_superuser) {
. PMA_getIcon('b_usrlist.png')
. $GLOBALS['strPrivileges'] . "\n"
. '</h2>' . "\n";
$message = new PMA_Message('strNoPrivileges', PMA_Message::ERROR);
$message->display();
PMA_Message::error('strNoPrivileges')->display();
require_once './libraries/footer.inc.php';
}
@@ -815,7 +814,7 @@ if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) {
. " WHERE `User` = '" . PMA_sqlAddslashes($username) . "'"
. " AND `Host` = '" . PMA_sqlAddslashes($hostname) . "';";
if (PMA_DBI_fetch_value($sql) == 1) {
$message = new PMA_Message('strUserAlreadyExists', PMA_Message::ERROR);
$message = PMA_Message::error('strUserAlreadyExists');
$message->addParam('[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]');
$_REQUEST['adduser'] = true;
} else {
@@ -1200,7 +1199,7 @@ if (isset($_REQUEST['delete']) || (isset($_REQUEST['change_copy']) && $_REQUEST[
}
if (empty($_REQUEST['change_copy'])) {
if (empty($queries)) {
$message = new PMA_Message('strDeleteNoUsersSelected', PMA_Message::ERROR);
$message = PMA_Message::error('strDeleteNoUsersSelected');
} else {
if ($_REQUEST['mode'] == 3) {
$queries[] = '# ' . $GLOBALS['strReloadingThePrivileges'] . ' ...';
@@ -1216,8 +1215,7 @@ if (isset($_REQUEST['delete']) || (isset($_REQUEST['change_copy']) && $_REQUEST[
}
$sql_query = join("\n", $queries);
if (! empty($drop_user_error)) {
$message = PMA_Message::error();
$message->setMessage($drop_user_error);
$message = PMA_Message::rawError($drop_user_error);
} else {
$message = PMA_Message::success('strUsersDeleted');
}
@@ -1243,7 +1241,7 @@ if (isset($_REQUEST['change_copy'])) {
}
$tmp_count++;
}
$message = new PMA_Message('strSuccess', PMA_Message::SUCCESS);
$message = PMA_Message::success();
$sql_query = join("\n", $queries);
}
@@ -1254,7 +1252,7 @@ if (isset($_REQUEST['change_copy'])) {
if (isset($_REQUEST['flush_privileges'])) {
$sql_query = 'FLUSH PRIVILEGES;';
PMA_DBI_query($sql_query);
$message = new PMA_Message('strPrivilegesReloaded', PMA_Message::SUCCESS);
$message = PMA_Message::success('strPrivilegesReloaded');
}

View File

@@ -21,10 +21,11 @@ require_once './libraries/server_common.inc.php';
*/
if (!empty($kill)) {
if (PMA_DBI_try_query('KILL ' . $kill . ';')) {
$message = sprintf($strThreadSuccessfullyKilled, $kill);
$message = PMA_Message::success('strThreadSuccessfullyKilled');
} else {
$message = sprintf($strCouldNotKill, $kill);
$message = PMA_Message::error('strCouldNotKill');
}
$message->addParam($kill);
}

36
sql.php
View File

@@ -311,7 +311,7 @@ if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
$table = '';
}
$active_page = $goto;
$message = PMA_Message::raw($error, PMA_Message::ERROR);
$message = PMA_Message::rawError($error);
require './' . PMA_securePath($goto);
} else {
require_once './libraries/header.inc.php';
@@ -464,21 +464,27 @@ if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
// No rows returned -> move back to the calling page
if ($num_rows < 1 || $is_affected) {
if ($is_delete) {
$message = $strDeletedRows . '&nbsp;' . $num_rows;
$message = PMA_Message::success('strDeletedRows');
$message->addMessage($num_rows);
} elseif ($is_insert) {
if ($is_replace) {
/* For replace we get DELETED + INSERTED row count, so we have to call it affected */
$message = $strAffectedRows . '&nbsp;' . $num_rows;
$message = PMA_Message::success('strAffectedRows');
$message->addMessage($num_rows);
} else {
$message = $strInsertedRows . '&nbsp;' . $num_rows;
$message = PMA_Message::success('strInsertedRows');
$message->addMessage($num_rows);
}
$insert_id = PMA_DBI_insert_id();
if ($insert_id != 0) {
// insert_id is id of FIRST record inserted in one insert, so if we inserted multiple rows, we had to increment this
$message .= '[br]'.$strInsertedRowId . '&nbsp;' . ($insert_id + $num_rows - 1);
$message->addMessage('[br]');
$message->addString('strInsertedRowId');
$message->addMessage($insert_id + $num_rows - 1);
}
} elseif ($is_affected) {
$message = $strAffectedRows . '&nbsp;' . $num_rows;
$message = PMA_Message::success('strAffectedRows');
$message->addMessage($num_rows);
// Ok, here is an explanation for the !$is_select.
// The form generated by sql_query_form.lib.php
@@ -489,19 +495,25 @@ if ($num_rows < 1 || $is_affected) {
// the form should not have priority over
// errors like $strEmptyResultSet
} elseif (!empty($zero_rows) && !$is_select) {
$message = $zero_rows;
$message = PMA_Message::rawSuccess($zero_rows);
} elseif (!empty($GLOBALS['show_as_php'])) {
$message = $strShowingPhp;
$message = PMA_Message::success('strShowingPhp');
} elseif (isset($GLOBALS['show_as_php'])) {
/* User disable showing as PHP, query is only displayed */
$message = $strShowingSQL;
$message = PMA_Message::notice('strShowingSQL');
} elseif (!empty($GLOBALS['validatequery'])) {
$message = $strValidateSQL;
$message = PMA_Message::notice('strValidateSQL');
} else {
$message = $strEmptyResultSet;
$message = PMA_Message::success('strEmptyResultSet');
}
$message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
if (isset($GLOBALS['querytime'])) {
$_querytime = PMA_Message::notice('strQueryTime');
$_querytime->addParam($GLOBALS['querytime']);
$message->addMessage('(');
$message->addMessage($_querytime);
$message->addMessage(')');
}
if ($is_gotofile) {
$goto = PMA_securePath($goto);

View File

@@ -180,7 +180,8 @@ if (isset($submit_num_fields)) {
// Go back to the structure sub-page
$sql_query = $sql_query_cpy;
unset($sql_query_cpy);
$message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
$message = PMA_Message::success('strTableAlteredSuccessfully');
$message->addParam($table);
$active_page = 'tbl_structure.php';
require './tbl_structure.php';
} else {

View File

@@ -217,9 +217,12 @@ if (isset($_REQUEST['do_save_data'])) {
}
}
$message = $strTable . ' '
. htmlspecialchars(PMA_backquote($db) . '.' . PMA_backquote($table))
. ' ' . $strHasBeenCreated;
//$message = PMA_Message::success('strTableCreatedSuccessfully');
//$message->addParam(PMA_backquote($db) . '.' . PMA_backquote($table));
$message = PMA_Message::success('strTable');
$message->addMessage(htmlspecialchars(PMA_backquote($db) . '.' . PMA_backquote($table)));
$message->addString('strHasBeenCreated');
$display_query = $sql_query;
$sql_query = '';

View File

@@ -108,7 +108,7 @@ if (! empty($sql_query)) {
}
}
}
$message = $GLOBALS['strSuccess'];
$message = PMA_Message::success();
}
/**

View File

@@ -176,9 +176,9 @@ if (!defined('PMA_IDX_INCLUDED')
$sql_query .= $index_fields . ')';
}
$result = PMA_DBI_query($sql_query);
$message = $strTable . ' ' . htmlspecialchars($table) . ' '
. $strHasBeenAltered;
$result = PMA_DBI_query($sql_query);
$message = PMA_Message::success('strTableAlteredSuccessfully');
$message->addParam($table);
$active_page = 'tbl_structure.php';
require './tbl_structure.php';

View File

@@ -49,9 +49,9 @@ if (PMA_isValid($_REQUEST['new_name'])) {
$message = PMA_Message::success('strCopyTableOK');
}
$old = PMA_backquote($db) . '.' . PMA_backquote($table);
$message->addParam(htmlspecialchars($old));
$message->addParam($old);
$new = PMA_backquote($_REQUEST['target_db']) . '.' . PMA_backquote($_REQUEST['new_name']);
$message->addParam(htmlspecialchars($new));
$message->addParam($new);
/* Check: Work on new table or on old table? */
if (isset($_REQUEST['submit_move']) || PMA_isValid($_REQUEST['switch_to_new'])) {

View File

@@ -150,7 +150,6 @@ if (isset($_REQUEST['primary_key'])) {
}
$query = array();
$message = new PMA_Message();
$value_sets = array();
$func_no_param = array(
'NOW',
@@ -274,15 +273,12 @@ if ($is_insert && count($value_sets) > 0) {
unset($query_fields, $value_sets);
$message->setString('strInsertedRows');
$message->isSuccess(true);
$message = PMA_Message::success('strInsertedRows');
} elseif (! empty($query)) {
$message->setString('strAffectedRows');
$message->isSuccess(true);
$message = PMA_Message::success('strAffectedRows');
} else {
// No change -> move back to the calling script
$message->setString('strNoModification');
$message->isSuccess(true);
$message = PMA_Message::success('strNoModification');
$GLOBALS['js_include'][] = 'functions.js';
$active_page = $goto_include;
require_once './libraries/header.inc.php';
@@ -301,9 +297,9 @@ if (! empty($GLOBALS['sql_query'])) {
}
$GLOBALS['sql_query'] = implode('; ', $query) . ';';
$total_affected_rows = 0;
$last_message = '';
$warning_message = '';
$error_message = '';
$last_messages = array();
$warning_messages = array();
$error_messages = array();
foreach ($query as $single_query) {
if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) {
@@ -313,7 +309,7 @@ foreach ($query as $single_query) {
}
if (! $result) {
$error_message .= '<br />' . PMA_DBI_getError();
$error_messages[] = PMA_DBI_getError();
} else {
if (@PMA_DBI_affected_rows()) {
$total_affected_rows += @PMA_DBI_affected_rows();
@@ -327,13 +323,15 @@ foreach ($query as $single_query) {
if ($total_affected_rows > 0) {
$insert_id = $insert_id + $total_affected_rows - 1;
}
$last_message .= '<br />' . $GLOBALS['strInsertedRowId'] . '&nbsp;' . $insert_id;
$last_message = PMA_Message::notice('strInsertedRowId');
$last_message->addParam($insert_id);
$last_messages[] = $last_message;
}
PMA_DBI_free_result($result);
} // end if
foreach (PMA_DBI_get_warnings() as $warning) {
$warning_message .= '<br />' . $warning['Level'] . ': #' . $warning['Code']
$warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
. ' ' . $warning['Message'];
}
@@ -341,21 +339,22 @@ foreach ($query as $single_query) {
}
unset($single_query, $query);
$message->append(' ' . $total_affected_rows . $last_message);
$message->addMessage($total_affected_rows);
$message->addMessages($last_messages, '<br />');
if (! empty($warning_message)) {
if (! empty($warning_messages)) {
/**
* @todo use a <div class="warning"> in PMA_showMessage() for this part of
* the message
*/
$message->append($warning_message);
$message->addMessages($warning_messages, '<br />');
$message->isWarning(true);
}
if (! empty($error_message)) {
$message->append($error_message);
if (! empty($error_messages)) {
$message->addMessages($error_messages);
$message->isError(true);
}
unset($error_message, $warning_message, $total_affected_rows, $last_message);
unset($error_messages, $warning_messages, $total_affected_rows, $last_messages, $last_message);
if (isset($return_to_sql_query)) {
$disp_query = $GLOBALS['sql_query'];

View File

@@ -75,8 +75,7 @@ if (isset($_REQUEST['createview'])) {
require './' . $cfg['DefaultTabDatabase'];
exit();
} else {
$message = PMA_Message::error();
$message->setMessage(PMA_DBI_getError());
$message = PMA_Message::rawError(PMA_DBI_getError());
}
}