Struggeling with relocating
Dieser Commit ist enthalten in:
Commit
89ea01c429
301 geänderte Dateien mit 59926 neuen und 0 gelöschten Zeilen
185
inc/sqlbrowser/db/list_databases.php
Normale Datei
185
inc/sqlbrowser/db/list_databases.php
Normale Datei
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
$do = isset($_POST['do']) ? $_POST['do'] : '';
|
||||
$dbs = isset($_POST['database']) ? $_POST['database'] : array();
|
||||
// truncte 1 db
|
||||
if (isset($_GET['truncate_db'])) {
|
||||
$do = 'db_truncate';
|
||||
$dbs = array(
|
||||
$_GET['truncate_db']);
|
||||
}
|
||||
|
||||
// drop 1 db
|
||||
if (isset($_GET['drop_db'])) {
|
||||
$do = 'db_delete';
|
||||
$dbs = array(
|
||||
$_GET['drop_db']);
|
||||
}
|
||||
|
||||
if ($do > '' && sizeof($dbs) > 0) {
|
||||
$sql = array();
|
||||
$associatedDatabase = array();
|
||||
$tplSqlbrowserDbOperation = new MSDTemplate();
|
||||
$tplSqlbrowserDbOperation->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserDbOperation' => 'tpl/sqlbrowser/db/operation.tpl'
|
||||
)
|
||||
);
|
||||
|
||||
$i = 0;
|
||||
foreach ($dbs as $database) {
|
||||
$database = base64_decode($database);
|
||||
// truncate all tables but keep database
|
||||
if ($do == 'db_truncate') {
|
||||
$actionOutput = $lang['L_CLEAR_DATABASE'];
|
||||
// clear table array to not delete other tables by accident
|
||||
unset($tableInfos);
|
||||
$tableInfos = getTableInfo($database);
|
||||
$sql[] = 'SET FOREIGN_KEY_CHECKS=0';
|
||||
$associatedDatabase[] = $database;
|
||||
foreach ($tableInfos[$database]['tables'] as $table => $val) {
|
||||
$query = $val['engine'] == 'VIEW' ? 'DROP VIEW ' : 'DROP TABLE ';
|
||||
$sql[] = sprintf($query . '`%s`.`%s`', $database, $table);
|
||||
$associatedDatabase[] = $database;
|
||||
}
|
||||
$sql[] = 'SET FOREIGN_KEY_CHECKS=1';
|
||||
$associatedDatabase[] = $database;
|
||||
}
|
||||
|
||||
// delete complete database
|
||||
if ($do == 'db_delete') {
|
||||
$actionOutput = $lang['L_DELETE_DATABASE'];
|
||||
$sql[] = 'DROP DATABASE `' . $database . '`';
|
||||
$associatedDatabase[] = $database;
|
||||
}
|
||||
}
|
||||
|
||||
$tplSqlbrowserDbOperation->assign_vars(
|
||||
array(
|
||||
'ACTION' => $actionOutput,
|
||||
'ICON_OK' => $icon['ok'],
|
||||
'ICON_NOTOK' => $icon['not_ok']
|
||||
)
|
||||
);
|
||||
|
||||
//process all sql commands and output result to template
|
||||
foreach ($sql as $index => $query) {
|
||||
//$res = MSD_query($query, false);
|
||||
$res = $dbo->query($query, MsdDbFactory::SIMPLE);
|
||||
if (true === $res) {
|
||||
$tplSqlbrowserDbOperation->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $index % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $index + 1,
|
||||
'DBNAME' => $associatedDatabase[$index],
|
||||
'ACTION' => $actionOutput,
|
||||
'QUERY' => $query
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$tplSqlbrowserDbOperation->assign_block_vars(
|
||||
'ERROR',
|
||||
array(
|
||||
'ROWCLASS' => $index % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $index + 1,
|
||||
'DBNAME' => $associatedDatabase[$index],
|
||||
'ACTION' => $actionOutput,
|
||||
'QUERY' => $query,
|
||||
'ERROR' => mysql_error($config['dbconnection'])
|
||||
)
|
||||
);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
if ($do == 'db_delete') {
|
||||
setDefaultConfig();
|
||||
}
|
||||
}
|
||||
|
||||
//list databases
|
||||
$tplSqlbrowserDbListDatabases = new MSDTemplate();
|
||||
$tplSqlbrowserDbListDatabases->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserDbListDatabases' => 'tpl/sqlbrowser/db/list_databases.tpl'
|
||||
)
|
||||
);
|
||||
$tplSqlbrowserDbListDatabases->assign_vars(
|
||||
array(
|
||||
'ICON_DB' => $icon['db'],
|
||||
'ICON_VIEW' => $icon['view'],
|
||||
'ICON_EDIT' => $icon['edit'],
|
||||
'ICON_DELETE' => $icon['delete'],
|
||||
'ICON_PLUS' => $icon['plus'],
|
||||
'ICON_MINUS' => $icon['minus'],
|
||||
'ICON_TRUNCATE' => $icon['truncate'],
|
||||
'CONFIRM_TRUNCATE_DATABASES' =>
|
||||
Html::getJsQuote($lang['L_CONFIRM_TRUNCATE_DATABASES'], true),
|
||||
'CONFIRM_DROP_DATABASES' =>
|
||||
Html::getJsQuote($lang['L_CONFIRM_DROP_DATABASES'], true)
|
||||
)
|
||||
);
|
||||
|
||||
$i = 0;
|
||||
foreach ($databases as $dbName => $val) {
|
||||
$rowclass = ($i % 2) ? 'dbrow' : 'dbrow1';
|
||||
if ($dbName == $config['db_actual']) {
|
||||
$rowclass = "dbrowsel";
|
||||
}
|
||||
//does the database exist?
|
||||
if (!$dbo->selectDb($dbName, true)) {
|
||||
// no -> show message "doesn't exist"
|
||||
$tplSqlbrowserDbListDatabases->assign_block_vars(
|
||||
'DB_NOT_FOUND',
|
||||
array(
|
||||
'ROWCLASS' => $rowclass,
|
||||
'NR' => ($i + 1),
|
||||
'DB_NAME' => $dbName,
|
||||
'DB_ID' => $i
|
||||
)
|
||||
);
|
||||
// if this happens the list is not accurate
|
||||
// -> reload db-list to remove deleted dbs
|
||||
setDefaultConfig();
|
||||
} else {
|
||||
// yes, db exists -> show nr of tables
|
||||
$tables=$dbo->getTableStatus();
|
||||
$numTables = (int) sizeof($tables);
|
||||
$tplSqlbrowserDbListDatabases->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $rowclass,
|
||||
'NR' => ($i + 1),
|
||||
'DB_NAME' => $dbName,
|
||||
'DATABASE_NAME_URLENCODED' => base64_encode($dbName),
|
||||
'DB_ID' => base64_encode($dbName),
|
||||
'TABLE_COUNT' => $numTables,
|
||||
'CONFIRM_DELETE' =>
|
||||
Html::getJsQuote(sprintf($lang['L_ASKDBDELETE'], $dbName)),
|
||||
'CONFIRM_TRUNCATE' =>
|
||||
Html::getJsQuote(sprintf($lang['L_ASKDBEMPTY'], $dbName))
|
||||
)
|
||||
);
|
||||
|
||||
if ($numTables == 1) {
|
||||
$tplSqlbrowserDbListDatabases->assign_block_vars(
|
||||
'ROW.TABLE', array()
|
||||
);
|
||||
} else {
|
||||
$tplSqlbrowserDbListDatabases->assign_block_vars(
|
||||
'ROW.TABLES', array()
|
||||
);
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
17
inc/sqlbrowser/general/footer.php
Normale Datei
17
inc/sqlbrowser/general/footer.php
Normale Datei
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1205 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
|
||||
$tplSqlbrowserGeneralFooter = new MSDTemplate();
|
||||
$tplSqlbrowserGeneralFooter->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserGeneralFooter' => 'tpl/sqlbrowser/general/footer.tpl')
|
||||
);
|
||||
65
inc/sqlbrowser/general/mysql_variables.php
Normale Datei
65
inc/sqlbrowser/general/mysql_variables.php
Normale Datei
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
$selectedFilter = -1;
|
||||
if (isset($_POST['filter_selected'])) {
|
||||
$selectedFilter = $_POST['filter_selected'];
|
||||
}
|
||||
$vars = array();
|
||||
$res = $dbo->query('SHOW VARIABLES', MsdDbFactory::ARRAY_ASSOC);
|
||||
$numrows = @sizeof($res);
|
||||
foreach ($res as $row) {
|
||||
$vars[$row['Variable_name']] = $row['Value'];
|
||||
}
|
||||
|
||||
$filter = getPrefixArray($vars);
|
||||
$tplSqlbrowserGeneralMysqlVariables = new MSDTemplate();
|
||||
$tplSqlbrowserGeneralMysqlVariables->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserGeneralMysqlVariables' =>
|
||||
'tpl/sqlbrowser/general/mysqlVariables.tpl'
|
||||
)
|
||||
);
|
||||
$tplSqlbrowserGeneralMysqlVariables->assign_vars(
|
||||
array('SEL_FILTER' => Html::getOptionlist($filter, $selectedFilter))
|
||||
);
|
||||
|
||||
if (count($vars) == 0) {
|
||||
$tpl->assign_block_vars('NO_VALUES', array());
|
||||
} else {
|
||||
$i = 0;
|
||||
foreach ($vars as $name => $val) {
|
||||
if ($selectedFilter != '-1'
|
||||
&& substr($name, 0, strlen($selectedFilter)) != $selectedFilter) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_numeric($val)) {
|
||||
if (strpos($name, 'time') === false) {
|
||||
$val = String::formatNumber($val);
|
||||
} else {
|
||||
$val = getTimeFormat($val);
|
||||
}
|
||||
}
|
||||
|
||||
$tplSqlbrowserGeneralMysqlVariables->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $i + 1,
|
||||
'VAR_NAME' => $name,
|
||||
'VAR_VALUE' => htmlspecialchars($val, ENT_COMPAT, 'UTF-8')
|
||||
)
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
96
inc/sqlbrowser/general/process.php
Normale Datei
96
inc/sqlbrowser/general/process.php
Normale Datei
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
$tplSqlbrowserGeneralProcess = new MSDTemplate();
|
||||
$tplSqlbrowserGeneralProcess->set_filenames(
|
||||
array('tplSqlbrowserGeneralProcess' => 'tpl/sqlbrowser/general/process.tpl')
|
||||
);
|
||||
|
||||
$killid = 0;
|
||||
if (isset($_GET['killid']) && $_GET['killid'] > 0) {
|
||||
$killid = (int) $_GET['killid'];
|
||||
if (isset($_POST['killid'])) intval($killid = $_POST['killid']);
|
||||
$wait = (isset($_POST['wait'])) ? $_POST['wait'] : 0;
|
||||
if ($wait == 0) {
|
||||
$tplSqlbrowserGeneralProcess->assign_block_vars(
|
||||
'KILL_STARTED', array('KILL_ID' => $killid)
|
||||
);
|
||||
$wait = $config['refresh_processlist'];
|
||||
try
|
||||
{
|
||||
$ret = $dbo->query('KILL ' . $_GET['killid'], MsdDbFactory::SIMPLE);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$tplSqlbrowserGeneralProcess->assign_block_vars(
|
||||
'KILL_ERROR',
|
||||
array('MESSAGE' => '('.$e->getCode().') '.$e->getMessage())
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$tplSqlbrowserGeneralProcess->assign_block_vars(
|
||||
'KILL_WAIT',
|
||||
array(
|
||||
'KILL_ID' => $killid,
|
||||
'WAIT_TIME' => $wait
|
||||
)
|
||||
);
|
||||
$wait += $config['refresh_processlist'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $dbo->query('SHOW FULL PROCESSLIST', MsdDbFactory::ARRAY_NUMERIC);
|
||||
$numrows = (int) @sizeof($res);
|
||||
if ($numrows == 0) {
|
||||
$tplSqlbrowserGeneralProcess->assign_block_vars('NO_PROCESS', array());
|
||||
} else {
|
||||
$processFound = false;
|
||||
foreach ($res as $row) {
|
||||
if ($row[0] == $killid) {
|
||||
$processFound = true;
|
||||
if ($row[4] == "Killed") $killid = 0;
|
||||
}
|
||||
|
||||
$tplSqlbrowserGeneralProcess->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $i + 1,
|
||||
'ID' => $row[0],
|
||||
'USER' => $row[1],
|
||||
'HOST' => $row[2],
|
||||
'DB' => $row[3],
|
||||
'QUERY' => $row[4],
|
||||
'TIME' => $row[5],
|
||||
'STATE' => $row[6],
|
||||
'INFO' => $row[7]
|
||||
)
|
||||
);
|
||||
if ($killid == 0) {
|
||||
$tplSqlbrowserGeneralProcess->assign_block_vars(
|
||||
'ROW.KILL', array()
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!$processFound) {
|
||||
$killid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$tplSqlbrowserGeneralProcess->assign_vars(
|
||||
array(
|
||||
'REFRESHTIME' => $config['refresh_processlist'],
|
||||
'REFRESHTIME_MS' => $config['refresh_processlist'] * 1000,
|
||||
'ICON_DELETE' => $icon['kill_process'],
|
||||
'KILL_ID' => $killid
|
||||
)
|
||||
);
|
||||
122
inc/sqlbrowser/general/sqlbox.php
Normale Datei
122
inc/sqlbrowser/general/sqlbox.php
Normale Datei
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
|
||||
include ('./inc/functions/functions_restore.php');
|
||||
$sql['sql_statements'] = '';
|
||||
$queries = array();
|
||||
|
||||
$db = (!isset($_GET['db'])) ? $config['db_actual'] : base64_decode($_GET['db']);
|
||||
if (isset($_GET['db'])) $config['db_actual'] = $db;
|
||||
$tablename = '';
|
||||
if (isset($_GET['tablename'])) {
|
||||
$tablename = base64_decode($_GET['tablename']);
|
||||
}
|
||||
if (isset($_POST['tablename'])) $tablename = base64_decode($_POST['tablename']);
|
||||
if (isset($_POST['sqltextarea'])) {
|
||||
$sql['sql_statements'] = $_POST['sqltextarea'];
|
||||
} else {
|
||||
if (isset($_SESSION['sql']['statements'])) {
|
||||
$sql['sql_statements'] = $_SESSION['sql']['statements'];
|
||||
}
|
||||
}
|
||||
$tdcompact = $config['interface_table_compact'];
|
||||
if (isset($_GET['tdc'])) {
|
||||
$tdcompact = $_GET['tdc'];
|
||||
}
|
||||
if (isset($_POST['tableselect']) && $_POST['tableselect'] != '1') {
|
||||
$tablename = $_POST['tableselect'];
|
||||
}
|
||||
$dbo->selectDb($db);
|
||||
|
||||
//Start SQL-Box
|
||||
$tplSqlbrowserSqlbox = new MSDTemplate();
|
||||
$tplSqlbrowserSqlbox->set_filenames(
|
||||
array('tplSqlbrowserSqlbox' => 'tpl/sqlbrowser/sqlbox/sqlbox.tpl')
|
||||
);
|
||||
|
||||
if (isset($_GET['readfile']) && $_GET['readfile'] == 1) {
|
||||
$tplSqlbrowserSqlbox->assign_block_vars(
|
||||
'SQLUPLOAD',
|
||||
array(
|
||||
'POSTTARGET' => $params,
|
||||
'LANG_OPENSQLFILE' => $lang['L_SQL_OPENFILE'],
|
||||
'LANG_OPENSQLFILE_BUTTON' => $lang['L_SQL_OPENFILE_BUTTON'],
|
||||
'LANG_SQL_MAXSIZE' => $lang['L_MAX_UPLOAD_SIZE'],
|
||||
'MAX_FILESIZE' => $config['upload_max_filesize']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($_POST['submit_openfile'])) {
|
||||
//open file
|
||||
if (!isset($_FILES['upfile']['name']) || empty($_FILES['upfile']['name'])) {
|
||||
$aus .= '<span class="error">' . $lang['L_FM_UPLOADFILEREQUEST'] . '</span>';
|
||||
} else {
|
||||
$fn = $_FILES['upfile']['tmp_name'];
|
||||
if (strtolower(substr($_FILES['upfile']['name'], -3)) == ".gz") {
|
||||
$readUserSqlfile = gzfile($fn);
|
||||
} else {
|
||||
$readUserSqlfile = file($fn);
|
||||
}
|
||||
$sqlLoaded = implode("", $readUserSqlfile);
|
||||
}
|
||||
}
|
||||
|
||||
// Do we have SQL-Queries in User-SQLLib?
|
||||
$sqlcombo = getSqlLibraryComboBox();
|
||||
if ($sqlcombo > '') {
|
||||
$tplSqlbrowserSqlbox->assign_block_vars(
|
||||
'SQLCOMBO', array('SQL_COMBOBOX' => $sqlcombo)
|
||||
);
|
||||
}
|
||||
// create Table select box
|
||||
$tables = $dbo->getTables($db);
|
||||
$tableSelectBox = Html::getOptionlist($tables, false, $lang['L_TABLE'] . ' `%s`');
|
||||
|
||||
$tplSqlbrowserSqlbox->assign_vars(
|
||||
array(
|
||||
'LANG_SQL_WARNING' => $lang['L_SQL_WARNING'],
|
||||
'ICONPATH' => $config['files']['iconpath'],
|
||||
'ICON_PLUS' => $icon['plus'],
|
||||
'ICON_MINUS' => $icon['minus'],
|
||||
'MYSQL_REF' => 'http://dev.mysql.com/doc/',
|
||||
'BOXSIZE' => $config['interface_sqlboxsize'],
|
||||
'BOXCONTENT' => $sql['sql_statements'],
|
||||
'LANG_SQL_BEFEHLE' => $lang['L_SQL_COMMANDS'],
|
||||
'TABLE_COMBOBOX' => $tableSelectBox,
|
||||
'LANG_SQL_EXEC' => $lang['L_SQL_EXEC'],
|
||||
'LANG_RESET' => $lang['L_RESET'],
|
||||
'DB' => $db,
|
||||
'DB_ENCODED' => base64_encode($db),
|
||||
'ICON_SEARCH' => $icon['search'],
|
||||
'ICON_UPLOAD' => $icon['upload'],
|
||||
'ICON_ARROW_LEFT' => $icon['arrow_left'],
|
||||
'ICON_MYSQL_HELP' => $icon['mysql_help'],
|
||||
'ICON_CLOSE' => $icon['close'],
|
||||
'MYSQL_HELP' => $lang['L_TITLE_MYSQL_HELP'],
|
||||
'LANG_TOOLBOX' => $lang['L_TOOLS_TOOLBOX'],
|
||||
'LANG_TOOLS' => $lang['L_TOOLS'],
|
||||
'LANG_DB' => $lang['L_DB'],
|
||||
'LANG_TABLE' => $lang['L_TABLE'],
|
||||
'LANG_SQL_TABLEVIEW' => $lang['L_SQL_TABLEVIEW'],
|
||||
'LANG_BACK_TO_DB_OVERVIEW' => $lang['L_SQL_BACKDBOVERVIEW']
|
||||
)
|
||||
);
|
||||
|
||||
if (isset($_POST['execsql']) || $action == 'general_sqlbox_show_results'
|
||||
|| $sql['sql_statements'] > '') {
|
||||
include ('./inc/sqlbrowser/sqlbox/show_results.php');
|
||||
}
|
||||
$_SESSION['db'] = $db;
|
||||
$_SESSION['tablename'] = $tablename;
|
||||
$_SESSION['sql']['statements'] = $sql['sql_statements'];
|
||||
72
inc/sqlbrowser/general/status.php
Normale Datei
72
inc/sqlbrowser/general/status.php
Normale Datei
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
$selectedFilter = -1;
|
||||
if (isset($_POST['filter_selected'])) {
|
||||
$selectedFilter = $_POST['filter_selected'];
|
||||
}
|
||||
$res = $dbo->query('SHOW GLOBAL STATUS', MsdDbFactory::ARRAY_ASSOC);
|
||||
foreach ($res as $row) {
|
||||
$status[$row['Variable_name']] = $row['Value'];
|
||||
}
|
||||
|
||||
$filter = getPrefixArray($status);
|
||||
// values that will be formatted as times
|
||||
$timeValues = array('Uptime', 'Uptime_since_flush_status');
|
||||
|
||||
$tplSqlbrowserGeneralStatus = new MSDTemplate();
|
||||
$tplSqlbrowserGeneralStatus->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserGeneralStatus' => 'tpl/sqlbrowser/general/status.tpl'
|
||||
)
|
||||
);
|
||||
|
||||
if ($selectedFilter != '-1') {
|
||||
$query = 'SHOW GLOBAL STATUS LIKE \'' . $selectedFilter . '_%\'';
|
||||
$res = $dbo->query($query, MsdDbFactory::ARRAY_ASSOC);
|
||||
}
|
||||
if (@sizeof($res) == 0) {
|
||||
$tpl->assign_block_vars('NO_STATUS', array());
|
||||
} else {
|
||||
if (count($filter) > 0) {
|
||||
$tplSqlbrowserGeneralStatus->assign_block_vars(
|
||||
'FILTER',
|
||||
array(
|
||||
'SEL_FILTER' => Html::getOptionlist($filter, $selectedFilter)
|
||||
)
|
||||
);
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($status as $key => $val) {
|
||||
if ($selectedFilter != '-1'
|
||||
&& substr($key, 0, strlen($selectedFilter)) != $selectedFilter) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($key, $timeValues)) {
|
||||
$val = getTimeFormat($val);
|
||||
} else {
|
||||
$val = String::formatNumber($val);
|
||||
}
|
||||
|
||||
$tplSqlbrowserGeneralStatus->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $i + 1,
|
||||
'VAR_NAME' => $key,
|
||||
'VAR_VALUE' => $val
|
||||
)
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
405
inc/sqlbrowser/mysql_search.php
Normale Datei
405
inc/sqlbrowser/mysql_search.php
Normale Datei
|
|
@ -0,0 +1,405 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
//alle Tabellen der aktuellen Datenbank ermitteln und Zugriffs-Array aufbauen
|
||||
$sql = 'SHOW TABLES FROM `' . $db . '`';
|
||||
$tables = ARRAY();
|
||||
$link = MSD_mysql_connect();
|
||||
$res = mysql_query($sql, $link);
|
||||
if (!$res === false)
|
||||
{
|
||||
WHILE ($row = mysql_fetch_array($res, MYSQL_NUM))
|
||||
{
|
||||
$tables[] = $row[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
die("No Tables in Database!");
|
||||
|
||||
// Suchkriterien aus Session holen oder aus POST-Umgebung
|
||||
// so bleiben die Suchkriterien auch erhalten wenn man zwischendurch woanders klickt
|
||||
if (isset($_POST['suchbegriffe'])) $_SESSION['mysql_search']['suchbegriffe'] = $_POST['suchbegriffe'];
|
||||
if (!isset($_SESSION['mysql_search']['suchbegriffe'])) $_SESSION['mysql_search']['suchbegriffe'] = '';
|
||||
$suchbegriffe = $_SESSION['mysql_search']['suchbegriffe'];
|
||||
|
||||
if (isset($_POST['suchart'])) $_SESSION['mysql_search']['suchart'] = $_POST['suchart'];
|
||||
if (!isset($_SESSION['mysql_search']['suchart']) || strlen($_SESSION['mysql_search']['suchart']) < 2) $_SESSION['mysql_search']['suchart'] = 'AND';
|
||||
$suchart = $_SESSION['mysql_search']['suchart'];
|
||||
|
||||
if (isset($_POST['table_selected'])) $_SESSION['mysql_search']['table_selected'] = $_POST['table_selected'];
|
||||
if (!isset($_SESSION['mysql_search']['table_selected'])) $_SESSION['mysql_search']['table_selected'] = 0;
|
||||
$table_selected = $_SESSION['mysql_search']['table_selected'];
|
||||
// Falls zwischendurch Tabellen geloescht wurden und der Index nicht mehr existiert, zuruecksetzen
|
||||
if ($table_selected > count($tables) - 1) $table_selected = 0;
|
||||
|
||||
$offset = (isset($_POST['offset'])) ? intval($_POST['offset']) : 0;
|
||||
|
||||
// Delete
|
||||
if (isset($_GET['mode']) && $_GET['mode'] == "kill" && $rk > '')
|
||||
{
|
||||
//echo "<br /> RK ist: ".$rk."<br /><br />";
|
||||
if (strpos($rk, "|") != false) $rk = str_replace('|', ' AND ', $rk);
|
||||
$sqlk = "DELETE FROM `$tablename` WHERE " . $rk . " LIMIT 1";
|
||||
echo $sqlk;
|
||||
$res = MSD_query($sqlk);
|
||||
// echo "<br />".$res;
|
||||
$aus .= '<p class="success">' . $lang['L_SQL_RECORDDELETED'] . '</p>';
|
||||
}
|
||||
|
||||
function mysql_search($db, $tabelle, $suchbegriffe, $suchart, $offset = 0, $anzahl_ergebnisse = 20, $auszuschliessende_tabellen = '')
|
||||
{
|
||||
global $tables, $config;
|
||||
$ret = false;
|
||||
$link = MSD_mysql_connect();
|
||||
if (sizeof($tables) > 0)
|
||||
{
|
||||
$suchbegriffe = trim(str_replace('*', '', $suchbegriffe));
|
||||
$suchworte = explode(' ', $suchbegriffe);
|
||||
if (($suchbegriffe > '') && (is_array($suchworte)))
|
||||
{
|
||||
// Leere Einträge (durch doppelte Leerzeichen) entfernen
|
||||
$anzahl_suchworte = sizeof($suchworte);
|
||||
for ($i = 0; $i < $anzahl_suchworte; $i++)
|
||||
{
|
||||
if (trim($suchworte[$i]) == '') unset($suchworte[$i]);
|
||||
}
|
||||
|
||||
$bedingung = '';
|
||||
$where = '';
|
||||
$felder = '';
|
||||
|
||||
// Felder ermitteln
|
||||
$sql = 'SHOW COLUMNS FROM `' . $db . '`.`' . $tables[$tabelle] . '`';
|
||||
$res = mysql_query($sql, $link);
|
||||
unset($felder);
|
||||
if (!$res === false)
|
||||
{
|
||||
// Felder der Tabelle ermitteln
|
||||
WHILE ($row = mysql_fetch_object($res))
|
||||
{
|
||||
$felder[] = $row->Field;
|
||||
}
|
||||
}
|
||||
|
||||
$feldbedingung = '';
|
||||
if ($suchart == 'CONCAT')
|
||||
{
|
||||
if (is_array($felder))
|
||||
{
|
||||
//Concat-String bildem
|
||||
$concat = implode('`),LOWER(`', $felder);
|
||||
$concat = 'CONCAT_WS(\'\',LOWER(`' . $concat . '`))';
|
||||
$where = '';
|
||||
foreach ($suchworte as $suchbegriff)
|
||||
{
|
||||
$where .= $concat . ' LIKE \'%' . strtolower($suchbegriff) . '%\' AND ';
|
||||
}
|
||||
$where = substr($where, 0, -4); // letztes AND entfernen
|
||||
$sql = 'SELECT * FROM `' . $db . '`.`' . $tables[$tabelle] . '` WHERE ' . $where . ' LIMIT ' . $offset . ',' . $anzahl_ergebnisse;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$pattern = '`{FELD}` LIKE \'%{SUCHBEGRIFF}%\'';
|
||||
if (is_array($felder))
|
||||
{
|
||||
foreach ($felder as $feld)
|
||||
{
|
||||
unset($feldbedingung);
|
||||
foreach ($suchworte as $suchbegriff)
|
||||
{
|
||||
$suchen = ARRAY(
|
||||
|
||||
'{FELD}',
|
||||
'{SUCHBEGRIFF}');
|
||||
$ersetzen = ARRAY(
|
||||
|
||||
$feld,
|
||||
$suchbegriff);
|
||||
$feldbedingung[] = str_replace($suchen, $ersetzen, $pattern);
|
||||
}
|
||||
$bedingung[] = '(' . implode(' ' . $suchart . ' ', $feldbedingung) . ') ';
|
||||
}
|
||||
}
|
||||
else
|
||||
die('<br />Fehler bei Suche: ich konnte nicht ermitteln welche Felder die Tabelle "' . $tabelle . '" hat!');
|
||||
$where = implode(' OR ', $bedingung);
|
||||
$sql = 'SELECT * FROM `' . $db . '`.`' . $tables[$tabelle] . '` WHERE (' . $where . ') LIMIT ' . $offset . ',' . $anzahl_ergebnisse;
|
||||
}
|
||||
}
|
||||
else
|
||||
$sql = 'SELECT * FROM `' . $db . '`.`' . $tables[$tabelle] . '` LIMIT ' . $offset . ',' . $anzahl_ergebnisse;
|
||||
|
||||
$res = @mysql_query($sql, $link);
|
||||
if ($res)
|
||||
{
|
||||
WHILE ($row = mysql_fetch_array($res, MYSQL_ASSOC))
|
||||
{
|
||||
//Treffer markieren
|
||||
foreach ($row as $key => $val)
|
||||
{
|
||||
foreach ($suchworte as $suchbegriff)
|
||||
{
|
||||
$row[$key] = markiere_suchtreffer($suchbegriff, $row[$key]);
|
||||
}
|
||||
$row[$key] = ersetze_suchtreffer($row[$key]);
|
||||
}
|
||||
$ret[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// Markiert den Suchbegriff mit einem Code (ASCII 01/02)
|
||||
// - falls nicht gefunden : Rückgabe des Originalstrings
|
||||
//
|
||||
function markiere_suchtreffer($suchbegriff, $suchstring)
|
||||
{
|
||||
$str = strtolower($suchstring);
|
||||
$suchbegriff = strtolower($suchbegriff);
|
||||
if ((strlen($str) > 0) && (strlen($suchbegriff) > 0))
|
||||
{
|
||||
// Treffer Position bestimmen
|
||||
$offset = 0;
|
||||
$trefferpos = 0;
|
||||
while (($offset <= strlen($str)))
|
||||
//Wenn nur der erste Treffer markiert werden soll, so muss die Zeile so lauten
|
||||
// while ( ($offset<=strlen($str)) || ($in_html==false) )
|
||||
{
|
||||
for ($offset = $trefferpos; $offset <= strlen($str); $offset++)
|
||||
{
|
||||
$start = strpos($str, $suchbegriff, $offset);
|
||||
if ($start === false) $offset = strlen($str) + 1;
|
||||
else
|
||||
{
|
||||
if ($offset <= strlen($str))
|
||||
{
|
||||
//Treffer überprüfen
|
||||
$in_html = false;
|
||||
// Steht die Fundstelle zwischen < und > (also im HTML-Tag) ?
|
||||
for ($position = $start; $position >= 0; $position--)
|
||||
{
|
||||
if (substr($str, $position, 1) == ">")
|
||||
{
|
||||
$in_html = false;
|
||||
$position = -1; // Schleife verlassen
|
||||
}
|
||||
if (substr($str, $position, 1) == "<")
|
||||
{
|
||||
$in_html = true;
|
||||
$position = -1; // Schleife verlassen
|
||||
}
|
||||
}
|
||||
if ($in_html)
|
||||
{
|
||||
for ($position2 = $start; $position2 < strlen($str); $position2++)
|
||||
{
|
||||
if (substr($str, $position2, 1) == "<")
|
||||
{
|
||||
$position2 = strlen($str) + 1;
|
||||
}
|
||||
if (substr($str, $position2, 1) == ">")
|
||||
{
|
||||
$in_html = true;
|
||||
$position2 = strlen($str) + 1;
|
||||
$offset = strlen($str) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$in_html)
|
||||
{
|
||||
$ersetzen = substr($suchstring, $start, strlen($suchbegriff));
|
||||
$str = substr($suchstring, 0, $start);
|
||||
$str .= chr(1) . $ersetzen . chr(2);
|
||||
$str .= substr($suchstring, ($start + strlen($ersetzen)), (strlen($suchstring) - strlen($ersetzen)));
|
||||
$suchstring = $str;
|
||||
}
|
||||
if ($in_html)
|
||||
{
|
||||
$trefferpos = $start + 1;
|
||||
$offset = $trefferpos;
|
||||
}
|
||||
}
|
||||
$offset = $start + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $suchstring;
|
||||
}
|
||||
|
||||
// Ersetzt die Codes letztlich durch die Fontangabe
|
||||
function ersetze_suchtreffer($text)
|
||||
{
|
||||
$such = ARRAY(
|
||||
|
||||
chr(1),
|
||||
chr(2));
|
||||
$ersetzen = ARRAY(
|
||||
|
||||
'<span class="treffer">',
|
||||
'</span>');
|
||||
return str_replace($such, $ersetzen, htmlspecialchars($text));
|
||||
}
|
||||
|
||||
$suchbegriffe = trim($suchbegriffe); // Leerzeichen vorne und hinten wegschneiden
|
||||
if (isset($_POST['reset']))
|
||||
{
|
||||
$suchbegriffe = '';
|
||||
$_SESSION['mysql_search']['suchbegriffe'] = '';
|
||||
$suchart = 'AND';
|
||||
$_SESSION['mysql_search']['suchart'] = 'AND';
|
||||
$table_selected = 0;
|
||||
$_SESSION['mysql_search']['table_selected'] = 0;
|
||||
}
|
||||
$showtables = 0; // Anzeige der Tabellendaten im restlichen SQL-Browser ausschalten
|
||||
|
||||
|
||||
// Fix bis zur kompletten Umstellung auf Templates
|
||||
echo $aus;
|
||||
$aus = '';
|
||||
|
||||
$anzahl_tabellen = sizeof($tables);
|
||||
$table_options = '';
|
||||
if ($anzahl_tabellen > 0)
|
||||
{
|
||||
for ($i = 0; $i < $anzahl_tabellen; $i++)
|
||||
{
|
||||
if (isset($tables[$i]))
|
||||
{
|
||||
$table_options .= '<option value="' . $i . '"';
|
||||
if (($i == $table_selected) || ($tables[$i] == $tablename))
|
||||
{
|
||||
$table_options .= ' selected';
|
||||
$table_selected = $i;
|
||||
}
|
||||
$table_options .= '>' . $tables[$i] . '</option>' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = new MSDTemplate();
|
||||
$tpl->set_filenames(array(
|
||||
|
||||
'show' => 'tpl/sqlbrowser/mysql_search.tpl'));
|
||||
|
||||
$tpl->assign_vars(array(
|
||||
'DB_NAME_URLENCODED' => base64_encode($db),
|
||||
'LANG_SQLSEARCH' => $lang['L_SQL_SEARCH'],
|
||||
'LANG_SQL_SEARCHWORDS' => $lang['L_SQL_SEARCHWORDS'],
|
||||
'SUCHBEGRIFFE' => $suchbegriffe,
|
||||
'LANG_START_SQLSEARCH' => $lang['L_START_SQL_SEARCH'],
|
||||
'LANG_RESET_SEARCHWORDS' => $lang['L_RESET_SEARCHWORDS'],
|
||||
'LANG_SEARCH_OPTIONS' => $lang['L_SEARCH_OPTIONS'],
|
||||
'AND_SEARCH' => $suchart == 'AND' ? ' checked' : '',
|
||||
'OR_SEARCH' => $suchart == 'OR' ? ' checked' : '',
|
||||
'CONCAT_SEARCH' => $suchart == 'CONCAT' ? ' checked' : '',
|
||||
'TABLE_OPTIONS' => $table_options,
|
||||
'LANG_SEARCH_OPTIONS_AND' => $lang['L_SEARCH_OPTIONS_AND'],
|
||||
'LANG_SEARCH_OPTIONS_OR' => $lang['L_SEARCH_OPTIONS_OR'],
|
||||
'LANG_SEARCH_OPTIONS_CONCAT' => $lang['L_SEARCH_OPTIONS_CONCAT'],
|
||||
'LANG_SEARCH_IN_TABLE' => $lang['L_SEARCH_IN_TABLE']));
|
||||
|
||||
$max_treffer = 20;
|
||||
$treffer = mysql_search($db, $table_selected, $suchbegriffe, $suchart, $offset, $max_treffer + 1);
|
||||
if (is_array($treffer) && isset($treffer[0]))
|
||||
{
|
||||
$search_message = sprintf($lang['L_SEARCH_RESULTS'], $suchbegriffe, $tables[$table_selected]);
|
||||
$anzahl_treffer = count($treffer);
|
||||
// Blaettern-Buttons
|
||||
$tpl->assign_block_vars('HITS', array(
|
||||
|
||||
'LANG_SEARCH_RESULTS' => $search_message,
|
||||
'LAST_OFFSET' => $offset - $max_treffer,
|
||||
'BACK_BUTTON_DISABLED' => $offset > 0 ? '' : ' disabled',
|
||||
'NEXT_OFFSET' => $offset + $max_treffer,
|
||||
'NEXT_BUTTON_DISABLED' => ($anzahl_treffer != $max_treffer + 1) ? ' disabled' : '',
|
||||
'LANG_ACCESS_KEYS' => $lang['L_SEARCH_ACCESS_KEYS']));
|
||||
|
||||
// Ausgabe der Treffertabelle
|
||||
$anzahl_felder = sizeof($treffer[0]);
|
||||
|
||||
// Ausgabe der Tabellenueberschrift/ Feldnamen
|
||||
foreach ($treffer[0] as $key => $val)
|
||||
{
|
||||
$tpl->assign_block_vars('HITS.TABLEHEAD', array(
|
||||
|
||||
'KEY' => $key));
|
||||
}
|
||||
|
||||
// Ausgabe der Daten
|
||||
$zeige_treffer = sizeof($treffer);
|
||||
if ($zeige_treffer == $max_treffer + 1) $zeige_treffer = $max_treffer;
|
||||
|
||||
// build key - does a primary key exist?
|
||||
$fieldinfos = getExtendedFieldinfo($db, $tables[$table_selected]);
|
||||
//v($fieldinfos);
|
||||
// auf zusammengesetzte Schlüssel untersuchen
|
||||
$table_keys = isset($fieldinfos['primary_keys']) ? $fieldinfos['primary_keys'] : '';
|
||||
|
||||
for ($a = 0; $a < $zeige_treffer; $a++)
|
||||
{
|
||||
$tablename = array_keys($treffer[$a]);
|
||||
if (is_array($table_keys) && sizeof($table_keys) > 0)
|
||||
{
|
||||
// a primary key exitst
|
||||
$keystring = '';
|
||||
foreach ($table_keys as $k)
|
||||
{
|
||||
// remove hit marker from value
|
||||
$x = str_replace('<span class="treffer">', '', $treffer[$a][$k]);
|
||||
$x = str_replace('</span>', '', $x);
|
||||
$keystring .= '`' . $k . '`="' . addslashes($x) . '"|';
|
||||
}
|
||||
$keystring = substr($keystring, 0, -1);
|
||||
$rk = build_recordkey($keystring);
|
||||
}
|
||||
else
|
||||
{
|
||||
$rk = urlencode(build_where_from_record($treffer[$a])); // no keys
|
||||
}
|
||||
|
||||
$delete_link = 'sql.php?search=1&mode=kill&db=' . base64_encode($db) . '&tablename=' . base64_encode($tables[$table_selected]) . '&rk=' . $rk;
|
||||
$edit_link = 'sql.php?mode=searchedit&db=' . base64_encode($db) . '&tablename=' . base64_encode($tables[$table_selected]) . '&recordkey=' . $rk;
|
||||
|
||||
$tpl->assign_block_vars('HITS.TABLEROW', array(
|
||||
|
||||
'CLASS' => ($a % 2) ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $a + $offset + 1,
|
||||
'TABLENAME' => $tables[$table_selected],
|
||||
'LINK_EDIT' => $edit_link,
|
||||
'ICON_EDIT' => $icon['edit'],
|
||||
'LINK_DELETE' => $delete_link,
|
||||
'ICON_DELETE' => $icon['delete']));
|
||||
|
||||
foreach ($treffer[$a] as $key => $val)
|
||||
{
|
||||
if ($val == '') $val = " ";
|
||||
$tpl->assign_block_vars('HITS.TABLEROW.TABLEDATA', array(
|
||||
|
||||
'VAL' => $val));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isset($tables[$table_selected])) $tables[$table_selected] = '';
|
||||
if ($suchbegriffe == '') $tpl->assign_block_vars('NO_ENTRIES', array(
|
||||
|
||||
'LANG_NO_ENTRIES' => sprintf($lang['L_NO_ENTRIES'], $tables[$table_selected])));
|
||||
else $tpl->assign_block_vars('NO_RESULTS', array(
|
||||
|
||||
'LANG_SEARCH_NO_RESULTS' => sprintf($lang['L_SEARCH_NO_RESULTS'], $suchbegriffe, $tables[$table_selected])));
|
||||
}
|
||||
|
||||
$tpl->pparse('show');
|
||||
26
inc/sqlbrowser/nav/topnav_general.php
Normale Datei
26
inc/sqlbrowser/nav/topnav_general.php
Normale Datei
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
|
||||
$tplSqlbrowserTopnav = new MSDTemplate();
|
||||
$tplSqlbrowserTopnav->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserTopnav' => 'tpl/sqlbrowser/nav/topnav_general.tpl'
|
||||
)
|
||||
);
|
||||
$tplSqlbrowserTopnav->assign_vars(
|
||||
array(
|
||||
'ICON_DB' => $icon['db'],
|
||||
'ICON_VIEW' => $icon['view'],
|
||||
'ICON_EDIT' => $icon['edit']
|
||||
)
|
||||
);
|
||||
382
inc/sqlbrowser/sqlbox/show_results.php
Normale Datei
382
inc/sqlbrowser/sqlbox/show_results.php
Normale Datei
|
|
@ -0,0 +1,382 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version $Rev$
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
|
||||
$orderDirection = 'ASC';
|
||||
if (isset($_SESSION['sql']['order_direction'])) {
|
||||
$orderDirection = $_SESSION['sql']['order_direction'];
|
||||
}
|
||||
if (isset($_GET['order_direction'])) {
|
||||
$orderDirection = $_GET['order_direction'];
|
||||
}
|
||||
if (!isset($_GET['order_by_field'])) {
|
||||
$orderByField = '';
|
||||
} else {
|
||||
$orderByField = base64_decode($_GET['order_by_field']);
|
||||
}
|
||||
$offset = 0;
|
||||
if (isset($_SESSION['sql']['offset'])) {
|
||||
$offset = (int) $_SESSION['sql']['offset'];
|
||||
}
|
||||
|
||||
$tplSqlbrowserSqlboxShowResults = new MSDTemplate();
|
||||
$tplSqlbrowserSqlboxShowResults->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserSqlboxShowResults' =>
|
||||
'tpl/sqlbrowser/sqlbox/showResults.tpl'
|
||||
)
|
||||
);
|
||||
if (!isset($_SESSION['sql']['last_statement'])) {
|
||||
$_SESSION['sql']['last_statement'] = '';
|
||||
}
|
||||
// execute last statement if we came from another site
|
||||
if (isset($sql['sql_statements']) && $sql['sql_statements'] > '') {
|
||||
$_POST['execsql'] = 1;
|
||||
$_POST['sqltextarea'] = $sql['sql_statements'];
|
||||
}
|
||||
//SQL-Statement given? Analyse and execute
|
||||
if ($_POST['sqltextarea'] > '' && (isset($_POST['execsql'])
|
||||
|| $action == 'general_sqlbox_show_results')) {
|
||||
//TODO Create class that handles queries and result sets using the same
|
||||
// parser like when restoring a backup file.
|
||||
// For the moment we do it quick and dirty by writing a temp file and hand
|
||||
// it over to the parser, pretending that this is a file to be restored.
|
||||
|
||||
// do we have only 1 query or more?
|
||||
if (isset($_POST['sqltextarea']) &&
|
||||
$_POST['sqltextarea'] != $_SESSION['sql']['last_statement']) {
|
||||
$_SESSION['sql']['last_statement'] = $_POST['sqltextarea'];
|
||||
$offset = 0;
|
||||
$data = $_POST['sqltextarea'];
|
||||
}
|
||||
|
||||
if ($action == 'general_sqlbox_show_results') {
|
||||
$data = $_SESSION['sql']['statements'];
|
||||
}
|
||||
if (isset($_POST['sqltextarea'])) {
|
||||
$data = $_POST['sqltextarea'];
|
||||
}
|
||||
// save as file and prepare vars to let the restore parser handle it
|
||||
$fileName = 'sqlbox_' . session_id() . '.sql';
|
||||
if (file_exists($config['paths']['backup'] . $fileName)) {
|
||||
unlink($config['paths']['backup'] . $fileName);
|
||||
}
|
||||
$f = fopen($config['paths']['backup'] . $fileName, 'w');
|
||||
fwrite($f, $data);
|
||||
fclose($f);
|
||||
$restore['filename'] = $fileName;
|
||||
$restore['filehandle'] = fopen($config['paths']['backup'] . $fileName, 'r');
|
||||
$restore['compressed'] = 0;
|
||||
$restore['dump_encoding'] = 'utf8';
|
||||
$restore['max_zeit'] = intval(
|
||||
$config['max_execution_time'] * $config['time_buffer']
|
||||
);
|
||||
if ($restore['max_zeit'] == 0) $restore['max_zeit'] = 20;
|
||||
$restore['restore_start_time'] = time();
|
||||
$restore['speed'] = $config['minspeed'];
|
||||
$restore['fileEOF'] = false;
|
||||
$restore['actual_table'] = '';
|
||||
$restore['offset'] = 0;
|
||||
$restore['page_refreshs'] = 0;
|
||||
$restore['table_ready'] = 0;
|
||||
$restore['errors'] = 0;
|
||||
$restore['notices'] = 0;
|
||||
$restore['actual_fieldcount'] = 0;
|
||||
$restore['records_inserted'] = 0;
|
||||
$restore['records_inserted_table'] = array();
|
||||
$restore['extended_inserts'] = 0;
|
||||
$restore['extended_insert_flag'] = -1;
|
||||
$restore['last_parser_status'] = 0;
|
||||
$restore['EOB'] = false;
|
||||
$restore['fileEOF'] = false;
|
||||
$restore['tables_to_restore'] = false; // restore complete file
|
||||
do {
|
||||
$query = getQueryFromFile(false);
|
||||
if (!is_array($query)) {
|
||||
$queries[] = $query;
|
||||
} else {
|
||||
// error in Query
|
||||
$error[] = $query[1];
|
||||
break;
|
||||
}
|
||||
} while (!$restore['fileEOF']);
|
||||
// close and remove temp file after the job is done
|
||||
fclose($restore['filehandle']);
|
||||
@unlink($config['paths']['backup'].$fileName);
|
||||
if (isset($_POST['tablecombo']) && $_POST['tablecombo'] > '') {
|
||||
$sql['sql_statements'] = $_POST['tablecombo'];
|
||||
$tablename = extractTablenameFromSQL($sql['sql_statements']);
|
||||
}
|
||||
$sql['sql_statements'] = implode("\n", $queries);
|
||||
}
|
||||
|
||||
//Pager clicked?
|
||||
if (isset($_POST['page_back'])) {
|
||||
$offset -= $config['resultsPerPage'];
|
||||
if ($offset < 0) $offset = 0;
|
||||
}
|
||||
if (isset($_POST['page_full_back'])) {
|
||||
$offset = 0;
|
||||
}
|
||||
if (isset($_POST['page_forward'])) {
|
||||
$offset += $config['resultsPerPage'];
|
||||
}
|
||||
|
||||
if (isset($_POST['page_full_forward'])) {
|
||||
$offset = $_SESSION['num_records_total'] - $config['resultsPerPage'];
|
||||
}
|
||||
|
||||
if (sizeof($queries) == 1) {
|
||||
$tablename = extractTablenameFromSQL($queries[0]);
|
||||
$tplSqlbrowserSqlbox->assign_block_vars(
|
||||
'SHOW_TABLENAME', array(
|
||||
'TABLE' => $tablename,
|
||||
'TABLE_ENCODED' => base64_encode($tablename))
|
||||
);
|
||||
|
||||
// remove all values and names in query
|
||||
$tempQuery = preg_replace('/"(.*?)"/si', '', $queries[0]);
|
||||
$tempQuery = preg_replace('/\'(.*?)\'/si', '', $queries[0]);
|
||||
$tempQuery = preg_replace('/`(.*?)`/si', '', $queries[0]);
|
||||
|
||||
// now we can decide if we can add a limit clause or if it already has one
|
||||
if (strripos($tempQuery, ' LIMIT ') === false) {
|
||||
$queries[0] .= ' LIMIT ' . $offset . ', ' . $config['resultsPerPage'];
|
||||
}
|
||||
|
||||
// handle order direction if query doesn't have one
|
||||
if ($orderByField > '' && strripos($tempQuery, ' ORDER BY') === false) {
|
||||
$limitPosition = strripos($queries[0], ' LIMIT ');
|
||||
$orderClause = ' ORDER BY `' . $orderByField . '` ' . $orderDirection;
|
||||
if (false === $limitPosition) {
|
||||
// no limit found -> concat
|
||||
$queries[0] .= ' ORDER BY `' . $orderByField . '` ' . $orderDirection;
|
||||
} else {
|
||||
//inject order-clause in front of limit-clause
|
||||
$tempOne = substr($queries[0], 0, $limitPosition);
|
||||
$tempTwo = substr($queries[0], $limitPosition);
|
||||
$queries[0] = $tempOne . $orderClause . $tempTwo;
|
||||
}
|
||||
}
|
||||
|
||||
// Injcet SQL_CALC_NUM_ROWS if we have a select query
|
||||
if (strtoupper(substr($queries[0], 0, 7)) == 'SELECT ') {
|
||||
$queries[0] = 'SELECT SQL_CALC_FOUND_ROWS ' . substr($queries[0], 7);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$res = $dbo->query($queries[0], MsdDbFactory::ARRAY_ASSOC);
|
||||
$error = '';
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
//v($res);
|
||||
$error = '(' . $e->getCode() . ') ' . $e->getMessage();
|
||||
$_SESSION['sql']['offset'] = $offset;
|
||||
$_SESSION['num_records_total'] = 0;
|
||||
//echo "MySQL-Fehler: " . $queries[0] . "<br>" . $error;
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'MESSAGE', array(
|
||||
'TEXT' => Html::getJsQuote($error, true),
|
||||
'NOTIFICATION_POSITION' => $config['notification_position'])
|
||||
);
|
||||
}
|
||||
if ($error == '') {
|
||||
// get nr of total hits
|
||||
$query = 'SELECT FOUND_ROWS() as `num_rows`';
|
||||
$resRows = $dbo->query($query, MsdDbFactory::ARRAY_OBJECT);
|
||||
$numRecordsTotal = $resRows[0]->num_rows;
|
||||
$_SESSION['num_records_total'] = $numRecordsTotal;
|
||||
$showHeader = true;
|
||||
if ($offset + $config['resultsPerPage'] > $numRecordsTotal) {
|
||||
$entryTo = $numRecordsTotal;
|
||||
} else {
|
||||
$entryTo = $offset + $config['resultsPerPage'];
|
||||
}
|
||||
$showing = sprintf(
|
||||
$lang['L_SHOWING_ENTRY_X_TO_Y_OF_Z'],
|
||||
$offset + 1,
|
||||
$entryTo,
|
||||
$numRecordsTotal
|
||||
);
|
||||
$tplSqlbrowserSqlboxShowResults->assign_vars(
|
||||
array(
|
||||
'ICON_UP' => $icon['arrow_up'],
|
||||
'ICON_DOWN' => $icon['arrow_down'])
|
||||
);
|
||||
if ($numRecordsTotal > 0) {
|
||||
$forwardDisabled='';
|
||||
if ($offset + $config['resultsPerPage'] >= $numRecordsTotal) {
|
||||
$forwardDisabled = ' disabled="disabled"';
|
||||
}
|
||||
$backwardDisabled='';
|
||||
if ($offset == 0) {
|
||||
$backwardDisabled = ' disabled="disabled"';
|
||||
}
|
||||
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'PAGER', array(
|
||||
'PAGE_FORWARD_DISABLED' => $forwardDisabled,
|
||||
'PAGE_BACK_DISABLED' => $backwardDisabled,
|
||||
'SHOWING_ENTRY_X_OF_Y' => $showing)
|
||||
);
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($res as $row) {
|
||||
if ($showHeader) {
|
||||
// show Headline of table
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'HEADLINE', array()
|
||||
);
|
||||
|
||||
foreach ($row as $field => $val) {
|
||||
$nextOrderDirection = 'DESC';
|
||||
if ($orderDirection == 'DESC') {
|
||||
$nextOrderDirection = 'ASC';
|
||||
}
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'HEADLINE.FIELDS', array(
|
||||
'NAME' => $field,
|
||||
'FIELD_ENCODED' => base64_encode($field),
|
||||
'DIRECTION' => $nextOrderDirection)
|
||||
);
|
||||
// show order icon
|
||||
if ($field == $orderByField) {
|
||||
if ($orderDirection == 'ASC') {
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'HEADLINE.FIELDS.ICON_UP', array()
|
||||
);
|
||||
} else {
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'HEADLINE.FIELDS.ICON_DOWN', array()
|
||||
);
|
||||
}
|
||||
}
|
||||
$showHeader = false;
|
||||
}
|
||||
}
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'ROW', array(
|
||||
'NR' => $i + 1 + $offset,
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1')
|
||||
);
|
||||
foreach ($row as $field => $val) {
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'ROW.FIELD', array(
|
||||
'VAL' => $val)
|
||||
);
|
||||
if (is_numeric($val)) {
|
||||
$tplSqlbrowserSqlboxShowResults->assign_block_vars(
|
||||
'ROW.FIELD.NUMERIC', array()
|
||||
);
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$count = array(
|
||||
'create' => 0,
|
||||
'delete' => 0,
|
||||
'drop' => 0,
|
||||
'update' => 0,
|
||||
'insert' => 0,
|
||||
'select' => 0,
|
||||
'alter' => 0
|
||||
);
|
||||
|
||||
$tplSqlbrowserSqlboxShowQueryResults = new MSDTemplate();
|
||||
$tplSqlbrowserSqlboxShowQueryResults->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserSqlboxShowQueryResults' =>
|
||||
'tpl/sqlbrowser/sqlbox/showQueryResults.tpl')
|
||||
);
|
||||
$tplSqlbrowserSqlboxShowQueryResults->assign_vars(
|
||||
array(
|
||||
'NOTIFICATION_POSITION' => $config['notification_position'])
|
||||
);
|
||||
$i = 0;
|
||||
foreach ($queries as $key => $query) {
|
||||
$skip = false;
|
||||
$compare = strtoupper(substr($query, 0, 4));
|
||||
switch ($compare)
|
||||
{
|
||||
case 'CREA':
|
||||
$count['create']++;
|
||||
break;
|
||||
case 'DROP':
|
||||
$count['drop']++;
|
||||
break;
|
||||
case 'UPDA':
|
||||
$count['update']++;
|
||||
break;
|
||||
case 'INSE':
|
||||
$count['insert']++;
|
||||
break;
|
||||
case 'SELE':
|
||||
$count['select']++;
|
||||
break;
|
||||
case 'ALTE':
|
||||
$count['alter']++;
|
||||
break;
|
||||
case 'DELE':
|
||||
$count['delete']++;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (substr($compare, 0, 2) == '--' ||
|
||||
substr($compare, 0, 1) == '#') {
|
||||
$skip = true;
|
||||
}
|
||||
}
|
||||
if (!$skip) {
|
||||
$start = getMicrotime();
|
||||
try
|
||||
{
|
||||
$res = $dbo->query($query, MsdDbFactory::SIMPLE);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$logMsg = '(' . $e->getCode() . ') ' . $e->getMessage();
|
||||
$tplSqlbrowserSqlboxShowQueryResults->assign_block_vars(
|
||||
'ERROR', array(
|
||||
'TEXT' => Html::getJsQuote($logMsg))
|
||||
);
|
||||
}
|
||||
|
||||
$end = getMicrotime();
|
||||
$queries[$key]['time'] = $end - $start;
|
||||
$i++;
|
||||
$tplSqlbrowserSqlboxShowQueryResults->assign_block_vars(
|
||||
'SQL_COMMAND', array(
|
||||
'SQL' => substr($query, 0, 100),
|
||||
'EXEC_TIME' => $queries[$key]['time'],
|
||||
'NR' => $i)
|
||||
);
|
||||
}
|
||||
|
||||
$tplSqlbrowserSqlboxShowQueryResults->assign_vars(
|
||||
array(
|
||||
'COUNT_DROP' => String::formatNumber($count['drop']),
|
||||
'COUNT_DELETE' => String::formatNumber($count['delete']),
|
||||
'COUNT_CREATE' => String::formatNumber($count['create']),
|
||||
'COUNT_ALTER' => String::formatNumber($count['alter']),
|
||||
'COUNT_INSERT' => String::formatNumber($count['insert']),
|
||||
'COUNT_SELECT' => String::formatNumber($count['select']),
|
||||
'COUNT_UPDATE' => String::formatNumber($count['update']))
|
||||
);
|
||||
}
|
||||
}
|
||||
$_SESSION['sql']['statements'] = $sql['sql_statements'];
|
||||
$_SESSION['sql']['order_by_field'] = $orderByField;
|
||||
$_SESSION['sql']['order_direction'] = $orderDirection;
|
||||
$_SESSION['sql']['offset'] = $offset;
|
||||
115
inc/sqlbrowser/table/edit_table.php
Normale Datei
115
inc/sqlbrowser/table/edit_table.php
Normale Datei
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1205 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
/*
|
||||
* Fetch and check _GET variables
|
||||
*/
|
||||
$db = isset($_GET['db']) ? base64_decode($_GET['db']) : $config['db_actual'];
|
||||
$tablename = isset($_GET['tablename']) ? base64_decode($_GET['tablename']) : '';
|
||||
$dbo->selectDb($db);
|
||||
$tableInfos=$dbo->getTableColumns($tablename, $db);
|
||||
|
||||
$tplSqlbrowserTableEditTable = new MSDTemplate();
|
||||
$tplSqlbrowserTableEditTable->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserTableEditTable' => 'tpl/sqlbrowser/table/edit_table.tpl'
|
||||
)
|
||||
);
|
||||
|
||||
$tplSqlbrowserTableEditTable->assign_vars(
|
||||
array(
|
||||
'DB' => $db,
|
||||
'TABLE' => $tablename
|
||||
)
|
||||
);
|
||||
|
||||
$sumSize = 0;
|
||||
$i = 0;
|
||||
foreach ($tableInfos as $key => $tableInfo) {
|
||||
if ($key != 'primary_keys') {
|
||||
$type = $tableInfo['Type'];
|
||||
$typeTemp = array();
|
||||
|
||||
// ENUM-/SET-Handling
|
||||
if (strpos($type, 'enum') !== false || strpos($type, 'set') !== false) {
|
||||
$toBeReplaced = array(
|
||||
'set(',
|
||||
'enum(',
|
||||
')',
|
||||
'\'');
|
||||
$typeTemp = str_replace($toBeReplaced, '', $type);
|
||||
$typeTemp = explode(',', $typeTemp);
|
||||
sort($typeTemp);
|
||||
if (strpos($type, 'enum') !== false) {
|
||||
$type = 'enum';
|
||||
} else {
|
||||
$type = 'set';
|
||||
}
|
||||
}
|
||||
$tplSqlbrowserTableEditTable->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => ($i + 1),
|
||||
'NAME' => $tableInfo['Field'],
|
||||
'TYPE' => $type,
|
||||
'NULL' => $tableInfo['Null']=='NO' ? $lang['L_NO']:$lang['L_YES'],
|
||||
'KEY' => $tableInfo['Key'],
|
||||
'DEFAULT' => $tableInfo['Default'],
|
||||
'EXTRA' => $tableInfo['Extra'],
|
||||
'SORTIERUNG' => $tableInfo['Collation']
|
||||
)
|
||||
);
|
||||
|
||||
if (count($typeTemp) > 0) {
|
||||
$tplSqlbrowserTableEditTable->assign_block_vars(
|
||||
'ROW.ENUM_SET',
|
||||
array(
|
||||
'SIZE' => count($typeTemp) < 5 ? count($typeTemp) : 5,
|
||||
'ICON_BROWSE' => $icon['browse'],
|
||||
'NR' => $i
|
||||
)
|
||||
);
|
||||
foreach ($typeTemp as $val) {
|
||||
$tplSqlbrowserTableEditTable->assign_block_vars(
|
||||
'ROW.ENUM_SET.ENUM_SET_ELEMENT',
|
||||
array('ELEMENT' => $val)
|
||||
);
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Output list of tables of the selected database
|
||||
|
||||
$tplSqlbrowserTableEditTable->assign_vars(
|
||||
array(
|
||||
'DB_NAME_URLENCODED' => base64_encode($db),
|
||||
'TABLE_NAME_URLENCODED' => base64_encode($tablename),
|
||||
'ICON_VIEW' => $icon['view'],
|
||||
'ICON_EDIT' => $icon['edit'],
|
||||
'ICON_OK' => $icon['ok'],
|
||||
'ICON_NOT_OK' => $icon['not_ok'],
|
||||
'ICON_DELETE' => $icon['delete'],
|
||||
'ICON_UP' => $icon['arrow_up'],
|
||||
'ICON_DOWN' => $icon['arrow_down'],
|
||||
'ICON_PLUS' => $icon['plus'],
|
||||
'ICON_MINUS' => $icon['minus'],
|
||||
'ICON_CANCEL' => $icon['cancel'],
|
||||
'DB' => $db,
|
||||
'DB_ENCODED' => base64_encode($db),
|
||||
'TABLE_ENCODED' => base64_encode($tablename),
|
||||
'ICONPATH' => $config['files']['iconpath']
|
||||
)
|
||||
);
|
||||
|
||||
259
inc/sqlbrowser/table/list_tables.php
Normale Datei
259
inc/sqlbrowser/table/list_tables.php
Normale Datei
|
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
$checkit = (isset($_GET['checkit'])) ? base64_decode($_GET['checkit']) : '';
|
||||
$repair = (isset($_GET['repair'])) ? base64_decode($_GET['repair']) : 0;
|
||||
$tables = isset($_POST['table']) ? $_POST['table'] : array();
|
||||
$sortColumn = isset($_POST['sort_by_column']) ? $_POST['sort_by_column'] : 'name';
|
||||
$sortDirection = isset($_POST['sort_direction']) ? $_POST['sort_direction'] : 'a';
|
||||
$dbo->selectDb($db);
|
||||
$tableInfos = array();
|
||||
// is there any operation to do?
|
||||
if (isset($_POST['do']) && $_POST['do']>'' && sizeof($tables) > 0) {
|
||||
// which action should we perform?
|
||||
$queryResultType = MsdDbFactory::ARRAY_ASSOC;
|
||||
switch ($_POST['do'])
|
||||
{
|
||||
case 'analyze':
|
||||
$query = 'ANALYZE TABLE `%s`.`%s`';
|
||||
$actionOutput = $lang['L_ANALYZE'];
|
||||
break;
|
||||
case 'check':
|
||||
$query = 'CHECK TABLE `%s`.`%s`';
|
||||
$actionOutput = $lang['L_CHECK'];
|
||||
break;
|
||||
case 'repair':
|
||||
$query = 'REPAIR TABLE `%s`.`%s`';
|
||||
$actionOutput = $lang['L_REPAIR'];
|
||||
break;
|
||||
case 'drop':
|
||||
$query = 'DROP TABLE `%s`.`%s`';
|
||||
$actionOutput = $lang['L_DELETE'];
|
||||
$queryResultType = MsdDbFactory::SIMPLE;
|
||||
break;
|
||||
case 'truncate':
|
||||
$query = 'TRUNCATE TABLE `%s`.`%s`';
|
||||
$actionOutput = $lang['L_EMPTY'];
|
||||
$queryResultType = MsdDbFactory::SIMPLE;
|
||||
break;
|
||||
default:
|
||||
$query = 'OPTIMIZE TABLE `%s`.`%s`';
|
||||
$actionOutput = $lang['L_OPTIMIZE'];
|
||||
break;
|
||||
}
|
||||
|
||||
$tplSqlbrowserTableOperation = new MSDTemplate();
|
||||
$tplSqlbrowserTableOperation->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserTableOperation' => 'tpl/sqlbrowser/table/operation.tpl'
|
||||
)
|
||||
);
|
||||
$tplSqlbrowserTableOperation->assign_vars(
|
||||
array(
|
||||
'ACTION' => $actionOutput,
|
||||
'ICON_DELETE' => $icon['delete'],
|
||||
'ICON_OK' => $icon['ok'],
|
||||
'ICON_NOTOK' => $icon['not_ok'],
|
||||
)
|
||||
);
|
||||
$i = 0;
|
||||
foreach ($tables as $table) {
|
||||
$table = base64_decode($table);
|
||||
$res = $dbo->query(sprintf($query, $db, $table), $queryResultType);
|
||||
if ($res) {
|
||||
if (!is_array($res)) {
|
||||
// simple action without result (delete, truncate, ..)
|
||||
$tplSqlbrowserTableOperation->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $i + 1,
|
||||
'TABLENAME' => $table,
|
||||
'ACTION' => $actionOutput,
|
||||
'TYPE' => sprintf($query, $db, $table),
|
||||
'MESSAGE' => ''
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$row = $res[0];
|
||||
// mainatining functions with result
|
||||
// (optimize, repair, analyze,..
|
||||
$msgType = isset($row['Msg_type']) ? $row['Msg_type'] : '';
|
||||
$msgTxt = isset($row['Msg_text']) ? $row['Msg_text'] : '';
|
||||
$tplSqlbrowserTableOperation->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $i + 1,
|
||||
'TABLENAME' => $table,
|
||||
'ACTION' => isset($row['Op']) ? $row['Op'] : '',
|
||||
'TYPE' => $msgType,
|
||||
'MESSAGE' => $msgTxt
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// error
|
||||
$tplSqlbrowserTableOperation->assign_block_vars(
|
||||
'ERROR',
|
||||
array(
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => $i + 1,
|
||||
'TABLENAME' => $table,
|
||||
'ERROR' => mysql_error(),
|
||||
'QUERY' => sprintf($query, $db, $table)
|
||||
)
|
||||
);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Output list of tables of the selected database
|
||||
$tableInfos = getTableInfo($db);
|
||||
// extract sorted one-dimensional array with infos we need
|
||||
$orderArray = get_orderarray($sortColumn . ',' . $sortDirection . '|name,a');
|
||||
$sortedTableInfos = arfsort($tableInfos[$db]['tables'], $orderArray);
|
||||
$tplSqlbrowserTableListTables = new MSDTemplate();
|
||||
$tplSqlbrowserTableListTables->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserTableListTables' => 'tpl/sqlbrowser/table/listTables.tpl'
|
||||
)
|
||||
);
|
||||
$numrows = $tableInfos[$db]['table_count'];
|
||||
$up = $icon['arrow_up'];
|
||||
$down = $icon['arrow_down'];
|
||||
$sortName = $sortColumn == 'name' ? ($sortDirection == 'd' ? $down : $up) : '';
|
||||
$sD = $sortDirection;
|
||||
$sC = $sortColumn;
|
||||
$tplSqlbrowserTableListTables->assign_vars(
|
||||
array(
|
||||
'ICON_VIEW' => $icon['view'],
|
||||
'ICON_EDIT' => $icon['edit'],
|
||||
'ICON_OK' => $icon['ok'],
|
||||
'ICON_NOT_OK' => $icon['not_ok'],
|
||||
'ICON_DELETE' => $icon['delete'],
|
||||
'ICON_TRUNCATE' => $icon['truncate'],
|
||||
'ICON_UP' => $up,
|
||||
'ICON_DOWN' => $down,
|
||||
'ICON_PLUS' => $icon['plus'],
|
||||
'ICON_MINUS' => $icon['minus'],
|
||||
'ICON_CANCEL' => $icon['cancel'],
|
||||
'DB_NAME' => $db,
|
||||
'DB_NAME_URLENCODED' => base64_encode($db),
|
||||
'TABLE_COUNT' => String::formatNumber($numrows),
|
||||
'ICONPATH' => $config['files']['iconpath'],
|
||||
'SORT_BY_COLUMN' => $sC,
|
||||
'SORT_DIRECTION' => $sD,
|
||||
'SORT_NAME' => $sortName,
|
||||
'SORT_RECORDS' => $sC == 'records' ? ($sD == 'D' ? $down : $up) : '',
|
||||
'SORT_DATA_LENGTH' =>
|
||||
$sC == 'data_length' ? ($sD == 'D' ? $down : $up) : '',
|
||||
'SORT_INDEX_LENGTH' =>
|
||||
$sC == 'index_length' ? ($sD == 'D' ? $down : $up) : '',
|
||||
'SORT_AUTO_INCREMENT' =>
|
||||
$sC == 'auto_increment' ? ($sD == 'D' ? $down : $up) : '',
|
||||
'SORT_DATA_FREE' =>
|
||||
$sC == 'data_free' ? ($sD == 'D' ? $down : $up) : '',
|
||||
'SORT_UPDATE_TIME' =>
|
||||
$sC == 'update_time' ? ($sD == 'd' ? $down : $up) : '',
|
||||
'SORT_ENGINE' =>
|
||||
$sC == 'engine' ? ($sD == 'd' ? $down : $up) : '',
|
||||
'SORT_COLLATION' =>
|
||||
$sC == 'collation' ? ($sD == 'd' ? $down : $up) : '',
|
||||
'SORT_COMMENT' => $sC == 'comment' ? ($sD == 'd' ? $down : $up) : '',
|
||||
'CONFIRM_TRUNCATE_TABLES' =>
|
||||
Html::getJsQuote($lang['L_CONFIRM_TRUNCATE_TABLES']),
|
||||
'CONFIRM_DELETE_TABLES' =>
|
||||
Html::getJsQuote($lang['L_CONFIRM_DELETE_TABLES']),
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
if ($numrows > 1) {
|
||||
$tplSqlbrowserTableListTables->assign_block_vars('MORE_TABLES', array());
|
||||
} elseif ($numrows == 1) {
|
||||
$tplSqlbrowserTableListTables->assign_block_vars('1_TABLE', array());
|
||||
} elseif ($numrows == 0) {
|
||||
$tplSqlbrowserTableListTables->assign_block_vars(
|
||||
'NO_TABLE',
|
||||
array(
|
||||
'HIDE' => ' style="display:none;"'
|
||||
)
|
||||
);
|
||||
}
|
||||
$lastUpdate = 0; // remember the latest update for sum-line
|
||||
$i = 0;
|
||||
foreach ($sortedTableInfos as $val) {
|
||||
if ($val['update_time'] > $lastUpdate) {
|
||||
$lastUpdate = $val['update_time'];
|
||||
}
|
||||
$updateTime = $val['update_time'] > '' ? $val['update_time'] : ' ';
|
||||
$autoIncrement = '-';
|
||||
if ((int) $val['auto_increment'] > 0) {
|
||||
$autoIncrement = String::formatNumber($val['auto_increment']);
|
||||
}
|
||||
$tplSqlbrowserTableListTables->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'ROWCLASS' => $i % 2 ? 'dbrow' : 'dbrow1',
|
||||
'NR' => ($i + 1),
|
||||
'TABLE_NAME' => $val['name'],
|
||||
'TABLE_NAME_URLENCODED' => base64_encode($val['name']),
|
||||
'RECORDS' => String::formatNumber($val['records']),
|
||||
'DATA_LENGTH' => byteOutput($val['data_length']),
|
||||
'INDEX_LENGTH' => byteOutput($val['index_length']),
|
||||
'LAST_UPDATE' => $updateTime,
|
||||
'ENGINE' => $val['engine'],
|
||||
'COLLATION' => $val['collation'],
|
||||
'COMMENT' => $val['comment'] > '' ? $val['comment'] : '',
|
||||
'AUTO_INCREMENT' => $autoIncrement
|
||||
)
|
||||
);
|
||||
// re-check table if it was checked before
|
||||
if (in_array(base64_encode($val['name']), $tables)) {
|
||||
$tplSqlbrowserTableListTables->assign_block_vars(
|
||||
'ROW.TABLE_CHECKED', array()
|
||||
);
|
||||
}
|
||||
|
||||
// is table optimized?
|
||||
if (in_array($val['engine'], array('MyISAM', 'ARCHIVE'))) {
|
||||
if ($val['data_free'] == 0) {
|
||||
$tplSqlbrowserTableListTables->assign_block_vars(
|
||||
'ROW.OPTIMIZED', array()
|
||||
);
|
||||
} else {
|
||||
$tplSqlbrowserTableListTables->assign_block_vars(
|
||||
'ROW.NOT_OPTIMIZED',
|
||||
array('VALUE' => byteOutput($val['data_free']))
|
||||
);
|
||||
}
|
||||
}
|
||||
else // optimize is not supported for this engine
|
||||
$tplSqlbrowserTableListTables->assign_block_vars(
|
||||
'ROW.OPTIMIZE_NOT_SUPPORTED', array()
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Output sum-line
|
||||
$indexLen = $tableInfos[$db]['size_total'] - $tableInfos[$db]['datasize_total'];
|
||||
$tplSqlbrowserTableListTables->assign_block_vars(
|
||||
'SUM',
|
||||
array(
|
||||
'RECORDS' => String::formatNumber($tableInfos[$db]['records_total']),
|
||||
'DATA_LENGTH' => byteOutput($tableInfos[$db]['datasize_total']),
|
||||
'INDEX_LENGTH' => byteOutput($indexLen),
|
||||
'LAST_UPDATE' => $lastUpdate
|
||||
)
|
||||
);
|
||||
230
inc/sqlbrowser/table/show_tabledata.php
Normale Datei
230
inc/sqlbrowser/table/show_tabledata.php
Normale Datei
|
|
@ -0,0 +1,230 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @version $Rev$
|
||||
* @author $Author$
|
||||
* @lastmodified $Date$
|
||||
*/
|
||||
|
||||
if (!defined('MSD_VERSION')) die('No direct access.');
|
||||
$tablename = isset($_POST['tablename']) ? base64_decode($_POST['tablename']) : '';
|
||||
if (isset($_GET['tablename'])) {
|
||||
$tablename = base64_decode($_GET['tablename']);
|
||||
}
|
||||
$dbo->selectDb($db);
|
||||
$tableInfos = $dbo->getTableColumns($tablename);
|
||||
if ($tablename == '') {
|
||||
$tablenames = array_keys($tableInfos[$db]['tables']);
|
||||
$tablename = $tablenames[0];
|
||||
}
|
||||
//v($_POST);
|
||||
$tableInfos = $dbo->getTableColumns($tablename);
|
||||
$sortByColumn = '';
|
||||
if (isset($_POST['sort_by_column']) && isset($tableInfos[$sortByColumn])) {
|
||||
$sortByColumn = base64_decode($_POST['sort_by_column']);
|
||||
}
|
||||
$sortDirection = 'ASC';
|
||||
if (isset($_POST['sort_direction'])) {
|
||||
$sortDirection = (string) $_POST['sort_direction'];
|
||||
}
|
||||
if (in_array($sortDirection, array('d', 'D'))) {
|
||||
$desc = 'DESC';
|
||||
}
|
||||
$maxEntries = $config['resultsPerPage'];
|
||||
if (isset($_GET['limit_max_entries'])) {
|
||||
$maxEntries =(int) $_GET['limit_max_entries'];
|
||||
}
|
||||
$showAll = 0;
|
||||
$limitStart = 0;
|
||||
if (isset($_GET['limit_start']) && $_GET['limit_start'] > 0 && !$showAll) {
|
||||
$limitStart = $_GET['limit_start'];
|
||||
}
|
||||
|
||||
$tplSqlbrowserTableShowTabledata = new MSDTemplate();
|
||||
$tplSqlbrowserTableShowTabledata->set_filenames(
|
||||
array(
|
||||
'tplSqlbrowserTableShowTabledata' =>
|
||||
'tpl/sqlbrowser/table/show_tabledata.tpl'
|
||||
)
|
||||
);
|
||||
|
||||
//TODO: Language_vars im Sprachlabor anlegen und hier entfernen.
|
||||
$languageVars =
|
||||
array(
|
||||
'L_SQL_DATAOFTABLE' => 'Datensätze der Tabelle',
|
||||
'L_SQL_SHOW_NUM_ENTRIES' => 'Zeige Datensätze: ',
|
||||
'L_SHOW' => 'Zeige',
|
||||
'L_ENTRIES_PER_PAGE' => 'pro Seite (0 = alle anzeigen)',
|
||||
'L_STARTING_WITH' => 'beginnend mit Eintrag',
|
||||
'L_EDIT_ENTRY' => 'Eintrag editieren',
|
||||
'L_VIEW_ENTRY' => 'Eintrag anzeigen',
|
||||
'L_NEW_ENTRY' => 'Eintrag anlegen',
|
||||
'L_EXECUTED_QUERY' => 'Ausgeführte MySQL-Query:',
|
||||
'L_ROWS_AFFECTED' => 'Zeilen betroffen',
|
||||
'L_QUERY_FAILED' => 'Query fehlgeschlagen'
|
||||
);
|
||||
$tplSqlbrowserTableShowTabledata->assign_vars($languageVars);
|
||||
|
||||
if (isset($_POST['action'])) {
|
||||
processPostAction($tplSqlbrowserTableShowTabledata, $db, $tablename);
|
||||
}
|
||||
$query = "SELECT COUNT(*) as count FROM `$tablename`";
|
||||
$res=$dbo->query($query, MsdDbFactory::ARRAY_ASSOC);
|
||||
$numRecords=(int) $res[0];
|
||||
|
||||
if (isset($_GET['pager'])) {
|
||||
switch ($_GET['pager'])
|
||||
{
|
||||
case '<':
|
||||
$limitStart -= $maxEntries;
|
||||
break;
|
||||
case '<<':
|
||||
$limitStart = 0;
|
||||
break;
|
||||
case '>>':
|
||||
$limitStart = $showAll ? 0 : $numRecords - $maxEntries;
|
||||
break;
|
||||
case '>':
|
||||
$limitStart += $maxEntries;
|
||||
break;
|
||||
}
|
||||
$limitStart = min($numRecords - $maxEntries, $limitStart);
|
||||
$limitStart = max($limitStart, 0);
|
||||
}
|
||||
|
||||
$templateVars =
|
||||
array(
|
||||
'DB_NAME' => $db,
|
||||
'TABLE_NAME' => $tablename,
|
||||
'DB_NAME_URLENCODED' => base64_encode($db),
|
||||
'TABLE_NAME_URLENCODED' => base64_encode($tablename),
|
||||
'ENTRY_COUNT' => $numRecords,
|
||||
'LIMIT_START' => $limitStart,
|
||||
'FIRST_ENTRY_NUM' => $limitStart + 1,
|
||||
'LAST_ENTRY_NUM' => $showAll ? $num["count"] : $limitStart + $maxEntries,
|
||||
'MAX_ENTRIES' => $maxEntries,
|
||||
'SORT_DIRECTION' => $sortDirection == 'ASC' ? 'd':'a',
|
||||
'SORT_BY_COLUMN' => $sortByColumn,
|
||||
'ICON_VIEW' => $icon['view'],
|
||||
'ICON_EDIT' => $icon['edit'],
|
||||
'ICON_PLUS' => $icon['plus'],
|
||||
'ICON_MINUS' => $icon['minus'],
|
||||
'ICON_DELETE' => $icon['delete'],
|
||||
'ICON_EDIT' => $icon['edit']
|
||||
);
|
||||
$tplSqlbrowserTableShowTabledata->assign_vars($templateVars);
|
||||
|
||||
/*
|
||||
* Build the Table-Header columns
|
||||
*/
|
||||
$field_infos = getExtendedFieldInfo($db, $tablename);
|
||||
foreach ($field_infos as $field => $val) {
|
||||
$sD = '';
|
||||
if ($val['field'] == $sortByColumn) {
|
||||
$sD = $desc == 'DESC' ? $icon['arrow_down'] : $icon['arrow_up'];
|
||||
}
|
||||
$tplSqlbrowserTableShowTabledata->assign_block_vars(
|
||||
'COL_HEADER',
|
||||
array(
|
||||
'LABEL' => $val['field'],
|
||||
'NAME' => base64_encode($val['field']),
|
||||
'COMMENT' => $val['comment'],
|
||||
'SORT' => $sD
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the Datarows
|
||||
*/
|
||||
$query = "SELECT * FROM `$tablename`";
|
||||
if ($sortByColumn>'') {
|
||||
$query .= ' ORDER BY `'.$sortByColumn.'` '.$sortDirection;
|
||||
}
|
||||
if ($limitStart>0) {
|
||||
$query .= " LIMIT $limitStart, $maxEntries";
|
||||
}
|
||||
$result = $dbo->query($query, MsdDbFactory::ARRAY_ASSOC);
|
||||
$entryNum = $limitStart;
|
||||
//echo $order;
|
||||
|
||||
//Daten holen:
|
||||
$nr_of_fields = 0;
|
||||
$i = 1;
|
||||
foreach ($result as $row) {
|
||||
$nr_of_fields = sizeof($row);
|
||||
$tplSqlbrowserTableShowTabledata->assign_block_vars(
|
||||
'ROW',
|
||||
array(
|
||||
'NR' => $i,
|
||||
'RECORD_KEY_ENCODED' => base64_encode(getRecordIdentifier($db, $tablename, $row)),
|
||||
'ROW_CLASS' => $i % 2 ? 'dbrow' : 'dbrow1'
|
||||
)
|
||||
);
|
||||
foreach ($row as $val) {
|
||||
$tplSqlbrowserTableShowTabledata->assign_block_vars(
|
||||
'ROW.COL',
|
||||
array(
|
||||
'VAL' => htmlentities($val, ENT_COMPAT, 'utf-8'),
|
||||
'CLASS' => is_numeric($val) ? ' right' : ''
|
||||
)
|
||||
);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
$tplSqlbrowserTableShowTabledata->assign_vars(
|
||||
array('BUTTONBAR_COLSPAN' => $nr_of_fields + 3)
|
||||
);
|
||||
|
||||
function processPostAction($tplSqlbrowserTableShowTabledata, $db, $tablename)
|
||||
{
|
||||
global $dbo;
|
||||
$action = $_POST['action'];
|
||||
if (!in_array($action, array('edit', 'new'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fields = implode(', ', fetchSetFields($_POST, 'field_'));
|
||||
|
||||
$sql = "INSERT INTO `$tablename` SET " . $fields . ";";
|
||||
if ($action == 'edit') {
|
||||
$sql = "UPDATE `$tablename` SET " . $fields . " WHERE "
|
||||
. base64_decode($_POST['key']) . ' LIMIT 1;';
|
||||
}
|
||||
$result = $dbo->query($sql,MsdDbFactory::SIMPLE);
|
||||
if (!$result) {
|
||||
$tplSqlbrowserTableShowTabledata->assign_block_vars(
|
||||
'MYSQL_ERROR',
|
||||
array(
|
||||
'QUERY' => htmlspecialchars($sql),
|
||||
'ERROR' => mysql_error()
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
$tplSqlbrowserTableShowTabledata->assign_block_vars(
|
||||
'POSTED_MYSQL_QUERY',
|
||||
array(
|
||||
'QUERY' => htmlspecialchars($sql),
|
||||
'ROWS_AFFECTED' => $dbo->getAffectedRows()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function fetchSetFields($arr, $prefix)
|
||||
{
|
||||
global $dbo;
|
||||
$answer = array();
|
||||
foreach ($arr as $key => $value) {
|
||||
if (strpos($key, $prefix) === 0) {
|
||||
$field = base64_decode(substr($key, strlen($prefix)));
|
||||
$answer[] = "`$field` = \"" . $dbo->escape($value) . "\"";
|
||||
}
|
||||
}
|
||||
return $answer;
|
||||
}
|
||||
|
||||
Laden …
Tabelle hinzufügen
Einen Link hinzufügen
In neuem Issue referenzieren