Merge branch 'master' of github.com:phpmyadmin/phpmyadmin

This commit is contained in:
Madhura Jayaratne 2015-05-15 10:32:25 +05:30
commit a66261bbd7
11 changed files with 621 additions and 988 deletions

View File

@ -11,6 +11,7 @@ if (! defined('PHPMYADMIN')) {
require_once './libraries/logging.lib.php';
require_once './libraries/Index.class.php';
require_once './libraries/SystemDatabase.class.php';
/**
* Main interface for database interactions
@ -46,7 +47,7 @@ class PMA_DatabaseInterface
*
* @param PMA_DBI_Extension $ext Object to be used for database queries
*/
public function __construct(PMA_DBI_Extension $ext)
function __construct($ext)
{
$this->_extension = $ext;
}
@ -1149,6 +1150,50 @@ class PMA_DatabaseInterface
);
} // end of the '_usortComparisonCallback()' method
/**
* returns detailed array with all columns for sql
*
* @param string $sql_query target SQL query to get columns
* @param array $view_columns alias for columns
*
* @return array
*/
public function getColumnMapFromSql($sql_query, $view_columns = array())
{
$result = $this->tryQuery($sql_query);
if ($result === false) {
return array();
}
$meta = $this->getFieldsMeta(
$result
);
$nbFields = count($meta);
if ($nbFields <= 0) {
return array();
}
$column_map = array();
$nbColumns = count($view_columns);
for ($i=0; $i < $nbFields; $i++) {
$map = array();
$map['table_name'] = $meta[$i]->table;
$map['refering_column'] = $meta[$i]->name;
if ($nbColumns > 1) {
$map['real_column'] = $view_columns[$i];
}
$column_map[] = $map;
}
return $column_map;
}
/**
* returns detailed array with all columns for given table in database,
* or all tables/databases
@ -2862,5 +2907,15 @@ class PMA_DatabaseInterface
return 'KILL ' . $process . ';';
}
}
/**
* Get the phpmyadmin database manager
*
* @return PMA\SystemDatabase
*/
public function getSystemDatabase()
{
return new PMA\SystemDatabase($this);
}
}
?>

View File

