init web ems all
This commit is contained in:
39
phpMyAdmin/libraries/classes/Controllers/Controller.php
Executable file
39
phpMyAdmin/libraries/classes/Controllers/Controller.php
Executable file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Controller
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
namespace PhpMyAdmin\Controllers;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Response;
|
||||
|
||||
/**
|
||||
* Base class for all of controller
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
abstract class Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Response
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* @var DatabaseInterface
|
||||
*/
|
||||
protected $dbi;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($response, $dbi)
|
||||
{
|
||||
$this->response = $response;
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
}
|
||||
1115
phpMyAdmin/libraries/classes/Controllers/Database/DatabaseStructureController.php
Executable file
1115
phpMyAdmin/libraries/classes/Controllers/Database/DatabaseStructureController.php
Executable file
File diff suppressed because it is too large
Load Diff
30
phpMyAdmin/libraries/classes/Controllers/DatabaseController.php
Executable file
30
phpMyAdmin/libraries/classes/Controllers/DatabaseController.php
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\DatabaseController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
namespace PhpMyAdmin\Controllers;
|
||||
|
||||
/**
|
||||
* Handles database related logic
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
abstract class DatabaseController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var string $db
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($response, $dbi, $db)
|
||||
{
|
||||
parent::__construct($response, $dbi);
|
||||
$this->db = $db;
|
||||
}
|
||||
}
|
||||
263
phpMyAdmin/libraries/classes/Controllers/Server/ServerBinlogController.php
Executable file
263
phpMyAdmin/libraries/classes/Controllers/Server/ServerBinlogController.php
Executable file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Server\ServerBinlogController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
namespace PhpMyAdmin\Controllers\Server;
|
||||
|
||||
use PhpMyAdmin\Controllers\Controller;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Server\Common;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Handles viewing binary logs
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class ServerBinlogController extends Controller
|
||||
{
|
||||
/**
|
||||
* array binary log files
|
||||
*/
|
||||
protected $binary_logs;
|
||||
|
||||
/**
|
||||
* Constructs ServerBinlogController
|
||||
*/
|
||||
public function __construct($response, $dbi)
|
||||
{
|
||||
parent::__construct($response, $dbi);
|
||||
$this->binary_logs = $this->dbi->fetchResult(
|
||||
'SHOW MASTER LOGS',
|
||||
'Log_name',
|
||||
null,
|
||||
DatabaseInterface::CONNECT_USER,
|
||||
DatabaseInterface::QUERY_STORE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
/**
|
||||
* Does the common work
|
||||
*/
|
||||
include_once 'libraries/server_common.inc.php';
|
||||
|
||||
$url_params = array();
|
||||
if (! isset($_POST['log'])
|
||||
|| ! array_key_exists($_POST['log'], $this->binary_logs)
|
||||
) {
|
||||
$_POST['log'] = '';
|
||||
} else {
|
||||
$url_params['log'] = $_POST['log'];
|
||||
}
|
||||
|
||||
if (!empty($_POST['dontlimitchars'])) {
|
||||
$url_params['dontlimitchars'] = 1;
|
||||
}
|
||||
|
||||
$this->response->addHTML(
|
||||
Template::get('server/sub_page_header')->render([
|
||||
'type' => 'binlog',
|
||||
])
|
||||
);
|
||||
$this->response->addHTML($this->_getLogSelector($url_params));
|
||||
$this->response->addHTML($this->_getLogInfo($url_params));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for log selector.
|
||||
*
|
||||
* @param array $url_params links parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getLogSelector(array $url_params)
|
||||
{
|
||||
return Template::get('server/binlog/log_selector')->render(
|
||||
array(
|
||||
'url_params' => $url_params,
|
||||
'binary_logs' => $this->binary_logs,
|
||||
'log' => $_POST['log'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for binary log information.
|
||||
*
|
||||
* @param array $url_params links parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getLogInfo(array $url_params)
|
||||
{
|
||||
/**
|
||||
* Need to find the real end of rows?
|
||||
*/
|
||||
if (! isset($_POST['pos'])) {
|
||||
$pos = 0;
|
||||
} else {
|
||||
/* We need this to be a integer */
|
||||
$pos = (int) $_POST['pos'];
|
||||
}
|
||||
|
||||
$sql_query = 'SHOW BINLOG EVENTS';
|
||||
if (! empty($_POST['log'])) {
|
||||
$sql_query .= ' IN \'' . $_POST['log'] . '\'';
|
||||
}
|
||||
$sql_query .= ' LIMIT ' . $pos . ', ' . intval($GLOBALS['cfg']['MaxRows']);
|
||||
|
||||
/**
|
||||
* Sends the query
|
||||
*/
|
||||
$result = $this->dbi->query($sql_query);
|
||||
|
||||
/**
|
||||
* prepare some vars for displaying the result table
|
||||
*/
|
||||
// Gets the list of fields properties
|
||||
if (isset($result) && $result) {
|
||||
$num_rows = $this->dbi->numRows($result);
|
||||
} else {
|
||||
$num_rows = 0;
|
||||
}
|
||||
|
||||
if (empty($_POST['dontlimitchars'])) {
|
||||
$dontlimitchars = false;
|
||||
} else {
|
||||
$dontlimitchars = true;
|
||||
$url_params['dontlimitchars'] = 1;
|
||||
}
|
||||
|
||||
//html output
|
||||
$html = Util::getMessage(Message::success(), $sql_query);
|
||||
$html .= '<table id="binlogTable">'
|
||||
. '<thead>'
|
||||
. '<tr>'
|
||||
. '<td colspan="6" class="center">';
|
||||
|
||||
$html .= $this->_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars);
|
||||
|
||||
$html .= '</td>'
|
||||
. '</tr>'
|
||||
. '<tr>'
|
||||
. '<th>' . __('Log name') . '</th>'
|
||||
. '<th>' . __('Position') . '</th>'
|
||||
. '<th>' . __('Event type') . '</th>'
|
||||
. '<th>' . __('Server ID') . '</th>'
|
||||
. '<th>' . __('Original position') . '</th>'
|
||||
. '<th>' . __('Information') . '</th>'
|
||||
. '</tr>'
|
||||
. '</thead>'
|
||||
. '<tbody>';
|
||||
|
||||
$html .= $this->_getAllLogItemInfo($result, $dontlimitchars);
|
||||
|
||||
$html .= '</tbody>'
|
||||
. '</table>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for Navigation Row.
|
||||
*
|
||||
* @param array $url_params Links parameters
|
||||
* @param int $pos Position to display
|
||||
* @param int $num_rows Number of results row
|
||||
* @param bool $dontlimitchars Whether limit chars
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getNavigationRow(array $url_params, $pos, $num_rows, $dontlimitchars)
|
||||
{
|
||||
$html = "";
|
||||
// we do not know how much rows are in the binlog
|
||||
// so we can just force 'NEXT' button
|
||||
if ($pos > 0) {
|
||||
$this_url_params = $url_params;
|
||||
if ($pos > $GLOBALS['cfg']['MaxRows']) {
|
||||
$this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows'];
|
||||
}
|
||||
|
||||
$html .= '<a href="server_binlog.php" data-post="'
|
||||
. Url::getCommon($this_url_params, '', false) . '"';
|
||||
if (Util::showIcons('TableNavigationLinksMode')) {
|
||||
$html .= ' title="' . _pgettext('Previous page', 'Previous') . '">';
|
||||
} else {
|
||||
$html .= '>' . _pgettext('Previous page', 'Previous');
|
||||
} // end if... else...
|
||||
$html .= ' < </a> - ';
|
||||
}
|
||||
|
||||
$this_url_params = $url_params;
|
||||
if ($pos > 0) {
|
||||
$this_url_params['pos'] = $pos;
|
||||
}
|
||||
if ($dontlimitchars) {
|
||||
unset($this_url_params['dontlimitchars']);
|
||||
$tempTitle = __('Truncate Shown Queries');
|
||||
$tempImgMode = 'partial';
|
||||
} else {
|
||||
$this_url_params['dontlimitchars'] = 1;
|
||||
$tempTitle = __('Show Full Queries');
|
||||
$tempImgMode = 'full';
|
||||
}
|
||||
$html .= '<a href="server_binlog.php" data-post="' . Url::getCommon($this_url_params, '', false)
|
||||
. '" title="' . $tempTitle . '">'
|
||||
. '<img src="' . $GLOBALS['pmaThemeImage'] . 's_' . $tempImgMode
|
||||
. 'text.png" alt="' . $tempTitle . '" /></a>';
|
||||
|
||||
// we do not now how much rows are in the binlog
|
||||
// so we can just force 'NEXT' button
|
||||
if ($num_rows >= $GLOBALS['cfg']['MaxRows']) {
|
||||
$this_url_params = $url_params;
|
||||
$this_url_params['pos'] = $pos + $GLOBALS['cfg']['MaxRows'];
|
||||
$html .= ' - <a href="server_binlog.php" data-post="'
|
||||
. Url::getCommon($this_url_params, '', false)
|
||||
. '"';
|
||||
if (Util::showIcons('TableNavigationLinksMode')) {
|
||||
$html .= ' title="' . _pgettext('Next page', 'Next') . '">';
|
||||
} else {
|
||||
$html .= '>' . _pgettext('Next page', 'Next');
|
||||
} // end if... else...
|
||||
$html .= ' > </a>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for all binary log items.
|
||||
*
|
||||
* @param resource $result MySQL Query result
|
||||
* @param bool $dontlimitchars Whether limit chars
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getAllLogItemInfo($result, $dontlimitchars)
|
||||
{
|
||||
$html = "";
|
||||
while ($value = $this->dbi->fetchAssoc($result)) {
|
||||
$html .= Template::get('server/binlog/log_row')->render(
|
||||
array(
|
||||
'value' => $value,
|
||||
'dontlimitchars' => $dontlimitchars,
|
||||
)
|
||||
);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Server\ServerCollationsController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Server;
|
||||
|
||||
use PhpMyAdmin\Controllers\Controller;
|
||||
use PhpMyAdmin\Charsets;
|
||||
use PhpMyAdmin\Server\Common;
|
||||
use PhpMyAdmin\Template;
|
||||
|
||||
/**
|
||||
* Handles viewing character sets and collations
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class ServerCollationsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$dbi = $GLOBALS['dbi'];
|
||||
$disableIs = $GLOBALS['cfg']['Server']['DisableIS'];
|
||||
|
||||
/**
|
||||
* Does the common work
|
||||
*/
|
||||
include_once 'libraries/server_common.inc.php';
|
||||
|
||||
$this->response->addHTML(
|
||||
Template::get('server/sub_page_header')->render([
|
||||
'type' => 'collations',
|
||||
])
|
||||
);
|
||||
$this->response->addHTML(
|
||||
$this->_getHtmlForCharsets(
|
||||
Charsets::getMySQLCharsets($dbi, $disableIs),
|
||||
Charsets::getMySQLCollations($dbi, $disableIs),
|
||||
Charsets::getMySQLCharsetsDescriptions($dbi, $disableIs),
|
||||
Charsets::getMySQLCollationsDefault($dbi, $disableIs)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for server Character Sets and Collations.
|
||||
*
|
||||
* @param array $mysqlCharsets Mysql Charsets list
|
||||
* @param array $mysqlCollations Mysql Collations list
|
||||
* @param array $mysqlCharsetsDesc Charsets descriptions
|
||||
* @param array $mysqlDftCollations Default Collations list
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function _getHtmlForCharsets(array $mysqlCharsets, array $mysqlCollations,
|
||||
array $mysqlCharsetsDesc, array $mysqlDftCollations
|
||||
) {
|
||||
return Template::get('server/collations/charsets')->render(
|
||||
array(
|
||||
'mysql_charsets' => $mysqlCharsets,
|
||||
'mysql_collations' => $mysqlCollations,
|
||||
'mysql_charsets_desc' => $mysqlCharsetsDesc,
|
||||
'mysql_dft_collations' => $mysqlDftCollations,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
470
phpMyAdmin/libraries/classes/Controllers/Server/ServerDatabasesController.php
Executable file
470
phpMyAdmin/libraries/classes/Controllers/Server/ServerDatabasesController.php
Executable file
@@ -0,0 +1,470 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Server\ServerDatabasesController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Server;
|
||||
|
||||
use PhpMyAdmin\Controllers\Controller;
|
||||
use PhpMyAdmin\Charsets;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Server\Common;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Handles viewing and creating and deleting databases
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class ServerDatabasesController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var array array of database details
|
||||
*/
|
||||
private $_databases;
|
||||
/**
|
||||
* @var int number of databases
|
||||
*/
|
||||
private $_database_count;
|
||||
/**
|
||||
* @var string sort by column
|
||||
*/
|
||||
private $_sort_by;
|
||||
/**
|
||||
* @var string sort order of databases
|
||||
*/
|
||||
private $_sort_order;
|
||||
/**
|
||||
* @var boolean whether to show database statistics
|
||||
*/
|
||||
private $_dbstats;
|
||||
/**
|
||||
* @var int position in list navigation
|
||||
*/
|
||||
private $_pos;
|
||||
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
include_once 'libraries/check_user_privileges.inc.php';
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
if (isset($_POST['drop_selected_dbs'])
|
||||
&& $response->isAjax()
|
||||
&& ($GLOBALS['dbi']->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase'])
|
||||
) {
|
||||
$this->dropDatabasesAction();
|
||||
return;
|
||||
}
|
||||
|
||||
include_once 'libraries/replication.inc.php';
|
||||
|
||||
if (isset($_POST['new_db'])
|
||||
&& $response->isAjax()
|
||||
) {
|
||||
$this->createDatabaseAction();
|
||||
return;
|
||||
}
|
||||
|
||||
include_once 'libraries/server_common.inc.php';
|
||||
|
||||
$header = $this->response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('server_databases.js');
|
||||
|
||||
$this->_setSortDetails();
|
||||
$this->_dbstats = ! empty($_POST['dbstats']);
|
||||
$this->_pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
|
||||
|
||||
/**
|
||||
* Gets the databases list
|
||||
*/
|
||||
if ($GLOBALS['server'] > 0) {
|
||||
$this->_databases = $this->dbi->getDatabasesFull(
|
||||
null, $this->_dbstats, DatabaseInterface::CONNECT_USER, $this->_sort_by,
|
||||
$this->_sort_order, $this->_pos, true
|
||||
);
|
||||
$this->_database_count = count($GLOBALS['dblist']->databases);
|
||||
} else {
|
||||
$this->_database_count = 0;
|
||||
}
|
||||
|
||||
if ($this->_database_count > 0 && ! empty($this->_databases)) {
|
||||
$databases = $this->_getHtmlForDatabases($replication_types);
|
||||
}
|
||||
|
||||
$this->response->addHTML(Template::get('server/databases/index')->render([
|
||||
'show_create_db' => $GLOBALS['cfg']['ShowCreateDb'],
|
||||
'is_create_db_priv' => $GLOBALS['is_create_db_priv'],
|
||||
'dbstats' => $this->_dbstats,
|
||||
'db_to_create' => $GLOBALS['db_to_create'],
|
||||
'server_collation' => $GLOBALS['dbi']->getServerCollation(),
|
||||
'databases' => isset($databases) ? $databases : null,
|
||||
'dbi' => $GLOBALS['dbi'],
|
||||
'disable_is' => $GLOBALS['cfg']['Server']['DisableIS'],
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles creating a new database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createDatabaseAction()
|
||||
{
|
||||
// lower_case_table_names=1 `DB` becomes `db`
|
||||
if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
|
||||
$_POST['new_db'] = mb_strtolower(
|
||||
$_POST['new_db']
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Builds and executes the db creation sql query
|
||||
*/
|
||||
$sql_query = 'CREATE DATABASE ' . Util::backquote($_POST['new_db']);
|
||||
if (! empty($_POST['db_collation'])) {
|
||||
list($db_charset) = explode('_', $_POST['db_collation']);
|
||||
$charsets = Charsets::getMySQLCharsets(
|
||||
$GLOBALS['dbi'],
|
||||
$GLOBALS['cfg']['Server']['DisableIS']
|
||||
);
|
||||
$collations = Charsets::getMySQLCollations(
|
||||
$GLOBALS['dbi'],
|
||||
$GLOBALS['cfg']['Server']['DisableIS']
|
||||
);
|
||||
if (in_array($db_charset, $charsets)
|
||||
&& in_array($_POST['db_collation'], $collations[$db_charset])
|
||||
) {
|
||||
$sql_query .= ' DEFAULT'
|
||||
. Util::getCharsetQueryPart($_POST['db_collation']);
|
||||
}
|
||||
}
|
||||
$sql_query .= ';';
|
||||
|
||||
$result = $GLOBALS['dbi']->tryQuery($sql_query);
|
||||
|
||||
if (! $result) {
|
||||
// avoid displaying the not-created db name in header or navi panel
|
||||
$GLOBALS['db'] = '';
|
||||
|
||||
$message = Message::rawError($GLOBALS['dbi']->getError());
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', $message);
|
||||
} else {
|
||||
$GLOBALS['db'] = $_POST['new_db'];
|
||||
|
||||
$message = Message::success(__('Database %1$s has been created.'));
|
||||
$message->addParam($_POST['new_db']);
|
||||
$this->response->addJSON('message', $message);
|
||||
$this->response->addJSON(
|
||||
'sql_query', Util::getMessage(null, $sql_query, 'success')
|
||||
);
|
||||
|
||||
$this->response->addJSON(
|
||||
'url_query',
|
||||
Util::getScriptNameForOption(
|
||||
$GLOBALS['cfg']['DefaultTabDatabase'], 'database'
|
||||
)
|
||||
. Url::getCommon(array('db' => $_POST['new_db']))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles dropping multiple databases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropDatabasesAction()
|
||||
{
|
||||
if (! isset($_POST['selected_dbs'])) {
|
||||
$message = Message::error(__('No databases selected.'));
|
||||
} else {
|
||||
$action = 'server_databases.php';
|
||||
$err_url = $action . Url::getCommon();
|
||||
|
||||
$GLOBALS['submit_mult'] = 'drop_db';
|
||||
$GLOBALS['mult_btn'] = __('Yes');
|
||||
|
||||
include 'libraries/mult_submits.inc.php';
|
||||
|
||||
if (empty($message)) { // no error message
|
||||
$number_of_databases = count($selected);
|
||||
$message = Message::success(
|
||||
_ngettext(
|
||||
'%1$d database has been dropped successfully.',
|
||||
'%1$d databases have been dropped successfully.',
|
||||
$number_of_databases
|
||||
)
|
||||
);
|
||||
$message->addParam($number_of_databases);
|
||||
}
|
||||
}
|
||||
|
||||
if ($message instanceof Message) {
|
||||
$this->response->setRequestStatus($message->isSuccess());
|
||||
$this->response->addJSON('message', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts parameters $sort_order and $sort_by
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setSortDetails()
|
||||
{
|
||||
if (empty($_REQUEST['sort_by'])) {
|
||||
$this->_sort_by = 'SCHEMA_NAME';
|
||||
} else {
|
||||
$sort_by_whitelist = array(
|
||||
'SCHEMA_NAME',
|
||||
'DEFAULT_COLLATION_NAME',
|
||||
'SCHEMA_TABLES',
|
||||
'SCHEMA_TABLE_ROWS',
|
||||
'SCHEMA_DATA_LENGTH',
|
||||
'SCHEMA_INDEX_LENGTH',
|
||||
'SCHEMA_LENGTH',
|
||||
'SCHEMA_DATA_FREE'
|
||||
);
|
||||
if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
|
||||
$this->_sort_by = $_REQUEST['sort_by'];
|
||||
} else {
|
||||
$this->_sort_by = 'SCHEMA_NAME';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['sort_order'])
|
||||
&& mb_strtolower($_REQUEST['sort_order']) == 'desc'
|
||||
) {
|
||||
$this->_sort_order = 'desc';
|
||||
} else {
|
||||
$this->_sort_order = 'asc';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for Database List
|
||||
*
|
||||
* @param array $replication_types replication types
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getHtmlForDatabases(array $replication_types)
|
||||
{
|
||||
$first_database = reset($this->_databases);
|
||||
// table col order
|
||||
$column_order = $this->_getColumnOrder();
|
||||
|
||||
// calculate aggregate stats to display in footer
|
||||
foreach ($this->_databases as $current) {
|
||||
foreach ($column_order as $stat_name => $stat) {
|
||||
if (array_key_exists($stat_name, $current)
|
||||
&& is_numeric($stat['footer'])
|
||||
) {
|
||||
$column_order[$stat_name]['footer'] += $current[$stat_name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$_url_params = array(
|
||||
'pos' => $this->_pos,
|
||||
'dbstats' => $this->_dbstats,
|
||||
'sort_by' => $this->_sort_by,
|
||||
'sort_order' => $this->_sort_order,
|
||||
);
|
||||
|
||||
$html = Template::get('server/databases/databases_header')->render([
|
||||
'database_count' => $this->_database_count,
|
||||
'pos' => $this->_pos,
|
||||
'url_params' => $_url_params,
|
||||
'max_db_list' => $GLOBALS['cfg']['MaxDbList'],
|
||||
'sort_by' => $this->_sort_by,
|
||||
'sort_order' => $this->_sort_order,
|
||||
'column_order' => $column_order,
|
||||
'first_database' => $first_database,
|
||||
'master_replication' => $GLOBALS['replication_info']['master']['status'],
|
||||
'slave_replication' => $GLOBALS['replication_info']['slave']['status'],
|
||||
'is_superuser' => $GLOBALS['dbi']->isSuperuser(),
|
||||
'allow_user_drop_database' => $GLOBALS['cfg']['AllowUserDropDatabase'],
|
||||
]);
|
||||
|
||||
$html .= $this->_getHtmlForTableBody($column_order, $replication_types);
|
||||
|
||||
$html .= Template::get('server/databases/databases_footer')->render([
|
||||
'column_order' => $column_order,
|
||||
'first_database' => $first_database,
|
||||
'master_replication' => $GLOBALS['replication_info']['master']['status'],
|
||||
'slave_replication' => $GLOBALS['replication_info']['slave']['status'],
|
||||
'database_count' => $this->_database_count,
|
||||
'is_superuser' => $GLOBALS['dbi']->isSuperuser(),
|
||||
'allow_user_drop_database' => $GLOBALS['cfg']['AllowUserDropDatabase'],
|
||||
'pma_theme_image' => $GLOBALS['pmaThemeImage'],
|
||||
'text_dir' => $GLOBALS['text_dir'],
|
||||
'dbstats' => $this->_dbstats,
|
||||
]);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the $column_order array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _getColumnOrder()
|
||||
{
|
||||
$column_order = array();
|
||||
$column_order['DEFAULT_COLLATION_NAME'] = array(
|
||||
'disp_name' => __('Collation'),
|
||||
'description_function' => array(Charsets::class, 'getCollationDescr'),
|
||||
'format' => 'string',
|
||||
'footer' => $this->dbi->getServerCollation(),
|
||||
);
|
||||
$column_order['SCHEMA_TABLES'] = array(
|
||||
'disp_name' => __('Tables'),
|
||||
'format' => 'number',
|
||||
'footer' => 0,
|
||||
);
|
||||
$column_order['SCHEMA_TABLE_ROWS'] = array(
|
||||
'disp_name' => __('Rows'),
|
||||
'format' => 'number',
|
||||
'footer' => 0,
|
||||
);
|
||||
$column_order['SCHEMA_DATA_LENGTH'] = array(
|
||||
'disp_name' => __('Data'),
|
||||
'format' => 'byte',
|
||||
'footer' => 0,
|
||||
);
|
||||
$column_order['SCHEMA_INDEX_LENGTH'] = array(
|
||||
'disp_name' => __('Indexes'),
|
||||
'format' => 'byte',
|
||||
'footer' => 0,
|
||||
);
|
||||
$column_order['SCHEMA_LENGTH'] = array(
|
||||
'disp_name' => __('Total'),
|
||||
'format' => 'byte',
|
||||
'footer' => 0,
|
||||
);
|
||||
$column_order['SCHEMA_DATA_FREE'] = array(
|
||||
'disp_name' => __('Overhead'),
|
||||
'format' => 'byte',
|
||||
'footer' => 0,
|
||||
);
|
||||
|
||||
return $column_order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for Database List
|
||||
*
|
||||
* @param array $column_order column order
|
||||
* @param array $replication_types replication types
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getHtmlForTableBody(array $column_order, array $replication_types)
|
||||
{
|
||||
$html = '<tbody>' . "\n";
|
||||
|
||||
foreach ($this->_databases as $current) {
|
||||
$tr_class = ' db-row';
|
||||
if ($this->dbi->isSystemSchema($current['SCHEMA_NAME'], true)) {
|
||||
$tr_class .= ' noclick';
|
||||
}
|
||||
|
||||
$generated_html = $this->_buildHtmlForDb(
|
||||
$current,
|
||||
$column_order,
|
||||
$replication_types,
|
||||
$GLOBALS['replication_info'],
|
||||
$tr_class
|
||||
);
|
||||
$html .= $generated_html;
|
||||
} // end foreach ($this->_databases as $key => $current)
|
||||
$html .= '</tbody>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the HTML for one database to display in the list
|
||||
* of databases from server_databases.php
|
||||
*
|
||||
* @param array $current current database
|
||||
* @param array $column_order column order
|
||||
* @param array $replication_types replication types
|
||||
* @param array $replication_info replication info
|
||||
* @param string $tr_class HTMl class for the row
|
||||
*
|
||||
* @return array $column_order, $out
|
||||
*/
|
||||
function _buildHtmlForDb(
|
||||
array $current, array $column_order,
|
||||
array $replication_types, array $replication_info, $tr_class = ''
|
||||
) {
|
||||
$master_replication = $slave_replication = '';
|
||||
foreach ($replication_types as $type) {
|
||||
if ($replication_info[$type]['status']) {
|
||||
$out = '';
|
||||
$key = array_search(
|
||||
$current["SCHEMA_NAME"],
|
||||
$replication_info[$type]['Ignore_DB']
|
||||
);
|
||||
if (strlen($key) > 0) {
|
||||
$out = Util::getIcon(
|
||||
's_cancel',
|
||||
__('Not replicated')
|
||||
);
|
||||
} else {
|
||||
$key = array_search(
|
||||
$current["SCHEMA_NAME"], $replication_info[$type]['Do_DB']
|
||||
);
|
||||
|
||||
if (strlen($key) > 0
|
||||
|| count($replication_info[$type]['Do_DB']) == 0
|
||||
) {
|
||||
// if ($key != null) did not work for index "0"
|
||||
$out = Util::getIcon(
|
||||
's_success',
|
||||
__('Replicated')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type == 'master') {
|
||||
$master_replication = $out;
|
||||
} elseif ($type == 'slave') {
|
||||
$slave_replication = $out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Template::get('server/databases/table_row')->render([
|
||||
'current' => $current,
|
||||
'tr_class' => $tr_class,
|
||||
'column_order' => $column_order,
|
||||
'master_replication_status' => $GLOBALS['replication_info']['master']['status'],
|
||||
'master_replication' => $master_replication,
|
||||
'slave_replication_status' => $GLOBALS['replication_info']['slave']['status'],
|
||||
'slave_replication' => $slave_replication,
|
||||
'is_superuser' => $GLOBALS['dbi']->isSuperuser(),
|
||||
'allow_user_drop_database' => $GLOBALS['cfg']['AllowUserDropDatabase'],
|
||||
'is_system_schema' => $GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true),
|
||||
'default_tab_database' => $GLOBALS['cfg']['DefaultTabDatabase'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
100
phpMyAdmin/libraries/classes/Controllers/Server/ServerEnginesController.php
Executable file
100
phpMyAdmin/libraries/classes/Controllers/Server/ServerEnginesController.php
Executable file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Server\ServerEnginesController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Server;
|
||||
|
||||
use PhpMyAdmin\Controllers\Controller;
|
||||
use PhpMyAdmin\Server\Common;
|
||||
use PhpMyAdmin\StorageEngine;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Handles viewing storage engine details
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class ServerEnginesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
/**
|
||||
* Does the common work
|
||||
*/
|
||||
require 'libraries/server_common.inc.php';
|
||||
|
||||
/**
|
||||
* Displays the sub-page heading
|
||||
*/
|
||||
$this->response->addHTML(
|
||||
Template::get('server/sub_page_header')->render([
|
||||
'type' => 'engines',
|
||||
])
|
||||
);
|
||||
|
||||
/**
|
||||
* Did the user request information about a certain storage engine?
|
||||
*/
|
||||
if (empty($_REQUEST['engine'])
|
||||
|| ! StorageEngine::isValid($_REQUEST['engine'])
|
||||
) {
|
||||
$this->response->addHTML($this->_getHtmlForAllServerEngines());
|
||||
} else {
|
||||
$engine = StorageEngine::getEngine($_REQUEST['engine']);
|
||||
$this->response->addHTML($this->_getHtmlForServerEngine($engine));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML with all Storage Engine information
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getHtmlForAllServerEngines()
|
||||
{
|
||||
return Template::get('server/engines/engines')->render(
|
||||
array('engines' => StorageEngine::getStorageEngines())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML for a given Storage Engine
|
||||
*
|
||||
* @param StorageEngine $engine storage engine
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getHtmlForServerEngine(StorageEngine $engine)
|
||||
{
|
||||
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : '';
|
||||
$pageOutput = ! empty($page) ? $engine->getPage($page) : '';
|
||||
|
||||
/**
|
||||
* Displays details about a given Storage Engine
|
||||
*/
|
||||
return Template::get('server/engines/engine')->render(
|
||||
array(
|
||||
'title' => $engine->getTitle(),
|
||||
'help_page' => $engine->getMysqlHelpPage(),
|
||||
'comment' => $engine->getComment(),
|
||||
'info_pages' => $engine->getInfoPages(),
|
||||
'support' => $engine->getSupportInformationMessage(),
|
||||
'variables' => $engine->getHtmlVariables(),
|
||||
'page_output' => $pageOutput,
|
||||
'page' => $page,
|
||||
'engine' => $_REQUEST['engine'],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
111
phpMyAdmin/libraries/classes/Controllers/Server/ServerPluginsController.php
Executable file
111
phpMyAdmin/libraries/classes/Controllers/Server/ServerPluginsController.php
Executable file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Server\ServerPluginsController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
|
||||
namespace PhpMyAdmin\Controllers\Server;
|
||||
|
||||
use PhpMyAdmin\Controllers\Controller;
|
||||
use PhpMyAdmin\Server\Common;
|
||||
use PhpMyAdmin\Template;
|
||||
|
||||
/**
|
||||
* Handles viewing server plugin details
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class ServerPluginsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var array plugin details
|
||||
*/
|
||||
protected $plugins;
|
||||
|
||||
/**
|
||||
* Constructs ServerPluginsController
|
||||
*/
|
||||
public function __construct($response, $dbi)
|
||||
{
|
||||
parent::__construct($response, $dbi);
|
||||
$this->_setServerPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
include 'libraries/server_common.inc.php';
|
||||
|
||||
$header = $this->response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
|
||||
$scripts->addFile('server_plugins.js');
|
||||
|
||||
/**
|
||||
* Displays the page
|
||||
*/
|
||||
$this->response->addHTML(
|
||||
Template::get('server/sub_page_header')->render([
|
||||
'type' => 'plugins',
|
||||
])
|
||||
);
|
||||
$this->response->addHTML($this->_getPluginsHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets details about server plugins
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setServerPlugins()
|
||||
{
|
||||
$sql = "SELECT plugin_name,
|
||||
plugin_type,
|
||||
(plugin_status = 'ACTIVE') AS is_active,
|
||||
plugin_type_version,
|
||||
plugin_author,
|
||||
plugin_description,
|
||||
plugin_license
|
||||
FROM information_schema.plugins
|
||||
ORDER BY plugin_type, plugin_name";
|
||||
|
||||
$res = $this->dbi->query($sql);
|
||||
$this->plugins = array();
|
||||
while ($row = $this->dbi->fetchAssoc($res)) {
|
||||
$this->plugins[$row['plugin_type']][] = $row;
|
||||
}
|
||||
$this->dbi->freeResult($res);
|
||||
ksort($this->plugins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html for plugin Tab.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getPluginsHtml()
|
||||
{
|
||||
$html = '<div id="plugins_plugins">';
|
||||
$html .= Template::get('server/plugins/section_links')
|
||||
->render(array('plugins' => $this->plugins));
|
||||
|
||||
foreach ($this->plugins as $plugin_type => $plugin_list) {
|
||||
$html .= Template::get('server/plugins/section')
|
||||
->render(
|
||||
array(
|
||||
'plugin_type' => $plugin_type,
|
||||
'plugin_list' => $plugin_list,
|
||||
)
|
||||
);
|
||||
}
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
2837
phpMyAdmin/libraries/classes/Controllers/Server/ServerVariablesController.php
Executable file
2837
phpMyAdmin/libraries/classes/Controllers/Server/ServerVariablesController.php
Executable file
File diff suppressed because it is too large
Load Diff
246
phpMyAdmin/libraries/classes/Controllers/Table/TableChartController.php
Executable file
246
phpMyAdmin/libraries/classes/Controllers/Table/TableChartController.php
Executable file
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Table\TableChartController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
namespace PhpMyAdmin\Controllers\Table;
|
||||
|
||||
use PhpMyAdmin\Controllers\TableController;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\SqlParser\Components\Limit;
|
||||
use PhpMyAdmin\SqlParser\Parser;
|
||||
use PhpMyAdmin\Table;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Handles table related logic
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class TableChartController extends TableController
|
||||
{
|
||||
/**
|
||||
* @var string $sql_query
|
||||
*/
|
||||
protected $sql_query;
|
||||
|
||||
/**
|
||||
* @var string $url_query
|
||||
*/
|
||||
protected $url_query;
|
||||
|
||||
/**
|
||||
* @var array $cfg
|
||||
*/
|
||||
protected $cfg;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $sql_query Query
|
||||
* @param string $url_query Query URL
|
||||
* @param array $cfg Configuration
|
||||
*/
|
||||
public function __construct(
|
||||
$response,
|
||||
$dbi,
|
||||
$db,
|
||||
$table,
|
||||
$sql_query,
|
||||
$url_query,
|
||||
array $cfg
|
||||
) {
|
||||
parent::__construct($response, $dbi, $db, $table);
|
||||
|
||||
$this->sql_query = $sql_query;
|
||||
$this->url_query = $url_query;
|
||||
$this->cfg = $cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query and return the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$response = Response::getInstance();
|
||||
if ($response->isAjax()
|
||||
&& isset($_REQUEST['pos'])
|
||||
&& isset($_REQUEST['session_max_rows'])
|
||||
) {
|
||||
$this->ajaxAction();
|
||||
return;
|
||||
}
|
||||
|
||||
// Throw error if no sql query is set
|
||||
if (!isset($this->sql_query) || $this->sql_query == '') {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addHTML(
|
||||
Message::error(__('No SQL query was set to fetch data.'))
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->getHeader()->getScripts()->addFiles(
|
||||
array(
|
||||
'chart.js',
|
||||
'tbl_chart.js',
|
||||
'vendor/jqplot/jquery.jqplot.js',
|
||||
'vendor/jqplot/plugins/jqplot.barRenderer.js',
|
||||
'vendor/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js',
|
||||
'vendor/jqplot/plugins/jqplot.canvasTextRenderer.js',
|
||||
'vendor/jqplot/plugins/jqplot.categoryAxisRenderer.js',
|
||||
'vendor/jqplot/plugins/jqplot.dateAxisRenderer.js',
|
||||
'vendor/jqplot/plugins/jqplot.pointLabels.js',
|
||||
'vendor/jqplot/plugins/jqplot.pieRenderer.js',
|
||||
'vendor/jqplot/plugins/jqplot.enhancedPieLegendRenderer.js',
|
||||
'vendor/jqplot/plugins/jqplot.highlighter.js'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Extract values for common work
|
||||
* @todo Extract common files
|
||||
*/
|
||||
$db = &$this->db;
|
||||
$table = &$this->table;
|
||||
$url_params = array();
|
||||
|
||||
/**
|
||||
* Runs common work
|
||||
*/
|
||||
if (strlen($this->table) > 0) {
|
||||
$url_params['goto'] = Util::getScriptNameForOption(
|
||||
$this->cfg['DefaultTabTable'], 'table'
|
||||
);
|
||||
$url_params['back'] = 'tbl_sql.php';
|
||||
include 'libraries/tbl_common.inc.php';
|
||||
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
|
||||
} elseif (strlen($this->db) > 0) {
|
||||
$url_params['goto'] = Util::getScriptNameForOption(
|
||||
$this->cfg['DefaultTabDatabase'], 'database'
|
||||
);
|
||||
$url_params['back'] = 'sql.php';
|
||||
include 'libraries/db_common.inc.php';
|
||||
} else {
|
||||
$url_params['goto'] = Util::getScriptNameForOption(
|
||||
$this->cfg['DefaultTabServer'], 'server'
|
||||
);
|
||||
$url_params['back'] = 'sql.php';
|
||||
include 'libraries/server_common.inc.php';
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
$result = $this->dbi->tryQuery($this->sql_query);
|
||||
$fields_meta = $this->dbi->getFieldsMeta($result);
|
||||
while ($row = $this->dbi->fetchAssoc($result)) {
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$keys = array_keys($data[0]);
|
||||
|
||||
$numeric_types = array('int', 'real');
|
||||
$numeric_column_count = 0;
|
||||
foreach ($keys as $idx => $key) {
|
||||
if (in_array($fields_meta[$idx]->type, $numeric_types)) {
|
||||
$numeric_column_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($numeric_column_count == 0) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON(
|
||||
'message',
|
||||
__('No numeric columns present in the table to plot.')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$url_params['db'] = $this->db;
|
||||
$url_params['reload'] = 1;
|
||||
|
||||
/**
|
||||
* Displays the page
|
||||
*/
|
||||
$this->response->addHTML(
|
||||
Template::get('table/chart/tbl_chart')->render(
|
||||
array(
|
||||
'url_query' => $this->url_query,
|
||||
'url_params' => $url_params,
|
||||
'keys' => $keys,
|
||||
'fields_meta' => $fields_meta,
|
||||
'numeric_types' => $numeric_types,
|
||||
'numeric_column_count' => $numeric_column_count,
|
||||
'sql_query' => $this->sql_query
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ajax request
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxAction()
|
||||
{
|
||||
/**
|
||||
* Extract values for common work
|
||||
* @todo Extract common files
|
||||
*/
|
||||
$db = &$this->db;
|
||||
$table = &$this->table;
|
||||
|
||||
if (strlen($this->table) > 0 && strlen($this->db) > 0) {
|
||||
include './libraries/tbl_common.inc.php';
|
||||
}
|
||||
|
||||
$parser = new Parser($this->sql_query);
|
||||
$statement = $parser->statements[0];
|
||||
if (empty($statement->limit)) {
|
||||
$statement->limit = new Limit(
|
||||
$_REQUEST['session_max_rows'], $_REQUEST['pos']
|
||||
);
|
||||
} else {
|
||||
$start = $statement->limit->offset + $_REQUEST['pos'];
|
||||
$rows = min(
|
||||
$_REQUEST['session_max_rows'],
|
||||
$statement->limit->rowCount - $_REQUEST['pos']
|
||||
);
|
||||
$statement->limit = new Limit($rows, $start);
|
||||
}
|
||||
$sql_with_limit = $statement->build();
|
||||
|
||||
$data = array();
|
||||
$result = $this->dbi->tryQuery($sql_with_limit);
|
||||
while ($row = $this->dbi->fetchAssoc($result)) {
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
if (empty($data)) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', __('No data to display'));
|
||||
return;
|
||||
}
|
||||
$sanitized_data = array();
|
||||
|
||||
foreach ($data as $data_row_number => $data_row) {
|
||||
$tmp_row = array();
|
||||
foreach ($data_row as $data_column => $data_value) {
|
||||
$tmp_row[htmlspecialchars($data_column)] = htmlspecialchars(
|
||||
$data_value
|
||||
);
|
||||
}
|
||||
$sanitized_data[] = $tmp_row;
|
||||
}
|
||||
$this->response->setRequestStatus(true);
|
||||
$this->response->addJSON('message', null);
|
||||
$this->response->addJSON('chartData', json_encode($sanitized_data));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Table\TableIndexesController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
namespace PhpMyAdmin\Controllers\Table;
|
||||
|
||||
use PhpMyAdmin\Controllers\TableController;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Gis\GisVisualization;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
require_once 'libraries/common.inc.php';
|
||||
require_once 'libraries/db_common.inc.php';
|
||||
|
||||
/**
|
||||
* Class TableGisVisualizationController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class TableGisVisualizationController extends TableController
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array $url_params
|
||||
*/
|
||||
protected $url_params;
|
||||
|
||||
/**
|
||||
* @var string $sql_query
|
||||
*/
|
||||
protected $sql_query;
|
||||
|
||||
/**
|
||||
* @var array $visualizationSettings
|
||||
*/
|
||||
protected $visualizationSettings;
|
||||
|
||||
/**
|
||||
* @var \PhpMyAdmin\Gis\GisVisualization $visualization
|
||||
*/
|
||||
protected $visualization;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $sql_query SQL query for retrieving GIS data
|
||||
* @param array $url_params array of URL parameters
|
||||
* @param string $goto goto script
|
||||
* @param string $back back script
|
||||
* @param array $visualizationSettings visualization settings
|
||||
*/
|
||||
public function __construct(
|
||||
$response,
|
||||
$dbi,
|
||||
$db,
|
||||
$table,
|
||||
$sql_query,
|
||||
array $url_params,
|
||||
$goto,
|
||||
$back,
|
||||
array $visualizationSettings
|
||||
) {
|
||||
parent::__construct($response, $dbi, $db, $table);
|
||||
|
||||
$this->sql_query = $sql_query;
|
||||
$this->url_params = $url_params;
|
||||
$this->url_params['goto'] = $goto;
|
||||
$this->url_params['back'] = $back;
|
||||
$this->visualizationSettings = $visualizationSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save to file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saveToFileAction()
|
||||
{
|
||||
$this->response->disable();
|
||||
$file_name = $this->visualizationSettings['spatialColumn'];
|
||||
$save_format = $_GET['fileFormat'];
|
||||
$this->visualization->toFile($file_name, $save_format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
// Throw error if no sql query is set
|
||||
if (! isset($this->sql_query) || $this->sql_query == '') {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addHTML(
|
||||
Message::error(__('No SQL query was set to fetch data.'))
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Execute the query and return the result
|
||||
$result = $this->dbi->tryQuery($this->sql_query);
|
||||
// Get the meta data of results
|
||||
$meta = $this->dbi->getFieldsMeta($result);
|
||||
|
||||
// Find the candidate fields for label column and spatial column
|
||||
$labelCandidates = array();
|
||||
$spatialCandidates = array();
|
||||
foreach ($meta as $column_meta) {
|
||||
if ($column_meta->type == 'geometry') {
|
||||
$spatialCandidates[] = $column_meta->name;
|
||||
} else {
|
||||
$labelCandidates[] = $column_meta->name;
|
||||
}
|
||||
}
|
||||
|
||||
// Get settings if any posted
|
||||
if (Core::isValid($_POST['visualizationSettings'], 'array')) {
|
||||
$this->visualizationSettings = $_POST['visualizationSettings'];
|
||||
}
|
||||
|
||||
// Check mysql version
|
||||
$this->visualizationSettings['mysqlVersion'] = $this->dbi->getVersion();
|
||||
|
||||
if (!isset($this->visualizationSettings['labelColumn'])
|
||||
&& isset($labelCandidates[0])
|
||||
) {
|
||||
$this->visualizationSettings['labelColumn'] = '';
|
||||
}
|
||||
|
||||
// If spatial column is not set, use first geometric column as spatial column
|
||||
if (! isset($this->visualizationSettings['spatialColumn'])) {
|
||||
$this->visualizationSettings['spatialColumn'] = $spatialCandidates[0];
|
||||
}
|
||||
|
||||
// Convert geometric columns from bytes to text.
|
||||
$pos = isset($_GET['pos']) ? $_GET['pos']
|
||||
: $_SESSION['tmpval']['pos'];
|
||||
if (isset($_GET['session_max_rows'])) {
|
||||
$rows = $_GET['session_max_rows'];
|
||||
} else {
|
||||
if ($_SESSION['tmpval']['max_rows'] != 'all') {
|
||||
$rows = $_SESSION['tmpval']['max_rows'];
|
||||
} else {
|
||||
$rows = $GLOBALS['cfg']['MaxRows'];
|
||||
}
|
||||
}
|
||||
$this->visualization = GisVisualization::get(
|
||||
$this->sql_query,
|
||||
$this->visualizationSettings,
|
||||
$rows,
|
||||
$pos
|
||||
);
|
||||
|
||||
if (isset($_GET['saveToFile'])) {
|
||||
$this->saveToFileAction();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->getHeader()->getScripts()->addFiles(
|
||||
array(
|
||||
'vendor/openlayers/OpenLayers.js',
|
||||
'vendor/jquery/jquery.svg.js',
|
||||
'tbl_gis_visualization.js',
|
||||
)
|
||||
);
|
||||
|
||||
// If all the rows contain SRID, use OpenStreetMaps on the initial loading.
|
||||
if (! isset($_POST['displayVisualization'])) {
|
||||
if ($this->visualization->hasSrid()) {
|
||||
$this->visualizationSettings['choice'] = 'useBaseLayer';
|
||||
} else {
|
||||
unset($this->visualizationSettings['choice']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->visualization->setUserSpecifiedSettings($this->visualizationSettings);
|
||||
if ($this->visualizationSettings != null) {
|
||||
foreach ($this->visualization->getSettings() as $setting => $val) {
|
||||
if (! isset($this->visualizationSettings[$setting])) {
|
||||
$this->visualizationSettings[$setting] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the page
|
||||
*/
|
||||
$this->url_params['sql_query'] = $this->sql_query;
|
||||
$downloadUrl = 'tbl_gis_visualization.php' . Url::getCommon(
|
||||
array_merge(
|
||||
$this->url_params,
|
||||
array(
|
||||
'sql_signature' => Core::signSqlQuery($this->sql_query),
|
||||
'saveToFile' => true,
|
||||
'session_max_rows' => $rows,
|
||||
'pos' => $pos
|
||||
)
|
||||
)
|
||||
);
|
||||
$html = Template::get('table/gis_visualization/gis_visualization')->render(
|
||||
array(
|
||||
'url_params' => $this->url_params,
|
||||
'download_url' => $downloadUrl,
|
||||
'label_candidates' => $labelCandidates,
|
||||
'spatial_candidates' => $spatialCandidates,
|
||||
'visualization_settings' => $this->visualizationSettings,
|
||||
'sql_query' => $this->sql_query,
|
||||
'visualization' => $this->visualization->toImage('svg'),
|
||||
'draw_ol' => $this->visualization->asOl(),
|
||||
'pma_theme_image' => $GLOBALS['pmaThemeImage']
|
||||
)
|
||||
);
|
||||
|
||||
$this->response->addHTML($html);
|
||||
}
|
||||
}
|
||||
177
phpMyAdmin/libraries/classes/Controllers/Table/TableIndexesController.php
Executable file
177
phpMyAdmin/libraries/classes/Controllers/Table/TableIndexesController.php
Executable file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Table\TableIndexesController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
namespace PhpMyAdmin\Controllers\Table;
|
||||
|
||||
use PhpMyAdmin\Controllers\TableController;
|
||||
use PhpMyAdmin\Index;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Class TableIndexesController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class TableIndexesController extends TableController
|
||||
{
|
||||
/**
|
||||
* @var Index $index
|
||||
*/
|
||||
protected $index;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Index $index Index
|
||||
*/
|
||||
public function __construct(
|
||||
$response,
|
||||
$dbi,
|
||||
$db,
|
||||
$table,
|
||||
$index
|
||||
) {
|
||||
parent::__construct($response, $dbi, $db, $table);
|
||||
|
||||
$this->index = $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
if (isset($_POST['do_save_data'])) {
|
||||
$this->doSaveDataAction();
|
||||
return;
|
||||
} // end builds the new index
|
||||
|
||||
$this->displayFormAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the form to edit/create an index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function displayFormAction()
|
||||
{
|
||||
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
|
||||
$add_fields = 0;
|
||||
if (isset($_POST['index']) && is_array($_POST['index'])) {
|
||||
// coming already from form
|
||||
if (isset($_POST['index']['columns']['names'])) {
|
||||
$add_fields = count($_POST['index']['columns']['names'])
|
||||
- $this->index->getColumnCount();
|
||||
}
|
||||
if (isset($_POST['add_fields'])) {
|
||||
$add_fields += $_POST['added_fields'];
|
||||
}
|
||||
} elseif (isset($_POST['create_index'])) {
|
||||
$add_fields = $_POST['added_fields'];
|
||||
} // end preparing form values
|
||||
|
||||
// Get fields and stores their name/type
|
||||
if (isset($_POST['create_edit_table'])) {
|
||||
$fields = json_decode($_POST['columns'], true);
|
||||
$index_params = array(
|
||||
'Non_unique' => ($_POST['index']['Index_choice'] == 'UNIQUE')
|
||||
? '0' : '1',
|
||||
);
|
||||
$this->index->set($index_params);
|
||||
$add_fields = count($fields);
|
||||
} else {
|
||||
$fields = $this->dbi->getTable($this->db, $this->table)
|
||||
->getNameAndTypeOfTheColumns();
|
||||
}
|
||||
|
||||
$form_params = array(
|
||||
'db' => $this->db,
|
||||
'table' => $this->table,
|
||||
);
|
||||
|
||||
if (isset($_POST['create_index'])) {
|
||||
$form_params['create_index'] = 1;
|
||||
} elseif (isset($_POST['old_index'])) {
|
||||
$form_params['old_index'] = $_POST['old_index'];
|
||||
} elseif (isset($_POST['index'])) {
|
||||
$form_params['old_index'] = $_POST['index'];
|
||||
}
|
||||
|
||||
$this->response->getHeader()->getScripts()->addFile('indexes.js');
|
||||
|
||||
$this->response->addHTML(
|
||||
Template::get('table/index_form')->render(
|
||||
array(
|
||||
'fields' => $fields,
|
||||
'index' => $this->index,
|
||||
'form_params' => $form_params,
|
||||
'add_fields' => $add_fields,
|
||||
'create_edit_table' => isset($_POST['create_edit_table'])
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the data from the edit/create index form,
|
||||
* run the query to build the new index
|
||||
* and moves back to "tbl_sql.php"
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doSaveDataAction()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$sql_query = $this->dbi->getTable($this->db, $this->table)
|
||||
->getSqlQueryForIndexCreateOrEdit($this->index, $error);
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_POST['preview_sql'])) {
|
||||
|
||||
$this->response->addJSON(
|
||||
'sql_data',
|
||||
Template::get('preview_sql')
|
||||
->render(
|
||||
array(
|
||||
'query_data' => $sql_query
|
||||
)
|
||||
)
|
||||
);
|
||||
} elseif (!$error) {
|
||||
|
||||
$this->dbi->query($sql_query);
|
||||
$response = Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
$message = Message::success(
|
||||
__('Table %1$s has been altered successfully.')
|
||||
);
|
||||
$message->addParam($this->table);
|
||||
$this->response->addJSON(
|
||||
'message', Util::getMessage($message, $sql_query, 'success')
|
||||
);
|
||||
$this->response->addJSON(
|
||||
'index_table',
|
||||
Index::getHtmlForIndexes(
|
||||
$this->table, $this->db
|
||||
)
|
||||
);
|
||||
} else {
|
||||
include 'tbl_structure.php';
|
||||
}
|
||||
} else {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', $error);
|
||||
}
|
||||
}
|
||||
}
|
||||
390
phpMyAdmin/libraries/classes/Controllers/Table/TableRelationController.php
Executable file
390
phpMyAdmin/libraries/classes/Controllers/Table/TableRelationController.php
Executable file
@@ -0,0 +1,390 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\Table\TableRelationController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
namespace PhpMyAdmin\Controllers\Table;
|
||||
|
||||
use PhpMyAdmin\Controllers\TableController;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Index;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\Table;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Handles table relation logic
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
class TableRelationController extends TableController
|
||||
{
|
||||
/**
|
||||
* @var array $options_array
|
||||
*/
|
||||
protected $options_array;
|
||||
|
||||
/**
|
||||
* @var array $cfgRelation
|
||||
*/
|
||||
protected $cfgRelation;
|
||||
|
||||
/**
|
||||
* @var array $existrel
|
||||
*/
|
||||
protected $existrel;
|
||||
|
||||
/**
|
||||
* @var string $tbl_storage_engine
|
||||
*/
|
||||
protected $tbl_storage_engine;
|
||||
|
||||
/**
|
||||
* @var array $existrel_foreign
|
||||
*/
|
||||
protected $existrel_foreign;
|
||||
|
||||
/**
|
||||
* @var Table $udp_query
|
||||
*/
|
||||
protected $upd_query;
|
||||
|
||||
/**
|
||||
* @var Relation $relation
|
||||
*/
|
||||
private $relation;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|null $options_array Options
|
||||
* @param array|null $cfgRelation Config relation
|
||||
* @param string $tbl_storage_engine Table storage engine
|
||||
* @param array|null $existrel Relations
|
||||
* @param array|null $existrel_foreign External relations
|
||||
* @param string $upd_query Update query
|
||||
*/
|
||||
public function __construct(
|
||||
$response,
|
||||
$dbi,
|
||||
$db,
|
||||
$table,
|
||||
$options_array,
|
||||
$cfgRelation,
|
||||
$tbl_storage_engine,
|
||||
$existrel,
|
||||
$existrel_foreign,
|
||||
$upd_query
|
||||
) {
|
||||
parent::__construct($response, $dbi, $db, $table);
|
||||
|
||||
$this->options_array = $options_array;
|
||||
$this->cfgRelation = $cfgRelation;
|
||||
$this->tbl_storage_engine = $tbl_storage_engine;
|
||||
$this->existrel = $existrel;
|
||||
$this->existrel_foreign = $existrel_foreign;
|
||||
$this->upd_query = $upd_query;
|
||||
$this->relation = new Relation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
// Send table of column names to populate corresponding dropdowns depending
|
||||
// on the current selection
|
||||
if (isset($_POST['getDropdownValues'])
|
||||
&& $_POST['getDropdownValues'] === 'true'
|
||||
) {
|
||||
// if both db and table are selected
|
||||
if (isset($_POST['foreignTable'])) {
|
||||
$this->getDropdownValueForTableAction();
|
||||
} else { // if only the db is selected
|
||||
$this->getDropdownValueForDbAction();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->getHeader()->getScripts()->addFiles(
|
||||
array(
|
||||
'tbl_relation.js',
|
||||
'indexes.js'
|
||||
)
|
||||
);
|
||||
|
||||
// Set the database
|
||||
$this->dbi->selectDb($this->db);
|
||||
|
||||
// updates for Internal relations
|
||||
if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) {
|
||||
$this->updateForInternalRelationAction();
|
||||
}
|
||||
|
||||
// updates for foreign keys
|
||||
$this->updateForForeignKeysAction();
|
||||
|
||||
// Updates for display field
|
||||
if ($this->cfgRelation['displaywork'] && isset($_POST['display_field'])) {
|
||||
$this->updateForDisplayField();
|
||||
}
|
||||
|
||||
// If we did an update, refresh our data
|
||||
if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) {
|
||||
$this->existrel = $this->relation->getForeigners(
|
||||
$this->db, $this->table, '', 'internal'
|
||||
);
|
||||
}
|
||||
if (isset($_POST['destination_foreign_db'])
|
||||
&& Util::isForeignKeySupported($this->tbl_storage_engine)
|
||||
) {
|
||||
$this->existrel_foreign = $this->relation->getForeigners(
|
||||
$this->db, $this->table, '', 'foreign'
|
||||
);
|
||||
}
|
||||
|
||||
// display secondary level tabs if necessary
|
||||
$engine = $this->dbi->getTable($this->db, $this->table)->getStorageEngine();
|
||||
|
||||
$this->response->addHTML(
|
||||
Template::get('table/secondary_tabs')->render(
|
||||
array(
|
||||
'url_params' => array(
|
||||
'db' => $GLOBALS['db'],
|
||||
'table' => $GLOBALS['table']
|
||||
),
|
||||
'is_foreign_key_supported' => Util::isForeignKeySupported($engine),
|
||||
'cfg_relation' => $this->relation->getRelationsParam(),
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->response->addHTML('<div id="structure_content">');
|
||||
|
||||
/**
|
||||
* Dialog
|
||||
*/
|
||||
// Now find out the columns of our $table
|
||||
// need to use DatabaseInterface::QUERY_STORE with $this->dbi->numRows()
|
||||
// in mysqli
|
||||
$columns = $this->dbi->getColumns($this->db, $this->table);
|
||||
|
||||
$column_array = array();
|
||||
$column_array[''] = '';
|
||||
foreach ($columns as $column) {
|
||||
if (strtoupper($this->tbl_storage_engine) == 'INNODB'
|
||||
|| ! empty($column['Key'])
|
||||
) {
|
||||
$column_array[$column['Field']] = $column['Field'];
|
||||
}
|
||||
}
|
||||
if ($GLOBALS['cfg']['NaturalOrder']) {
|
||||
uksort($column_array, 'strnatcasecmp');
|
||||
}
|
||||
|
||||
// common form
|
||||
$this->response->addHTML(
|
||||
Template::get('table/relation/common_form')->render([
|
||||
'db' => $this->db,
|
||||
'table' => $this->table,
|
||||
'cfg_relation' => $this->cfgRelation,
|
||||
'tbl_storage_engine' => $this->tbl_storage_engine,
|
||||
'existrel' => isset($this->existrel) ? $this->existrel : array(),
|
||||
'existrel_foreign' => is_array($this->existrel_foreign) && array_key_exists('foreign_keys_data', $this->existrel_foreign)
|
||||
? $this->existrel_foreign['foreign_keys_data'] : array(),
|
||||
'options_array' => $this->options_array,
|
||||
'column_array' => $column_array,
|
||||
'save_row' => array_values($columns),
|
||||
'url_params' => $GLOBALS['url_params'],
|
||||
'databases' => $GLOBALS['dblist']->databases,
|
||||
'dbi' => $GLOBALS['dbi'],
|
||||
])
|
||||
);
|
||||
|
||||
if (Util::isForeignKeySupported($this->tbl_storage_engine)) {
|
||||
$this->response->addHTML(Index::getHtmlForDisplayIndexes());
|
||||
}
|
||||
$this->response->addHTML('</div>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update for display field
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateForDisplayField()
|
||||
{
|
||||
if ($this->upd_query->updateDisplayField(
|
||||
$_POST['display_field'], $this->cfgRelation
|
||||
)
|
||||
) {
|
||||
$this->response->addHTML(
|
||||
Util::getMessage(
|
||||
__('Display column was successfully updated.'),
|
||||
'', 'success'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update for FK
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateForForeignKeysAction()
|
||||
{
|
||||
$multi_edit_columns_name = isset($_POST['foreign_key_fields_name'])
|
||||
? $_POST['foreign_key_fields_name']
|
||||
: null;
|
||||
$preview_sql_data = '';
|
||||
$seen_error = false;
|
||||
|
||||
// (for now, one index name only; we keep the definitions if the
|
||||
// foreign db is not the same)
|
||||
if (isset($_POST['destination_foreign_db'])
|
||||
&& isset($_POST['destination_foreign_table'])
|
||||
&& isset($_POST['destination_foreign_column'])) {
|
||||
list($html, $preview_sql_data, $display_query, $seen_error)
|
||||
= $this->upd_query->updateForeignKeys(
|
||||
$_POST['destination_foreign_db'],
|
||||
$multi_edit_columns_name, $_POST['destination_foreign_table'],
|
||||
$_POST['destination_foreign_column'], $this->options_array,
|
||||
$this->table,
|
||||
is_array($this->existrel_foreign) && array_key_exists('foreign_keys_data', $this->existrel_foreign)
|
||||
? $this->existrel_foreign['foreign_keys_data']
|
||||
: []
|
||||
);
|
||||
$this->response->addHTML($html);
|
||||
}
|
||||
|
||||
// If there is a request for SQL previewing.
|
||||
if (isset($_POST['preview_sql'])) {
|
||||
Core::previewSQL($preview_sql_data);
|
||||
}
|
||||
|
||||
if (!empty($display_query) && !$seen_error) {
|
||||
$GLOBALS['display_query'] = $display_query;
|
||||
$this->response->addHTML(
|
||||
Util::getMessage(
|
||||
__('Your SQL query has been executed successfully.'),
|
||||
null, 'success'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update for internal relation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateForInternalRelationAction()
|
||||
{
|
||||
$multi_edit_columns_name = isset($_POST['fields_name'])
|
||||
? $_POST['fields_name']
|
||||
: null;
|
||||
|
||||
if ($this->upd_query->updateInternalRelations(
|
||||
$multi_edit_columns_name,
|
||||
$_POST['destination_db'],
|
||||
$_POST['destination_table'],
|
||||
$_POST['destination_column'],
|
||||
$this->cfgRelation,
|
||||
isset($this->existrel) ? $this->existrel : null
|
||||
)
|
||||
) {
|
||||
$this->response->addHTML(
|
||||
Util::getMessage(
|
||||
__('Internal relationships were successfully updated.'),
|
||||
'', 'success'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send table columns for foreign table dropdown
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public function getDropdownValueForTableAction()
|
||||
{
|
||||
$foreignTable = $_POST['foreignTable'];
|
||||
$table_obj = $this->dbi->getTable($_POST['foreignDb'], $foreignTable);
|
||||
// Since views do not have keys defined on them provide the full list of
|
||||
// columns
|
||||
if ($table_obj->isView()) {
|
||||
$columnList = $table_obj->getColumns(false, false);
|
||||
} else {
|
||||
$columnList = $table_obj->getIndexedColumns(false, false);
|
||||
}
|
||||
$columns = array();
|
||||
foreach ($columnList as $column) {
|
||||
$columns[] = htmlspecialchars($column);
|
||||
}
|
||||
if ($GLOBALS['cfg']['NaturalOrder']) {
|
||||
usort($columns, 'strnatcasecmp');
|
||||
}
|
||||
$this->response->addJSON('columns', $columns);
|
||||
|
||||
// @todo should be: $server->db($db)->table($table)->primary()
|
||||
$primary = Index::getPrimary($foreignTable, $_POST['foreignDb']);
|
||||
if (false === $primary) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->addJSON('primary', array_keys($primary->getColumns()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send database selection values for dropdown
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public function getDropdownValueForDbAction()
|
||||
{
|
||||
$tables = array();
|
||||
$foreign = isset($_POST['foreign']) && $_POST['foreign'] === 'true';
|
||||
|
||||
if ($foreign) {
|
||||
$query = 'SHOW TABLE STATUS FROM '
|
||||
. Util::backquote($_POST['foreignDb']);
|
||||
$tables_rs = $this->dbi->query(
|
||||
$query,
|
||||
DatabaseInterface::CONNECT_USER,
|
||||
DatabaseInterface::QUERY_STORE
|
||||
);
|
||||
|
||||
while ($row = $this->dbi->fetchArray($tables_rs)) {
|
||||
if (isset($row['Engine'])
|
||||
&& mb_strtoupper($row['Engine']) == $this->tbl_storage_engine
|
||||
) {
|
||||
$tables[] = htmlspecialchars($row['Name']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$query = 'SHOW TABLES FROM '
|
||||
. Util::backquote($_POST['foreignDb']);
|
||||
$tables_rs = $this->dbi->query(
|
||||
$query,
|
||||
DatabaseInterface::CONNECT_USER,
|
||||
DatabaseInterface::QUERY_STORE
|
||||
);
|
||||
while ($row = $this->dbi->fetchArray($tables_rs)) {
|
||||
$tables[] = htmlspecialchars($row[0]);
|
||||
}
|
||||
}
|
||||
if ($GLOBALS['cfg']['NaturalOrder']) {
|
||||
usort($tables, 'strnatcasecmp');
|
||||
}
|
||||
$this->response->addJSON('tables', $tables);
|
||||
}
|
||||
}
|
||||
1173
phpMyAdmin/libraries/classes/Controllers/Table/TableSearchController.php
Executable file
1173
phpMyAdmin/libraries/classes/Controllers/Table/TableSearchController.php
Executable file
File diff suppressed because it is too large
Load Diff
1502
phpMyAdmin/libraries/classes/Controllers/Table/TableStructureController.php
Executable file
1502
phpMyAdmin/libraries/classes/Controllers/Table/TableStructureController.php
Executable file
File diff suppressed because it is too large
Load Diff
40
phpMyAdmin/libraries/classes/Controllers/TableController.php
Executable file
40
phpMyAdmin/libraries/classes/Controllers/TableController.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Holds the PhpMyAdmin\Controllers\TableController
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
namespace PhpMyAdmin\Controllers;
|
||||
|
||||
/**
|
||||
* Handles table related logic
|
||||
*
|
||||
* @package PhpMyAdmin\Controllers
|
||||
*/
|
||||
abstract class TableController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var string $db
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var string $table
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(
|
||||
$response,
|
||||
$dbi,
|
||||
$db,
|
||||
$table
|
||||
) {
|
||||
parent::__construct($response, $dbi);
|
||||
$this->db = $db;
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user