diff options
author | Sebastian Mendel <cybot_tm@users.sourceforge.net> | 2007-10-04 13:22:50 +0400 |
---|---|---|
committer | Sebastian Mendel <cybot_tm@users.sourceforge.net> | 2007-10-04 13:22:50 +0400 |
commit | 40b3ce9fd191d00159c601b986f92291a4bfccb5 (patch) | |
tree | 6c15bf472e002dc3514b045153588bb17c497cb9 | |
parent | e9f1ed82c6fdb783f98884d670097175df03e484 (diff) |
use array to define included JavaScript libraries
-rw-r--r-- | db_create.php | 2 | ||||
-rw-r--r-- | export.php | 10 | ||||
-rw-r--r-- | import.php | 2 | ||||
-rw-r--r-- | libraries/common.inc.php | 5 | ||||
-rw-r--r-- | libraries/db_common.inc.php | 2 | ||||
-rw-r--r-- | libraries/header.inc.php | 83 | ||||
-rw-r--r-- | libraries/mult_submits.inc.php | 2 | ||||
-rw-r--r-- | libraries/tbl_links.inc.php | 2 | ||||
-rw-r--r-- | server_databases.php | 2 | ||||
-rw-r--r-- | server_export.php | 2 | ||||
-rw-r--r-- | server_privileges.php | 3 | ||||
-rw-r--r-- | server_sql.php | 2 | ||||
-rw-r--r-- | sql.php | 4 | ||||
-rw-r--r-- | tbl_addfield.php | 2 | ||||
-rw-r--r-- | tbl_alter.php | 2 | ||||
-rw-r--r-- | tbl_change.php | 4 | ||||
-rw-r--r-- | tbl_create.php | 2 | ||||
-rw-r--r-- | tbl_indexes.php | 5 | ||||
-rw-r--r-- | tbl_move_copy.php | 2 | ||||
-rw-r--r-- | tbl_replace.php | 25 | ||||
-rw-r--r-- | tbl_row_action.php | 9 | ||||
-rw-r--r-- | user_password.php | 2 |
22 files changed, 70 insertions, 104 deletions
diff --git a/db_create.php b/db_create.php index a690643167..3606a673a1 100644 --- a/db_create.php +++ b/db_create.php @@ -9,7 +9,7 @@ * Gets some core libraries */ require_once './libraries/common.inc.php'; -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/mysql_charsets.lib.php'; PMA_checkParameters(array('db')); diff --git a/export.php b/export.php index ab84554d9c..e179139d95 100644 --- a/export.php +++ b/export.php @@ -60,7 +60,7 @@ if (empty($_REQUEST['asfile'])) { if (isset($export_list[$type]['force_file']) && ! $asfile) { $message = $strExportMustBeFile; $GLOBALS['show_error_header'] = true; - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; @@ -315,7 +315,7 @@ if ($save_on_server) { } } if (isset($message)) { - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; @@ -362,7 +362,7 @@ if (!$save_on_server) { $num_tables = count($tables); if ($num_tables == 0) { $message = $strNoTablesFound; - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; $active_page = 'db_export.php'; require './db_export.php'; @@ -553,7 +553,7 @@ if (!PMA_exportFooter()) { // End of fake loop if ($save_on_server && isset($message)) { - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; @@ -610,7 +610,7 @@ if (!empty($asfile)) { $message = sprintf($strDumpSaved, htmlspecialchars($save_filename)); } - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; diff --git a/import.php b/import.php index 6559b17cfa..1bc2e28f6e 100644 --- a/import.php +++ b/import.php @@ -10,7 +10,7 @@ * Get the variables sent or posted to this script and a core script */ require_once './libraries/common.inc.php'; -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; // default values $GLOBALS['reload'] = false; diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 92e879d692..2010f7b467 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -441,6 +441,11 @@ $_REQUEST['js_frame'] = PMA_ifSetOr($_REQUEST['js_frame'], ''); //$_REQUEST['lang']; // checked by LABEL_loading_language_file +/** + * holds name of JavaScript files to be included in HTML header + * @global array $js_include + */ +$GLOBALS['js_include'] = array(); /******************************************************************************/ /* parsing configuration file LABEL_parsing_config_file */ diff --git a/libraries/db_common.inc.php b/libraries/db_common.inc.php index 805bac5593..418a799cdd 100644 --- a/libraries/db_common.inc.php +++ b/libraries/db_common.inc.php @@ -55,7 +55,7 @@ if (isset($submitcollation) && !empty($db_collation)) { unset($db_charset, $db_collation); } -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; /** diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 4f12f244dc..9fe886c207 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -59,79 +59,54 @@ if (empty($GLOBALS['is_header_sent'])) { // Updates the title of the frameset if possible (ns4 does not allow this) if (typeof(parent.document) != 'undefined' && typeof(parent.document) != 'unknown' && typeof(parent.document.title) == 'string') { - parent.document.title = '<?php echo PMA_sanitize(str_replace('\'', '\\\'', $title)); ?>'; + parent.document.title = '<?php echo PMA_sanitize(PMA_escapeJsString($title)); ?>'; } + <?php // Add some javascript instructions if required - if (isset($js_to_run) && $js_to_run == 'functions.js') { - echo "\n"; + if (in_array('functions.js', $GLOBALS['js_include'])) { + PMA_jsFormat() ?> // js form validation stuff - var errorMsg0 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>'; - var errorMsg1 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>'; + var errorMsg0 = '<?php echo PMA_escapeJsString($GLOBALS['strFormEmpty']); ?>'; + var errorMsg1 = '<?php echo PMA_escapeJsString($GLOBALS['strNotNumber']); ?>'; var noDropDbMsg = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase']) - ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''; ?>'; - var confirmMsg = '<?php echo(($GLOBALS['cfg']['Confirm']) ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''); ?>'; - var confirmMsgDropDB = '<?php echo(($GLOBALS['cfg']['Confirm']) ? str_replace('\'', '\\\'', $GLOBALS['strDropDatabaseStrongWarning']) : ''); ?>'; - // ]]> - </script> - <script src="./js/functions.js" type="text/javascript"></script> - <?php - } elseif (isset($js_to_run) && $js_to_run == 'user_password.js') { - echo "\n"; - ?> - // js form validation stuff - var jsHostEmpty = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strHostEmpty']); ?>'; - var jsUserEmpty = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strUserEmpty']); ?>'; - var jsPasswordEmpty = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strPasswordEmpty']); ?>'; - var jsPasswordNotSame = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strPasswordNotSame']); ?>'; - // ]]> - </script> - <script src="./js/user_password.js" type="text/javascript"></script> + ? PMA_escapeJsString($GLOBALS['strNoDropDatabases']) : ''; ?>'; + var confirmMsg = '<?php echo(($GLOBALS['cfg']['Confirm']) ? PMA_escapeJsString($GLOBALS['strDoYouReally']) : ''); ?>'; + var confirmMsgDropDB = '<?php echo(($GLOBALS['cfg']['Confirm']) ? PMA_escapeJsString($GLOBALS['strDropDatabaseStrongWarning']) : ''); ?>'; <?php - } elseif (isset($js_to_run) && $js_to_run == 'server_privileges.js') { - echo "\n"; - ?> - // js form validation stuff - var jsHostEmpty = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strHostEmpty']); ?>'; - var jsUserEmpty = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strUserEmpty']); ?>'; - var jsPasswordEmpty = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strPasswordEmpty']); ?>'; - var jsPasswordNotSame = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strPasswordNotSame']); ?>'; - // ]]> - </script> - <script src="./js/server_privileges.js" type="text/javascript"></script> - <script src="./js/functions.js" type="text/javascript"></script> - <?php - } elseif (isset($js_to_run) && $js_to_run == 'indexes.js') { - echo "\n"; + } elseif (in_array('indexes.js', $GLOBALS['js_include'])) { ?> // js index validation stuff - var errorMsg0 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>'; - var errorMsg1 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>'; - // ]]> - </script> - <script src="./js/indexes.js" type="text/javascript"></script> + var errorMsg0 = '<?php echo PMA_escapeJsString($GLOBALS['strFormEmpty']); ?>'; + var errorMsg1 = '<?php echo PMA_escapeJsString($GLOBALS['strNotNumber']); ?>'; <?php - } elseif (isset($js_to_run) && $js_to_run == 'tbl_change.js') { - echo "\n"; + } + + if (in_array('user_password.js', $GLOBALS['js_include']) + || in_array('server_privileges.js', $GLOBALS['js_include'])) { ?> - // ]]> - </script> - <script src="./js/tbl_change.js" type="text/javascript"></script> + // js form validation stuff + var jsHostEmpty = '<?php echo PMA_escapeJsString($GLOBALS['strHostEmpty']); ?>'; + var jsUserEmpty = '<?php echo PMA_escapeJsString($GLOBALS['strUserEmpty']); ?>'; + var jsPasswordEmpty = '<?php echo PMA_escapeJsString($GLOBALS['strPasswordEmpty']); ?>'; + var jsPasswordNotSame = '<?php echo PMA_escapeJsString($GLOBALS['strPasswordNotSame']); ?>'; <?php - } else { - echo "\n"; - ?> + } + + ?> // ]]> </script> - <?php + + <?php + $GLOBALS['js_include'][] = 'tooltip.js'; + foreach ($GLOBALS['js_include'] as $js_script_file) { + echo '<script src="./js/' . $js_script_file . '" type="text/javascript"></script>' . "\n"; } - echo "\n"; // Reloads the navigation frame via JavaScript if required PMA_reloadNavigation(); ?> - <script src="./js/tooltip.js" type="text/javascript"></script> <meta name="OBGZip" content="<?php echo ($GLOBALS['cfg']['OBGzip'] ? 'true' : 'false'); ?>" /> <?php /* remove vertical scroll bar bug in ie */ ?> <!--[if IE 6]> diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index ba43eef8e0..8cc87074d8 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -115,7 +115,7 @@ if (! empty($submit_mult) * Displays the confirmation form if required */ if (!empty($submit_mult) && !empty($what)) { - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; unset($message); require_once './libraries/header.inc.php'; diff --git a/libraries/tbl_links.inc.php b/libraries/tbl_links.inc.php index c7a5322627..0e8f748315 100644 --- a/libraries/tbl_links.inc.php +++ b/libraries/tbl_links.inc.php @@ -37,7 +37,7 @@ $err_url = $cfg['DefaultTabTable'] . PMA_generate_common_url($url_params); /** * Displays headers */ -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; /** diff --git a/server_databases.php b/server_databases.php index 02075ee324..d12f564485 100644 --- a/server_databases.php +++ b/server_databases.php @@ -11,7 +11,7 @@ require_once './libraries/common.inc.php'; -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; require './libraries/server_common.inc.php'; /** diff --git a/server_export.php b/server_export.php index 7505710d70..ea79c169a5 100644 --- a/server_export.php +++ b/server_export.php @@ -10,7 +10,7 @@ */ require_once './libraries/common.inc.php'; -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; /** * Displays the links diff --git a/server_privileges.php b/server_privileges.php index 13e6552ecb..24fa965d43 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -13,7 +13,8 @@ require_once './libraries/common.inc.php'; /** * Does the common work */ -$js_to_run = 'server_privileges.js'; +$GLOBALS['js_include'][] = 'server_privileges.js'; +$GLOBALS['js_include'][] = 'functions.js'; require './libraries/server_common.inc.php'; diff --git a/server_sql.php b/server_sql.php index 449025aa3e..de6bd7f9b3 100644 --- a/server_sql.php +++ b/server_sql.php @@ -13,7 +13,7 @@ require_once './libraries/common.inc.php'; /** * Does the common work */ -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/server_common.inc.php'; require_once './libraries/sql_query_form.lib.php'; @@ -517,7 +517,7 @@ if ($num_rows < 1 || $is_affected) { // Loads to target script if (strpos($goto, 'db_') === 0 || strpos($goto, 'tbl_') === 0) { - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; } if ($goto != 'main.php') { require_once './libraries/header.inc.php'; @@ -543,7 +543,7 @@ else { if (isset($printview) && $printview == '1') { require_once './libraries/header_printview.inc.php'; } else { - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; unset($message); if (strlen($table)) { require './libraries/tbl_common.php'; diff --git a/tbl_addfield.php b/tbl_addfield.php index 21abf792e9..45a3308b2c 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -11,7 +11,7 @@ require_once './libraries/common.inc.php'; require_once './libraries/Table.class.php'; -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; // Check parameters diff --git a/tbl_alter.php b/tbl_alter.php index badcb39558..94c87293a9 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -11,7 +11,7 @@ require_once './libraries/common.inc.php'; require_once './libraries/Table.class.php'; -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; // Check parameters diff --git a/tbl_change.php b/tbl_change.php index 8fb67a14e1..fe2d48e9d0 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -111,7 +111,7 @@ if ($GLOBALS['cfg']['ShowPropertyComments']) { /** * used in ./libraries/header.inc.php to load JavaScript library file */ -$js_to_run = 'tbl_change.js'; +$GLOBALS['js_include'][] = 'tbl_change.js'; /** * HTTP and HTML headers @@ -610,7 +610,7 @@ foreach ($rows as $row_id => $vrow) { // The value column (depends on type) // ---------------- - $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', ''); + $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', ''); echo ' <td>' . "\n"; if ($foreignData['foreign_link'] == true) { echo $backup_field . "\n"; diff --git a/tbl_create.php b/tbl_create.php index d7cbf7be72..6eb7a02cf0 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -41,7 +41,7 @@ require_once './libraries/common.inc.php'; require_once './libraries/Table.class.php'; -$js_to_run = 'functions.js'; +$GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; diff --git a/tbl_indexes.php b/tbl_indexes.php index 0a306ac681..c393c08bb2 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -51,9 +51,8 @@ if (!defined('PMA_IDX_INCLUDED')) { } // Displays headers (if needed) - $js_to_run = isset($index) && isset($do_save_data) - ? 'functions.js' - : 'indexes.js'; + $GLOBALS['js_include'][] = 'functions.js'; + $GLOBALS['js_include'][] = 'indexes.js'; require_once './libraries/header.inc.php'; } // end if diff --git a/tbl_move_copy.php b/tbl_move_copy.php index 02f44c4827..bd0a1e6320 100644 --- a/tbl_move_copy.php +++ b/tbl_move_copy.php @@ -34,7 +34,7 @@ if (isset($new_name) && trim($new_name) != '') { $message = (isset($submit_move) ? $strMoveTableSameNames : $strCopyTableSameNames); } else { PMA_Table::moveCopy($db, $table, $target_db, $new_name, $what, isset($submit_move), 'one_table'); - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; $message = (isset($submit_move) ? $strMoveTableOK : $strCopyTableOK); $message = sprintf($message, htmlspecialchars($table), htmlspecialchars($new_name)); $reload = 1; diff --git a/tbl_replace.php b/tbl_replace.php index 3cc0d218d8..8421402511 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -66,7 +66,7 @@ $goto_include = false; if (isset($_REQUEST['insert_rows']) && is_numeric($_REQUEST['insert_rows']) && $_REQUEST['insert_rows'] != $cfg['InsertRows']) { $cfg['InsertRows'] = $_REQUEST['insert_rows']; - $js_to_run = 'tbl_change.js'; + $GLOBALS['js_include'][] = 'tbl_change.js'; require_once './libraries/header.inc.php'; require './tbl_change.php'; exit; @@ -280,7 +280,7 @@ if ($is_insert && count($value_sets) > 0) { } else { // No change -> move back to the calling script $message .= $GLOBALS['strNoModification']; - $js_to_run = 'functions.js'; + $GLOBALS['js_include'][] = 'functions.js'; $active_page = $goto_include; require_once './libraries/header.inc.php'; require './' . PMA_securePath($goto_include); @@ -307,7 +307,7 @@ foreach ($query as $single_query) { } else { $result = PMA_DBI_query($single_query); } - + if (! $result) { $message .= PMA_DBI_getError(); } else { @@ -329,10 +329,10 @@ foreach ($query as $single_query) { } // end if foreach (PMA_DBI_get_warnings() as $warning) { - $warning_message .= $warning['Level'] . ': #' . $warning['Code'] + $warning_message .= $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message'] . '[br]'; } - + unset($result); } unset($single_query, $query); @@ -355,18 +355,9 @@ if (isset($return_to_sql_query)) { $GLOBALS['sql_query'] = $return_to_sql_query; } -// if user asked to "Insert another new row", we need tbl_change.js -// otherwise the calendar icon does not work -if ($goto_include == 'tbl_change.php') { - /** - * @todo if we really need to run many different js at header time, - * $js_to_run would become an array and header.inc.php would iterate - * thru it, instead of the bunch of if/elseif it does now - */ - $js_to_run = 'tbl_change.js'; -} else { - $js_to_run = 'functions.js'; -} +$GLOBALS['js_include'][] = 'tbl_change.js'; +$GLOBALS['js_include'][] = 'functions.js'; + $active_page = $goto_include; require_once './libraries/header.inc.php'; require './' . PMA_securePath($goto_include); diff --git a/tbl_row_action.php b/tbl_row_action.php index 50626f105c..e6497783bb 100644 --- a/tbl_row_action.php +++ b/tbl_row_action.php @@ -70,13 +70,8 @@ switch($submit_mult) { break; } -if ($submit_mult == 'row_edit') { - $js_to_run = 'tbl_change.js'; -} - -if ($submit_mult == 'row_delete' || $submit_mult == 'row_export') { - $js_to_run = 'functions.js'; -} +$GLOBALS['js_include'][] = 'tbl_change.js'; +$GLOBALS['js_include'][] = 'functions.js'; require_once './libraries/header.inc.php'; diff --git a/user_password.php b/user_password.php index 1b0bdf975b..96b1630948 100644 --- a/user_password.php +++ b/user_password.php @@ -88,7 +88,7 @@ if (isset($nopass)) { * aren't valid -> displays the form */ // Loads the headers -$js_to_run = 'user_password.js'; +$GLOBALS['js_include'][] = 'user_password.js'; require_once './libraries/header.inc.php'; echo '<h1>' . $strChangePassword . '</h1>' . "\n\n"; |