diff --git a/js/server_privileges.js b/js/server_privileges.js index 192475e9be..19c907b30f 100644 --- a/js/server_privileges.js +++ b/js/server_privileges.js @@ -80,6 +80,72 @@ function appendNewUser(new_user_string, new_user_initial, new_user_initial_strin $(checkboxes_sel).trigger("change"); } +function addUser($form) +{ + if (! checkAddUser($form.get(0))) { + return false; + } + + //We also need to post the value of the submit button in order to get this to work correctly + $.post($form.attr('action'), $form.serialize() + "&adduser_submit=" + $("input[name=adduser_submit]").val(), function(data) { + if (data.success == true) { + // Refresh navigation, if we created a database with the name + // that is the same as the username of the new user + if ($('#add_user_dialog #createdb-1:checked').length) { + PMA_reloadNavigation(); + } + + $('#page_content').show(); + $("#add_user_dialog").remove(); + + PMA_ajaxShowMessage(data.message); + $("#result_query").remove(); + $('#page_content').prepend(data.sql_query); + $("#result_query").css({ + 'margin-top' : '0.5em' + }); + + //Remove the empty notice div generated due to a NULL query passed to PMA_getMessage() + var $notice_class = $("#result_query").find('.notice'); + if ($notice_class.text() == '') { + $notice_class.remove(); + } + if ($('#fieldset_add_user a.ajax').attr('name') == 'db_specific') { + + /*process the fieldset_add_user attribute and get the val of privileges*/ + var url = $('#fieldset_add_user a.ajax').attr('rel'); + + if (url.substring(url.length - 23, url.length) == "&goto=db_operations.php") { + url = url.substring(0, url.length - 23); + } + url = url + "&ajax_request=true&db_specific=true"; + + /* post request for get the updated userForm table */ + $.post($form.attr('action'), url, function(priv_data) { + + /*Remove the old userForm table*/ + if ($('#userFormDiv').length != 0) { + $('#userFormDiv').remove(); + } else { + $("#usersForm").remove(); + } + if (priv_data.success == true) { + $('
') + .html(priv_data.user_form) + .insertAfter('#result_query'); + } else { + PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + priv_data.error, false); + } + }); + } else { + appendNewUser(data.new_user_string, data.new_user_initial, data.new_user_initial_string); + } + } else { + PMA_ajaxShowMessage(data.error, false); + } + }); +} + /** * AJAX scripts for server_privileges page. * @@ -125,113 +191,30 @@ AJAX.registerOnload('server_privileges.js', function() { $("#fieldset_add_user a.ajax").live("click", function(event) { /** @lends jQuery */ event.preventDefault(); - var $msgbox = PMA_ajaxShowMessage(); - /** - * @var button_options Object containing options for jQueryUI dialog buttons - */ - var button_options = {}; - button_options[PMA_messages['strAddUser']] = function() { - - /** - * @var $form stores reference to current form - */ - var $form = $(this).find("form[name=usersForm]").last(); - - if (! checkAddUser($form.get(0))) { - return false; - } - - //We also need to post the value of the submit button in order to get this to work correctly - $.post($form.attr('action'), $form.serialize() + "&adduser_submit=" + $(this).find("input[name=adduser_submit]").val(), function(data) { - if (data.success == true) { - // Refresh navigation, if we created a database with the name - // that is the same as the username of the new user - if ($('#add_user_dialog #createdb_1:checked').length) { - PMA_reloadNavigation(); - } - - $("#add_user_dialog").dialog("close"); - PMA_ajaxShowMessage(data.message); - $("#result_query").remove(); - $('#page_content').prepend(data.sql_query); - - //Remove the empty notice div generated due to a NULL query passed to PMA_getMessage() - var $notice_class = $("#result_query").find('.notice'); - if ($notice_class.text() == '') { - $notice_class.remove(); - } - if ($('#fieldset_add_user a.ajax').attr('name') == 'db_specific') { - - /*process the fieldset_add_user attribute and get the val of privileges*/ - var url = $('#fieldset_add_user a.ajax').attr('rel'); - - if (url.substring(url.length - 23, url.length) == "&goto=db_operations.php") { - url = url.substring(0, url.length - 23); - } - url = url + "&ajax_request=true&db_specific=true"; - - /* post request for get the updated userForm table */ - $.post($form.attr('action'), url, function(priv_data) { - - /*Remove the old userForm table*/ - if ($('#userFormDiv').length != 0) { - $('#userFormDiv').remove(); - } else { - $("#usersForm").remove(); - } - if (priv_data.success == true) { - $('
') - .html(priv_data.user_form) - .insertAfter('#result_query'); - } else { - PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + priv_data.error, false); - } - }); - } else { - appendNewUser(data.new_user_string, data.new_user_initial, data.new_user_initial_string); - } - } else { - PMA_ajaxShowMessage(data.error, false); - } - }); - }; - button_options[PMA_messages['strCancel']] = function() { $(this).dialog("close"); }; - $.get($(this).attr("href"), {'ajax_request':true}, function(data) { if (data.success == true) { - var $div = $('
') - .prepend(data.message) - .find("#fieldset_add_user_footer").hide() //showing the "Go" and "Create User" buttons together will confuse the user - .end() - .find("form[name=usersForm]").append('') - .end() - .dialog({ - title: PMA_messages['strAddUser'], - width: 800, - // height is a workaround for this Chrome problem: - // http://bugs.jqueryui.com/ticket/4671 - // also it's interesting to be able to scroll this window - height: 600, - modal: true, - buttons: button_options, - close: function () { - $(this).remove(); - } - }); //dialog options end + $('#page_content').hide(); + var $div = $('#add_user_dialog'); + if ($div.length == 0) { + $div = $('
') + .insertBefore('#page_content'); + } else { + $div.empty(); + } + $div.html(data.message) + .find("form[name=usersForm]") + .append('') + .end(); displayPasswordGenerateButton(); PMA_showHints($div); PMA_ajaxRemoveMessage($msgbox); - $div.find("input[autofocus]").focus(); + $div.find("input.autofocus").focus(); - $div.find('form[name=usersForm]').bind('submit', function (e) { - e.preventDefault(); - $(this) - .closest('.ui-dialog') - .find('.ui-dialog-buttonpane .ui-button') - .first() - .click(); + $div.find('form[name=usersForm]').bind('submit', function (event) { + event.preventDefault(); + addUser($(this)); }); } else { PMA_ajaxShowMessage(data.error, false); @@ -332,12 +315,6 @@ AJAX.registerOnload('server_privileges.js', function() { $(this).parents('tr').addClass('current_row'); - /** - * @var button_options Object containing options for jQueryUI dialog buttons - */ - var button_options = {}; - button_options[PMA_messages['strCancel']] = function() {$(this).dialog("close");}; - var token = $(this).parents('form').find('input[name="token"]').val(); $.get( $(this).attr('href'), @@ -348,16 +325,15 @@ AJAX.registerOnload('server_privileges.js', function() { }, function(data) { if (data.success == true) { - var $div = $('
') - .append(data.message) - .dialog({ - width: 900, - height: 600, - buttons: button_options, - close: function () { - $(this).remove(); - } - }); //dialog options end + $('#page_content').hide(); + var $div = $('#edit_user_dialog'); + if ($div.length == 0) { + $div = $('
') + .insertBefore('#page_content'); + } else { + $div.empty(); + } + $div.html(data.message); displayPasswordGenerateButton(); PMA_ajaxRemoveMessage($msgbox); PMA_showHints($div); @@ -401,15 +377,17 @@ AJAX.registerOnload('server_privileges.js', function() { $.post($t.attr('action'), $t.serialize() + '&' + curr_submit_name + '=' + curr_submit_value, function(data) { if (data.success == true) { + $('#page_content').show(); + $("#edit_user_dialog").remove(); PMA_ajaxShowMessage(data.message); - //Close the jQueryUI dialog - $("#edit_user_dialog").dialog("close"); - if (data.sql_query) { $("#result_query").remove(); $('#page_content').prepend(data.sql_query); + $("#result_query").css({ + 'margin-top' : '0.5em' + }); var $notice_class = $("#result_query").find('.notice'); if ($notice_class.text() == '') { $notice_class.remove(); diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 3c6f741410..4f2d0711ae 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -364,8 +364,6 @@ function PMA_getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname) /** * Displays the privileges form table * - * @param string $random_n a random number that will be appended - * to the id of the user forms * @param string $db the database * @param string $table the table * @param boolean $submit wheather to display the submit button or not @@ -375,7 +373,7 @@ function PMA_getSqlQueryForDisplayPrivTable($db, $table, $username, $hostname) * * @return string html snippet */ -function PMA_getHtmlToDisplayPrivilegesTable($random_n, $db = '*', +function PMA_getHtmlToDisplayPrivilegesTable($db = '*', $table = '*', $submit = true ) { $html_output = ''; @@ -468,9 +466,7 @@ function PMA_getHtmlToDisplayPrivilegesTable($random_n, $db = '*', ); } else { // g l o b a l o r d b - s p e c i f i c - $html_output .= PMA_getHtmlForGlobalOrDbSpecificPrivs( - $db, $table, $row, $random_n - ); + $html_output .= PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row); } $html_output .= '' . "\n"; if ($submit) { @@ -744,12 +740,10 @@ function PMA_getHtmlForNotAttachedPrivilegesToTableSpecificColumn($row) * @param string $db the database * @param string $table the table * @param string $row first row from result or boolean false - * @param string $random_n a random number that will be appended - * to the id of the user forms * * @return string $html_output */ -function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n) +function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row) { $privTable_names = array(0 => __('Data'), 1 => __('Structure'), @@ -771,27 +765,25 @@ function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0) ) - . '" />' . "\n" - . '
' . "\n" - . '' . "\n" - . ' ' - . ($db == '*' - ? __('Global privileges') - : ($table == '*' - ? __('Database-specific privileges') - : __('Table-specific privileges'))) . "\n" - . '(' - . __('Check All') . ' /' . "\n" + . '" />'; + $html_output .= '
'; + if ($db == '*') { + $html_output .= __('Global privileges'); + } else if ($table == '*') { + $html_output .= __('Database-specific privileges'); + } else { + $html_output .= __('Table-specific privileges'); + } + $html_output .= ' (' . __('Check All') . ' /' . '' - . __('Uncheck All') . ')' . "\n" - . '' . "\n" - . '

' + . 'onclick="setCheckboxes(\'fieldset_user_global_rights\', false); ' + . 'return false;">' . __('Uncheck All') . ')'; + $html_output .= ''; + $html_output .= '

