Skip to content

Commit

Permalink
Integrated pmd with the new Header class
Browse files Browse the repository at this point in the history
  • Loading branch information
roccivic committed Jun 11, 2012
1 parent a9e97a9 commit e306fad
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 73 deletions.
6 changes: 3 additions & 3 deletions libraries/Scripts.class.php
Expand Up @@ -23,10 +23,10 @@ public function __construct()

}

public function addFile($filename)
public function addFile($filename, $conditional_ie = false)
{
if (! in_array($filename, $this->_files)) {
$this->_files[] = $filename;
$this->_files[] = PMA_includeJS($filename, $conditional_ie);
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public function getDisplay()
$retval = '';

foreach ($this->_files as $file) {
$retval .= PMA_includeJS($file);
$retval .= $file;
}
$retval .= '<script type="text/javascript">';
$retval .= "// <![CDATA[\n";
Expand Down
33 changes: 6 additions & 27 deletions libraries/pmd_common.php
Expand Up @@ -10,23 +10,18 @@
exit;
}

PMA_Header::getInstance()->sendHttpHeaders();

$GLOBALS['PMD']['STYLE'] = 'default';

$cfgRelation = PMA_getRelationsParam();

$GLOBALS['script_display_field']
= '<script type="text/javascript">' . "\n" .
'// <![CDATA[' . "\n" .
'var display_field = new Array();' . "\n";

/**
* retrieves table info and stores it in $GLOBALS['PMD']
*
*/
function get_tables_info()
{
$GLOBALS['script_display_field'] = 'var display_field = new Array();' . "\n";

$GLOBALS['PMD']['TABLE_NAME'] = array();// that foreach no error
$GLOBALS['PMD']['OWNER'] = array();
$GLOBALS['PMD']['TABLE_NAME_SMALL'] = array();
Expand Down Expand Up @@ -60,10 +55,7 @@ function get_tables_info()
$i++;
}

$GLOBALS['script_display_field'] .=
'// ]]>' . "\n" .
'</script>' . "\n";
// return $GLOBALS['PMD']; // many bases // not use ??????
return $GLOBALS['script_display_field'];
}

/**
Expand Down Expand Up @@ -130,10 +122,7 @@ function get_script_contr()
}

$ti = 0;
$script_contr
= '<script type="text/javascript">' . "\n" .
'// <![CDATA[' . "\n" .
'var contr = new Array();' . "\n";
$script_contr = 'var contr = new Array();' . "\n";
for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
$js_var = ' contr[' . $ti . ']';
$script_contr .= $js_var . " = new Array();\n";
Expand All @@ -152,9 +141,6 @@ function get_script_contr()
}
$ti++;
}
$script_contr .=
'// ]]>' . "\n" .
'</script>' . "\n";
return $script_contr;
}

Expand Down Expand Up @@ -202,19 +188,13 @@ function get_all_keys($unique_only = false)
*/
function get_script_tabs()
{
$script_tabs
= '<script type="text/javascript">' . "\n" .
'// <![CDATA[' . "\n" .
'var j_tabs = new Array();' . "\n" .
'var h_tabs = new Array();' . "\n" ;
$script_tabs = 'var j_tabs = new Array();' . "\n"
. 'var h_tabs = new Array();' . "\n" ;
for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) {
$script_tabs .= "j_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = '"
. (PMA_isForeignKeySupported($GLOBALS['PMD']['TABLE_TYPE'][$i]) ? '1' : '0') . "';\n";
$script_tabs .="h_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = 1;"."\n" ;
}
$script_tabs .=
'// ]]>' . "\n" .
'</script>' . "\n";
return $script_tabs;
}

Expand All @@ -240,5 +220,4 @@ function get_tab_pos()
return count($tab_pos) ? $tab_pos : null;
}

get_tables_info();
?>
57 changes: 29 additions & 28 deletions pmd_general.php
Expand Up @@ -9,10 +9,8 @@
/**
*
*/
require_once './libraries/common.inc.php';
require_once 'libraries/common.inc.php';
require_once 'libraries/pmd_common.php';
require 'libraries/db_common.inc.php';
require 'libraries/db_info.inc.php';

