Recently used tables (class, configuration, remember in pma database)
This commit is contained in:
parent
576fca3dc2
commit
23021911b1
@ -52,6 +52,7 @@ $cfg['Servers'][$i]['AllowNoPassword'] = false;
|
||||
// $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
|
||||
// $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
|
||||
// $cfg['Servers'][$i]['history'] = 'pma_history';
|
||||
// $cfg['Servers'][$i]['recent'] = 'pma_recent';
|
||||
// $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
|
||||
// $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
|
||||
// $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';
|
||||
|
||||
198
libraries/RecentTable.class.php
Normal file
198
libraries/RecentTable.class.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
*
|
||||
* @package phpMyAdmin
|
||||
*/
|
||||
|
||||
require_once './libraries/Message.class.php';
|
||||
|
||||
/**
|
||||
* Handles the recently used tables.
|
||||
*
|
||||
* @TODO Add documentation about configuration LeftRecentTable
|
||||
* @TODO Add documentation about table pma_recent (#recent) in Documentation.html
|
||||
* @TODO Add SQL script to generate pma_recent table
|
||||
*
|
||||
* @package phpMyAdmin
|
||||
*/
|
||||
class RecentTable
|
||||
{
|
||||
/**
|
||||
* Defines the internal PMA table which contains recent tables.
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $pma_table;
|
||||
|
||||
/**
|
||||
* Reference to session variable containing recently used tables.
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $tables;
|
||||
|
||||
/**
|
||||
* RecentTable instance.
|
||||
*
|
||||
* @var RecentTable
|
||||
*/
|
||||
private static $_instance;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (strlen($GLOBALS['cfg']['Server']['pmadb']) &&
|
||||
strlen($GLOBALS['cfg']['Server']['recent'])) {
|
||||
$this->pma_table = PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) .".".
|
||||
PMA_backquote($GLOBALS['cfg']['Server']['recent']);
|
||||
}
|
||||
if (!isset($_SESSION['tmp_user_values']['recent_tables'])) {
|
||||
$_SESSION['tmp_user_values']['recent_tables'] =
|
||||
isset($this->pma_table) ? $this->getFromDb() : array();
|
||||
}
|
||||
$this->tables =& $_SESSION['tmp_user_values']['recent_tables'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns class instance.
|
||||
*
|
||||
* @return RecentTable
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$_instance)) {
|
||||
self::$_instance = new RecentTable();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns recently used tables from phpMyAdmin database.
|
||||
*
|
||||
* @uses $pma_table
|
||||
* @uses PMA_query_as_controluser()
|
||||
* @uses PMA_DBI_fetch_array()
|
||||
* @uses json_decode()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFromDb()
|
||||
{
|
||||
// Read from phpMyAdmin database, if recent tables is not in session
|
||||
$sql_query =
|
||||
" SELECT `tables` FROM " . $this->pma_table .
|
||||
" WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'";
|
||||
|
||||
$row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query));
|
||||
if (isset($row[0])) {
|
||||
return json_decode($row[0]);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save recent tables into phpMyAdmin database.
|
||||
*
|
||||
* @uses PMA_query_as_controluser()
|
||||
* @uses PMA_DBI_fetch_value()
|
||||
* @uses PMA_DBI_try_query()
|
||||
* @uses json_decode()
|
||||
* @uses PMA_Message
|
||||
*
|
||||
* @return true|PMA_Message
|
||||
*/
|
||||
public function saveToDb()
|
||||
{
|
||||
$username = $GLOBALS['cfg']['Server']['user'];
|
||||
$sql_query =
|
||||
" SELECT COUNT(*) FROM " . $this->pma_table .
|
||||
" WHERE `username` = '" . $username . "'";
|
||||
|
||||
$exist = PMA_DBI_fetch_value(PMA_query_as_controluser($sql_query));
|
||||
if ($exist) {
|
||||
$sql_query =
|
||||
" UPDATE " . $this->pma_table .
|
||||
" SET `tables` = '" . PMA_sqlAddslashes(json_encode($this->tables)) . "'" .
|
||||
" WHERE `username` = '" . $username . "'";
|
||||
|
||||
$success = PMA_DBI_try_query($sql_query, $GLOBALS['controllink']);
|
||||
} else {
|
||||
$sql_query =
|
||||
" INSERT INTO " . $this->pma_table . " (`username`, `tables`)" .
|
||||
" VALUES ('" . $username . "', '" . PMA_sqlAddslashes(json_encode($this->tables)) . "')";
|
||||
|
||||
$success = PMA_DBI_try_query($sql_query, $GLOBALS['controllink']);
|
||||
}
|
||||
|
||||
if (!$success) {
|
||||
$message = PMA_Message::error(__('Could not save configuration'));
|
||||
$message->addMessage('<br /><br />');
|
||||
$message->addMessage(PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink'])));
|
||||
return $message;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim recent table according to the LeftRecentTable configuration.
|
||||
*/
|
||||
public function trim()
|
||||
{
|
||||
while (count($this->tables) > $GLOBALS['cfg']['LeftRecentTable']) {
|
||||
array_pop($this->tables);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML code "select" for recently used tables.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHtmlSelect()
|
||||
{
|
||||
$this->trim();
|
||||
|
||||
$html = '<select onchange="if (this.value != \'\') {'.
|
||||
'arr=this.value.split(\'.\');'.
|
||||
'window.parent.setDb(arr[0]);'.
|
||||
'window.parent.setTable(arr[1]);'.
|
||||
'window.parent.refreshMain(\'' . $GLOBALS['cfg']['LeftDefaultTabTable'] . '\');'.
|
||||
'}">';
|
||||
$html .= '<option value="">(' . __('Recent tables') . ') ...</option>';
|
||||
foreach ($this->tables as $table) {
|
||||
$html .= '<option value="' . $table . '">' . $table . '</option>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add recently used tables.
|
||||
*
|
||||
* @param string $db Database name where the table is located
|
||||
* @param string $table Table name
|
||||
*
|
||||
* @return true|PMA_Message True if success, PMA_Message if not
|
||||
*/
|
||||
public function add($db, $table)
|
||||
{
|
||||
$table_str = $db . '.' . $table;
|
||||
|
||||
// add only if this is new table
|
||||
if (!isset($this->tables[0]) || $this->tables[0] != $table_str) {
|
||||
array_unshift($this->tables, $table_str);
|
||||
$this->tables = array_unique($this->tables);
|
||||
$this->trim();
|
||||
if (isset($this->pma_table)) {
|
||||
return $this->saveToDb();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -3023,35 +3023,4 @@ function PMA_buildActionTitles() {
|
||||
$titles['Edit'] = PMA_getIcon('b_edit.png', __('Edit'), true);
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim recent table according to the LeftRecentTable configuration
|
||||
*/
|
||||
function PMA_trimRecentTable() {
|
||||
while (count($_SESSION['tmp_user_values']['recent_tables']) > $GLOBALS['cfg']['LeftRecentTable']) {
|
||||
array_pop($_SESSION['tmp_user_values']['recent_tables']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add recently used tables
|
||||
*
|
||||
* @param string $db Database name where the table is located
|
||||
* @param string $table Table name
|
||||
*
|
||||
* @uses PMA_trimRecentTable()
|
||||
*/
|
||||
function PMA_addRecentTable($db, $table) {
|
||||
$recent_tables =& $_SESSION['tmp_user_values']['recent_tables'];
|
||||
if (isset($recent_tables)) {
|
||||
array_unshift($recent_tables, $db . '.' . $table);
|
||||
$recent_tables = array_unique($recent_tables);
|
||||
PMA_trimRecentTable();
|
||||
} else {
|
||||
$recent_tables = array();
|
||||
array_unshift($recent_tables, $db . '.' . $table);
|
||||
}
|
||||
$GLOBALS['reload'] = true;
|
||||
PMA_reloadNavigation();
|
||||
}
|
||||
?>
|
||||
|
||||
@ -338,6 +338,13 @@ $cfg['Servers'][$i]['history'] = '';
|
||||
*/
|
||||
$cfg['Servers'][$i]['designer_coords'] = '';
|
||||
|
||||
/**
|
||||
* table to store recently used tables
|
||||
* - leave blank for no "persistent" recently used tables
|
||||
* SUGGESTED: 'pma_recent'
|
||||
*/
|
||||
$cfg['Servers'][$i]['recent'] = '';
|
||||
|
||||
/**
|
||||
* table to store SQL tracking
|
||||
* - leave blank for no SQL tracking
|
||||
|
||||
@ -282,6 +282,8 @@ $strConfigLeftLogoLinkWindow_desc = __('Open the linked page in the main window
|
||||
$strConfigLeftLogoLinkWindow_name = __('Logo link target');
|
||||
$strConfigLeftPointerEnable_desc = __('Highlight server under the mouse cursor');
|
||||
$strConfigLeftPointerEnable_name = __('Enable highlighting');
|
||||
$strConfigLeftRecentTable_desc = __('Maximum number of recently used tables; set 0 to disable');
|
||||
$strConfigLeftRecentTable_name = __('Recently used tables');
|
||||
$strConfigLightTabs_desc = __('Use less graphically intense tabs');
|
||||
$strConfigLightTabs_name = __('Light tabs');
|
||||
$strConfigLimitChars_desc = __('Maximum number of characters shown in any non-numeric column on browse view');
|
||||
|
||||
@ -8,10 +8,8 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once './libraries/common.inc.php';
|
||||
require_once './libraries/RecentTable.class.php';
|
||||
|
||||
|
||||
/**
|
||||
@ -152,8 +150,15 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) {
|
||||
.'"</span>' . "\n";
|
||||
} // end if
|
||||
|
||||
// remember accessed table
|
||||
PMA_addRecentTable($GLOBALS['db'], $GLOBALS['table']);
|
||||
// add recently used table and reload the navigation
|
||||
$result = RecentTable::getInstance()->add($GLOBALS['db'], $GLOBALS['table']);
|
||||
if ($result === true) {
|
||||
$GLOBALS['reload'] = true;
|
||||
PMA_reloadNavigation();
|
||||
} else {
|
||||
$error = $result;
|
||||
$error->display();
|
||||
}
|
||||
} else {
|
||||
// no table selected, display database comment if present
|
||||
/**
|
||||
|
||||
@ -138,6 +138,10 @@ function PMA_printRelationsParamDiagnostic($cfgRelation)
|
||||
|
||||
PMA_printDiagMessageForFeature(__('Designer'), 'designerwork', $messages);
|
||||
|
||||
PMA_printDiagMessageForParameter('recent', isset($cfgRelation['recent']), $messages, 'recent');
|
||||
|
||||
PMA_printDiagMessageForFeature(__('Recently used tables'), 'recentwork', $messages);
|
||||
|
||||
PMA_printDiagMessageForParameter('tracking', isset($cfgRelation['tracking']), $messages, 'tracking');
|
||||
|
||||
PMA_printDiagMessageForFeature(__('Tracking'), 'trackingwork', $messages);
|
||||
@ -220,6 +224,7 @@ function PMA__getRelationsParam()
|
||||
$cfgRelation['commwork'] = false;
|
||||
$cfgRelation['mimework'] = false;
|
||||
$cfgRelation['historywork'] = false;
|
||||
$cfgRelation['recentwork'] = false;
|
||||
$cfgRelation['trackingwork'] = false;
|
||||
$cfgRelation['designerwork'] = false;
|
||||
$cfgRelation['userconfigwork'] = false;
|
||||
@ -271,6 +276,8 @@ function PMA__getRelationsParam()
|
||||
$cfgRelation['pdf_pages'] = $curr_table[0];
|
||||
} elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) {
|
||||
$cfgRelation['history'] = $curr_table[0];
|
||||
} elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) {
|
||||
$cfgRelation['recent'] = $curr_table[0];
|
||||
} elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) {
|
||||
$cfgRelation['tracking'] = $curr_table[0];
|
||||
} elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) {
|
||||
@ -325,6 +332,10 @@ function PMA__getRelationsParam()
|
||||
$cfgRelation['historywork'] = true;
|
||||
}
|
||||
|
||||
if (isset($cfgRelation['recent'])) {
|
||||
$cfgRelation['recentwork'] = true;
|
||||
}
|
||||
|
||||
if (isset($cfgRelation['tracking'])) {
|
||||
$cfgRelation['trackingwork'] = true;
|
||||
}
|
||||
@ -346,8 +357,9 @@ function PMA__getRelationsParam()
|
||||
if ($cfgRelation['relwork'] && $cfgRelation['displaywork']
|
||||
&& $cfgRelation['pdfwork'] && $cfgRelation['commwork']
|
||||
&& $cfgRelation['mimework'] && $cfgRelation['historywork']
|
||||
&& $cfgRelation['trackingwork'] && $cfgRelation['userconfigwork']
|
||||
&& $cfgRelation['bookmarkwork'] && $cfgRelation['designerwork']) {
|
||||
&& $cfgRelation['recentwork'] && $cfgRelation['trackingwork']
|
||||
&& $cfgRelation['userconfigwork'] && $cfgRelation['bookmarkwork']
|
||||
&& $cfgRelation['designerwork']) {
|
||||
$cfgRelation['allworks'] = true;
|
||||
}
|
||||
|
||||
|
||||
@ -180,27 +180,13 @@ require_once './libraries/header_http.inc.php';
|
||||
<?php
|
||||
require './libraries/navigation_header.inc.php';
|
||||
|
||||
require_once './libraries/common.lib.php';
|
||||
require_once './libraries/RecentTable.class.php';
|
||||
|
||||
// display recently used tables
|
||||
if ($GLOBALS['cfg']['LeftRecentTable'] && count($_SESSION['tmp_user_values']['recent_tables'])) {
|
||||
PMA_trimRecentTable();
|
||||
?>
|
||||
<div id="recentTableList">
|
||||
<select onchange="if (this.value != '') {
|
||||
arr=this.value.split('.');
|
||||
window.parent.setDb(arr[0]);
|
||||
window.parent.setTable(arr[1]);
|
||||
window.parent.refreshMain('<?php echo $GLOBALS['cfg']['LeftDefaultTabTable']; ?>'); }">
|
||||
<option value="">(<?php echo __('Recent tables'); ?>) ...</option>
|
||||
<?php
|
||||
foreach ($_SESSION['tmp_user_values']['recent_tables'] as $table) {
|
||||
echo '<option value="' . $table . '">' . $table . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<?php
|
||||
if ($GLOBALS['cfg']['LeftRecentTable'] && count(RecentTable::getInstance()->tables)) {
|
||||
echo '<div id="recentTableList">';
|
||||
echo RecentTable::getInstance()->getHtmlSelect();
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if (! $GLOBALS['server']) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user