' . __('Note: MySQL privilege names are expressed in English') - . '

' . "\n"; + . '

'; // Output the Global privilege tables with checkboxes $html_output .= PMA_getHtmlForGlobalPrivTableWithCheckboxes( @@ -803,7 +795,7 @@ function PMA_getHtmlForGlobalOrDbSpecificPrivs($db, $table, $row, $random_n) $html_output .= PMA_getHtmlForDisplayResourceLimits($row); } // for Safari 2.0.2 - $html_output .= '
' . "\n"; + $html_output .= '
'; return $html_output; } @@ -1066,8 +1058,8 @@ function PMA_getHtmlForDisplayLoginInformationFields($mode = 'new') $html_output .= '' . "\n" . '' . "\n"; - $html_output .= '' . "\n" + . ' onchange="pred_username.value = \'userdefined\';" />' . "\n" . '' . "\n"; $html_output .= '
' . "\n" @@ -1431,20 +1422,19 @@ function PMA_getWithClauseForAddUserAndUpdatePrivs() /** * Get HTML for addUsersForm, This function call if isset($_REQUEST['adduser']) * - * @param int $random_n * @param string $dbname * * @return string HTML for addUserForm */ -function PMA_getHtmlForAddUser($random_n, $dbname) +function PMA_getHtmlForAddUser($dbname) { $GLOBALS['url_query'] .= '&adduser=1'; $html_output = '

' . "\n" . PMA_Util::getIcon('b_usradd.png') . __('Add user') . "\n" . '

' . "\n" - . '
' . "\n" + . '' . "\n" . PMA_generate_common_hidden_inputs('', '') . PMA_getHtmlForDisplayLoginInformationFields('new'); @@ -1477,9 +1467,7 @@ function PMA_getHtmlForAddUser($random_n, $dbname) } $html_output .= '
' . "\n"; - $html_output .= PMA_getHtmlToDisplayPrivilegesTable( - $random_n, '*', '*', false - ); + $html_output .= PMA_getHtmlToDisplayPrivilegesTable('*', '*', false); $html_output .= '