/**
* Sets globals from $_GET
Expand All @@ -28,6 +26,7 @@
}
}

$script_display_field = get_tables_info();
$tab_column = get_columns_info();
$script_tabs = get_script_tabs();
$script_contr = get_script_contr();
Expand All @@ -39,42 +38,44 @@
if (isset($GLOBALS['db'])) {
$params['db'] = $GLOBALS['db'];
}
require_once 'libraries/header_scripts.inc.php';
?>
<script type="text/javascript">
// <![CDATA[
<?php
echo '


$header = PMA_Header::getInstance();
$header->setBodyId('pmd_body');
$scripts = $header->getScripts();
$scripts->addFile('pmd/ajax.js');
$scripts->addFile('pmd/history.js');
$scripts->addFile('pmd/move.js');
$scripts->addFile('pmd/iecanvas.js', true);
$scripts->addCode('
var server = "' . PMA_escapeJsString($server) . '";
var db = "' . PMA_escapeJsString($db) . '";
var token = "' . PMA_escapeJsString($token) . '";';
echo "\n";
var token = "' . PMA_escapeJsString($token) . '";
');
if (isset($_REQUEST['query'])) {
echo '
$(function() {
$scripts->addCode('
$(function() {
$(".trigger").click(function() {
$(".panel").toggle("fast");
$(this).toggleClass("active");
return false;
});
});';
});
');
}
?>
// ]]>
</script>
<script src="js/pmd/ajax.js" type="text/javascript"></script>
<script src="js/pmd/history.js" type="text/javascript"></script>
<script src="js/pmd/move.js" type="text/javascript"></script>
<!--[if IE]>
<script src="js/pmd/iecanvas.js" type="text/javascript"></script>
<![endif]-->
<?php
echo $script_tabs . $script_contr . $script_display_field;
?>
$scripts->addCode('
$(function() {
Main();
});
');
$scripts->addCode($script_tabs);
$scripts->addCode($script_contr);
$scripts->addCode($script_display_field);

</head>
<body onload="Main()" class="general_body" id="pmd_body">
require 'libraries/db_common.inc.php';
require 'libraries/db_info.inc.php';

?>
<div class="pmd_header" id="top_menu">
<a href="#"
onclick="Show_left_menu(document.getElementById('key_Show_left_menu')); return false" class="M_butt first" target="_self">
Expand Down
8 changes: 4 additions & 4 deletions pmd_pdf.php
Expand Up @@ -77,11 +77,11 @@
}
}

// no need to use pmd/styles
require_once 'libraries/header_meta_style.inc.php';
$header = PMA_Header::getInstance();
$header->disableMenu();
$header->display();

?>
</head>
<body>
<br>
<div>
<?php
Expand Down
25 changes: 16 additions & 9 deletions pmd_relation_new.php
Expand Up @@ -31,28 +31,35 @@
// note: in InnoDB, the index does not requires to be on a PRIMARY
// or UNIQUE key
// improve: check all other requirements for InnoDB relations
$result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($T1) . ';');
$result = PMA_DBI_query(
'SHOW INDEX FROM ' . PMA_backquote($db)
. '.' . PMA_backquote($T1) . ';'
);
$index_array1 = array(); // will be use to emphasis prim. keys in the table view
while ($row = PMA_DBI_fetch_assoc($result)) {
$index_array1[$row['Column_name']] = 1;
}
PMA_DBI_free_result($result);

$result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($T2) . ';');
$result = PMA_DBI_query(
'SHOW INDEX FROM ' . PMA_backquote($db)
. '.' . PMA_backquote($T2) . ';'
);
$index_array2 = array(); // will be used to emphasis prim. keys in the table view
while ($row = PMA_DBI_fetch_assoc($result)) {
$index_array2[$row['Column_name']] = 1;
}
PMA_DBI_free_result($result);

if (! empty($index_array1[$F1]) && ! empty($index_array2[$F2])) {
$upd_query = 'ALTER TABLE ' . PMA_backquote($T2)
. ' ADD FOREIGN KEY ('
. PMA_backquote($F2) . ')'
. ' REFERENCES '
. PMA_backquote($db) . '.'
. PMA_backquote($T1) . '('
. PMA_backquote($F1) . ')';
$upd_query = 'ALTER TABLE ' . PMA_backquote($db)
. '.' . PMA_backquote($T2)
. ' ADD FOREIGN KEY ('
. PMA_backquote($F2) . ')'
. ' REFERENCES '
. PMA_backquote($db) . '.'
. PMA_backquote($T1) . '('
. PMA_backquote($F1) . ')';

if ($on_delete != 'nix') {
$upd_query .= ' ON DELETE ' . $on_delete;
Expand Down
4 changes: 2 additions & 2 deletions pmd_relation_upd.php
Expand Up @@ -29,8 +29,8 @@
$existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');

if (isset($existrel_foreign[$F2]['constraint'])) {
$upd_query = 'ALTER TABLE ' . PMA_backquote($T2)
. ' DROP FOREIGN KEY '
$upd_query = 'ALTER TABLE ' . PMA_backquote($DB2)
. '.' . PMA_backquote($T2) . ' DROP FOREIGN KEY '
. PMA_backquote($existrel_foreign[$F2]['constraint'])
. ';';
$upd_rs = PMA_DBI_query($upd_query);
Expand Down

0 comments on commit e306fad

Please sign in to comment.