@ -0,0 +1,119 @@
<?php
namespace PMA;
if (! defined('PHPMYADMIN')) {
exit;
}
require_once 'libraries/database_interface.inc.php';
class SystemDatabase {
/**
* @var \PMA_DatabaseInterface
*/
protected $_dbi;
/**
* Get instance of SystemDatabase
*
* @param \PMA_DatabaseInterface Database interface for the system database
*
* @return SystemDatabase
*/
function __construct(\PMA_DatabaseInterface $dbi)
{
$this->_dbi = $dbi;
}
/**
* Get existing data on transformations applied for
* columns in a particular table
*
* @param string $db Database name looking for
*
* @return \mysqli_result Result of executed SQL query
*/
public function getExistingTransformationData($db)
{
$cfgRelation = \PMA_getRelationsParam();
// Get the existing transformation details of the same database
// from pma__column_info table
$pma_transformation_sql = sprintf(
"SELECT * FROM %s.%s WHERE `db_name` = '%s'",
\PMA_Util::backquote($cfgRelation['db']),
\PMA_Util::backquote($cfgRelation['column_info']),
\PMA_Util::sqlAddSlashes($db)
);
return $this->_dbi->tryQuery($pma_transformation_sql);
}
/**
* Get SQL query for store new transformation details of a VIEW
*
* @param object $pma_transformation_data Result set of SQL execution
* @param array $column_map Details of VIEW columns
* @param string $view_name Name of the VIEW
* @param string $db Database name of the VIEW
*
* @return string $new_transformations_sql SQL query for new transformations
*/
function getNewTransformationDataSql(
$pma_transformation_data, $column_map, $view_name, $db
) {
$cfgRelation = \PMA_getRelationsParam();
// Need to store new transformation details for VIEW
$new_transformations_sql = sprintf(
"INSERT INTO %s.%s ("
. "`db_name`, `table_name`, `column_name`, "
. "`comment`, `mimetype`, `transformation`, "
. "`transformation_options`) VALUES",
\PMA_Util::backquote($cfgRelation['db']),
\PMA_Util::backquote($cfgRelation['column_info'])
);
$column_count = 0;
$add_comma = false;
while ($data_row = $this->_dbi->fetchAssoc($pma_transformation_data)) {
foreach ($column_map as $column) {
if ($data_row['table_name'] != $column['table_name']
|| $data_row['column_name'] != $column['refering_column']
) {
continue;
}
$new_transformations_sql .= sprintf(
"%s ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
$add_comma ? ', ' : '',
$db,
$view_name,
isset($column['real_column'])
? $column['real_column']
: $column['refering_column'],
$data_row['comment'],
$data_row['mimetype'],
$data_row['transformation'],
\PMA_Util::sqlAddSlashes(
$data_row['transformation_options']
)
);
$add_comma = true;
$column_count++;
break;
}
if ($column_count == count($column_map)) {
break;
}
}
return ($column_count > 0) ? $new_transformations_sql : '';
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace PMA;
if (! defined('PHPMYADMIN')) {
exit;
}
class Template {
protected $name = null;
const BASE_PATH = 'templates/';
protected function __construct($name)
{
$this->name = $name;
}
public static function get($name)
{
return new Template($name);
}
public function render($data = array())
{
$template = static::BASE_PATH . $this->name . '.php';
try {
extract($data);
ob_start();
if (file_exists($template)) {
include $template;
} else {
throw new \LogicException(
'The template "' . $template . '" not found.'
);
}
$content = ob_get_clean();
return $content;
} catch (\LogicException $e) {
ob_end_clean();
throw new \LogicException($e->getMessage());
}
}
}

View File

@ -12,285 +12,8 @@ if (! defined('PHPMYADMIN')) {
exit;
}
/**
* Function to get html for pma_token and url_query
*
* @param string $url_query url query
*
* @return string
*/
function PMA_getHtmlForPmaTokenAndUrlQuery($url_query)
{
$htmlString = '<script type="text/javascript">'
. "pma_token = '" . $_SESSION[' PMA_token '] . "';"
. "url_query = '" . $url_query . "';"
. '</script>';
return $htmlString;
}
/**
* Function to get html for the chart type options
*
* @return string
*/
function PMA_getHtmlForChartTypeOptions()
{
$html = '<input type="radio" name="chartType" value="bar" id="radio_bar" />'
. '<label for ="radio_bar">' . _pgettext('Chart type', 'Bar') . '</label>'
. '<input type="radio" name="chartType" value="column" id="radio_column" />'
. '<label for ="radio_column">' . _pgettext('Chart type', 'Column')
. '</label>'
. '<input type="radio" name="chartType" value="line" id="radio_line"'
. ' checked="checked" />'
. '<label for ="radio_line">' . _pgettext('Chart type', 'Line') . '</label>'
. '<input type="radio" name="chartType" value="spline" id="radio_spline" />'
. '<label for ="radio_spline">' . _pgettext('Chart type', 'Spline')
. '</label>'
. '<input type="radio" name="chartType" value="area" id="radio_area" />'
. '<label for ="radio_area">' . _pgettext('Chart type', 'Area') . '</label>'
. '<span class="span_pie" style="display:none;">'
. '<input type="radio" name="chartType" value="pie" id="radio_pie" />'
. '<label for ="radio_pie">' . _pgettext('Chart type', 'Pie') . '</label>'
. '</span>'
. '<span class="span_timeline" style="display:none;">'
. '<input type="radio" name="chartType" '
. 'value="timeline" id="radio_timeline" />'
. '<label for ="radio_timeline">' . _pgettext('Chart type', 'Timeline')
. '</label>'
. '</span>'
. '<span class="span_scatter" style="display:none;">'
. '<input type="radio" name="chartType" '
. 'value="scatter" id="radio_scatter" />'
. '<label for ="radio_scatter">' . _pgettext('Chart type', 'Scatter')
. '</label>'
. '</span>'
. '<br /><br />';
return $html;
}
/**
* Function to get html for the bar stacked option
*
* @return string
*/
function PMA_getHtmlForStackedOption()
{
$html = '<span class="barStacked" style="display:none;">'
. '<input type="checkbox" name="barStacked" value="1"'
. ' id="checkbox_barStacked" />'
. '<label for ="checkbox_barStacked">' . __('Stacked') . '</label>'
. '</span>'
. '<br /><br />';
return $html;
}
/**
* Function to get html for the chart x axis options
*
* @param array $keys keys
* @param int &$xaxis x axis
*
* @return string
*/
function PMA_getHtmlForChartXAxisOptions($keys, &$xaxis)
{
$htmlString = '<div style="float:left; padding-left:40px;">'
. '<label for="select_chartXAxis">' . __('X-Axis:') . '</label>'
. '<select name="chartXAxis" id="select_chartXAxis">';
foreach ($keys as $idx => $key) {
if ($xaxis === null) {
$htmlString .= '<option value="' . htmlspecialchars($idx)
. '" selected="selected">' . htmlspecialchars($key) . '</option>';
$xaxis = $idx;
} else {
$htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
. htmlspecialchars($key) . '</option>';
}
}
$htmlString .= '</select>';
return $htmlString;
}
/**
* Function to get html for chart series options
*
* @param array $keys keys
* @param array $fields_meta fields meta
* @param array $numeric_types numeric types
* @param int $xaxis x axis
* @param int $numeric_column_count numeric column count
*
* @return string
*/
function PMA_getHtmlForChartSeriesOptions($keys, $fields_meta, $numeric_types,
$xaxis, $numeric_column_count
) {
$htmlString = '<br />'
. '<label for="select_chartSeries">' . __('Series:') . '</label>'
. '<select name="chartSeries" id="select_chartSeries" multiple="multiple">';
foreach ($keys as $idx => $key) {
if (in_array($fields_meta[$idx]->type, $numeric_types)) {
if ($idx == $xaxis && $numeric_column_count > 1) {
$htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
. htmlspecialchars($key) . '</option>';
} else {
$htmlString .= '<option value="' . htmlspecialchars($idx)
. '" selected="selected">' . htmlspecialchars($key)
. '</option>';
}
}
}
$htmlString .= '</select>';
return $htmlString;
}
/**
* Function to get html for date time columns
*
* @param array $keys keys
* @param array $fields_meta fields meta
*
* @return string
*/
function PMA_getHtmlForDateTimeCols($keys, $fields_meta)
{
$htmlString = '<input type="hidden" name="dateTimeCols" value="';
$date_time_types = array('date', 'datetime', 'timestamp');
foreach ($keys as $idx => $key) {
if (in_array($fields_meta[$idx]->type, $date_time_types)) {
$htmlString .= $idx . " ";
}
}
$htmlString .= '" />';
return $htmlString;
}
/**
* Function to get html for date time columns
*
* @param array $keys keys
* @param array $fields_meta fields meta
* @param array $numeric_types numeric types
*
* @return string
*/
function PMA_getHtmlForNumericCols($keys, $fields_meta, $numeric_types)
{
$htmlString = '<input type="hidden" name="numericCols" value="';
foreach ($keys as $idx => $key) {
if (in_array($fields_meta[$idx]->type, $numeric_types)) {
$htmlString .= $idx . " ";
}
}
$htmlString .= '" />';
return $htmlString;
}
/**
* Function to get html for the table axis label options
*
* @param int $xaxis x axis
* @param array $keys keys
*
* @return string
*/
function PMA_getHtmlForTableAxisLabelOptions($xaxis, $keys)
{
$htmlString = '<div style="float:left; padding-left:40px;">'
. '<label for="xaxis_label">' . __('X-Axis label:') . '</label>'
. '<input style="margin-top:0;" type="text" name="xaxis_label" id="xaxis_label"'
. ' value="'
. (($xaxis == -1) ? __('X Values') : htmlspecialchars($keys[$xaxis]))
. '" /><br />'
. '<label for="yaxis_label">' . __('Y-Axis label:') . '</label>'
. '<input type="text" name="yaxis_label" id="yaxis_label" value="'
. __('Y Values') . '" /><br />'
. '</div>';
return $htmlString;
}
/**
* Function to get html for switching to alternative data format
*
* @param array $keys keys
* @param array $fields_meta fields meta
* @param array $numeric_types numeric types
* @param int $xaxis x axis
*
* @return string
*/
function PMA_getHtmlForAlternativeDataFormat($keys, $fields_meta, $numeric_types,
$xaxis
) {
$htmlString = '<p style="clear:both;">&nbsp;</p>'
. '<div><input type="checkbox" id="chkAlternative" '
. 'name="chkAlternative" value="alternativeFormat">'
. __('Series names are in a column') . '</input>';
$htmlString .= '<br />'
. '<label for="select_seriesColumn">' . __('Series column:') . '</label>'
. '<select name="chartSeriesColumn" id="select_seriesColumn" disabled>';
foreach ($keys as $idx => $key) {
$htmlString .= '<option value="' . htmlspecialchars($idx) . '"';
if ($idx == 1) {
$htmlString .= ' selected="selected"';
$seriesColumn = $idx;
}
$htmlString .= '>' . htmlspecialchars($key) . '</option>';
}
$htmlString .= '</select>';
$htmlString .= '<label for="select_valueColumn">'
. __('Value column:') . '</label>'
. '<select name="chartValueColumn" id="select_valueColumn" disabled>';
$selected = false;
foreach ($keys as $idx => $key) {
if (in_array($fields_meta[$idx]->type, $numeric_types)) {
if (! $selected && $idx != $xaxis && $idx != $seriesColumn) {
$htmlString .= '<option value="' . htmlspecialchars($idx)
. '" selected="selected">' . htmlspecialchars($key)
. '</option>';
$selected = true;
} else {
$htmlString .= '<option value="' . htmlspecialchars($idx) . '">'
. htmlspecialchars($key) . '</option>';
}
}
}
$htmlString .= '</select></div>';
return $htmlString;
}
/**
* Function to get html for the chart area div
*
* @return string
*/
function PMA_getHtmlForChartAreaDiv()
{
$htmlString = '<p style="clear:both;">&nbsp;</p>'
. '<div id="resizer" style="width:600px; height:400px;">'
. '<div id="saveChart"'
. ' style="position: absolute; right: 10px;'
. ' top: 10px; cursor: pointer; z-index: 1000;">'
. PMA_Util::getImage('b_saveimage', __('Save chart as image'))
. '</div>'
. '<div id="querychart">'
. '</div>'
. '</div>';
return $htmlString;
}
require_once 'libraries/Template.class.php';
use PMA\Template;
/**
* Function to get html for displaying table chart
@ -308,44 +31,13 @@ function PMA_getHtmlForChartAreaDiv()
function PMA_getHtmlForTableChartDisplay($url_query, $url_params, $keys,
$fields_meta, $numeric_types, $numeric_column_count, $sql_query
) {
// pma_token/url_query needed for chart export
$htmlString = PMA_getHtmlForPmaTokenAndUrlQuery($url_query);
$htmlString .= '<!-- Display Chart options -->'
. '<div id="div_view_options">'
. '<form method="post" id="tblchartform" action="tbl_chart.php" '
. 'class="ajax">'
. PMA_URL_getHiddenInputs($url_params)
. '<fieldset>'
. '<legend>' . __('Display chart') . '</legend>'
. '<div style="float:left; width:420px;">';
$htmlString .= PMA_getHtmlForChartTypeOptions();
$htmlString .= PMA_getHtmlForStackedOption();
$htmlString .= '<input type="text" name="chartTitle" value="'
. __('Chart title')
. '">'
. '</div>';
$xaxis = null;
$htmlString .= PMA_getHtmlForChartXAxisOptions($keys, $xaxis);
$htmlString .= PMA_getHtmlForChartSeriesOptions(
$keys, $fields_meta, $numeric_types, $xaxis, $numeric_column_count
);
$htmlString .= PMA_getHtmlForDateTimeCols($keys, $fields_meta);
$htmlString .= PMA_getHtmlForNumericCols($keys, $fields_meta, $numeric_types);
$htmlString .= '</div>';
$htmlString .= PMA_getHtmlForTableAxisLabelOptions($xaxis, $keys);
$htmlString .= PMA_getHtmlForAlternativeDataFormat(
$keys, $fields_meta, $numeric_types, $xaxis
);
$htmlString .= PMA_Util::getStartAndNumberOfRowsPanel($sql_query);
$htmlString .= PMA_getHtmlForChartAreaDiv();
$htmlString .= '</fieldset>'
. '</form>'
. '</div>';
return $htmlString;
return Template::get('tbl_chart')->render(array(
'url_query' => $url_query,
'url_params' => $url_params,
'keys' => $keys,
'fields_meta' => $fields_meta,
'numeric_types' => $numeric_types,
'numeric_column_count' => $numeric_column_count,
'sql_query' => $sql_query
));
}
?>

View File

@ -1,161 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Set of functions related to applying transformations for VIEWs
*
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
* Get the column details of VIEW with its original references
*
* @param string $sql_query SQL for original resource
* @param array $view_columns Columns of VIEW if defined new column names
*
* @return array $column_map Details of VIEW columns
*/
function PMA_getColumnMap($sql_query, $view_columns)
{
$column_map = array();
// Select query which give results for VIEW
$real_source_result = $GLOBALS['dbi']->tryQuery($sql_query);
if ($real_source_result !== false) {
$real_source_fields_meta = $GLOBALS['dbi']->getFieldsMeta(
$real_source_result
);
$nbColumns = count($view_columns);
$nbFields = count($real_source_fields_meta);
if ($nbFields > 0) {
for ($i = 0; $i < $nbFields; $i++) {
$map = array();
$map['table_name'] = $real_source_fields_meta[$i]->table;
$map['refering_column'] = $real_source_fields_meta[$i]->name;
if ($nbColumns > 1) {
$map['real_column'] = $view_columns[$i];
}
$column_map[] = $map;
}
}
}
unset($real_source_result);
return $column_map;
}
/**
* Get existing data on transformations applied for
* columns in a particular table
*
* @param string $db Database name looking for
*
* @return mysqli_result Result of executed SQL query
*/
function PMA_getExistingTransformationData($db)
{
$cfgRelation = PMA_getRelationsParam();
// Get the existing transformation details of the same database
// from pma__column_info table
$pma_transformation_sql = 'SELECT * FROM '
. PMA_Util::backquote($cfgRelation['db']) . '.'
. PMA_Util::backquote($cfgRelation['column_info'])
. ' WHERE `db_name` = \''
. PMA_Util::sqlAddSlashes($db) . '\'';
return $GLOBALS['dbi']->tryQuery($pma_transformation_sql);
}
/**
* Get SQL query for store new transformation details of a VIEW
*
* @param mysqli_result $pma_transformation_data Result set of SQL execution
* @param array $column_map Details of VIEW columns
* @param string $view_name Name of the VIEW
* @param string $db Database name of the VIEW
*
* @return string $new_transformations_sql SQL query for new transformations
*/
function PMA_getNewTransformationDataSql(
$pma_transformation_data, $column_map, $view_name, $db
) {
$cfgRelation = PMA_getRelationsParam();
// Need to store new transformation details for VIEW
$new_transformations_sql = 'INSERT INTO '
. PMA_Util::backquote($cfgRelation['db']) . '.'
. PMA_Util::backquote($cfgRelation['column_info'])
. ' (`db_name`, `table_name`, `column_name`, `comment`, '
. '`mimetype`, `transformation`, `transformation_options`)'
. ' VALUES ';
$column_count = 0;
$add_comma = false;
while ($data_row = $GLOBALS['dbi']->fetchAssoc($pma_transformation_data)) {
foreach ($column_map as $column) {
if ($data_row['table_name'] == $column['table_name']
&& $data_row['column_name'] == $column['refering_column']
) {
$new_transformations_sql .= $add_comma ? ', ' : '';
$new_transformations_sql .= '('
. '\'' . $db . '\', '
. '\'' . $view_name . '\', '
. '\'';
$new_transformations_sql .= (isset($column['real_column']))
? $column['real_column']
: $column['refering_column'];
$new_transformations_sql .= '\', '
. '\'' . $data_row['comment'] . '\', '
. '\'' . $data_row['mimetype'] . '\', '
. '\'' . $data_row['transformation'] . '\', '
. '\''
. PMA_Util::sqlAddSlashes(
$data_row['transformation_options']
)
. '\')';
$add_comma = true;
$column_count++;
break;
}
}
if ($column_count == count($column_map)) {
break;
}
}
return ($column_count > 0) ? $new_transformations_sql : '';
}
?>

146
templates/tbl_chart.php Normal file
View File

@ -0,0 +1,146 @@
<?php
require_once 'libraries/url_generating.lib.php';
global $url_query, $url_params, $keys,
$fields_meta, $numeric_types,
$numeric_column_count, $sql_query, $seriesColumn;
?>
<script type="text/javascript">
pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
url_query = '<?php echo $url_query; ?>';
</script>
<!-- Display Chart options -->
<div id="div_view_options">
<form method="post" id="tblchartform" action="tbl_chart.php" class="ajax">
<?php echo PMA_URL_getHiddenInputs($url_params); ?>
<fieldset>
<legend>
<?php echo __('Display chart'); ?>
</legend>
<div style="float:left; width:420px;">
<input type="radio" name="chartType" value="bar" id="radio_bar" />
<label for ="radio_bar"><?php echo _pgettext('Chart type', 'Bar') ?></label>
<input type="radio" name="chartType" value="column" id="radio_column" />
<label for ="radio_column"><?php echo _pgettext('Chart type', 'Column') ?></label>
<input type="radio" name="chartType" value="line" id="radio_line" checked="checked" />
<label for ="radio_line"><?php echo _pgettext('Chart type', 'Line') ?></label>
<input type="radio" name="chartType" value="spline" id="radio_spline" />
<label for ="radio_spline"><?php echo _pgettext('Chart type', 'Spline') ?></label>
<input type="radio" name="chartType" value="area" id="radio_area" />
<label for ="radio_area"><?php echo _pgettext('Chart type', 'Area') ?></label>
<span class="span_pie" style="display:none;">
<input type="radio" name="chartType" value="pie" id="radio_pie" />
<label for ="radio_pie"><?php echo _pgettext('Chart type', 'Pie') ?></label>
</span>
<span class="span_timeline" style="display:none;">
<input type="radio" name="chartType" value="timeline" id="radio_timeline" />
<label for ="radio_timeline"><?php echo _pgettext('Chart type', 'Timeline') ?></label>
</span>
<span class="span_scatter" style="display:none;">
<input type="radio" name="chartType" value="scatter" id="radio_scatter" />
<label for ="radio_scatter"><?php echo _pgettext('Chart type', 'Scatter') ?></label>
</span>
<br /><br />
<span class="barStacked" style="display:none;">
<input type="checkbox" name="barStacked" value="1" id="checkbox_barStacked" />
<label for ="checkbox_barStacked"><?php echo __('Stacked') ?></label>
</span>
<br /><br />
<input type="text" name="chartTitle" value="<?php echo __('Chart title'); ?>">
</div>
<?php $xaxis = null; ?>
<div style="float:left; padding-left:40px;">
<label for="select_chartXAxis"><?php echo __('X-Axis:'); ?></label>
<select name="chartXAxis" id="select_chartXAxis">
<?php foreach ($keys as $idx => $key) : ?>
<?php if ($xaxis === null) : ?>
<option value="<?php echo htmlspecialchars($idx); ?>" selected="selected"><?php echo htmlspecialchars($key); ?></option>
<?php $xaxis = $idx; ?>
<?php else : ?>
<option value="<?php echo htmlspecialchars($idx); ?>" selected="selected"><?php echo htmlspecialchars($key); ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
<br />
<label for="select_chartSeries">
<?php echo __('Series:'); ?>
</label>
<select name="chartSeries" id="select_chartSeries" multiple="multiple">
<?php foreach ($keys as $idx => $key) : ?>
<?php if (in_array($fields_meta[$idx]->type, $numeric_types)) : ?>
<?php if ($idx == $xaxis && $numeric_column_count > 1) : ?>
<option value="<?php echo htmlspecialchars($idx); ?>"><?php echo htmlspecialchars($key); ?></option>
<?php else : ?>
<option value="<?php echo htmlspecialchars($idx); ?>" selected="selected"><?php echo htmlspecialchars($key); ?></option>
<?php endif; ?>
<?php endif; ?>
<?php endforeach;?>
</select>
<input type="hidden" name="dateTimeCols" value="<?php $date_time_types = array('date', 'datetime', 'timestamp');
foreach ($keys as $idx => $key) {
if (in_array($fields_meta[$idx]->type, $date_time_types)) {
echo $idx . ' ';
}
}?>"
/>
<input type="hidden" name="numericCols" value="<?php
foreach ($keys as $idx => $key) {
if (in_array($fields_meta[$idx]->type, $numeric_types)) {
echo $idx . ' ';
}
}?>"
/>
</div>
<div style="float:left; padding-left:40px;">
<label for="xaxis_panel">
<?php echo __('X-Axis label:'); ?>
</label>
<input style="margin-top:0;" type="text" name="xaxis_label" id="xaxis_label" value="<?php echo (($xaxis == -1) ? __('X Values') : htmlspecialchars($keys[$xaxis])); ?>" />
<br />
<label for="yaxis_label">
<?php echo __('Y-Axis label:'); ?>
</label>
<input type="text" name="yaxis_label" id="yaxis_label" value="<?php echo __('Y Values'); ?>" />
<br />
</div>
<p style="clear:both;">&nbsp;</p>
<div>
<input type="checkbox" id="chkAlternative" name="chkAlternative" value="alternativeFormat" />
<label for="chkAlternative"><?php echo __('Series names are in a column'); ?></label>
<br />
<label for="select_seriesColumn">
<?php echo __('Series column:'); ?>
</label>
<select name="chartSeriesColumn" id="select_seriesColumn" disabled>
<?php foreach ($keys as $idx => $key) : ?>
<option value="<?php echo htmlspecialchars($idx);
if ($idx == 1) { echo ' selected="selected"'; } $seriesColumn = $idx; ?>"><?php echo htmlspecialchars($key); ?></option>
<?php endforeach; ?>
</select>
<label for="select_valueColumn">
<?php echo __('Value Column:'); ?>
</label>
<select name="chartValueColumn" id="select_valueColumn" disabled>
<?php $selected = false;
foreach ($keys as $idx => $key) : ?>
<?php if (in_array($fields_meta[$idx]->type, $numeric_types)) : ?>
<?php if (! $selected && $idx != $xaxis && $idx != $seriesColumn) : ?>
<option value="<?php echo htmlspecialchars($idx); ?>" selected="selected"><?php echo htmlspecialchars($key); $selected = true; ?></option>
<?php else: ?>
<option value="<?php echo htmlspecialchars($idx); ?>"><?php echo htmlspecialchars($key); ?></option>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<?php echo PMA_Util::getStartAndNumberOfRowsPanel($sql_query); ?>
<p style="clear:both;">&nbsp;</p>
<div id="resizer" style="width:600px; height:400px;">
<div id="saveChart" style="position: absolute; right: 10px; top: 10px; cursor: pointer; z-index: 1000;">
<?php echo PMA_Util::getImage('b_saveimage', __('Save chart as image')); ?>
</div>
<div id="querychart">
</div>
</div>
</fieldset>
</form>
</div>

View File

@ -0,0 +1,118 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for faked database access
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/dbi/DBIDummy.class.php';
require_once 'libraries/DatabaseInterface.class.php';
require_once 'libraries/SystemDatabase.class.php';
/**
* Tests basic functionality of dummy dbi driver
*
* @package PhpMyAdmin-test
*/
class PMA_DatabaseInterface_Test extends PHPUnit_Framework_TestCase
{
private $dbi;
/**
* Configures test parameters.
*
* @return void
*/
function setup()
{
//$extension = new PMA_DBI_Dummy();
$extension = $this->getMockBuilder('PMA_DBI_Dummy')
->disableOriginalConstructor()
->getMock();
$extension->expects($this->any())
->method('realQuery')
->will($this->returnValue(true));
$meta1 = new FieldMeta();
$meta1->table = "meta1_table";
$meta1->name = "meta1_name";
$meta2 = new FieldMeta();
$meta2->table = "meta2_table";
$meta2->name = "meta2_name";
$getFieldsMeta = array($meta1, $meta2);
$extension->expects($this->any())
->method('getFieldsMeta')
->will($this->returnValue(array(
$meta1, $meta2
)));
$this->dbi = new PMA_DatabaseInterface($extension);
}
/**
* Tests for DBI::getColumnMapFromSql() method.
*
* @return void
* @test
*/
public function testPMAGetColumnMap()
{
$sql_query = "PMA_sql_query";
$view_columns = array(
"view_columns1", "view_columns2"
);
$column_map = $this->dbi->getColumnMapFromSql(
$sql_query, $view_columns
);
$this->assertEquals(
array(
'table_name' => 'meta1_table',
'refering_column' => 'meta1_name',
'real_column' => 'view_columns1'
),
$column_map[0]
);
$this->assertEquals(
array(
'table_name' => 'meta2_table',
'refering_column' => 'meta2_name',
'real_column' => 'view_columns2'
),
$column_map[1]
);
}
/**
* Tests for DBI::getSystemDatabase() method.
*
* @return void
* @test
*/
public function testGetSystemDatabase()
{
$sd = $this->dbi->getSystemDatabase();
$this->assertInstanceOf('PMA\\SystemDatabase', $sd);
}
}
/**
* class for Table Field Meta
*
* @package PhpMyAdmin-test
*/
class FieldMeta
{
public $table;
public $name;
}

View File

@ -0,0 +1,115 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
require_once 'libraries/SystemDatabase.class.php';
/**
* Tests for libraries/SystemDatabase.class.php
*
* @package PhpMyAdmin-test
*/
class PMA_SystemDatabaseTest extends PHPUnit_Framework_TestCase
{
/**
* Setup function for test cases
*
* @access protected
* @return void
*/
protected function setUp()
{
/**
* SET these to avoid undefine d index error
*/
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['Server']['pmadb'] = '';
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())
->method('tryQuery')
->will($this->returnValue('executeResult2'));
//_SESSION
$_SESSION['relation'][$GLOBALS['server']] = array(
'table_coords' => "table_name",
'displaywork' => 'displaywork',
'db' => "information_schema",
'table_info' => 'table_info',
'relwork' => 'relwork',
'commwork' => 'commwork',
'displaywork' => 'displaywork',
'pdfwork' => 'pdfwork',
'column_info' => 'column_info',
'relation' => 'relation',
'relwork' => 'relwork',
);
$dbi->expects($this->any())
->method('fetchAssoc')
->will($this->returnValue(array(
'table_name' => "table_name",
'column_name' => "column_name",
'comment' => "comment",
'mimetype' => "mimetype",
'transformation' => "transformation",
'transformation_options' => "transformation_options",
)));
$this->sysDb = new PMA\SystemDatabase($dbi);
}
/**
* Tests for PMA_getExistingTransformationData() method.
*
* @return void
* @test
*/
public function testPMAGetExistingTransformationData()
{
$db = "PMA_db";
$ret = $this->sysDb->getExistingTransformationData($db);
//validate that is the same as $GLOBALS['dbi']->tryQuery
$this->assertEquals(
'executeResult2',
$ret
);
}
/**
* Tests for PMA_getNewTransformationDataSql() method.
*
* @return void
* @test
*/
public function testPMAGetNewTransformationDataSql()
{
$db = "PMA_db";
$pma_transformation_data = array();
$column_map = array(
array(
"table_name" => "table_name",
"refering_column" => "column_name"
)
);
$view_name = "view_name";
$ret = $this->sysDb->getNewTransformationDataSql(
$pma_transformation_data, $column_map, $view_name, $db
);
$sql = "INSERT INTO `information_schema`.`column_info` "
. "(`db_name`, `table_name`, `column_name`, `comment`, `mimetype`, "
. "`transformation`, `transformation_options`) VALUES "
. "('PMA_db', 'view_name', 'column_name', 'comment', 'mimetype', "
. "'transformation', 'transformation_options')";
$this->assertEquals(
$sql,
$ret
);
}
}

View File

@ -1,296 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/tbl_chart.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/tbl_chart.lib.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Index.class.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/sanitizing.lib.php';
/**
* Tests for libraries/tbl_chart.lib.php
*
* @package PhpMyAdmin-test
*/
class PMA_TblChartTest extends PHPUnit_Framework_TestCase
{
/**
* Setup function for test cases
*
* @access protected
* @return void
*/
protected function setUp()
{
/**
* SET these to avoid undefined index error
*/
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['Server']['pmadb'] = '';
$GLOBALS['pmaThemeImage'] = 'theme/';
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['ShowHint'] = true;
$_REQUEST['unlim_num_rows'] = 100;
$_REQUEST['pos'] = 0;
$_REQUEST['session_max_rows'] = 25;
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
}
/**
* Tests for PMA_getHtmlForPmaTokenAndUrlQuery() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForPmaTokenAndUrlQuery()
{
$url_query = "url_query";
$_SESSION[' PMA_token '] = "PMA_token";
$html = PMA_getHtmlForPmaTokenAndUrlQuery($url_query);
$this->assertContains(
$_SESSION[' PMA_token '],
$html
);
$this->assertContains(
$url_query,
$html
);
}
/**
* Tests for PMA_getHtmlForChartTypeOptions() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForChartTypeOptions()
{
$html = PMA_getHtmlForChartTypeOptions();
$this->assertContains(
_pgettext('Chart type', 'Bar'),
$html
);
$this->assertContains(
_pgettext('Chart type', 'Column'),
$html
);
$this->assertContains(
_pgettext('Chart type', 'Line'),
$html
);
$this->assertContains(
_pgettext('Chart type', 'Spline'),
$html
);
$this->assertContains(
_pgettext('Chart type', 'Area'),
$html
);
$this->assertContains(
_pgettext('Chart type', 'Pie'),
$html
);
$this->assertContains(
_pgettext('Chart type', 'Timeline'),
$html
);
}
/**
* Tests for PMA_getHtmlForStackedOption() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForStackedOption()
{
$html = PMA_getHtmlForStackedOption();
$this->assertContains(
__('Stacked'),
$html
);
}
/**
* Tests for PMA_getHtmlForChartXAxisOptions() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForChartXAxisOptions()
{
$keys = array(
"x1" => "value1",
"x2" => "value2",
);
$yaxis = null;
$html = PMA_getHtmlForChartXAxisOptions($keys, $yaxis);
$this->assertContains(
__('X-Axis:'),
$html
);
//x-Axis values
$this->assertContains(
"x1",
$html
);
$this->assertContains(
"value1",
$html
);
$this->assertContains(
"x2",
$html
);
$this->assertContains(
"value2",
$html
);
}
/**
* Tests for PMA_getHtmlForTableChartDisplay() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForTableChartDisplay()
{
$_SESSION[' PMA_token '] = "PMA_token";
$_SESSION['tmpval']['pos'] = "pos";
$_SESSION['tmpval']['max_rows'] = "all";
$GLOBALS['cfg']['MaxRows'] = 10;
$url_query = "url_query";
$url_params = array("url" => "url_params");
$keys = array(
"x1" => "value1",
"x2" => "value2",
);
$fields_meta = array(
"x1" => new Mock_Meta("type1"),
"x2" => new Mock_Meta("type3"),
);
$numeric_types = array("type1", "type2");
$numeric_column_count = 2;
$sql_query = "sql_query";
$yaxis = null;
$html = PMA_getHtmlForTableChartDisplay(
$url_query, $url_params, $keys,
$fields_meta, $numeric_types,
$numeric_column_count, $sql_query
);
//case 1: PMA_getHtmlForPmaTokenAndUrlQuery
$this->assertContains(
PMA_getHtmlForPmaTokenAndUrlQuery($url_query),
$html
);
//case 2: PMA_getHtmlForPmaTokenAndUrlQuery
$this->assertContains(
PMA_URL_getHiddenInputs($url_params),
$html
);
//case 3: options
$this->assertContains(
PMA_getHtmlForChartTypeOptions(),
$html
);
$this->assertContains(
PMA_getHtmlForStackedOption(),
$html
);
//case 4: options
$this->assertContains(
__('Chart title'),
$html
);
//case 5: options
$this->assertContains(
PMA_getHtmlForChartXAxisOptions($keys, $yaxis),
$html
);
$this->assertContains(
PMA_getHtmlForChartSeriesOptions(
$keys, $fields_meta, $numeric_types, $yaxis, $numeric_column_count
),
$html
);
//case 6: PMA_getHtmlForDateTimeCols
$this->assertContains(
PMA_getHtmlForDateTimeCols($keys, $fields_meta),
$html
);
$this->assertContains(
PMA_getHtmlForTableAxisLabelOptions($yaxis, $keys),
$html
);
$this->assertContains(
PMA_Util::getStartAndNumberOfRowsPanel($sql_query),
$html
);
$this->assertContains(
PMA_getHtmlForChartAreaDiv(),
$html
);
}
}
/**
* Mock class for Meta Field
*
* @package PhpMyAdmin-test
*/
class Mock_Meta
{
var $type;
/**
* Constructor
*
* @param string $type1 meta type
*/
public function __construct($type1)
{
$this->type = $type1;
}
}
?>

View File

@ -1,201 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/tbl_views.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/tbl_views.lib.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/relation.lib.php';
/**
* Tests for libraries/tbl_views.lib.php
*
* @package PhpMyAdmin-test
*/
class PMA_TblViewsTest extends PHPUnit_Framework_TestCase
{
/**
* Setup function for test cases
*
* @access protected
* @return void
*/
protected function setUp()
{
/**
* SET these to avoid undefined index error
*/
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['Server']['pmadb'] = '';
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())
->method('tryQuery')
->will($this->returnValue('executeResult2'));
//_SESSION
$_SESSION['relation'][$GLOBALS['server']] = array(
'table_coords' => "table_name",
'displaywork' => 'displaywork',
'db' => "information_schema",
'table_info' => 'table_info',
'relwork' => 'relwork',
'relation' => 'relation',
'column_info' => 'column_info',
);
//_SESSION
$_SESSION['relation'][$GLOBALS['server']] = array(
'table_coords' => "table_name",
'displaywork' => 'displaywork',
'db' => "information_schema",
'table_info' => 'table_info',
'relwork' => 'relwork',
'commwork' => 'commwork',
'displaywork' => 'displaywork',
'pdfwork' => 'pdfwork',
'column_info' => 'column_info',
'relation' => 'relation',
'relwork' => 'relwork',
);
$meta1 = new FieldMeta();
$meta1->table = "meta1_table";
$meta1->name = "meta1_name";
$meta2 = new FieldMeta();
$meta2->table = "meta2_table";
$meta2->name = "meta2_name";
$getFieldsMeta = array($meta1, $meta2);
$dbi->expects($this->any())
->method('getFieldsMeta')
->will($this->returnValue($getFieldsMeta));
$GLOBALS['dbi'] = $dbi;
}
/**
* Tests for PMA_getColumnMap() method.
*
* @return void
* @test
*/
public function testPMAGetColumnMap()
{
$sql_query = "PMA_sql_query";
$view_columns = array(
"view_columns1", "view_columns2"
);
$column_map = PMA_getColumnMap($sql_query, $view_columns);
$this->assertEquals(
array(
'table_name' => 'meta1_table',
'refering_column' => 'meta1_name',
'real_column' => 'view_columns1'
),
$column_map[0]
);
$this->assertEquals(
array(
'table_name' => 'meta2_table',
'refering_column' => 'meta2_name',
'real_column' => 'view_columns2'
),
$column_map[1]
);
}
/**
* Tests for PMA_getExistingTransformationData() method.
*
* @return void
* @test
*/
public function testPMAGetExistingTransformationData()
{
$db = "PMA_db";
$ret = PMA_getExistingTransformationData($db);
//validate that is the same as $GLOBALS['dbi']->tryQuery
$this->assertEquals(
'executeResult2',
$ret
);
}
/**
* Tests for PMA_getNewTransformationDataSql() method.
*
* @return void
* @test
*/
public function testPMAGetNewTransformationDataSql()
{
$dbi = $GLOBALS['dbi'];
$value = array(
'table_name' => "table_name",
'column_name' => "column_name",
'comment' => "comment",
'mimetype' => "mimetype",
'transformation' => "transformation",
'transformation_options' => "transformation_options",
);
$dbi->expects($this->at(0))->method('fetchAssoc')
->will($this->returnValue($value));
$GLOBALS['dbi'] = $dbi;
$db = "PMA_db";
$pma_tranformation_data = array();
$column_map = array(
array(
"table_name" => "table_name",
"refering_column" => "column_name"
)
);
$view_name = "view_name";
$ret = PMA_getNewTransformationDataSql(
$pma_tranformation_data, $column_map, $view_name, $db
);
$sql = "INSERT INTO `information_schema`.`column_info` "
. "(`db_name`, `table_name`, `column_name`, `comment`, `mimetype`, "
. "`transformation`, `transformation_options`) VALUES "
. "('PMA_db', 'view_name', 'column_name', 'comment', 'mimetype', "
. "'transformation', 'transformation_options')";
$this->assertEquals(
$sql,
$ret
);
}
}
/**
* class for Table Field Meta
*
* @package PhpMyAdmin-test
*/
class FieldMeta
{
public $table;
public $name;
}
?>

View File

@ -8,10 +8,8 @@
* @package PhpMyAdmin
*/
/**
*
*/
require_once './libraries/common.inc.php';
require_once './libraries/SystemDatabase.class.php';
/**
* Runs common work
@ -95,15 +93,19 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) {
$view_columns = explode(',', $_REQUEST['view']['column_names']);
}
$column_map = PMA_getColumnMap($_REQUEST['view']['as'], $view_columns);
$pma_tranformation_data = PMA_getExistingTransformationData($GLOBALS['db']);
$column_map = $GLOBALS['dbi']->getColumnMapFromSql(
$_REQUEST['view']['as'], $view_columns
);
$pma_transformation_data = $GLOBALS['dbi']->getSystemDatabase()->getExistingTransformationData(
$GLOBALS['db']
);
if ($pma_tranformation_data !== false) {
if ($pma_transformation_data !== false) {
// SQL for store new transformation details of VIEW
$new_transformations_sql = PMA_getNewTransformationDataSql(
$pma_tranformation_data, $column_map, $_REQUEST['view']['name'],
$GLOBALS['db']
$new_transformations_sql = $GLOBALS['dbi']->getSystemDatabase()->getNewTransformationDataSql(
$pma_transformation_data, $column_map,
$_REQUEST['view']['name'], $GLOBALS['db']
);
// Store new transformations
@ -112,7 +114,7 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) {
}
}
unset($pma_tranformation_data);
unset($pma_transformation_data);
if (! isset($_REQUEST['ajax_dialog'])) {
$message = PMA_Message::success();