This is possible and actually rather simple.
The basic idea is that the $_GET variable is glued to the URL in the displayHtml function and is then available again in the initiateEditor function as a $_GET variable.
As an example I will build a Table Monitor where the name of the table is passed as a $_GET variable. This example assumes that all of your tables in your database have a column 'id'. Also the code is for the paid version, but it works in the same way in the free version.
So first we have to adjust the displayHtml function to add a dropdown with all the table names in your database and reload the page with the table name attached to the URL:
- Code: Select all
function displayHtml()
{
$js = '<script type="text/javascript">
<!--
function myjumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location=\'"+selObj.options[selObj.selectedIndex].value+"\'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>';
echo $js;
$query = 'SHOW TABLES';
$result = mysql_query($query) or die("Could not query: ". mysql_error());
$shtml = '<h1>Table monitor</h1>
<form action="" method="get">
<select name="jumpMenu" id="jumpMenu" onchange="myjumpMenu(\'parent\',this,0)">
<option value="">--- Kies Tabel ---</option>';
while ($td = mysql_fetch_array($result)) {
$tbl = $td[0];
$shtml .= '<option value="'.$_SERVER["PHP_SELF"].'?tbl='.$tbl.'">'.$tbl.'</option>';
}
$shtml .= '</select></form>';
echo $shtml;
$html = '
<div id="historyContainer">
<div id="information">
......
......
}
The javascript portion is to directly reload the page (jump Menu) as soon as you select the table name.
Next we need to glue the $_GET variable to the URL.
Also in the function displayHtml find the line with the URL
- Code: Select all
setAjaxInfo({url: "'.$_SERVER["PHP_SELF"].'", history: true});
and replace with :
- Code: Select all
setAjaxInfo({url: "'.$_SERVER["PHP_SELF"].'?tbl='.$_GET["tbl"].'", history: true});
Now the variable gets passed and it is available in the initiateEditor function as a $_GET variable again.
Since it is empty the first time the script is invoked we need a default tablename and since you are using MATE you should have a table called “mate_columns”:
- Code: Select all
$dump_table = ! empty($_GET['tbl']) ? $_GET['tbl'] : 'mate_columns';
Now we can use the variable $dump_table to query for the fields of the table and build the $tableColumns array.
- Code: Select all
$query = 'SHOW COLUMNS FROM '.$dump_table ;
$result = mysql_query($query) or die("Could not query: ". mysql_error());
while ($row = mysql_fetch_assoc($result)){
$tableColumns[$row['Field']] = array('display_text' => $row['Field'], 'perms' => 'VTXQX');
}
As the last step we should set tne $tableName:
- Code: Select all
$tableName = $dump_table ;
And here is the complete code of the script.
- Code: Select all
<?php
require_once('../include/Common32.php');
require_once('../mate-3.2/php/lang/LangVars-nl.php');
require_once('../mate-3.2/php/AjaxTableEditor.php');
class TableMonitor extends Common
{
function displayHtml()
{
$js = '<script type="text/javascript">
<!--
function myjumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location=\'"+selObj.options[selObj.selectedIndex].value+"\'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>';
echo $js;
$query = 'SHOW TABLES';
$result = mysql_query($query) or die("Could not query: ". mysql_error());
$shtml = '<h1>Table monitor</h1>
<form action="" method="get">
<select name="jumpMenu" id="jumpMenu" onchange="myjumpMenu(\'parent\',this,0)">
<option value="">--- Kies Tabel ---</option>';
while ($td = mysql_fetch_array($result)) {
$tbl = $td[0];
$shtml .= '<option value="'.$_SERVER["PHP_SELF"].'?tbl='.$tbl.'">'.$tbl.'</option>';
}
$shtml .= '</select></form>';
echo $shtml;
$html = '
<div id="historyContainer">
<div id="information">
</div>
<div id="titleLayer" style="padding: 2px; font-weight: bold; font-size: 18px; text-align: left;">
</div>
<div id="tableLayer" align="left" style=" width: 100%; overflow-x:auto; position: relative;">
</div>
<div id="recordLayer" align="left" style="width:900px">
</div>
<div id="searchButtonsLayer" align="left">
</div>
</div>
<br /><br /><br />';
echo $html;
// Set default session configuration variables here
$defaultSessionData['orderByColumn'] = 'id';
$defaultSessionData = base64_encode($this->Editor->jsonEncode($defaultSessionData));
$javascript = '
<script type="text/javascript">
setAjaxInfo({url: "'.$_SERVER["PHP_SELF"].'?tbl='.$_GET["tbl"].'", history: true});
if(ajaxInfo.history == false)
{
toAjaxTableEditor("update_html","");
}
else if(window.location.hash.length == 0)
{
var defaultInfo = {info: "", action: "update_html", sessionData: "'.$defaultSessionData.'"};
window.location.href = window.location.href+"#"+Base64.encode(Object.toJSON(defaultInfo));
}
</script>';
echo $javascript;
}
function initiateEditor()
{
$dump_table = ! empty($_GET['tbl']) ? $_GET['tbl'] : 'mate_columns';
$query = 'SHOW COLUMNS FROM '.$dump_table ;
$result = mysql_query($query) or die("Could not query: ". mysql_error());
while ($row = mysql_fetch_assoc($result)){
$tableColumns[$row['Field']] = array('display_text' => $row['Field'], 'perms' => 'VTXQX');
}
$tableName = $dump_table ;
$primaryCol = 'id';
$errorFun = array(&$this,'logError');
$permissions = 'VIQSX';
require_once('../mate-3.2/php/AjaxTableEditor.php');
$this->Editor = new AjaxTableEditor($tableName,$primaryCol,$errorFun,$permissions,$tableColumns);
$this->Editor->setConfig('tableInfo','cellpadding="1" width="100%" class="mateTable"');
$this->Editor->setConfig('tableTitle',$dump_table);
$this->Editor->setConfig('paginationLinks',true);
$this->Editor->setConfig('iconColPosition','first');
}
function __construct()
{
session_start();
$this->mysqlConnect();
$this->initiateEditor();
if(isset($_POST['json']))
{
if(ini_get('magic_quotes_gpc'))
{
$_POST['json'] = stripslashes($_POST['json']);
}
$this->Editor->data = $this->Editor->jsonDecode($_POST['json']);
$this->Editor->setDefaults();
$this->Editor->main();
echo $this->Editor->jsonEncode($this->Editor->retArr);
}
else if(isset($_GET['export']))
{
$this->Editor->data->sessionData = $_GET['session_data'];
$this->Editor->setDefaults();
//echo mb_convert_encoding($this->Editor->exportInfo(),"Windows-1252","UTF-8");
echo $this->Editor->exportInfo();
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-type: application/x-msexcel');
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="'.$this->Editor->tableName.'.csv"');
exit();
}
else if(isset($_POST) && count($_POST) > 0)
{
$this->Editor->setDefaults();
$this->Editor->handleFileUpload();
}
else
{
$this->displayHeaderHtml();
$this->displayHtml();
$this->displayFooterHtml();
}
}
}
$lte = new TableMonitor();
?>
Now you should have a very simple Table Monitor where the tablename is passed as a $_GET variable.
That is all.