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

This commit is contained in:
Madhura Jayaratne 2015-06-18 10:32:33 +05:30
commit 637de2a14d
41 changed files with 2252 additions and 3452 deletions

View File

@ -60,7 +60,9 @@ phpMyAdmin - ChangeLog
- bug #4957 "With selected" links doesn't work in table browse
- bug #4795 Query builder: missing joint for the intermediary table
4.4.10.0 (not yet released)
4.4.11.0 (not yet released)
4.4.10.0 (2015-06-17)
- bug #4950 Issues in database selection for replication
- bug #4951 Trying to save chart as image crashes the browser
- bug #4953 cant drag sql.gz file onto import input

View File

@ -10,7 +10,6 @@
* Gets some core libraries
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/tbl_columns_definition_form.lib.php';
require_once 'libraries/central_columns.lib.php';
if (isset($_POST['edit_save']) || isset($_POST['add_new_column'])) {

View File

@ -130,7 +130,10 @@ if (! $result) {
)
);
$response->addJSON(
'url_query', $GLOBALS['cfg']['DefaultTabDatabase']
'url_query',
PMA_Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabDatabase'], 'database'
)
. $url_query . '&db='
. urlencode($current['SCHEMA_NAME'])
);

View File

@ -22,7 +22,6 @@ function escape($variable)
require_once 'libraries/common.inc.php';
require_once 'libraries/gis/GIS_Factory.class.php';
require_once 'libraries/gis/GIS_Visualization.class.php';
require_once 'libraries/tbl_gis_visualization.lib.php';
// Get data if any posted
$gis_data = array();
@ -89,10 +88,9 @@ $visualizationSettings = array(
'spatialColumn' => 'wkt'
);
$data = array(array('wkt' => $wkt_with_zero, 'srid' => $srid));
$visualization = PMA_GIS_visualizationResults(
$data, $visualizationSettings, $format
);
$open_layers = PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol');
$visualization = PMA_GIS_Visualization::getByData($data, $visualizationSettings)->toImage($format);
$open_layers = PMA_GIS_Visualization::getByData($data, $visualizationSettings)->asOl();
// If the call is to update the WKT and visualization make an AJAX response
if (isset($_REQUEST['generate']) && $_REQUEST['generate'] == true) {

View File

@ -1516,6 +1516,22 @@ class PMA_Table
return $return;
}
/**
* Get meta info for fields in table
*
* @return mixed
*/
public function getColumnsMeta()
{
$move_columns_sql_query = sprintf(
'SELECT * FROM %s.%s LIMIT 1',
PMA_Util::backquote($this->_db_name),
PMA_Util::backquote($this->_name)
);
$move_columns_sql_result = $this->_dbi->tryQuery($move_columns_sql_query);
return $this->_dbi->getFieldsMeta($move_columns_sql_result);
}
/**
* Return UI preferences for this table from phpMyAdmin database.
*
@ -1956,5 +1972,362 @@ class PMA_Table
return $sql_query;
}
/**
* Function to handle update for display field
*
* @param string $disp current display field
* @param string $display_field display field
* @param array $cfgRelation configuration relation
*
* @return boolean True on update succeed or False on failure
*/
public function updateDisplayField($disp, $display_field, $cfgRelation) {
$upd_query = false;
if ($disp) {
if ($display_field == '') {
$upd_query = 'DELETE FROM '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($this->_db_name) . '\''
. ' AND table_name = \'' . PMA_Util::sqlAddSlashes($this->_name) . '\'';
} elseif ($disp != $display_field) {
$upd_query = 'UPDATE '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['table_info'])
. ' SET display_field = \''
. PMA_Util::sqlAddSlashes($display_field) . '\''
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($this->_db_name) . '\''
. ' AND table_name = \'' . PMA_Util::sqlAddSlashes($this->_name) . '\'';
}
} elseif ($display_field != '') {
$upd_query = 'INSERT INTO '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['table_info'])
. '(db_name, table_name, display_field) VALUES('
. '\'' . PMA_Util::sqlAddSlashes($this->_db_name) . '\','
. '\'' . PMA_Util::sqlAddSlashes($this->_name) . '\','
. '\'' . PMA_Util::sqlAddSlashes($display_field) . '\')';
}
if ($upd_query) {
$this->_dbi->query(
$upd_query,
$GLOBALS['controllink'],
0,
false
);
return true;
}
return false;
}
/**
* Function to get update query for updating internal relations
*
* @param array $multi_edit_columns_name multi edit column names
* @param array $destination_db destination tables
* @param array $destination_table destination tables
* @param array $destination_column destination columns
* @param array $cfgRelation configuration relation
* @param array|null $existrel db, table, column
*
* @return boolean
*/
public function updateInternalRelations($multi_edit_columns_name,
$destination_db, $destination_table, $destination_column,
$cfgRelation, $existrel) {
$updated = false;
foreach ($destination_db as $master_field_md5 => $foreign_db) {
$upd_query = null;
// Map the fieldname's md5 back to its real name
$master_field = $multi_edit_columns_name[$master_field_md5];
$foreign_table = $destination_table[$master_field_md5];
$foreign_field = $destination_column[$master_field_md5];
if (! empty($foreign_db)
&& ! empty($foreign_table)
&& ! empty($foreign_field)
) {
if (! isset($existrel[$master_field])) {
$upd_query = 'INSERT INTO '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['relation'])
. '(master_db, master_table, master_field, foreign_db,'
. ' foreign_table, foreign_field)'
. ' values('
. '\'' . PMA_Util::sqlAddSlashes($this->_db_name) . '\', '
. '\'' . PMA_Util::sqlAddSlashes($this->_name) . '\', '
. '\'' . PMA_Util::sqlAddSlashes($master_field) . '\', '
. '\'' . PMA_Util::sqlAddSlashes($foreign_db) . '\', '
. '\'' . PMA_Util::sqlAddSlashes($foreign_table) . '\','
. '\'' . PMA_Util::sqlAddSlashes($foreign_field) . '\')';
} elseif ($existrel[$master_field]['foreign_db'] != $foreign_db
|| $existrel[$master_field]['foreign_table'] != $foreign_table
|| $existrel[$master_field]['foreign_field'] != $foreign_field
) {
$upd_query = 'UPDATE '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['relation']) . ' SET'
. ' foreign_db = \''
. PMA_Util::sqlAddSlashes($foreign_db) . '\', '
. ' foreign_table = \''
. PMA_Util::sqlAddSlashes($foreign_table) . '\', '
. ' foreign_field = \''
. PMA_Util::sqlAddSlashes($foreign_field) . '\' '
. ' WHERE master_db = \''
. PMA_Util::sqlAddSlashes($this->_db_name) . '\''
. ' AND master_table = \''
. PMA_Util::sqlAddSlashes($this->_name) . '\''
. ' AND master_field = \''
. PMA_Util::sqlAddSlashes($master_field) . '\'';
} // end if... else....
} elseif (isset($existrel[$master_field])) {
$upd_query = 'DELETE FROM '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_Util::sqlAddSlashes($this->_db_name) . '\''
. ' AND master_table = \'' . PMA_Util::sqlAddSlashes($this->_name) . '\''
. ' AND master_field = \'' . PMA_Util::sqlAddSlashes($master_field)
. '\'';
} // end if... else....
if (isset($upd_query)) {
$this->_dbi->query(
$upd_query,
$GLOBALS['controllink'],
0,
false
);
$updated = true;
}
}
return $updated;
}
/**
* Function to handle foreign key updates
*
* @param array $destination_foreign_db destination foreign database
* @param array $multi_edit_columns_name multi edit column names
* @param array $destination_foreign_table destination foreign table
* @param array $destination_foreign_column destination foreign column
* @param array $options_array options array
* @param string $table current table
* @param array $existrel_foreign db, table, column
*
* @return array
*/
public function updateForeignKeys($destination_foreign_db,
$multi_edit_columns_name, $destination_foreign_table,
$destination_foreign_column, $options_array, $table, $existrel_foreign) {
$html_output = '';
$preview_sql_data = '';
$display_query = '';
$seen_error = false;
foreach ($destination_foreign_db as $master_field_md5 => $foreign_db) {
$create = false;
$drop = false;
// Map the fieldname's md5 back to its real name
$master_field = $multi_edit_columns_name[$master_field_md5];
$foreign_table = $destination_foreign_table[$master_field_md5];
$foreign_field = $destination_foreign_column[$master_field_md5];
if (isset($existrel_foreign[$master_field_md5]['ref_db_name'])) {
$ref_db_name = $existrel_foreign[$master_field_md5]['ref_db_name'];
} else {
$ref_db_name = $GLOBALS['db'];
}
$empty_fields = false;
foreach ($master_field as $key => $one_field) {
if ((! empty($one_field) && empty($foreign_field[$key]))
|| (empty($one_field) && ! empty($foreign_field[$key]))
) {
$empty_fields = true;
}
if (empty($one_field) && empty($foreign_field[$key])) {
unset($master_field[$key]);
unset($foreign_field[$key]);
}
}
if (! empty($foreign_db)
&& ! empty($foreign_table)
&& ! $empty_fields
) {
if (isset($existrel_foreign[$master_field_md5])) {
$constraint_name = $existrel_foreign[$master_field_md5]['constraint'];
$on_delete = ! empty(
$existrel_foreign[$master_field_md5]['on_delete'])
? $existrel_foreign[$master_field_md5]['on_delete']
: 'RESTRICT';
$on_update = ! empty(
$existrel_foreign[$master_field_md5]['on_update'])
? $existrel_foreign[$master_field_md5]['on_update']
: 'RESTRICT';
if ($ref_db_name != $foreign_db
|| $existrel_foreign[$master_field_md5]['ref_table_name'] != $foreign_table
|| $existrel_foreign[$master_field_md5]['ref_index_list'] != $foreign_field
|| $existrel_foreign[$master_field_md5]['index_list'] != $master_field
|| $_REQUEST['constraint_name'][$master_field_md5] != $constraint_name
|| ($_REQUEST['on_delete'][$master_field_md5] != $on_delete)
|| ($_REQUEST['on_update'][$master_field_md5] != $on_update)
) {
// another foreign key is already defined for this field
// or an option has been changed for ON DELETE or ON UPDATE
$drop = true;
$create = true;
} // end if... else....
} else {
// no key defined for this field(s)
$create = true;
}
} elseif (isset($existrel_foreign[$master_field_md5])) {
$drop = true;
} // end if... else....
$tmp_error_drop = false;
if ($drop) {
$drop_query = 'ALTER TABLE ' . PMA_Util::backquote($table)
. ' DROP FOREIGN KEY ' . PMA_Util::backquote($existrel_foreign[$master_field_md5]['constraint']) . ';';
if (! isset($_REQUEST['preview_sql'])) {
$display_query .= $drop_query . "\n";
$this->_dbi->tryQuery($drop_query);
$tmp_error_drop = $GLOBALS['dbi']->getError();
if (! empty($tmp_error_drop)) {
$seen_error = true;
$html_output .= PMA_Util::mysqlDie(
$tmp_error_drop, $drop_query, false, '', false
);
continue;
}
} else {
$preview_sql_data .= $drop_query . "\n";
}
}
$tmp_error_create = false;
if (!$create) {
continue;
}
$create_query = $this->getSQLToCreateForeignKey(
$table, $master_field, $foreign_db, $foreign_table, $foreign_field,
$_REQUEST['constraint_name'][$master_field_md5],
$options_array[$_REQUEST['on_delete'][$master_field_md5]],
$options_array[$_REQUEST['on_update'][$master_field_md5]]
);
if (! isset($_REQUEST['preview_sql'])) {
$display_query .= $create_query . "\n";
$GLOBALS['dbi']->tryQuery($create_query);
$tmp_error_create = $GLOBALS['dbi']->getError();
if (! empty($tmp_error_create)) {
$seen_error = true;
if (substr($tmp_error_create, 1, 4) == '1005') {
$message = PMA_Message::error(
__('Error creating foreign key on %1$s (check data types)')
);
$message->addParam(implode(', ', $master_field));
$html_output .= $message->getDisplay();
} else {
$html_output .= PMA_Util::mysqlDie(
$tmp_error_create, $create_query, false, '', false
);
}
$html_output .= PMA_Util::showMySQLDocu(
'InnoDB_foreign_key_constraints'
) . "\n";
}
} else {
$preview_sql_data .= $create_query . "\n";
}
// this is an alteration and the old constraint has been dropped
// without creation of a new one
if ($drop && $create && empty($tmp_error_drop)
&& ! empty($tmp_error_create)
) {
// a rollback may be better here
$sql_query_recreate = '# Restoring the dropped constraint...' . "\n";
$sql_query_recreate .= $this->getSQLToCreateForeignKey(
$table,
$master_field,
$existrel_foreign[$master_field_md5]['ref_db_name'],
$existrel_foreign[$master_field_md5]['ref_table_name'],
$existrel_foreign[$master_field_md5]['ref_index_list'],
$existrel_foreign[$master_field_md5]['constraint'],
$options_array[$existrel_foreign[$master_field_md5]['on_delete']],
$options_array[$existrel_foreign[$master_field_md5]['on_update']]
);
if (! isset($_REQUEST['preview_sql'])) {
$display_query .= $sql_query_recreate . "\n";
$this->_dbi->tryQuery($sql_query_recreate);
} else {
$preview_sql_data .= $sql_query_recreate;
}
}
} // end foreach
return array(
$html_output,
$preview_sql_data,
$display_query,
$seen_error
);
}
/**
* Returns the SQL query for foreign key constraint creation
*
* @param string $table table name
* @param array $field field names
* @param string $foreignDb foreign database name
* @param string $foreignTable foreign table name
* @param array $foreignField foreign field names
* @param string $name name of the constraint
* @param string $onDelete on delete action
* @param string $onUpdate on update action
*
* @return string SQL query for foreign key constraint creation
*/
private function getSQLToCreateForeignKey($table, $field, $foreignDb, $foreignTable,
$foreignField, $name = null, $onDelete = null, $onUpdate = null
) {
$sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ADD ';
// if user entered a constraint name
if (! empty($name)) {
$sql_query .= ' CONSTRAINT ' . PMA_Util::backquote($name);
}
foreach ($field as $key => $one_field) {
$field[$key] = PMA_Util::backquote($one_field);
}
foreach ($foreignField as $key => $one_field) {
$foreignField[$key] = PMA_Util::backquote($one_field);
}
$sql_query .= ' FOREIGN KEY (' . implode(', ', $field) . ')'
. ' REFERENCES ' . PMA_Util::backquote($foreignDb)
. '.' . PMA_Util::backquote($foreignTable)
. '(' . implode(', ', $foreignField) . ')';
if (! empty($onDelete)) {
$sql_query .= ' ON DELETE ' . $onDelete;
}
if (! empty($onUpdate)) {
$sql_query .= ' ON UPDATE ' . $onUpdate;
}
$sql_query .= ';';
return $sql_query;
}
}
?>

View File

@ -9,6 +9,8 @@ if (! defined('PHPMYADMIN')) {
exit;
}
require_once './libraries/Template.class.php';
/**
* Defines the central_columns parameters for the current user
*
@ -93,8 +95,8 @@ function PMA_getCentralColumnsCount($db)
$GLOBALS['dbi']->selectDb($pmadb, $GLOBALS['controllink']);
$central_list_table = $cfgCentralColumns['table'];
$query = 'SELECT count(db_name) FROM ' .
PMA_Util::backquote($central_list_table) . ' '
. 'WHERE db_name = \'' . $db . '\';';
PMA_Util::backquote($central_list_table) . ' '
. 'WHERE db_name = \'' . $db . '\';';
$res = $GLOBALS['dbi']->fetchResult(
$query, null, null, $GLOBALS['controllink']
);
@ -189,15 +191,15 @@ function PMA_getInsertQuery($column, $def, $db, $central_list_table)
$extra = isset($def['Extra'])?$def['Extra']:"";
$default = isset($def['Default'])?$def['Default']:"";
$insQuery = 'INSERT INTO '
. PMA_Util::backquote($central_list_table) . ' '
. 'VALUES ( \'' . PMA_Util::sqlAddSlashes($db) . '\' ,'
. '\'' . PMA_Util::sqlAddSlashes($column) . '\',\''
. PMA_Util::sqlAddSlashes($type) . '\','
. '\'' . PMA_Util::sqlAddSlashes($length) . '\',\''
. PMA_Util::sqlAddSlashes($collation) . '\','
. '\'' . PMA_Util::sqlAddSlashes($isNull) . '\','
. '\'' . implode(',', array($extra, $attribute))
. '\',\'' . PMA_Util::sqlAddSlashes($default) . '\');';
. PMA_Util::backquote($central_list_table) . ' '
. 'VALUES ( \'' . PMA_Util::sqlAddSlashes($db) . '\' ,'
. '\'' . PMA_Util::sqlAddSlashes($column) . '\',\''
. PMA_Util::sqlAddSlashes($type) . '\','
. '\'' . PMA_Util::sqlAddSlashes($length) . '\',\''
. PMA_Util::sqlAddSlashes($collation) . '\','
. '\'' . PMA_Util::sqlAddSlashes($isNull) . '\','
. '\'' . implode(',', array($extra, $attribute))
. '\',\'' . PMA_Util::sqlAddSlashes($default) . '\');';
return $insQuery;
}
@ -259,7 +261,7 @@ function PMA_syncUniqueColumns($field_select, $isTable=true, $table=null)
foreach ($field_select as $column) {
$cols .= "'" . PMA_Util::sqlAddSlashes($column) . "',";
}
$has_list = PMA_findExistingColNames($db, trim($cols, ','));
$has_list = PMA_findExistingColNames($db, trim($cols, ','));
foreach ($field_select as $column) {
if (!in_array($column, $has_list)) {
$has_list[] = $column;
@ -365,21 +367,21 @@ function PMA_deleteColumnsFromList($field_select, $isTable=true)
}
}
}
if (! empty($colNotExist)) {
$colNotExist = implode(",", array_unique($colNotExist));
$message = PMA_Message::notice(
sprintf(
__(
'Couldn\'t remove Column(s) %1$s '
. 'as they don\'t exist in central columns list!'
), htmlspecialchars($colNotExist)
)
);
if (!empty($colNotExist)) {
$colNotExist = implode(",", array_unique($colNotExist));
$message = PMA_Message::notice(
sprintf(
__(
'Couldn\'t remove Column(s) %1$s '
. 'as they don\'t exist in central columns list!'
), htmlspecialchars($colNotExist)
)
);
}
$GLOBALS['dbi']->selectDb($pmadb, $GLOBALS['controllink']);
$query = 'DELETE FROM ' . PMA_Util::backquote($central_list_table) . ' '
. 'WHERE db_name = \'' . $db . '\' AND col_name IN (' . $cols . ');';
. 'WHERE db_name = \'' . $db . '\' AND col_name IN (' . $cols . ');';
if (!$GLOBALS['dbi']->tryQuery($query, $GLOBALS['controllink'])) {
$message = PMA_Message::error(__('Could not remove columns!'));
@ -433,12 +435,12 @@ function PMA_makeConsistentWithList($db, $selected_tables)
if ($column['col_default']) {
if ($column['col_default'] != 'CURRENT_TIMESTAMP') {
$query .= ' DEFAULT \'' . PMA_Util::sqlAddSlashes(
$column['col_default']
) . '\'';
$column['col_default']
) . '\'';
} else {
$query .= ' DEFAULT ' . PMA_Util::sqlAddSlashes(
$column['col_default']
);
$column['col_default']
);
}
}
$query .= ',';
@ -512,7 +514,7 @@ function PMA_getCentralColumnsFromTable($db, $table, $allFields=false)
* @return true|PMA_Message
*/
function PMA_updateOneColumn($db, $orig_col_name, $col_name, $col_type,
$col_attribute,$col_length, $col_isNull, $collation, $col_extra, $col_default
$col_attribute,$col_length, $col_isNull, $collation, $col_extra, $col_default
) {
$cfgCentralColumns = PMA_centralColumnsGetParams();
if (empty($cfgCentralColumns)) {
@ -534,24 +536,24 @@ function PMA_updateOneColumn($db, $orig_col_name, $col_name, $col_type,
$query = PMA_getInsertQuery($col_name, $def, $db, $centralTable);
} else {
$query = 'UPDATE ' . PMA_Util::backquote($centralTable)
. ' SET col_type = \'' . PMA_Util::sqlAddSlashes($col_type) . '\''
. ', col_name = \'' . PMA_Util::sqlAddSlashes($col_name) . '\''
. ', col_length = \'' . PMA_Util::sqlAddSlashes($col_length) . '\''
. ', col_isNull = ' . $col_isNull
. ', col_collation = \'' . PMA_Util::sqlAddSlashes($collation) . '\''
. ', col_extra = \''
. implode(',', array($col_extra, $col_attribute)) . '\''
. ', col_default = \'' . PMA_Util::sqlAddSlashes($col_default) . '\''
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\' '
. 'AND col_name = \'' . PMA_Util::sqlAddSlashes($orig_col_name)
. '\'';
. ' SET col_type = \'' . PMA_Util::sqlAddSlashes($col_type) . '\''
. ', col_name = \'' . PMA_Util::sqlAddSlashes($col_name) . '\''
. ', col_length = \'' . PMA_Util::sqlAddSlashes($col_length) . '\''
. ', col_isNull = ' . $col_isNull
. ', col_collation = \'' . PMA_Util::sqlAddSlashes($collation) . '\''
. ', col_extra = \''
. implode(',', array($col_extra, $col_attribute)) . '\''
. ', col_default = \'' . PMA_Util::sqlAddSlashes($col_default) . '\''
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\' '
. 'AND col_name = \'' . PMA_Util::sqlAddSlashes($orig_col_name)
. '\'';
}
if (!$GLOBALS['dbi']->tryQuery($query, $GLOBALS['controllink'])) {
return PMA_Message::error(
$GLOBALS['dbi']->getError($GLOBALS['controllink'])
);
}
return true;
return true;
}
/**
@ -592,7 +594,7 @@ function PMA_updateMultipleColumn()
return $message;
}
}
return true;
return true;
}
/**
@ -862,23 +864,44 @@ function PMA_getHTMLforCentralColumnsTableRow($row, $odd_row, $row_num, $db)
. '<span>' . htmlspecialchars($row['col_name']) . '</span>'
. '<input name="orig_col_name" type="hidden" '
. 'value="' . htmlspecialchars($row['col_name']) . '">'
. PMA_getHtmlForColumnName(
$row_num, 0, 0, array('Field'=>$row['col_name']),
array('central_columnswork'=>false)
)
. PMA\Template::get('columns_definitions/column_name')
->render(array(
'columnNumber' => $row_num,
'ci' => 0,
'ci_offset' => 0,
'columnMeta' => array(
'Field'=>$row['col_name']
),
'cfgRelation' => array(
'central_columnswork' => false
)
))
. '</td>';
$tableHtml .=
'<td name = "col_type" class="nowrap"><span>'
. htmlspecialchars($row['col_type']) . '</span>'
. PMA_getHtmlForColumnType(
$row_num, 1, 0, /*overload*/mb_strtoupper($row['col_type']), array()
)
. PMA\Template::get('columns_definitions/column_type')
->render(array(
'columnNumber' => $row_num,
'ci' => 1,
'ci_offset' => 0,
'type_upper' => /*overload*/mb_strtoupper($row['col_type']),
'columnMeta' => array()
))
. '</td>';
$tableHtml .=
'<td class="nowrap" name="col_length">'
. '<span>' . ($row['col_length']?htmlspecialchars($row['col_length']):"")
. '</span>'
. PMA_getHtmlForColumnLength($row_num, 2, 0, 8, $row['col_length'])
. PMA\Template::get('columns_definitions/column_length')->render(
array(
'columnNumber' => $row_num,
'ci' => 2,
'ci_offset' => 0,
'length_values_input_size' => 8,
'length_to_display' => $row['col_length']
)
)
. '</td>';
$meta = array();
@ -896,42 +919,68 @@ function PMA_getHTMLforCentralColumnsTableRow($row, $odd_row, $row_num, $db)
}
$tableHtml .=
'<td class="nowrap" name="col_default"><span>' . (isset($row['col_default'])
? htmlspecialchars($row['col_default']) : 'None')
? htmlspecialchars($row['col_default']) : 'None')
. '</span>'
. PMA_getHtmlForColumnDefault(
$row_num, 3, 0, /*overload*/mb_strtoupper($row['col_type']), '', $meta
)
. PMA\Template::get('columns_definitions/column_default')
->render(array(
'columnNumber' => $row_num,
'ci' => 3,
'ci_offset' => 0,
'type_upper' => /*overload*/mb_strtoupper($row['col_type']),
'columnMeta' => $meta
))
. '</td>';
$tableHtml .=
'<td name="collation" class="nowrap">'
. '<span>' . htmlspecialchars($row['col_collation']) . '</span>'
. PMA_getHtmlForColumnCollation(
$row_num, 4, 0, array('Collation'=>$row['col_collation'])
. PMA_generateCharsetDropdownBox(
PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $row_num . ']',
'field_' . $row_num . '_4', $row['col_collation'], false
)
. '</td>';
$tableHtml .=
'<td class="nowrap" name="col_attribute">'
. '<span>' .
($row['col_attribute']
? htmlspecialchars($row['col_attribute']) : "" )
? htmlspecialchars($row['col_attribute']) : "" )
. '</span>'
. PMA_getHtmlForColumnAttribute(
$row_num, 5, 0, array(), $row['col_attribute'], false, null
)
. PMA\Template::get('columns_definitions/column_attribute')
->render(array(
'columnNumber' => $row_num,
'ci' => 5,
'ci_offset' => 0,
'extracted_columnspec' => array(),
'columnMeta' => $row['col_attribute'],
'submit_attribute' => false,
'analyzed_sql' => null
))
. '</td>';
$tableHtml .=
'<td class="nowrap" name="col_isNull">'
. '<span>' . ($row['col_isNull'] ? __('Yes') : __('No'))
. '</span>'
. PMA_getHtmlForColumnNull($row_num, 6, 0, array('Null'=>$row['col_isNull']))
. PMA\Template::get('columns_definitions/column_null')
->render(array(
'columnNumber' => $row_num,
'ci' => 6,
'ci_offset' => 0,
'columnMeta' => array(
'Null' => $row['col_isNull']
)
))
. '</td>';
$tableHtml .=
'<td class="nowrap" name="col_extra"><span>'
. htmlspecialchars($row['col_extra']) . '</span>'
. PMA_getHtmlForColumnExtra(
$row_num, 7, 0, array('Extra'=>$row['col_extra'])
. PMA\Template::get('columns_definitions/column_extra')->render(
array(
'columnNumber' => $row_num,
'ci' => 7,
'ci_offset' => 0,
'columnMeta' => array('Extra'=>$row['col_extra'])
)
)
. '</td>';
@ -956,20 +1005,41 @@ function PMA_getHTMLforCentralColumnsEditTableRow($row, $odd_row, $row_num)
. '<input name="orig_col_name[' . $row_num . ']" type="hidden" '
. 'value="' . htmlspecialchars($row['col_name']) . '">'
. '<td name="col_name" class="nowrap">'
. PMA_getHtmlForColumnName(
$row_num, 0, 0, array('Field'=>$row['col_name']),
array('central_columnswork'=>false)
)
. PMA\Template::get('columns_definitions/column_name')
->render(array(
'columnNumber' => $row_num,
'ci' => 0,
'ci_offset' => 0,
'columnMeta' => array(
'Field' => $row['col_name']
),
'cfgRelation' => array(
'central_columnswork' => false
)
))
. '</td>';
$tableHtml .=
'<td name = "col_type" class="nowrap">'
. PMA_getHtmlForColumnType(
$row_num, 1, 0, /*overload*/mb_strtoupper($row['col_type']), array()
)
. PMA\Template::get('columns_definitions/column_type')
->render(array(
'columnNumber' => $row_num,
'ci' => 1,
'ci_offset' => 0,
'type_upper' => /*overload*/mb_strtoupper($row['col_type']),
'columnMeta' => array()
))
. '</td>';
$tableHtml .=
'<td class="nowrap" name="col_length">'
. PMA_getHtmlForColumnLength($row_num, 2, 0, 8, $row['col_length'])
. PMA\Template::get('columns_definitions/column_length')->render(
array(
'columnNumber' => $row_num,
'ci' => 2,
'ci_offset' => 0,
'length_values_input_size' => 8,
'length_to_display' => $row['col_length']
)
)
. '</td>';
$meta = array();
if (!isset($row['col_default']) || $row['col_default'] == '') {
@ -986,32 +1056,59 @@ function PMA_getHTMLforCentralColumnsEditTableRow($row, $odd_row, $row_num)
}
$tableHtml .=
'<td class="nowrap" name="col_default">'
. PMA_getHtmlForColumnDefault(
$row_num, 3, 0, /*overload*/mb_strtoupper($row['col_default']), '', $meta
)
. PMA\Template::get('columns_definitions/column_default')
->render(array(
'columnNumber' => $row_num,
'ci' => 3,
'ci_offset' => 0,
'type_upper' => /*overload*/mb_strtoupper($row['col_default']),
'columnMeta' => $meta
))
. '</td>';
$tableHtml .=
'<td name="collation" class="nowrap">'
. PMA_getHtmlForColumnCollation(
$row_num, 4, 0, array('Collation'=>$row['col_collation'])
. PMA_generateCharsetDropdownBox(
PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $row_num . ']',
'field_' . $row_num . '_4', $row['col_collation'], false
)
. '</td>';
$tableHtml .=
'<td class="nowrap" name="col_attribute">'
. PMA_getHtmlForColumnAttribute(
$row_num, 5, 0, array("attribute"=>$row['col_attribute']),
array(), false, null
)
. PMA\Template::get('columns_definitions/column_attribute')
->render(array(
'columnNumber' => $row_num,
'ci' => 5,
'ci_offset' => 0,
'extracted_columnspec' => array(
'attribute' => $row['col_attribute']
),
'columnMeta' => array(),
'submit_attribute' => false,
'analyzed_sql' => null
))
. '</td>';
$tableHtml .=
'<td class="nowrap" name="col_isNull">'
. PMA_getHtmlForColumnNull($row_num, 6, 0, array('Null'=>$row['col_isNull']))
. PMA\Template::get('columns_definitions/column_null')
->render(array(
'columnNumber' => $row_num,
'ci' => 6,
'ci_offset' => 0,
'columnMeta' => array(
'Null' => $row['col_isNull']
)
))
. '</td>';
$tableHtml .=
'<td class="nowrap" name="col_extra">'
. PMA_getHtmlForColumnExtra(
$row_num, 7, 0, array('Extra' => $row['col_extra'])
. PMA\Template::get('columns_definitions/column_extra')->render(
array(
'columnNumber' => $row_num,
'ci' => 7,
'ci_offset' => 0,
'columnMeta' => array('Extra' => $row['col_extra'])
)
)
. '</td>';
$tableHtml .= '</tr>';
@ -1036,7 +1133,7 @@ function PMA_getCentralColumnsListRaw($db, $table)
$centralTable = $cfgCentralColumns['table'];
if (empty($table) || $table == '') {
$query = 'SELECT * FROM ' . PMA_Util::backquote($centralTable) . ' '
. 'WHERE db_name = \'' . $db . '\';';
. 'WHERE db_name = \'' . $db . '\';';
} else {
$GLOBALS['dbi']->selectDb($db, $GLOBALS['userlink']);
$columns = (array) $GLOBALS['dbi']->getColumnNames(
@ -1157,32 +1254,84 @@ function PMA_getHTMLforAddNewColumn($db)
$addNewColumn .= '<tr>'
. '<td></td>'
. '<td name="col_name" class="nowrap">'
. PMA_getHtmlForColumnName(
0, 0, 0, array(), array('central_columnswork'=>false)
)
. PMA\Template::get('columns_definitions/column_name')
->render(array(
'columnNumber' => 0,
'ci' => 0,
'ci_offset' => 0,
'columnMeta' => array(),
'cfgRelation' => array(
'central_columnswork' => false
)
))
. '</td>'
. '<td name = "col_type" class="nowrap">'
. PMA_getHtmlForColumnType(0, 1, 0, '', array())
. PMA\Template::get('columns_definitions/column_type')
->render(array(
'columnNumber' => 0,
'ci' => 1,
'ci_offset' => 0,
'type_upper' => '',
'columnMeta' => array()
))
. '</td>'
. '<td class="nowrap" name="col_length">'
. PMA_getHtmlForColumnLength(0, 2, 0, 8, '')
. PMA\Template::get('columns_definitions/column_length')->render(
array(
'columnNumber' => 0,
'ci' => 2,
'ci_offset' => 0,
'length_values_input_size' => 8,
'length_to_display' => ''
)
)
. '</td>'
. '<td class="nowrap" name="col_default">'
. PMA_getHtmlForColumnDefault(0, 3, 0, '', '', array())
. PMA\Template::get('columns_definitions/column_default')
->render(array(
'columnNumber' => 0,
'ci' => 3,
'ci_offset' => 0,
'type_upper' => '',
'columnMeta' => array()
))
. '</td>'
. '<td name="collation" class="nowrap">'
. PMA_getHtmlForColumnCollation(
0, 4, 0, array()
. PMA_generateCharsetDropdownBox(
PMA_CSDROPDOWN_COLLATION, 'field_collation[0]',
'field_0_4', null, false
)
. '</td>'
. '<td class="nowrap" name="col_attribute">'
. PMA_getHtmlForColumnAttribute(0, 5, 0, array(), array(), false, null)
. PMA\Template::get('columns_definitions/column_attribute')
->render(array(
'columnNumber' => 0,
'ci' => 5,
'ci_offset' => 0,
'extracted_columnspec' => array(),
'columnMeta' => array(),
'submit_attribute' => false,
'analyzed_sql' => null
))
. '</td>'
. '<td class="nowrap" name="col_isNull">'
. PMA_getHtmlForColumnNull(0, 6, 0, array())
. PMA\Template::get('columns_definitions/column_null')
->render(array(
'columnNumber' => 0,
'ci' => 6,
'ci_offset' => 0,
'columnMeta' => array()
))
. '</td>'
. '<td class="nowrap" name="col_extra">'
. PMA_getHtmlForColumnExtra(0, 7, 0, array())
. PMA\Template::get('columns_definitions/column_extra')->render(
array(
'columnNumber' => 0,
'ci' => 7,
'ci_offset' => 0,
'columnMeta' => array()
)
)
. '</td>'
. ' <td>'
. '<input id="add_column_save" type="submit" '

View File

@ -10,6 +10,8 @@ if (! defined('PHPMYADMIN')) {
exit;
}
require_once 'libraries/sql.lib.php';
/**
* Handles visualization of GIS data
*
@ -22,6 +24,8 @@ class PMA_GIS_Visualization
*/
private $_data;
private $modified_sql;
/**
* @var array Set of default settings values are here.
*/
@ -71,18 +75,49 @@ class PMA_GIS_Visualization
return $this->_settings;
}
public static function get($sql_query, $options, $row, $pos)
{
return new PMA_GIS_Visualization($sql_query, $options, $row, $pos);
}
public static function getByData($data, $options)
{
return new PMA_GIS_Visualization(null, $options, null, null, $data);
}
public function hasSrid()
{
foreach ($this->_data as $row) {
if ($row['srid'] == 0) {
return true;
}
}
return false;
}
/**
* Constructor. Stores user specified options.
*
* @param array $data Data for the visualization
* @param array $options Users specified options
* @param string $sql_query SQL to fetch raw data for visualization
* @param array $options Users specified options
* @param integer $row number of rows
* @param integer $pos start position
* @param array $data raw data. If set, parameters other than $options will be ignored
*
* @access public
*/
public function __construct($data, $options)
private function __construct($sql_query, $options, $row, $pos, $data = null)
{
$this->_userSpecifiedSettings = $options;
$this->_data = $data;
if (isset($data))
{
$this->_data = $data;
}
else {
$this->modified_sql = $this->modifySqlQuery($sql_query, $row, $pos);
$this->_data = $this->fetchRawData();
}
}
/**
@ -96,6 +131,68 @@ class PMA_GIS_Visualization
$this->_handleOptions();
}
/**
* Returns sql for fetching raw data
*
* @param string $sql_query The SQL to modify.
* @param integer $rows Number of rows.
* @param integer $pos Start posistion.
*
* @return string the modified sql query.
*/
private function modifySqlQuery($sql_query, $rows, $pos)
{
$modified_query = 'SELECT ';
// If label column is chosen add it to the query
if (! empty($this->_userSpecifiedSettings['labelColumn'])) {
$modified_query .= PMA_Util::backquote($this->_userSpecifiedSettings['labelColumn'])
. ', ';
}
// Wrap the spatial column with 'ASTEXT()' function and add it
$modified_query .= 'ASTEXT('
. PMA_Util::backquote($this->_userSpecifiedSettings['spatialColumn'])
. ') AS ' . PMA_Util::backquote($this->_userSpecifiedSettings['spatialColumn'])
. ', ';
// Get the SRID
$modified_query .= 'SRID('
. PMA_Util::backquote($this->_userSpecifiedSettings['spatialColumn'])
. ') AS ' . PMA_Util::backquote('srid') . ' ';
// Append the original query as the inner query
$modified_query .= 'FROM (' . $sql_query . ') AS '
. PMA_Util::backquote('temp_gis');
// LIMIT clause
if (is_numeric($rows) && $rows > 0) {
$modified_query .= ' LIMIT ';
if (is_numeric($pos) && $pos >= 0) {
$modified_query .= $pos . ', ' . $rows;
} else {
$modified_query .= $rows;
}
}
return $modified_query;
}
/**
* Returns raw data for GIS visualization.
*
* @return string the raw data.
*/
private function fetchRawData()
{
$modified_result = $GLOBALS['dbi']->tryQuery($this->modified_sql);
$data = array();
while ($row = $GLOBALS['dbi']->fetchAssoc($modified_result)) {
$data[] = $row;
}
return $data;
}
/**
* A function which handles passed parameters. Useful if desired
* chart needs to be a little bit different from the default one.
@ -355,6 +452,26 @@ class PMA_GIS_Visualization
$pdf->Output($file_name, 'D');
}
public function toImage($format) {
if ($format == 'svg') {
return $this->asSvg();
} elseif ($format == 'png') {
return $this->asPng();
} elseif ($format == 'ol') {
return $this->asOl();
}
}
public function toFile($filename, $format) {
if ($format == 'svg') {
$this->toFileAsSvg($filename);
} elseif ($format == 'png') {
$this->toFileAsPng($filename);
} elseif ($format == 'pdf') {
$this->toFileAsPdf($filename);
}
}
/**
* Calculates the scale, horizontal and vertical offset that should be used.
*

View File

@ -19,7 +19,7 @@ if (! defined('PHPMYADMIN')) {
* @param array $where_clause_array array of where clauses
* @param string $err_url error url
*
* @return array $_form_params array of insert/edit form parameters
* @return array $form_params array of insert/edit form parameters
*/
function PMA_getFormParametersForInsertForm($db, $table, $where_clauses,
$where_clause_array, $err_url

View File

@ -34,7 +34,7 @@ function PMA_getHtmlForColumnsList(
$columnTypeList = $types[$colTypeCategory];
}
$GLOBALS['dbi']->selectDb($db, $GLOBALS['userlink']);
$columns = (array) $GLOBALS['dbi']->getColumns(
$columns = $GLOBALS['dbi']->getColumns(
$db, $table, null,
true, $GLOBALS['userlink']
);
@ -81,31 +81,38 @@ function PMA_getHtmlForCreateNewColumn(
$content_cells = array();
$available_mime = array();
$mime_map = array();
$header_cells = PMA_getHeaderCells(
true, null, $cfgRelation['mimework']
);
if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
$mime_map = PMA_getMIME($db, $table);
$available_mime = PMA_getAvailableMIMEtypes();
}
$comments_map = PMA_getComments($db, $table);
for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
$content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes(
$columnNumber, $columnMeta, '',
8, '', null, array(), null, null,
$comments_map, null, true,
array(), $cfgRelation,
isset($available_mime)?$available_mime:array(), $mime_map
$content_cells[$columnNumber] = array(
'columnNumber' => $columnNumber,
'columnMeta' => $columnMeta,
'type_upper' => '',
'length_values_input_size' => 8,
'length' => '',
'extracted_columnspec' => array(),
'submit_attribute' => null,
'analyzed_sql' => null,
'comments_map' => $comments_map,
'fields_meta' => null,
'is_backup' => true,
'move_columns' => array(),
'cfgRelation' => $cfgRelation,
'available_mime' => isset($available_mime)?$available_mime:array(),
'mime_map' => $mime_map
);
}
return PMA\Template::get('columns_definitions/table_fields_definitions')
->render(
array(
'header_cells' => $header_cells,
'content_cells' => $content_cells
)
);
->render(array(
'is_backup' => true,
'fields_meta' => null,
'mimework' => $cfgRelation['mimework'],
'content_cells' => $content_cells
));
}
/**
* build the html for step 1.1 of normalization

View File

@ -477,8 +477,8 @@ function PMA_saveDisplayField($db, $table, $field)
$field = '';
}
include_once 'libraries/tbl_relation.lib.php';
PMA_handleUpdateForDisplayField($disp, $field, $db, $table, $cfgRelation);
$upd_query = new PMA_Table($table, $db, $GLOBALS['dbi']);
$upd_query->updateDisplayField($disp, $field, $cfgRelation);
return true;
}

View File

@ -14,6 +14,7 @@ if (! defined('PHPMYADMIN')) {
* Check parameters
*/
require_once './libraries/Util.class.php';
require_once './libraries/Template.class.php';
PMA_Util::checkParameters(array('server', 'db', 'table', 'action', 'num_fields'));
@ -30,9 +31,6 @@ if (! isset($mime_map)) {
if (! isset($columnMeta)) {
$columnMeta = array();
}
if (! isset($content_cells)) {
$content_cells = array();
}
// Get available character sets and storage engines
@ -44,18 +42,49 @@ require_once './libraries/StorageEngine.class.php';
*/
require_once './libraries/Partition.class.php';
require_once './libraries/tbl_columns_definition_form.lib.php';
/** @var PMA_String $pmaString */
$pmaString = $GLOBALS['PMA_String'];
$length_values_input_size = 8;
$_form_params = PMA_getFormsParameters(
$db, $table, $action, isset($num_fields) ? $num_fields : null,
isset($selected) ? $selected : null
$content_cells = array();
$form_params = array(
'db' => $db
);
if ($action == 'tbl_create.php') {
$form_params['reload'] = 1;
} elseif ($action == 'tbl_addfield.php') {
if (isset($_REQUEST['field_where'])) {
$form_params['field_where'] = $_REQUEST['field_where'];
}
if (isset($_REQUEST['field_where'])) {
$form_params['after_field'] = $_REQUEST['after_field'];
}
$form_params['table'] = $table;
} else {
$form_params['table'] = $table;
}
if (isset($num_fields)) {
$form_params['orig_num_fields'] = $num_fields;
}
if (isset($_REQUEST['field_where'])) {
$form_params['orig_field_where'] = $_REQUEST['field_where'];
}
if (isset($_REQUEST['after_field'])) {
$form_params['orig_after_field'] = $_REQUEST['after_field'];
}
if (isset($selected) && is_array($selected)) {
foreach ($selected as $o_fld_nr => $o_fld_val) {
$form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
}
}
$is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php');
require_once './libraries/transformations.lib.php';
@ -64,20 +93,17 @@ $cfgRelation = PMA_getRelationsParam();
$comments_map = PMA_getComments($db, $table);
$move_columns = array();
if (isset($fields_meta)) {
$move_columns = PMA_getMoveColumns($db, $table);
$move_columns = $GLOBALS['dbi']->getTable($db, $table)->getColumnsMeta();
}
$available_mime = array();
if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
$mime_map = PMA_getMIME($db, $table);
$available_mime = PMA_getAvailableMIMEtypes();
}
$header_cells = PMA_getHeaderCells(
$is_backup, isset($fields_meta) ? $fields_meta : null,
$cfgRelation['mimework']
);
// workaround for field_fulltext, because its submitted indices contain
// the index as a value, not a key. Inserted here for easier maintenance
// and less code to change in existing files.
@ -98,21 +124,146 @@ $child_references = null;
if (PMA_MYSQL_INT_VERSION < 50606) {
$child_references = PMA_getChildReferences($db, $table);
}
for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
if (! empty($regenerate)) {
list($columnMeta, $submit_length, $submit_attribute,
$submit_default_current_timestamp, $comments_map, $mime_map)
= PMA_handleRegeneration(
$columnNumber,
isset($available_mime) ? $mime_map : null,
$comments_map, $mime_map
);
} elseif (isset($fields_meta[$columnNumber])) {
$columnMeta = PMA_getColumnMetaForDefault(
$fields_meta[$columnNumber],
isset($analyzed_sql[0]['create_table_fields']
[$fields_meta[$columnNumber]['Field']]['default_value'])
);
$type = '';
$length = '';
$columnMeta = array();
$submit_attribute = null;
$extracted_columnspec = array();
if (!empty($regenerate)) {
$columnMeta['Field'] = isset($_REQUEST['field_name'][$columnNumber])
? $_REQUEST['field_name'][$columnNumber]
: false;
$columnMeta['Type'] = isset($_REQUEST['field_type'][$columnNumber])
? $_REQUEST['field_type'][$columnNumber]
: false;
$columnMeta['Collation'] = isset($_REQUEST['field_collation'][$columnNumber])
? $_REQUEST['field_collation'][$columnNumber]
: '';
$columnMeta['Null'] = isset($_REQUEST['field_null'][$columnNumber])
? $_REQUEST['field_null'][$columnNumber]
: '';
$columnMeta['Key'] = '';
if (isset($_REQUEST['field_key'][$columnNumber])) {
$parts = explode('_', $_REQUEST['field_key'][$columnNumber], 2);
if (count($parts) == 2 && $parts[1] == $columnNumber) {
switch ($parts[0]) {
case 'primary':
$columnMeta['Key'] = 'PRI';
break;
case 'index':
$columnMeta['Key'] = 'MUL';
break;
case 'unique':
$columnMeta['Key'] = 'UNI';
break;
case 'fulltext':
$columnMeta['Key'] = 'FULLTEXT';
break;
case 'spatial':
$columnMeta['Key'] = 'SPATIAL';
break;
}
}
}
// put None in the drop-down for Default, when someone adds a field
$columnMeta['DefaultType']
= isset($_REQUEST['field_default_type'][$columnNumber])
? $_REQUEST['field_default_type'][$columnNumber]
: 'NONE';
$columnMeta['DefaultValue']
= isset($_REQUEST['field_default_value'][$columnNumber])
? $_REQUEST['field_default_value'][$columnNumber]
: '';
switch ($columnMeta['DefaultType']) {
case 'NONE':
$columnMeta['Default'] = null;
break;
case 'USER_DEFINED':
$columnMeta['Default'] = $columnMeta['DefaultValue'];
break;
case 'NULL':
case 'CURRENT_TIMESTAMP':
$columnMeta['Default'] = $columnMeta['DefaultType'];
break;
}
$columnMeta['Extra']
= (isset($_REQUEST['field_extra'][$columnNumber])
? $_REQUEST['field_extra'][$columnNumber]
: false);
$columnMeta['Comment']
= (isset($submit_fulltext[$columnNumber])
&& ($submit_fulltext[$columnNumber] == $columnNumber)
? 'FULLTEXT'
: false);
$length
= (isset($_REQUEST['field_length'][$columnNumber])
? $_REQUEST['field_length'][$columnNumber]
: $length);
$submit_attribute
= (isset($_REQUEST['field_attribute'][$columnNumber])
? $_REQUEST['field_attribute'][$columnNumber]
: false);
if (isset($_REQUEST['field_comments'][$columnNumber])) {
$comments_map[$columnMeta['Field']]
= $_REQUEST['field_comments'][$columnNumber];
}
if (isset($_REQUEST['field_mimetype'][$columnNumber])) {
$mime_map[$columnMeta['Field']]['mimetype']
= $_REQUEST['field_mimetype'][$columnNumber];
}
if (isset($_REQUEST['field_transformation'][$columnNumber])) {
$mime_map[$columnMeta['Field']]['transformation']
= $_REQUEST['field_transformation'][$columnNumber];
}
if (isset($_REQUEST['field_transformation_options'][$columnNumber])) {
$mime_map[$columnMeta['Field']]['transformation_options']
= $_REQUEST['field_transformation_options'][$columnNumber];
}
}
elseif (isset($fields_meta[$columnNumber]))
{
$columnMeta = $fields_meta[$columnNumber];
switch ($columnMeta['Default']) {
case null:
if ($columnMeta['Null'] == 'YES') {
$columnMeta['DefaultType'] = 'NULL';
$columnMeta['DefaultValue'] = '';
// SHOW FULL COLUMNS does not report the case
// when there is a DEFAULT value which is empty so we need to use the
// results of SHOW CREATE TABLE
} elseif (isset($analyzed_sql[0]['create_table_fields']
[$fields_meta[$columnNumber]['Field']]['default_value'])) {
$columnMeta['DefaultType'] = 'USER_DEFINED';
$columnMeta['DefaultValue'] = $columnMeta['Default'];
} else {
$columnMeta['DefaultType'] = 'NONE';
$columnMeta['DefaultValue'] = '';
}
break;
case 'CURRENT_TIMESTAMP':
$columnMeta['DefaultType'] = 'CURRENT_TIMESTAMP';
$columnMeta['DefaultValue'] = '';
break;
default:
$columnMeta['DefaultType'] = 'USER_DEFINED';
$columnMeta['DefaultValue'] = $columnMeta['Default'];
break;
}
}
if (isset($columnMeta['Type'])) {
@ -122,70 +273,152 @@ for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
= PMA_Util::convertBitDefaultValue($columnMeta['Default']);
}
$type = $extracted_columnspec['type'];
$length = $extracted_columnspec['spec_in_brackets'];
if ($length == '') {
$length = $extracted_columnspec['spec_in_brackets'];
}
} else {
// creating a column
$columnMeta['Type'] = '';
$type = '';
$length = '';
$extracted_columnspec = array();
}
// some types, for example longtext, are reported as
// "longtext character set latin7" when their charset and / or collation
// differs from the ones of the corresponding database.
$tmp = /*overload*/mb_strpos($type, 'character set');
if ($tmp) {
$type = /*overload*/mb_substr($type, 0, $tmp - 1);
}
// rtrim the type, for cases like "float unsigned"
$type = rtrim($type);
if (isset($submit_length) && $submit_length != false) {
$length = $submit_length;
}
// Variable tell if current column is bound in a foreign key constraint or not.
// MySQL version from 5.6.6 allow renaming columns with foreign keys
if (isset($columnMeta['Field'])
&& isset($_form_params['table'])
&& isset($form_params['table'])
&& PMA_MYSQL_INT_VERSION < 50606
) {
$columnMeta['column_status'] = PMA_checkChildForeignReferences(
$_form_params['db'],
$_form_params['table'],
$form_params['db'],
$form_params['table'],
$columnMeta['Field'],
$foreigners,
$child_references
);
}
// old column attributes
// some types, for example longtext, are reported as
// "longtext character set latin7" when their charset and / or collation
// differs from the ones of the corresponding database.
// rtrim the type, for cases like "float unsigned"
$type = rtrim(mb_ereg_replace(
'[\w\W]character set[\w\W]*', '', $type
));
/**
* old column attributes
*/
if ($is_backup) {
$_form_params = PMA_getFormParamsForOldColumn(
$columnMeta, $length, $_form_params, $columnNumber, $type,
$extracted_columnspec
);
// old column name
if (isset($columnMeta['Field'])) {
$form_params['field_orig[' . $columnNumber . ']']
= $columnMeta['Field'];
if (isset($columnMeta['column_status'])
&& !$columnMeta['column_status']['isEditable']
) {
$form_params['field_name[' . $columnNumber . ']']
= $columnMeta['Field'];
}
} else {
$form_params['field_orig[' . $columnNumber . ']'] = '';
}
// old column type
if (isset($columnMeta['Type'])) {
// keep in uppercase because the new type will be in uppercase
$form_params['field_type_orig[' . $columnNumber . ']']
= /*overload*/mb_strtoupper($type);
if (isset($columnMeta['column_status'])
&& !$columnMeta['column_status']['isEditable']
) {
$form_params['field_type[' . $columnNumber . ']']
= /*overload*/mb_strtoupper($type);
}
} else {
$form_params['field_type_orig[' . $columnNumber . ']'] = '';
}
// old column length
$form_params['field_length_orig[' . $columnNumber . ']'] = $length;
// old column default
$form_params['field_default_value_orig[' . $columnNumber . ']']
= (isset($columnMeta['Default']) ? $columnMeta['Default'] : '');
$form_params['field_default_type_orig[' . $columnNumber . ']']
= (isset($columnMeta['DefaultType']) ? $columnMeta['DefaultType'] : '');
// old column collation
if (isset($columnMeta['Collation'])) {
$form_params['field_collation_orig[' . $columnNumber . ']']
= $columnMeta['Collation'];
} else {
$form_params['field_collation_orig[' . $columnNumber . ']'] = '';
}
// old column attribute
if (isset($extracted_columnspec['attribute'])) {
$form_params['field_attribute_orig[' . $columnNumber . ']']
= trim($extracted_columnspec['attribute']);
} else {
$form_params['field_attribute_orig[' . $columnNumber . ']'] = '';
}
// old column null
if (isset($columnMeta['Null'])) {
$form_params['field_null_orig[' . $columnNumber . ']']
= $columnMeta['Null'];
} else {
$form_params['field_null_orig[' . $columnNumber . ']'] = '';
}
// old column extra (for auto_increment)
if (isset($columnMeta['Extra'])) {
$form_params['field_extra_orig[' . $columnNumber . ']']
= $columnMeta['Extra'];
} else {
$form_params['field_extra_orig[' . $columnNumber . ']'] = '';
}
// old column comment
if (isset($columnMeta['Comment'])) {
$form_params['field_comments_orig[' . $columnNumber . ']']
= $columnMeta['Comment'];
} else {
$form_params['field_comment_orig[' . $columnNumber . ']'] = '';
}
}
$content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes(
$columnNumber, isset($columnMeta) ? $columnMeta : array(),
/*overload*/mb_strtoupper($type), $length_values_input_size, $length,
isset($default_current_timestamp) ? $default_current_timestamp : null,
isset($extracted_columnspec) ? $extracted_columnspec : null,
isset($submit_attribute) ? $submit_attribute : null,
isset($analyzed_sql) ? $analyzed_sql : null,
$comments_map, isset($fields_meta) ? $fields_meta : null, $is_backup,
isset($move_columns) ? $move_columns : array(), $cfgRelation,
isset($available_mime) ? $available_mime : array(),
isset($mime_map) ? $mime_map : array()
$content_cells[$columnNumber] = array(
'columnNumber' => $columnNumber,
'columnMeta' => $columnMeta,
'type_upper' => /*overload*/mb_strtoupper($type),
'length_values_input_size' => $length_values_input_size,
'length' => $length,
'extracted_columnspec' => $extracted_columnspec,
'submit_attribute' => $submit_attribute,
'analyzed_sql' => isset($analyzed_sql) ? $analyzed_sql : null,
'comments_map' => $comments_map,
'fields_meta' => isset($fields_meta) ? $fields_meta : null,
'is_backup' => $is_backup,
'move_columns' => $move_columns,
'cfgRelation' => $cfgRelation,
'available_mime' => $available_mime,
'mime_map' => isset($mime_map) ? $mime_map : array()
);
} // end for
$html = PMA_getHtmlForTableCreateOrAddField(
$action, $_form_params, $content_cells, $header_cells
);
unset($_form_params);
$html = PMA\Template::get('columns_definitions/column_definitions_form')
->render(array(
'is_backup' => $is_backup,
'fields_meta' => isset($fields_meta) ? $fields_meta : null,
'mimework' => $cfgRelation['mimework'],
'action' => $action,
'form_params' => $form_params,
'content_cells' => $content_cells
));
unset($form_params);
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();

File diff suppressed because it is too large Load Diff

View File

@ -1,166 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functions used to generate GIS visualizations.
*
* @package PhpMyAdmin
*/
if (!defined('PHPMYADMIN')) {
exit;
}
require_once 'libraries/sql.lib.php';
require_once 'libraries/Template.class.php';
/**
* Returns a modified sql query with only the label column
* and spatial column(wrapped with 'ASTEXT()' function).
*
* @param string $sql_query original sql query
* @param array $visualizationSettings settings for the visualization
* @param integer $rows number of rows
* @param integer $pos start position
*
* @return string the modified sql query.
*/
function PMA_GIS_modifyQuery(
$sql_query, $visualizationSettings, $rows = null, $pos = null
) {
$modified_query = 'SELECT ';
// If label column is chosen add it to the query
if (! empty($visualizationSettings['labelColumn'])) {
$modified_query .= PMA_Util::backquote($visualizationSettings['labelColumn'])
. ', ';
}
// Wrap the spatial column with 'ASTEXT()' function and add it
$modified_query .= 'ASTEXT('
. PMA_Util::backquote($visualizationSettings['spatialColumn'])
. ') AS ' . PMA_Util::backquote($visualizationSettings['spatialColumn'])
. ', ';
// Get the SRID
$modified_query .= 'SRID('
. PMA_Util::backquote($visualizationSettings['spatialColumn'])
. ') AS ' . PMA_Util::backquote('srid') . ' ';
// Append the original query as the inner query
$modified_query .= 'FROM (' . $sql_query . ') AS '
. PMA_Util::backquote('temp_gis');
// LIMIT clause
if (is_numeric($rows) && $rows > 0) {
$modified_query .= ' LIMIT ';
if (is_numeric($pos) && $pos >= 0) {
$modified_query .= $pos . ', ' . $rows;
} else {
$modified_query .= $rows;
}
}
return $modified_query;
}
/**
* Formats a visualization for the GIS query results.
*
* @param array $data Data for the status chart
* @param array &$visualizationSettings Settings used to generate the chart
* @param string $format Format of the visualization
*
* @return string|bool HTML and JS code for the GIS visualization or false on failure
*/
function PMA_GIS_visualizationResults($data, &$visualizationSettings, $format)
{
include_once './libraries/gis/GIS_Visualization.class.php';
include_once './libraries/gis/GIS_Factory.class.php';
if (! isset($data[0])) {
// empty data
return __('No data found for GIS visualization.');
}
$visualization = new PMA_GIS_Visualization($data, $visualizationSettings);
if ($visualizationSettings != null) {
foreach ($visualization->getSettings() as $setting => $val) {
if (! isset($visualizationSettings[$setting])) {
$visualizationSettings[$setting] = $val;
}
}
}
if ($format == 'svg') {
return $visualization->asSvg();
} elseif ($format == 'png') {
return $visualization->asPng();
} elseif ($format == 'ol') {
return $visualization->asOl();
}
return false;
}
/**
* Generate visualization for the GIS query results and save it to a file.
*
* @param array $data data for the status chart
* @param array $visualizationSettings settings used to generate the chart
* @param string $format format of the visualization
* @param string $fileName file name
*
* @return file File containing the visualization
*/
function PMA_GIS_saveToFile($data, $visualizationSettings, $format, $fileName)
{
include_once './libraries/gis/GIS_Visualization.class.php';
include_once './libraries/gis/GIS_Factory.class.php';
if (isset($data[0])) {
$visualization = new PMA_GIS_Visualization($data, $visualizationSettings);
if ($format == 'svg') {
$visualization->toFileAsSvg($fileName);
} elseif ($format == 'png') {
$visualization->toFileAsPng($fileName);
} elseif ($format == 'pdf') {
$visualization->toFileAsPdf($fileName);
}
}
}
/**
* Function to generate HTML for the GIS visualization page
*
* @param array $url_params url parameters
* @param array $labelCandidates list of candidates for the label
* @param array $spatialCandidates list of candidates for the spatial column
* @param array $visualizationSettings visualization settings
* @param String $sql_query the sql query
* @param String $visualization HTML and js code for the visualization
* @param boolean $svgSupport whether svg download format is supported
* @param array $data array of visualizing data
*
* @return string HTML code for the GIS visualization
*/
function PMA_getHtmlForGisVisualization(
$url_params, $labelCandidates, $spatialCandidates, $visualizationSettings,
$sql_query, $visualization, $svgSupport, $data
) {
$url_params['sql_query'] = $sql_query;
$downloadUrl = 'tbl_gis_visualization.php' . PMA_URL_getCommon($url_params)
. '&saveToFile=true';
return PMA\Template::get('gis_visualization/gis_visualization')->render(
array(
'url_params' => $url_params,
'downloadUrl' => $downloadUrl,
'labelCandidates' => $labelCandidates,
'spatialCandidates' => $spatialCandidates,
'visualizationSettings' => $visualizationSettings,
'sql_query' => $sql_query,
'visualization' => $visualization,
'svgSupport' => $svgSupport,
'data' => $data
)
);
}
?>

View File

@ -1,900 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functions for the table relation page
*
* @package PhpMyAdmin
*/
require_once 'libraries/Template.class.php';
/**
* Generate dropdown choices
*
* @param string $dropdown_question Message to display
* @param string $select_name Name of the <select> field
* @param array $choices Choices for dropdown
* @param string $selected_value Selected value
*
* @return string The html code for existing value (for selected)
*
* @access public
*/
function PMA_generateDropdown(
$dropdown_question, $select_name, $choices, $selected_value
) {
return PMA\Template::get('tbl_relation/dropdown_generate')->render(
array(
'dropdown_question' => $dropdown_question,
'select_name' => $select_name,
'choices' => $choices,
'selected_value' => $selected_value
)
);
}
/**
* Split a string on backquote pairs
*
* @param string $text original string
*
* @return array containing the elements (and their surrounding backquotes)
*
* @access public
*/
function PMA_backquoteSplit($text)
{
$elements = array();
$final_pos = /*overload*/mb_strlen($text) - 1;
$pos = 0;
while ($pos <= $final_pos) {
$first_backquote = /*overload*/mb_strpos($text, '`', $pos);
$second_backquote = /*overload*/mb_strpos($text, '`', $first_backquote + 1);
// after the second one, there might be another one which means
// this is an escaped backquote
if ($second_backquote < $final_pos && '`' == $text[$second_backquote + 1]) {
$second_backquote
= /*overload*/mb_strpos($text, '`', $second_backquote + 2);
}
if (false === $first_backquote || false === $second_backquote) {
break;
}
$elements[] = /*overload*/mb_substr(
$text, $first_backquote, $second_backquote - $first_backquote + 1
);
$pos = $second_backquote + 1;
}
return($elements);
}
/**
* Returns the DROP query for a foreign key constraint
*
* @param string $table table of the foreign key
* @param string $fk foreign key name
*
* @return string DROP query for the foreign key constraint
*/
function PMA_getSQLToDropForeignKey($table, $fk)
{
return 'ALTER TABLE ' . PMA_Util::backquote($table)
. ' DROP FOREIGN KEY ' . PMA_Util::backquote($fk) . ';';
}
/**
* Returns the SQL query for foreign key constraint creation
*
* @param string $table table name
* @param array $field field names
* @param string $foreignDb foreign database name
* @param string $foreignTable foreign table name
* @param array $foreignField foreign field names
* @param string $name name of the constraint
* @param string $onDelete on delete action
* @param string $onUpdate on update action
*
* @return string SQL query for foreign key constraint creation
*/
function PMA_getSQLToCreateForeignKey($table, $field, $foreignDb, $foreignTable,
$foreignField, $name = null, $onDelete = null, $onUpdate = null
) {
$sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ADD ';
// if user entered a constraint name
if (! empty($name)) {
$sql_query .= ' CONSTRAINT ' . PMA_Util::backquote($name);
}
foreach ($field as $key => $one_field) {
$field[$key] = PMA_Util::backquote($one_field);
}
foreach ($foreignField as $key => $one_field) {
$foreignField[$key] = PMA_Util::backquote($one_field);
}
$sql_query .= ' FOREIGN KEY (' . implode(', ', $field) . ')'
. ' REFERENCES ' . PMA_Util::backquote($foreignDb)
. '.' . PMA_Util::backquote($foreignTable)
. '(' . implode(', ', $foreignField) . ')';
if (! empty($onDelete)) {
$sql_query .= ' ON DELETE ' . $onDelete;
}
if (! empty($onUpdate)) {
$sql_query .= ' ON UPDATE ' . $onUpdate;
}
$sql_query .= ';';
return $sql_query;
}
/**
* Creates and populates dropdowns to select foreign db/table/column
*
* @param string $name name of the dropdowns
* @param array $values dropdown values
* @param string|boolean $foreign value of the item to be selected
* @param string $title title to show on hovering the dropdown
*
* @return string HTML for the dropdown
*/
function PMA_generateRelationalDropdown(
$name, $values = array(), $foreign = false, $title = ''
) {
return PMA\Template::get('tbl_relation/relational_dropdown')->render(
array(
'name' => $name,
'title' => $title,
'values' => $values,
'foreign' => $foreign
)
);
}
/**
* Function to get html for the common form
*
* @param string $db current database
* @param string $table current table
* @param array $columns columns
* @param array $cfgRelation configuration relation
* @param string $tbl_storage_engine table storage engine
* @param array $existrel db, table, column
* @param array $existrel_foreign db, table, column
* @param array $options_array options array
*
* @return string
*/
function PMA_getHtmlForCommonForm($db, $table, $columns, $cfgRelation,
$tbl_storage_engine, $existrel, $existrel_foreign, $options_array
) {
return PMA\Template::get('tbl_relation/common_form')->render(
array(
'db' => $db,
'table' => $table,
'columns' => $columns,
'cfgRelation' => $cfgRelation,
'tbl_storage_engine' => $tbl_storage_engine,
'existrel' => $existrel,
'existrel_foreign' => $existrel_foreign,
'options_array' => $options_array
)
);
}
/**
* Function to get html for an entire row in common form
*
* @param array $save_row save row
* @param int $i counter
* @param bool $odd_row whether odd row or not
* @param array $existrel db, table, column
* @param string $db current db
*
* @return string
*/
function PMA_getHtmlForInternalRelationRow($save_row, $i, $odd_row,
$existrel, $db
) {
$myfield = $save_row[$i]['Field'];
// Use an md5 as array index to avoid having special characters
// in the name attribute (see bug #1746964 )
$myfield_md5 = md5($myfield);
$myfield_html = htmlspecialchars($myfield);
$foreign_table = false;
$foreign_column = false;
// database dropdown
if (isset($existrel[$myfield])) {
$foreign_db = $existrel[$myfield]['foreign_db'];
} else {
$foreign_db = $db;
}
// table dropdown
$tables = array();
if ($foreign_db) {
if (isset($existrel[$myfield])) {
$foreign_table = $existrel[$myfield]['foreign_table'];
}
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLES FROM ' . PMA_Util::backquote($foreign_db),
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
$tables[] = $row[0];
}
}
// column dropdown
$columns = array();
if ($foreign_db && $foreign_table) {
if (isset($existrel[$myfield])) {
$foreign_column = $existrel[$myfield]['foreign_field'];
}
$table_obj = new PMA_Table($foreign_table, $foreign_db);
$columns = $table_obj->getUniqueColumns(false, false);
}
return PMA\Template::get('tbl_relation/internal_relational_row')->render(
array(
'myfield_md5' => $myfield_md5,
'myfield_html' => $myfield_html,
'odd_row' => $odd_row,
'foreign_db' => $foreign_db,
'foreign_table' => $foreign_table,
'tables' => $tables,
'foreign_column' => $foreign_column,
'columns' => $columns
)
);
}
/**
* Function to get html for an entire row in foreign key form
*
* @param array $one_key Single foreign key constraint
* @param bool $odd_row whether odd or even row
* @param array $columns Array of table columns
* @param int $i Row number
* @param array $options_array Options array
* @param string $tbl_storage_engine table storage engine
* @param string $db Database
*
* @return string html
*/
function PMA_getHtmlForForeignKeyRow($one_key, $odd_row, $columns, $i,
$options_array, $tbl_storage_engine, $db
) {
$js_msg = '';
$this_params = null;
if (isset($one_key['constraint'])) {
$drop_fk_query = 'ALTER TABLE ' . PMA_Util::backquote($GLOBALS['table'])
. ' DROP FOREIGN KEY '
. PMA_Util::backquote($one_key['constraint']) . ';';
$this_params = $GLOBALS['url_params'];
$this_params['goto'] = 'tbl_relation.php';
$this_params['back'] = 'tbl_relation.php';
$this_params['sql_query'] = $drop_fk_query;
$this_params['message_to_show'] = sprintf(
__('Foreign key constraint %s has been dropped'),
$one_key['constraint']
);
$js_msg = PMA_jsFormat(
'ALTER TABLE ' . $GLOBALS['table']
. ' DROP FOREIGN KEY '
. $one_key['constraint'] . ';'
);
}
// For ON DELETE and ON UPDATE, the default action
// is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE
// won't display the clause if it's set as RESTRICT.
$on_delete = isset($one_key['on_delete'])
? $one_key['on_delete'] : 'RESTRICT';
$on_update = isset($one_key['on_update'])
? $one_key['on_update'] : 'RESTRICT';
$column_array = array();
$column_array[''] = '';
foreach ($columns as $column) {
if (! empty($column['Key'])) {
$column_array[$column['Field']] = $column['Field'];
}
}
$foreign_table = false;
// foreign database dropdown
$foreign_db = (isset($one_key['ref_db_name'])) ? $one_key['ref_db_name'] : $db;
$tables = array();
if ($foreign_db) {
$foreign_table = isset($one_key['ref_table_name'])
? $one_key['ref_table_name'] : '';
// In Drizzle, 'SHOW TABLE STATUS' will show status only for the tables
// which are currently in the table cache. Hence we have to use
// 'SHOW TABLES' and manualy retrieve table engine values.
if (PMA_DRIZZLE) {
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLES FROM ' . PMA_Util::backquote($foreign_db),
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
$engine = PMA_Table::sGetStatusInfo(
$foreign_db,
$row[0],
'Engine'
);
if (isset($engine)
&& /*overload*/mb_strtoupper($engine) == $tbl_storage_engine
) {
$tables[] = $row[0];
}
}
} else {
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($foreign_db),
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
if (isset($row[1])
&& /*overload*/mb_strtoupper($row[1]) == $tbl_storage_engine
) {
$tables[] = $row[0];
}
}
}
}
return PMA\Template::get('tbl_relation/foreign_key_row')->render(
array(
'odd_row' => $odd_row,
'js_msg' => $js_msg,
'one_key' => $one_key,
'this_params' => $this_params,
'on_delete' => $on_delete,
'on_update' => $on_update,
'column_array' => $column_array,
'foreign_db' => $foreign_db,
'foreign_table' => $foreign_table,
'tables' => $tables,
'i' => $i,
'options_array' => $options_array
)
);
}
/**
* Function to send html for table or column dropdown list
*
* @return void
*/
function PMA_sendHtmlForTableOrColumnDropdownList()
{
if (isset($_REQUEST['foreignTable'])) { // if both db and table are selected
PMA_sendHtmlForColumnDropdownList();
} else { // if only the db is selected
PMA_sendHtmlForTableDropdownList();
}
exit;
}
/**
* Function to send html for column dropdown list
*
* @return void
*/
function PMA_sendHtmlForColumnDropdownList()
{
$response = PMA_Response::getInstance();
$foreignTable = $_REQUEST['foreignTable'];
$table_obj = new PMA_Table($foreignTable, $_REQUEST['foreignDb']);
// Since views do not have keys defined on them provide the full list of columns
if (PMA_Table::isView($_REQUEST['foreignDb'], $foreignTable)) {
$columnList = $table_obj->getColumns(false, false);
} else {
$columnList = $table_obj->getIndexedColumns(false, false);
}
$columns = array();
foreach ($columnList as $column) {
$columns[] = htmlspecialchars($column);
}
$response->addJSON('columns', $columns);
// @todo should be: $server->db($db)->table($table)->primary()
$primary = PMA_Index::getPrimary($foreignTable, $_REQUEST['foreignDb']);
if (false === $primary) {
return;
}
$primarycols = array_keys($primary->getColumns());
$response->addJSON('primary', $primarycols);
}
/**
* Function to send html for table dropdown list
*
* @return void
*/
function PMA_sendHtmlForTableDropdownList()
{
$response = PMA_Response::getInstance();
$tables = array();
$foreign = isset($_REQUEST['foreign']) && $_REQUEST['foreign'] === 'true';
if ($foreign) {
$tbl_storage_engine = /*overload*/mb_strtoupper(
PMA_Table::sGetStatusInfo(
$_REQUEST['db'],
$_REQUEST['table'],
'Engine'
)
);
}
// In Drizzle, 'SHOW TABLE STATUS' will show status only for the tables
// which are currently in the table cache. Hence we have to use 'SHOW TABLES'
// and manually retrieve table engine values.
if ($foreign && ! PMA_DRIZZLE) {
$query = 'SHOW TABLE STATUS FROM '
. PMA_Util::backquote($_REQUEST['foreignDb']);
$tables_rs = $GLOBALS['dbi']->query(
$query,
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
if (isset($row['Engine'])
&& /*overload*/mb_strtoupper($row['Engine']) == $tbl_storage_engine
) {
$tables[] = htmlspecialchars($row['Name']);
}
}
} else {
$query = 'SHOW TABLES FROM '
. PMA_Util::backquote($_REQUEST['foreignDb']);
$tables_rs = $GLOBALS['dbi']->query(
$query,
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
if ($foreign && PMA_DRIZZLE) {
$engine = /*overload*/mb_strtoupper(
PMA_Table::sGetStatusInfo(
$_REQUEST['foreignDb'],
$row[0],
'Engine'
)
);
if (isset($engine) && $engine == $tbl_storage_engine) {
$tables[] = htmlspecialchars($row[0]);
}
} else {
$tables[] = htmlspecialchars($row[0]);
}
}
}
$response->addJSON('tables', $tables);
}
/**
* Function to handle update for display field
*
* @param string $disp current display field
* @param string $display_field display field
* @param string $db current database
* @param string $table current table
* @param array $cfgRelation configuration relation
*
* @return string
*/
function PMA_handleUpdateForDisplayField($disp, $display_field, $db, $table,
$cfgRelation
) {
$html_output = '';
$upd_query = PMA_getQueryForDisplayUpdate(
$disp, $display_field, $db, $table, $cfgRelation
);
if ($upd_query) {
PMA_queryAsControlUser($upd_query);
$html_output = PMA_Util::getMessage(
__('Display column was successfully updated.'),
'', 'success'
);
}
return $html_output;
}
/**
* Function to get display query for handlingdisplay update
*
* @param string $disp current display field
* @param string $display_field display field
* @param string $db current database
* @param string $table current table
* @param array $cfgRelation configuration relation
*
* @return string
*/
function PMA_getQueryForDisplayUpdate($disp, $display_field, $db, $table,
$cfgRelation
) {
$upd_query = false;
if ($disp) {
if ($display_field == '') {
$upd_query = 'DELETE FROM '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
. ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\'';
} elseif ($disp != $display_field) {
$upd_query = 'UPDATE '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['table_info'])
. ' SET display_field = \''
. PMA_Util::sqlAddSlashes($display_field) . '\''
. ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\''
. ' AND table_name = \'' . PMA_Util::sqlAddSlashes($table) . '\'';
}
} elseif ($display_field != '') {
$upd_query = 'INSERT INTO '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['table_info'])
. '(db_name, table_name, display_field) VALUES('
. '\'' . PMA_Util::sqlAddSlashes($db) . '\','
. '\'' . PMA_Util::sqlAddSlashes($table) . '\','
. '\'' . PMA_Util::sqlAddSlashes($display_field) . '\')';
}
return $upd_query;
}
/**
* Function to handle updates for internal relations
*
* @param array $destination_db destination databases
* @param array $multi_edit_columns_name multi edit column names
* @param array $destination_table destination tables
* @param array $destination_column destination columns
* @param array $cfgRelation configuration relation
* @param string $db current database
* @param string $table current table
* @param array|null $existrel db, table, column
*
* @return string
*/
function PMA_handleUpdatesForInternalRelations($destination_db,
$multi_edit_columns_name, $destination_table, $destination_column, $cfgRelation,
$db, $table, $existrel
) {
$html_output = '';
$updated = false;
foreach ($destination_db as $master_field_md5 => $foreign_db) {
$upd_query = PMA_getQueryForInternalRelationUpdate(
$multi_edit_columns_name,
$master_field_md5, $foreign_db, $destination_table, $destination_column,
$cfgRelation, $db, $table, isset($existrel) ? $existrel : null
);
if ($upd_query) {
PMA_queryAsControlUser($upd_query);
$updated = true;
}
}
if ($updated) {
$html_output = PMA_Util::getMessage(
__('Internal relations were successfully updated.'),
'', 'success'
);
}
return $html_output;
}
/**
* Function to get update query for updating internal relations
*
* @param array $multi_edit_columns_name multi edit column names
* @param string $master_field_md5 master field md5
* @param string $foreign_db foreign database
* @param array $destination_table destination tables
* @param array $destination_column destination columns
* @param array $cfgRelation configuration relation
* @param string $db current database
* @param string $table current table
* @param array|null $existrel db, table, column
*
* @return string
*/
function PMA_getQueryForInternalRelationUpdate($multi_edit_columns_name,
$master_field_md5, $foreign_db, $destination_table, $destination_column,
$cfgRelation, $db, $table, $existrel
) {
$upd_query = false;
// Map the fieldname's md5 back to its real name
$master_field = $multi_edit_columns_name[$master_field_md5];
$foreign_table = $destination_table[$master_field_md5];
$foreign_field = $destination_column[$master_field_md5];
if (! empty($foreign_db)
&& ! empty($foreign_table)
&& ! empty($foreign_field)
) {
if (! isset($existrel[$master_field])) {
$upd_query = 'INSERT INTO '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['relation'])
. '(master_db, master_table, master_field, foreign_db,'
. ' foreign_table, foreign_field)'
. ' values('
. '\'' . PMA_Util::sqlAddSlashes($db) . '\', '
. '\'' . PMA_Util::sqlAddSlashes($table) . '\', '
. '\'' . PMA_Util::sqlAddSlashes($master_field) . '\', '
. '\'' . PMA_Util::sqlAddSlashes($foreign_db) . '\', '
. '\'' . PMA_Util::sqlAddSlashes($foreign_table) . '\','
. '\'' . PMA_Util::sqlAddSlashes($foreign_field) . '\')';
} elseif ($existrel[$master_field]['foreign_db'] != $foreign_db
|| $existrel[$master_field]['foreign_table'] != $foreign_table
|| $existrel[$master_field]['foreign_field'] != $foreign_field
) {
$upd_query = 'UPDATE '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['relation']) . ' SET'
. ' foreign_db = \''
. PMA_Util::sqlAddSlashes($foreign_db) . '\', '
. ' foreign_table = \''
. PMA_Util::sqlAddSlashes($foreign_table) . '\', '
. ' foreign_field = \''
. PMA_Util::sqlAddSlashes($foreign_field) . '\' '
. ' WHERE master_db = \''
. PMA_Util::sqlAddSlashes($db) . '\''
. ' AND master_table = \''
. PMA_Util::sqlAddSlashes($table) . '\''
. ' AND master_field = \''
. PMA_Util::sqlAddSlashes($master_field) . '\'';
} // end if... else....
} elseif (isset($existrel[$master_field])) {
$upd_query = 'DELETE FROM '
. PMA_Util::backquote($GLOBALS['cfgRelation']['db'])
. '.' . PMA_Util::backquote($cfgRelation['relation'])
. ' WHERE master_db = \'' . PMA_Util::sqlAddSlashes($db) . '\''
. ' AND master_table = \'' . PMA_Util::sqlAddSlashes($table) . '\''
. ' AND master_field = \'' . PMA_Util::sqlAddSlashes($master_field)
. '\'';
} // end if... else....
return $upd_query;
}
/**
* Function to handle foreign key updates
*
* @param array $destination_foreign_db destination foreign database
* @param array $multi_edit_columns_name multi edit column names
* @param array $destination_foreign_table destination foreign table
* @param array $destination_foreign_column destination foreign column
* @param array $options_array options array
* @param string $table current table
* @param array $existrel_foreign db, table, column
*
* @return string
*/
function PMA_handleUpdatesForForeignKeys($destination_foreign_db,
$multi_edit_columns_name, $destination_foreign_table,
$destination_foreign_column, $options_array, $table, $existrel_foreign
) {
$html_output = '';
$preview_sql_data = '';
$display_query = '';
$seen_error = false;
$preview_sql = (isset($_REQUEST['preview_sql'])) ? true : false;
foreach ($destination_foreign_db as $master_field_md5 => $foreign_db) {
list($html, $sql_data) = PMA_handleUpdateForForeignKey(
$multi_edit_columns_name, $master_field_md5,
$destination_foreign_table, $destination_foreign_column, $options_array,
$existrel_foreign, $table, $seen_error, $display_query, $foreign_db,
$preview_sql
);
$html_output .= $html;
$preview_sql_data .= $sql_data;
} // end foreach
// If there is a request for SQL previewing.
if ($preview_sql) {
PMA_previewSQL($preview_sql_data);
}
if (! empty($display_query) && ! $seen_error) {
$GLOBALS['display_query'] = $display_query;
$html_output = PMA_Util::getMessage(
__('Your SQL query has been executed successfully.'),
null, 'success'
);
}
return $html_output;
}
/**
* Function to handle update for a foreign key
*
* @param array $multi_edit_columns_name multi edit columns names
* @param string $master_field_md5 master field md5
* @param array $destination_foreign_table destination foreign tables
* @param array $destination_foreign_column destination foreign columns
* @param array $options_array options array
* @param array $existrel_foreign db, table, column
* @param string $table current table
* @param bool &$seen_error whether seen error
* @param string &$display_query display query
* @param string $foreign_db foreign database
* @param bool $preview_sql preview sql before executing
*
* @return array
*/
function PMA_handleUpdateForForeignKey($multi_edit_columns_name, $master_field_md5,
$destination_foreign_table, $destination_foreign_column, $options_array,
$existrel_foreign, $table, &$seen_error, &$display_query,
$foreign_db, $preview_sql
) {
$html_output = '';
$preview_sql_data = '';
$create = false;
$drop = false;
// Map the fieldname's md5 back to its real name
$master_field = $multi_edit_columns_name[$master_field_md5];
$foreign_table = $destination_foreign_table[$master_field_md5];
$foreign_field = $destination_foreign_column[$master_field_md5];
if (isset($existrel_foreign[$master_field_md5]['ref_db_name'])) {
$ref_db_name = $existrel_foreign[$master_field_md5]['ref_db_name'];
} else {
$ref_db_name = $GLOBALS['db'];
}
$empty_fields = false;
foreach ($master_field as $key => $one_field) {
if ((! empty($one_field) && empty($foreign_field[$key]))
|| (empty($one_field) && ! empty($foreign_field[$key]))
) {
$empty_fields = true;
}
if (empty($one_field) && empty($foreign_field[$key])) {
unset($master_field[$key]);
unset($foreign_field[$key]);
}
}
if (! empty($foreign_db)
&& ! empty($foreign_table)
&& ! $empty_fields
) {
if (isset($existrel_foreign[$master_field_md5])) {
$constraint_name = $existrel_foreign[$master_field_md5]['constraint'];
$on_delete = ! empty(
$existrel_foreign[$master_field_md5]['on_delete'])
? $existrel_foreign[$master_field_md5]['on_delete']
: 'RESTRICT';
$on_update = ! empty(
$existrel_foreign[$master_field_md5]['on_update'])
? $existrel_foreign[$master_field_md5]['on_update']
: 'RESTRICT';
if ($ref_db_name != $foreign_db
|| $existrel_foreign[$master_field_md5]['ref_table_name'] != $foreign_table
|| $existrel_foreign[$master_field_md5]['ref_index_list'] != $foreign_field
|| $existrel_foreign[$master_field_md5]['index_list'] != $master_field
|| $_REQUEST['constraint_name'][$master_field_md5] != $constraint_name
|| ($_REQUEST['on_delete'][$master_field_md5] != $on_delete)
|| ($_REQUEST['on_update'][$master_field_md5] != $on_update)
) {
// another foreign key is already defined for this field
// or an option has been changed for ON DELETE or ON UPDATE
$drop = true;
$create = true;
} // end if... else....
} else {
// no key defined for this field(s)
$create = true;
}
} elseif (isset($existrel_foreign[$master_field_md5])) {
$drop = true;
} // end if... else....
$tmp_error_drop = false;
if ($drop) {
$drop_query = PMA_getSQLToDropForeignKey(
$table, $existrel_foreign[$master_field_md5]['constraint']
);
if (! $preview_sql) {
$display_query .= $drop_query . "\n";
$GLOBALS['dbi']->tryQuery($drop_query);
$tmp_error_drop = $GLOBALS['dbi']->getError();
if (! empty($tmp_error_drop)) {
$seen_error = true;
$html_output .= PMA_Util::mysqlDie(
$tmp_error_drop, $drop_query, false, '', false
);
return $html_output;
}
} else {
$preview_sql_data .= $drop_query . "\n";
}
}
$tmp_error_create = false;
if (!$create) {
return array($html_output, $preview_sql_data);
}
$create_query = PMA_getSQLToCreateForeignKey(
$table, $master_field, $foreign_db, $foreign_table, $foreign_field,
$_REQUEST['constraint_name'][$master_field_md5],
$options_array[$_REQUEST['on_delete'][$master_field_md5]],
$options_array[$_REQUEST['on_update'][$master_field_md5]]
);
if (! $preview_sql) {
$display_query .= $create_query . "\n";
$GLOBALS['dbi']->tryQuery($create_query);
$tmp_error_create = $GLOBALS['dbi']->getError();
if (! empty($tmp_error_create)) {
$seen_error = true;
if (substr($tmp_error_create, 1, 4) == '1005') {
$message = PMA_Message::error(
__('Error creating foreign key on %1$s (check data types)')
);
$message->addParam(implode(', ', $master_field));
$html_output .= $message->getDisplay();
} else {
$html_output .= PMA_Util::mysqlDie(
$tmp_error_create, $create_query, false, '', false
);
}
$html_output .= PMA_Util::showMySQLDocu(
'InnoDB_foreign_key_constraints'
) . "\n";
}
} else {
$preview_sql_data .= $create_query . "\n";
}
// this is an alteration and the old constraint has been dropped
// without creation of a new one
if ($drop && $create && empty($tmp_error_drop)
&& ! empty($tmp_error_create)
) {
// a rollback may be better here
$sql_query_recreate = '# Restoring the dropped constraint...' . "\n";
$sql_query_recreate .= PMA_getSQLToCreateForeignKey(
$table,
$master_field,
$existrel_foreign[$master_field_md5]['ref_db_name'],
$existrel_foreign[$master_field_md5]['ref_table_name'],
$existrel_foreign[$master_field_md5]['ref_index_list'],
$existrel_foreign[$master_field_md5]['constraint'],
$options_array[$existrel_foreign[$master_field_md5]['on_delete']],
$options_array[$existrel_foreign[$master_field_md5]['on_update']]
);
if (! $preview_sql) {
$display_query .= $sql_query_recreate . "\n";
$GLOBALS['dbi']->tryQuery($sql_query_recreate);
} else {
$preview_sql_data .= $sql_query_recreate;
}
}
return array($html_output, $preview_sql_data);
}
?>

View File

@ -12,7 +12,6 @@
require_once 'libraries/common.inc.php';
require_once 'libraries/transformations.lib.php';
require_once 'libraries/normalization.lib.php';
require_once 'libraries/tbl_columns_definition_form.lib.php';
require_once 'libraries/Index.class.php';
if (isset($_REQUEST['getColumns'])) {

View File

@ -230,6 +230,12 @@ done
# Cleanup
rm -rf phpMyAdmin-${version}
# Signing of files with default GPG key
echo "* Signing files"
for file in *.gz *.zip *.bz2 *.7z ; do
gpg --detach-sign --armor $file
done
echo ""
echo ""
@ -287,7 +293,7 @@ Todo now:
- the -all-languages.zip file is the default for Windows and Others
- the -all-languages.tar.gz file is the default for Solaris
- the -all-languages.tar.bz2 file is the default for Mac OS X, Linux and BSD
5. add a SF news item to phpMyAdmin project; a good idea is to include a link to the release notes such as https://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.3.7/phpMyAdmin-4.3.7-notes.html/view because this news item gets relayed via RSS to our Facebook page
5. add a SF news item to phpMyAdmin project; a good idea is to include a link to the release notes such as https://files.phpmyadmin.net/phpMyAdmin/4.4.10/phpMyAdmin-4.4.10-notes.html
6. send a short mail (with list of major changes) to
phpmyadmin-devel@lists.sourceforge.net
phpmyadmin-news@lists.sourceforge.net

View File

@ -30,6 +30,16 @@ put phpMyAdmin-$REL-all-languages.zip
put phpMyAdmin-$REL-english.zip
put phpMyAdmin-$REL-all-languages.7z
put phpMyAdmin-$REL-english.7z
put phpMyAdmin-$REL-all-languages.tar.bz2.asc
put phpMyAdmin-$REL-english.tar.bz2.asc
put phpMyAdmin-$REL-all-languages.tar.xz.asc
put phpMyAdmin-$REL-english.tar.xz.asc
put phpMyAdmin-$REL-all-languages.tar.gz.asc
put phpMyAdmin-$REL-english.tar.gz.asc
put phpMyAdmin-$REL-all-languages.zip.asc
put phpMyAdmin-$REL-english.zip.asc
put phpMyAdmin-$REL-all-languages.7z.asc
put phpMyAdmin-$REL-english.7z.asc
put phpMyAdmin-$REL-notes.html
EOT
@ -48,6 +58,16 @@ put phpMyAdmin-$REL-all-languages.zip
put phpMyAdmin-$REL-english.zip
put phpMyAdmin-$REL-all-languages.7z
put phpMyAdmin-$REL-english.7z
put phpMyAdmin-$REL-all-languages.tar.bz2.asc
put phpMyAdmin-$REL-english.tar.bz2.asc
put phpMyAdmin-$REL-all-languages.tar.xz.asc
put phpMyAdmin-$REL-english.tar.xz.asc
put phpMyAdmin-$REL-all-languages.tar.gz.asc
put phpMyAdmin-$REL-english.tar.gz.asc
put phpMyAdmin-$REL-all-languages.zip.asc
put phpMyAdmin-$REL-english.zip.asc
put phpMyAdmin-$REL-all-languages.7z.asc
put phpMyAdmin-$REL-english.7z.asc
put phpMyAdmin-$REL-notes.html
EOT

View File

@ -7,6 +7,8 @@
*/
require_once 'libraries/common.inc.php';
require_once './libraries/gis/GIS_Visualization.class.php';
require_once './libraries/gis/GIS_Factory.class.php';
// Runs common work
require_once 'libraries/db_common.inc.php';
@ -15,9 +17,6 @@ $url_params['goto'] = PMA_Util::getScriptNameForOption(
);
$url_params['back'] = 'sql.php';
// Import visualization functions
require_once 'libraries/tbl_gis_visualization.lib.php';
$response = PMA_Response::getInstance();
// Throw error if no sql query is set
if (! isset($sql_query) || $sql_query == '') {
@ -69,19 +68,13 @@ if (isset($_REQUEST['session_max_rows'])) {
$rows = $GLOBALS['cfg']['MaxRows'];
}
}
$modified_query = PMA_GIS_modifyQuery($sql_query, $visualizationSettings, $rows, $pos);
$modified_result = $GLOBALS['dbi']->tryQuery($modified_query);
$data = array();
while ($row = $GLOBALS['dbi']->fetchAssoc($modified_result)) {
$data[] = $row;
}
if (isset($_REQUEST['saveToFile'])) {
$response->disable();
$file_name = $visualizationSettings['spatialColumn'];
$save_format = $_REQUEST['fileFormat'];
PMA_GIS_saveToFile($data, $visualizationSettings, $save_format, $file_name);
$visualization = PMA_GIS_Visualization::get($sql_query, $visualizationSettings, $rows, $pos);
$visualization->toFile($file_name, $save_format);
exit();
}
@ -94,32 +87,45 @@ $scripts->addFile('OpenStreetMap.js');
// If all the rows contain SRID, use OpenStreetMaps on the initial loading.
if (! isset($_REQUEST['displayVisualization'])) {
$visualization = PMA_GIS_Visualization::get($sql_query, $visualizationSettings, $rows, $pos);
if ($visualization->hasSrid())
unset($visualizationSettings['choice']);
$visualizationSettings['choice'] = 'useBaseLayer';
foreach ($data as $row) {
if ($row['srid'] == 0) {
unset($visualizationSettings['choice']);
break;
}
}
}
$svgSupport = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8)
? false : true;
$format = $svgSupport ? 'svg' : 'png';
// get the chart and settings after chart generation
$visualization = PMA_GIS_visualizationResults(
$data, $visualizationSettings, $format
);
$visualization = PMA_GIS_Visualization::get($sql_query, $visualizationSettings, $rows, $pos);
if ($visualizationSettings != null) {
foreach ($visualization->getSettings() as $setting => $val) {
if (! isset($visualizationSettings[$setting])) {
$visualizationSettings[$setting] = $val;
}
}
}
$result = $visualization->toImage($format);
/**
* Displays the page
*/
$html = PMA_getHtmlForGisVisualization(
$url_params, $labelCandidates, $spatialCandidates,
$visualizationSettings, $sql_query, $visualization, $svgSupport,
$data
$url_params['sql_query'] = $sql_query;
$downloadUrl = 'tbl_gis_visualization.php' . PMA_URL_getCommon($url_params)
. '&saveToFile=true';
$html = PMA\Template::get('gis_visualization/gis_visualization')->render(
array(
'url_params' => $url_params,
'downloadUrl' => $downloadUrl,
'labelCandidates' => $labelCandidates,
'spatialCandidates' => $spatialCandidates,
'visualizationSettings' => $visualizationSettings,
'sql_query' => $sql_query,
'visualization' => $result,
'svgSupport' => $svgSupport,
'drawOl' => $visualization->asOl()
)
);
$response->addHTML($html);

View File

@ -123,16 +123,13 @@ if (isset($_REQUEST['create_index'])) {
}
$response = PMA_Response::getInstance();
$response->addHTML(
PMA\Template::get('index_form')
->render(
array(
'fields' => $fields,
'index' => $index,
'form_params' => $form_params,
'add_fields' => $add_fields
)
)
$response->addHTML(PMA\Template::get('index_form')
->render(array(
'fields' => $fields,
'index' => $index,
'form_params' => $form_params,
'add_fields' => $add_fields
))
);
$header = $response->getHeader();
$scripts = $header->getScripts();

View File

@ -19,7 +19,8 @@
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/index.lib.php';
require_once 'libraries/tbl_relation.lib.php';
require_once 'libraries/Template.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/structure.lib.php';
$response = PMA_Response::getInstance();
@ -29,7 +30,89 @@ $response = PMA_Response::getInstance();
if (isset($_REQUEST['getDropdownValues'])
&& $_REQUEST['getDropdownValues'] === 'true'
) {
PMA_sendHtmlForTableOrColumnDropdownList();
if (isset($_REQUEST['foreignTable'])) { // if both db and table are selected
$foreignTable = $_REQUEST['foreignTable'];
$table_obj = new PMA_Table($foreignTable, $_REQUEST['foreignDb']);
// Since views do not have keys defined on them provide the full list of columns
if (PMA_Table::isView($_REQUEST['foreignDb'], $foreignTable)) {
$columnList = $table_obj->getColumns(false, false);
} else {
$columnList = $table_obj->getIndexedColumns(false, false);
}
$columns = array();
foreach ($columnList as $column) {
$columns[] = htmlspecialchars($column);
}
$response->addJSON('columns', $columns);
// @todo should be: $server->db($db)->table($table)->primary()
$primary = PMA_Index::getPrimary($foreignTable, $_REQUEST['foreignDb']);
if (false === $primary) {
return;
}
$primarycols = array_keys($primary->getColumns());
$response->addJSON('primary', $primarycols);
} else { // if only the db is selected
$tables = array();
$foreign = isset($_REQUEST['foreign']) && $_REQUEST['foreign'] === 'true';
if ($foreign) {
$tbl_storage_engine = /*overload*/mb_strtoupper(
PMA_Table::sGetStatusInfo(
$_REQUEST['db'],
$_REQUEST['table'],
'Engine'
)
);
}
// In Drizzle, 'SHOW TABLE STATUS' will show status only for the tables
// which are currently in the table cache. Hence we have to use 'SHOW TABLES'
// and manually retrieve table engine values.
if ($foreign && ! PMA_DRIZZLE) {
$query = 'SHOW TABLE STATUS FROM '
. PMA_Util::backquote($_REQUEST['foreignDb']);
$tables_rs = $GLOBALS['dbi']->query(
$query,
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
if (isset($row['Engine'])
&& /*overload*/mb_strtoupper($row['Engine']) == $tbl_storage_engine
) {
$tables[] = htmlspecialchars($row['Name']);
}
}
} else {
$query = 'SHOW TABLES FROM '
. PMA_Util::backquote($_REQUEST['foreignDb']);
$tables_rs = $GLOBALS['dbi']->query(
$query,
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
if ($foreign && PMA_DRIZZLE) {
$engine = /*overload*/mb_strtoupper(
PMA_Table::sGetStatusInfo(
$_REQUEST['foreignDb'],
$row[0],
'Engine'
)
);
if (isset($engine) && $engine == $tbl_storage_engine) {
$tables[] = htmlspecialchars($row[0]);
}
} else {
$tables[] = htmlspecialchars($row[0]);
}
}
}
$response->addJSON('tables', $tables);
}
exit;
}
$header = $response->getHeader();
@ -76,15 +159,19 @@ $multi_edit_columns_name = isset($_REQUEST['fields_name'])
$html_output = '';
$upd_query = new PMA_Table($table, $db, $GLOBALS['dbi']);
// u p d a t e s f o r I n t e r n a l r e l a t i o n s
if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
$html_output .= PMA_handleUpdatesForInternalRelations(
$_POST['destination_db'], $multi_edit_columns_name,
$_POST['destination_table'],
$_POST['destination_column'], $cfgRelation, $db, $table,
isset($existrel) ? $existrel : null
);
if ($upd_query->updateInternalRelations(
$multi_edit_columns_name, $_POST['destination_db'], $_POST['destination_table'],
$_POST['destination_column'], $cfgRelation, isset($existrel) ? $existrel : null
)) {
$html_output .= PMA_Util::getMessage(
__('Internal relations were successfully updated.'),
'', 'success'
);
}
} // end if (updates for internal relations)
$multi_edit_columns_name = isset($_REQUEST['foreign_key_fields_name'])
@ -95,19 +182,36 @@ $multi_edit_columns_name = isset($_REQUEST['foreign_key_fields_name'])
// (for now, one index name only; we keep the definitions if the
// foreign db is not the same)
if (isset($_POST['destination_foreign_db'])) {
$html_output .= PMA_handleUpdatesForForeignKeys(
list($html, $preview_sql_data, $display_query, $seen_error) = $upd_query->updateForeignKeys(
$_POST['destination_foreign_db'],
$multi_edit_columns_name, $_POST['destination_foreign_table'],
$_POST['destination_foreign_column'], $options_array, $table,
isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : null
);
$html_output .= $html;
// If there is a request for SQL previewing.
if (isset($_REQUEST['preview_sql'])) {
PMA_previewSQL($preview_sql_data);
}
if (! empty($display_query) && ! $seen_error) {
$GLOBALS['display_query'] = $display_query;
$html_output .= PMA_Util::getMessage(
__('Your SQL query has been executed successfully.'),
null, 'success'
);
}
} // end if isset($destination_foreign)
// U p d a t e s f o r d i s p l a y f i e l d
if ($cfgRelation['displaywork'] && isset($_POST['display_field'])) {
$html_output .= PMA_handleUpdateForDisplayField(
$disp, $_POST['display_field'], $db, $table, $cfgRelation
);
if ($upd_query->updateDisplayField($disp, $_POST['display_field'], $cfgRelation)) {
$html_output .= PMA_Util::getMessage(
__('Display column was successfully updated.'),
'', 'success'
);
}
} // end if
// If we did an update, refresh our data
@ -139,11 +243,17 @@ $response->addHTML('<div id="structure_content">');
$columns = $GLOBALS['dbi']->getColumns($db, $table);
// common form
$html_output .= PMA_getHtmlForCommonForm(
$db, $table, $columns, $cfgRelation, $tbl_storage_engine,
isset($existrel) ? $existrel : array(),
isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : array(),
$options_array
$html_output .= PMA\Template::get('tbl_relation/common_form')->render(
array(
'db' => $db,
'table' => $table,
'columns' => $columns,
'cfgRelation' => $cfgRelation,
'tbl_storage_engine' => $tbl_storage_engine,
'existrel' => isset($existrel) ? $existrel : array(),
'existrel_foreign' => isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : array(),
'options_array' => $options_array
)
);
if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {

View File

@ -1,5 +1,5 @@
<input name="field_adjust_privileges[<?php echo $columnNumber; ?>]"
id="field_'<?php echo $columnNumber; ?>_<?php echo ($ci - $ci_offset); ?>"
id="field_<?php echo $columnNumber; ?>_<?php echo ($ci - $ci_offset); ?>"
checked="checked"
type="checkbox"
value="NULL"

View File

@ -1,12 +1,39 @@
<?php
$attribute_types = $GLOBALS['PMA_Types']->getAttributes();
$cnt_attribute_types = count($attribute_types);
$attribute = '';
if (isset($submit_attribute) && $submit_attribute != false) {
$attribute = $submit_attribute;
} elseif (isset($columnMeta['Extra'])
&& $columnMeta['Extra'] == 'on update CURRENT_TIMESTAMP') {
$attribute = 'on update CURRENT_TIMESTAMP';
} elseif (isset($extracted_columnspec['attribute'])) {
$attribute = $extracted_columnspec['attribute'];
}
// MySQL 4.1.2+ TIMESTAMP options
// (if on_update_current_timestamp is set, then it's TRUE)
if (isset($columnMeta['Field'])) {
// here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
// NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
// the latter.
$field = $analyzed_sql[0]['create_table_fields'][$columnMeta['Field']];
if (isset($field['on_update_current_timestamp'])) {
$attribute = 'on update CURRENT_TIMESTAMP';
}
}
$attribute = mb_strtoupper($attribute);
?>
<select style="width: 7em;"
name="field_attribute[<?php echo $columnNumber; ?>]"
id="field_<?php echo $columnNumber; ?>_<?php echo ($ci - $ci_offset); ?>">
<?php for ($j = 0; $j < $cnt_attribute_types; $j++): ?>
<option value="<?php echo $attribute_types[$j];?>"
<?php if (mb_strtoupper($attribute) == /*overload*/mb_strtoupper($attribute_types[$j])): ?>
<?php if ($attribute == /*overload*/mb_strtoupper($attribute_types[$j])): ?>
selected="selected"
<?php endif; ?>>
<?php echo $attribute_types[$j]; ?>
</option>
<?php endfor; ?>
</select>
</select>

View File

@ -0,0 +1,218 @@
<?php
// Cell index: If certain fields get left out, the counter shouldn't change.
$ci = 0;
// Every time a cell shall be left out the STRG-jumping feature, $ci_offset
// has to be incremented ($ci_offset++)
$ci_offset = -1;
?>
<td class="center">
<!-- column name -->
<?php echo PMA\Template::get('columns_definitions/column_name')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'columnMeta' => isset($columnMeta) ? $columnMeta : null,
'cfgRelation' => $cfgRelation
)); ?>
</td>
<td class="center">
<!-- column type -->
<?php echo PMA\Template::get('columns_definitions/column_type')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'type_upper' => $type_upper,
'columnMeta' => isset($columnMeta) ? $columnMeta : null
)); ?>
</td>
<td class="center">
<!-- column length -->
<?php echo PMA\Template::get('columns_definitions/column_length')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'length_values_input_size' => $length_values_input_size,
'length_to_display' => $length
)); ?>
</td>
<td class="center">
<!-- column default -->
<?php echo PMA\Template::get('columns_definitions/column_default')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'type_upper' => isset($type_upper) ? $type_upper : null,
'columnMeta' => isset($columnMeta) ? $columnMeta : null
)); ?>
</td>
<td class="center">
<!-- column collation -->
<?php $tmp_collation = empty($columnMeta['Collation']) ? null : $columnMeta['Collation']; ?>
<?php echo PMA_generateCharsetDropdownBox(
PMA_CSDROPDOWN_COLLATION,
'field_collation[' . $columnNumber . ']',
'field_' . $columnNumber . '_' . ($ci - $ci_offset),
$tmp_collation,
false
); ?>
</td>
<td class="center">
<!-- column attribute -->
<?php echo PMA\Template::get('columns_definitions/column_attribute')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'extracted_columnspec' => isset($extracted_columnspec) ? $extracted_columnspec : null,
'columnMeta' => isset($columnMeta) ? $columnMeta : null,
'submit_attribute' => isset($submit_attribute) ? $submit_attribute : null,
'analyzed_sql' => isset($analyzed_sql) ? $analyzed_sql : null
)); ?>
</td>
<td class="center">
<!-- column NULL -->
<?php echo PMA\Template::get('columns_definitions/column_null')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'columnMeta' => isset($columnMeta) ? $columnMeta : null
)); ?>
</td>
<?php if (isset($_REQUEST['change_column']) && !empty($_REQUEST['change_column'])): ?>
<!-- column Adjust Privileges, Only for 'Edit' Column(s) -->
<td class="center">
<?php echo PMA\Template::get('columns_definitions/column_adjust_privileges')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset
)); ?>
</td>
<?php endif; ?>
<?php if (!$is_backup): ?>
<!-- column indexes, See my other comment about this 'if'. -->
<td class="center">
<?php echo PMA\Template::get('columns_definitions/column_indexes')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'columnMeta' => $columnMeta
)); ?>
</td>
<?php endif; ?>
<td class="center">
<!-- column auto_increment -->
<?php echo PMA\Template::get('columns_definitions/column_auto_increment')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'columnMeta' => $columnMeta
)); ?>
</td>
<td class="center">
<!-- column comments -->
<?php echo PMA\Template::get('columns_definitions/column_comment')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'columnMeta' => isset($columnMeta) ? $columnMeta : null,
'comments_map' => $comments_map
)); ?>
</td>
<!-- move column -->
<?php if (isset($fields_meta)): ?>
<?php $current_index = 0;
for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
if ($move_columns[$mi]->name == $columnMeta['Field']) {
$current_index = $mi;
break;
}
} ?>
<td class="center">
<?php echo PMA\Template::get('columns_definitions/move_column')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'columnMeta' => $columnMeta,
'move_columns' => $move_columns,
'current_index' => $current_index
)); ?>
</td>
<?php endif; ?>
<?php if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && $cfgRelation['commwork']): ?>
<td class="center">
<!-- Column Mime-type -->
<?php echo PMA\Template::get('columns_definitions/mime_type')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'available_mime' => $available_mime,
'columnMeta' => $columnMeta,
'mime_map' => $mime_map
)); ?>
</td>
<td class="center">
<!-- Column Browser transformation -->
<?php echo PMA\Template::get('columns_definitions/transformation')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'available_mime' => $available_mime,
'columnMeta' => $columnMeta,
'mime_map' => $mime_map,
'type' => 'transformation'
)); ?>
</td>
<td class="center">
<!-- column Transformation options -->
<?php echo PMA\Template::get('columns_definitions/transformation_option')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'columnMeta' => $columnMeta,
'mime_map' => $mime_map,
'type_prefix' => '',
)); ?>
</td>
<td class="center">
<!-- Column Input transformation -->
<?php echo PMA\Template::get('columns_definitions/transformation')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'available_mime' => $available_mime,
'columnMeta' => $columnMeta,
'mime_map' => $mime_map,
'type' => 'input_transformation'
)); ?>
</td>
<td class="center">
<!-- column Input transformation options -->
<?php echo PMA\Template::get('columns_definitions/transformation_option')
->render(array(
'columnNumber' => $columnNumber,
'ci' => $ci++,
'ci_offset' => $ci_offset,
'columnMeta' => $columnMeta,
'mime_map' => $mime_map,
'type_prefix' => 'input_',
)); ?>
</td>
<?php endif; ?>

View File

@ -3,8 +3,8 @@
name="field_comments[<?php echo $columnNumber; ?>]"
size="12"
maxlength="<?php echo PMA_MYSQL_INT_VERSION >= 50503 ? 1024 : 255; ?>"
value="<?php echo (isset($columnMeta['Field'])
value="<?php if (isset($columnMeta['Field'])
&& is_array($comments_map)
&& isset($comments_map[$columnMeta['Field']]) ?
htmlspecialchars($comments_map[$columnMeta['Field']]) : ''); ?>"
&& isset($comments_map[$columnMeta['Field']]))
echo htmlspecialchars($comments_map[$columnMeta['Field']]); ?>"
class="textfield" />

View File

@ -1,3 +1,27 @@
<?php
// here we put 'NONE' as the default value of drop-down; otherwise
// users would have problems if they forget to enter the default
// value (example, for an INT)
$default_options = array(
'NONE' => _pgettext('for default', 'None'),
'USER_DEFINED' => __('As defined:'),
'NULL' => 'NULL',
'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
);
// for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default
// value
$defaultValue = '';
if (isset($columnMeta['DefaultValue'])) {
$defaultValue = $columnMeta['DefaultValue'];
}
if ($type_upper == 'BIT') {
$defaultValue = PMA_Util::convertBitDefaultValue($columnMeta['DefaultValue']);
} elseif ($type_upper == 'BINARY' || $type_upper == 'VARBINARY') {
$defaultValue = bin2hex($columnMeta['DefaultValue']);
}
?>
<select name="field_default_type[<?php echo $columnNumber; ?>]"
id="field_<?php echo $columnNumber; ?>_<?php echo($ci - $ci_offset); ?>"
class="default_type">
@ -16,12 +40,12 @@
cols="15"
class="textfield
default_value">
<?php echo $default_value; ?>
<?php echo htmlspecialchars($defaultValue); ?>
</textarea>
<?php else: ?>
<input type="text"
name="field_default_value[<?php echo $columnNumber; ?>]"
size="12"
value="<?php echo $default_value ?>"
value="<?php echo htmlspecialchars($defaultValue); ?>"
class="textfield default_value" />
<?php endif; ?>

View File

@ -34,40 +34,42 @@
<?php if ($action == 'tbl_create.php'): ?>
<div id="table_name_col_no_outer">
<table id="table_name_col_no">
<tr class="vmiddle floatleft">
<td> <?php echo __('Table name'); ?>:&nbsp;
<input type="text"
name="table"
size="40"
maxlength="64"
value="<?php echo (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : ''); ?>"
class="textfield" autofocus required />
</td>
<td>
Add
<input type="number"
id="added_fields"
name="added_fields"
size="2"
value="1"
min="1"
onfocus="this.select()" />
column(s)
<input type="button"
name="submit_num_fields"
value="<?php echo __('Go'); ?>" />
</td>
</tr>
</table>
<table id="table_name_col_no">
<tr class="vmiddle floatleft">
<td><?php echo __('Table name'); ?>:&nbsp;
<input type="text"
name="table"
size="40"
maxlength="64"
value="<?php echo (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : ''); ?>"
class="textfield" autofocus required />
</td>
<td>
Add
<input type="number"
id="added_fields"
name="added_fields"
size="2"
value="1"
min="1"
onfocus="this.select()" />
column(s)
<input type="button"
name="submit_num_fields"
value="<?php echo __('Go'); ?>" />
</td>
</tr>
</table>
</div>
<?php endif; ?>
<?php if (is_array($content_cells) && is_array($header_cells)): ?>
<?php if (is_array($content_cells)): ?>
<?php echo PMA\Template::get(
'columns_definitions/table_fields_definitions'
)->render(array(
'content_cells' => $content_cells,
'header_cells' => $header_cells
'is_backup' => $is_backup,
'fields_meta' => $fields_meta,
'mimework' => $mimework,
'content_cells' => $content_cells
)); ?>
<?php endif; ?>
<?php if ($action == 'tbl_create.php'): ?>
@ -164,4 +166,4 @@
</fieldset>
<div id="properties_message">
</div>
</form>
</form>

View File

@ -0,0 +1,48 @@
<?php
$title = '';
if (isset($columnMeta['column_status'])) {
if ($columnMeta['column_status']['isReferenced']) {
$title .= sprintf(
__('Referenced by %s.'),
implode(",", $columnMeta['column_status']['references'])
);
}
if ($columnMeta['column_status']['isForeignKey']) {
if (!empty($title)) {
$title .= "\n";
}
$title .= __('Is a foreign key.');
}
}
if (empty($title)) {
$title = __('Column');
}
?>
<input id="field_<?php echo $columnNumber; ?>_<?php echo ($ci - $ci_offset); ?>"
<?php if (isset($columnMeta['column_status'])
&& !$columnMeta['column_status']['isEditable']): ?>
disabled="disabled"
<?php endif; ?>
type="text"
name="field_name[<?php echo $columnNumber; ?>]"
maxlength="64"
class="textfield"
title="<?php echo $title; ?>"
size="10"
value="<?php if (isset($columnMeta['Field']))
echo htmlspecialchars($columnMeta['Field']); ?>" />
<?php if (isset($cfgRelation['central_columnswork'])
&& $cfgRelation['central_columnswork']
&& !(isset($columnMeta['column_status'])
&& !$columnMeta['column_status']['isEditable'])
): ?>
<p style="font-size:80%;margin:5px 2px"
id="central_columns_<?php echo $columnNumber; ?>_<?php echo ($ci - $ci_offset); ?>">
<a data-maxrows="<?php echo $GLOBALS['cfg']['MaxRows']; ?>"
href="#"
class="central_columns_dialog">
<?php echo __('Pick from Central Columns'); ?>
</a>
</p>
<?php endif; ?>

View File

@ -1,7 +1,7 @@
<select class="column_type"
name="field_type[<?php echo $columnNumber; ?>]"
id="<?php echo $select_id; ?>"
id="field_<?php echo $columnNumber; ?>_<?php echo ($ci - $ci_offset); ?>"
<?php if (isset($columnMeta['column_status']) && !$columnMeta['column_status']['isEditable'])
echo 'disabled="disabled"'; ?>>
<?php echo PMA_Util::getSupportedDatatypes(true, $type_upper); ?>
<?php echo PMA_Util::getSupportedDatatypes(true, $type_upper); ?>
</select>

View File

@ -1,20 +1,126 @@
<table id="table_columns" class="noclick">
<caption class="tblHeaders"><?php echo __('Structure'); echo PMA_Util::showMySQLDocu('CREATE_TABLE'); ?>
</caption>
<tr>
<?php foreach ($header_cells as $header_val): ?>
<th><?php echo $header_val; ?></th>
<?php endforeach; ?>
</tr>
<caption class="tblHeaders">
<?php echo __('Structure'); ?>
<?php echo PMA_Util::showMySQLDocu('CREATE_TABLE'); ?>
</caption>
<tr>
<th>
<?php echo __('Name'); ?>
</th>
<th>
<?php echo __('Type') . PMA_Util::showMySQLDocu('data-types'); ?>
</th>
<th>
<?php echo __('Length/Values') . PMA_Util::showHint(
__(
'If column type is "enum" or "set", please enter the values using'
. ' this format: \'a\',\'b\',\'c\'…<br />If you ever need to put'
. ' a backslash ("\") or a single quote ("\'") amongst those'
. ' values, precede it with a backslash (for example \'\\\\xyz\''
. ' or \'a\\\'b\').'
)
); ?>
</th>
<th>
<?php echo __('Default') . PMA_Util::showHint(
__(
'For default values, please enter just a single value,'
. ' without backslash escaping or quotes, using this format: a'
)
); ?>
</th>
<th>
<?php echo __('Collation'); ?>
</th>
<th>
<?php echo __('Attributes'); ?>
</th>
<th>
<?php echo __('Null'); ?>
</th>
<!-- Only for 'Edit' Column(s) -->
<?php if (isset($_REQUEST['change_column'])
&& ! empty($_REQUEST['change_column'])
): ?>
<th>
<?php echo __('Adjust Privileges') . PMA_Util::showDocu('faq', 'faq6-39'); ?>
</th>
<?php endif; ?>
<?php
// We could remove this 'if' and let the key information be shown and
// editable. However, for this to work, structure.lib.php must be modified
// to use the key fields, as tbl_addfield does.
if (!$is_backup): ?>
<th>
<?php echo __('Index'); ?>
</th>
<?php endif; ?>
<th>
<abbr title="AUTO_INCREMENT">A_I</abbr>
</th>
<th>
<?php echo __('Comments'); ?>
</th>
<?php if (isset($fields_meta)): ?>
<th>
<?php echo __('Move column'); ?>
</th>
<?php endif; ?>
<?php if ($mimework && $GLOBALS['cfg']['BrowseMIME']): ?>
<th>
<?php echo __('MIME type'); ?>
</th>
<th>
<a href="transformation_overview.php<?php echo PMA_URL_getCommon(); ?>#transformation"
title="<?php echo __('List of available transformations and their options'); ?>"
target="_blank">
<?php echo __('Browser display transformation'); ?>
</a>
</th>
<th>
<?php echo __('Browser display transformation options'); ?>
<?php echo PMA_Util::showHint(
__(
'Please enter the values for transformation options using this'
. ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put'
. ' a backslash ("\") or a single quote ("\'") amongst those'
. ' values, precede it with a backslash (for example \'\\\\xyz\''
. ' or \'a\\\'b\').'
)
); ?>
</th>
<th>
<a href="transformation_overview.php<?php echo PMA_URL_getCommon(); ?>#input_transformation"
title="<?php echo __('List of available transformations and their options'); ?>"
target="_blank">
<?php echo __('Input transformation'); ?>
</a>
</th>
<th>
<?php echo __('Input transformation options'); ?>
<?php echo PMA_Util::showHint(
__(
'Please enter the values for transformation options using this'
. ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put'
. ' a backslash ("\") or a single quote ("\'") amongst those'
. ' values, precede it with a backslash (for example \'\\\\xyz\''
. ' or \'a\\\'b\').'
)
); ?>
</th>
<?php endif; ?>
</tr>
<?php $odd_row = true;?>
<?php foreach($content_cells as $content_row): ?>
<tr class="<?php echo ($odd_row ? 'odd' : 'even'); ?>">
<?php $odd_row = !$odd_row; ?>
<?php if (is_array($content_row)): ?>
<?php foreach($content_row as $content_row_val): ?>
<td class="center"><?php echo $content_row_val; ?></td>
<?php endforeach; ?>
<?php endif; ?>
<?php $odd_row = !$odd_row; ?>
<?php echo PMA\Template::get('columns_definitions/column_attributes')
->render($content_row); ?>
</tr>
<?php endforeach; ?>
</table>

View File

@ -1,6 +1,12 @@
<?php $options_key = $type_prefix . 'transformation_options'; ?>
<input id="field_<?php echo $columnNumber; ?>_<?php echo ($ci - $ci_offset); ?>"
type="text"
name="field_<?php echo $options_key; ?>[<?php echo $columnNumber; ?>]"
size="16"
class="textfield"
value="<?php echo $val; ?>"/>
value="<?php if (isset($columnMeta['Field'])
&& isset($mime_map[$columnMeta['Field']][$options_key]))
echo htmlspecialchars(
$mime_map[$columnMeta['Field']]
[$options_key]
); ?>" />

View File

@ -8,4 +8,4 @@
<input type="hidden" name="page_number" value="<?php echo htmlspecialchars($page); ?>" />
<?php echo PMA_pluginGetOptions('Schema', $export_list); ?>
</fieldset>
</form>';
</form>

View File

@ -76,7 +76,7 @@
function drawOpenLayers()
{
<?php if (! $GLOBALS['PMA_Config']->isHttps()): ?>
<?php echo PMA_GIS_visualizationResults($data, $visualizationSettings, 'ol'); ?>
<?php echo $drawOl; ?>
<?php endif; ?>
}
</script>

View File

@ -17,8 +17,15 @@
</th>
<?php $odd_row = true; ?>
<?php for ($i = 0; $i < $saved_row_cnt; $i++): ?>
<?php echo PMA_getHtmlForInternalRelationRow(
$save_row, $i, $odd_row, $existrel, $db);
<?php echo PMA\Template::get('tbl_relation/internal_relational_row')->render(
array(
'save_row' => $save_row,
'i' => $i,
'odd_row' => $odd_row,
'existrel' => $existrel,
'db' => $db
)
);
$odd_row = ! $odd_row; ?>
<?php endfor; ?>
</table>
@ -44,25 +51,29 @@
</tr>
<?php $odd_row = true; $i = 0; ?>
<?php foreach ($existrel_foreign as $key => $one_key): ?>
<?php echo PMA_getHtmlForForeignKeyRow(
$one_key,
$odd_row,
$columns,
$i++,
$options_array,
$tbl_storage_engine,
$db
<?php echo PMA\Template::get('tbl_relation/foreign_key_row')->render(
array(
'one_key' => $one_key,
'odd_row' => $odd_row,
'columns' => $columns,
'i' => $i++,
'options_array' => $options_array,
'tbl_storage_engine' => $tbl_storage_engine,
'db' => $db
)
);
$odd_row = ! $odd_row;?>
<?php endforeach; ?>
<?php echo PMA_getHtmlForForeignKeyRow(
array(),
$odd_row,
$columns,
$i++,
$options_array,
$tbl_storage_engine,
$db
<?php echo PMA\Template::get('tbl_relation/foreign_key_row')->render(
array(
'one_key' => array(),
'odd_row' => $odd_row,
'columns' => $columns,
'i' => $i++,
'options_array' => $options_array,
'tbl_storage_engine' => $tbl_storage_engine,
'db' => $db
)
); ?>
<tr>
<td colspan="5">

View File

@ -1,3 +1,87 @@
<?php
$js_msg = '';
$this_params = null;
if (isset($one_key['constraint'])) {
$drop_fk_query = 'ALTER TABLE ' . PMA_Util::backquote($GLOBALS['table'])
. ' DROP FOREIGN KEY '
. PMA_Util::backquote($one_key['constraint']) . ';';
$this_params = $GLOBALS['url_params'];
$this_params['goto'] = 'tbl_relation.php';
$this_params['back'] = 'tbl_relation.php';
$this_params['sql_query'] = $drop_fk_query;
$this_params['message_to_show'] = sprintf(
__('Foreign key constraint %s has been dropped'),
$one_key['constraint']
);
$js_msg = PMA_jsFormat(
'ALTER TABLE ' . $GLOBALS['table']
. ' DROP FOREIGN KEY '
. $one_key['constraint'] . ';'
);
}
// For ON DELETE and ON UPDATE, the default action
// is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE
// won't display the clause if it's set as RESTRICT.
$on_delete = isset($one_key['on_delete'])
? $one_key['on_delete'] : 'RESTRICT';
$on_update = isset($one_key['on_update'])
? $one_key['on_update'] : 'RESTRICT';
$column_array = array();
$column_array[''] = '';
foreach ($columns as $column) {
if (! empty($column['Key'])) {
$column_array[$column['Field']] = $column['Field'];
}
}
$foreign_table = false;
// foreign database dropdown
$foreign_db = (isset($one_key['ref_db_name'])) ? $one_key['ref_db_name'] : $db;
$tables = array();
if ($foreign_db) {
$foreign_table = isset($one_key['ref_table_name'])
? $one_key['ref_table_name'] : '';
// In Drizzle, 'SHOW TABLE STATUS' will show status only for the tables
// which are currently in the table cache. Hence we have to use
// 'SHOW TABLES' and manualy retrieve table engine values.
if (PMA_DRIZZLE) {
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLES FROM ' . PMA_Util::backquote($foreign_db),
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
$engine = PMA_Table::sGetStatusInfo(
$foreign_db,
$row[0],
'Engine'
);
if (isset($engine)
&& /*overload*/mb_strtoupper($engine) == $tbl_storage_engine
) {
$tables[] = $row[0];
}
}
} else {
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($foreign_db),
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
if (isset($row[1])
&& /*overload*/mb_strtoupper($row[1]) == $tbl_storage_engine
) {
$tables[] = $row[0];
}
}
}
}
?>
<tr class="<?php echo ($odd_row ? 'odd' : 'even'); ?>">
<!-- Drop key anchor -->
<td>
@ -21,19 +105,23 @@
</span>
<div class="floatleft">
<span class="formelement">
<?php echo PMA_generateDropdown(
'ON DELETE',
'on_delete[' . $i . ']',
$options_array,
$on_delete
<?php echo PMA\Template::get('tbl_relation/dropdown_generate')->render(
array(
'dropdown_question' => 'ON DELETE',
'select_name' => 'on_delete[' . $i . ']',
'choices' => $options_array,
'selected_value' => $on_delete
)
); ?>
</span>
<span class="formelement">
<?php echo PMA_generateDropdown(
'ON UPDATE',
'on_update[' . $i . ']',
$options_array,
$on_update
<?php echo PMA\Template::get('tbl_relation/dropdown_generate')->render(
array(
'dropdown_question' => 'ON UPDATE',
'select_name' => 'on_update[' . $i . ']',
'choices' => $options_array,
'selected_value' => $on_update
)
); ?>
</span>
</div>
@ -42,22 +130,26 @@
<?php if (isset($one_key['index_list'])): ?>
<?php foreach ($one_key['index_list'] as $key => $column): ?>
<span class="formelement clearfloat">
<?php echo PMA_generateDropdown(
'',
'foreign_key_fields_name[' . $i . '][]',
$column_array,
$column
<?php echo PMA\Template::get('tbl_relation/dropdown_generate')->render(
array(
'dropdown_question' => '',
'select_name' => 'foreign_key_fields_name[' . $i . '][]',
'choices' => $column_array,
'selected_value' => $column
)
); ?>
</span>
<?php endforeach; ?>
<?php else: ?>
<span class="formelement clearfloat">
<?php echo PMA_generateDropdown(
'',
'foreign_key_fields_name[' . $i . '][]',
$column_array,
''
);?>
<?php echo PMA\Template::get('tbl_relation/dropdown_generate')->render(
array(
'dropdown_question' => '',
'select_name' => 'foreign_key_fields_name[' . $i . '][]',
'choices' => $column_array,
'selected_value' => ''
)
); ?>
</span>
<?php endif; ?>
<a class="formelement clearfloat add_foreign_key_field"
@ -68,20 +160,24 @@
</td>
<td>
<span class="formelement clearfloat">
<?php echo PMA_generateRelationalDropdown(
'destination_foreign_db[' . $i . ']',
$GLOBALS['pma']->databases,
$foreign_db,
__('Database')
<?php echo PMA\Template::get('tbl_relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_db[' . $i . ']',
'title' => __('Database'),
'values' => $GLOBALS['pma']->databases,
'foreign' => $foreign_db
)
); ?>
</td>
<td>
<span class="formelement clearfloat">
<?php echo PMA_generateRelationalDropdown(
'destination_foreign_table[' . $i . ']',
$tables,
$foreign_table,
__('Table')
<?php echo PMA\Template::get('tbl_relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_table[' . $i . ']',
'title' => __('Table'),
'values' => $tables,
'foreign' => $foreign_table
)
); ?>
</span>
</td>
@ -93,21 +189,25 @@
$columns = $table_obj->getUniqueColumns(false, false);
?>
<span class="formelement clearfloat">
<?php echo PMA_generateRelationalDropdown(
'destination_foreign_column[' . $i . '][]',
$columns,
$foreign_column,
__('Column')
);?>
<?php echo PMA\Template::get('tbl_relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_column[' . $i . '][]',
'title' => __('Column'),
'values' => $columns,
'foreign' => $foreign_column
)
); ?>
</span>
<?php endforeach; ?>
<?php else: ?>
<span class="formelement clearfloat">
<?php echo PMA_generateRelationalDropdown(
'destination_foreign_column[' . $i . '][]',
array(),
'',
__('Column')
<?php echo PMA\Template::get('tbl_relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_column[' . $i . '][]',
'title' => __('Column'),
'values' => array(),
'foreign' => ''
)
); ?>
</span>
<?php endif; ?>

View File

@ -1,3 +1,46 @@
<?php
$myfield = $save_row[$i]['Field'];
// Use an md5 as array index to avoid having special characters
// in the name attribute (see bug #1746964 )
$myfield_md5 = md5($myfield);
$myfield_html = htmlspecialchars($myfield);
$foreign_table = false;
$foreign_column = false;
// database dropdown
if (isset($existrel[$myfield])) {
$foreign_db = $existrel[$myfield]['foreign_db'];
} else {
$foreign_db = $db;
}
// table dropdown
$tables = array();
if ($foreign_db) {
if (isset($existrel[$myfield])) {
$foreign_table = $existrel[$myfield]['foreign_table'];
}
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLES FROM ' . PMA_Util::backquote($foreign_db),
null,
PMA_DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
$tables[] = $row[0];
}
}
// column dropdown
$columns = array();
if ($foreign_db && $foreign_table) {
if (isset($existrel[$myfield])) {
$foreign_column = $existrel[$myfield]['foreign_field'];
}
$table_obj = new PMA_Table($foreign_table, $foreign_db);
$columns = $table_obj->getUniqueColumns(false, false);
}
?>
<tr class="<?php echo ($odd_row ? 'odd' : 'even'); ?>">
<td class="vmiddle">
<strong><?php echo $myfield_html; ?></strong>
@ -6,11 +49,29 @@
</td>
<td>
<?php echo PMA_generateRelationalDropdown('destination_db[' . $myfield_md5 . ']',
$GLOBALS['pma']->databases, $foreign_db, __('Database')); ?>
<?php echo PMA_generateRelationalDropdown('destination_table[' . $myfield_md5 . ']',
$tables, $foreign_table, __('Table')); ?>
<?php echo PMA_generateRelationalDropdown('destination_column[' . $myfield_md5 . ']',
$columns, $foreign_column, __('Column')); ?>
<?php echo PMA\Template::get('tbl_relation/relational_dropdown')->render(
array(
'name' => 'destination_db[' . $myfield_md5 . ']',
'title' => __('Database'),
'values' => $GLOBALS['pma']->databases,
'foreign' => $foreign_db
)
); ?>
<?php echo PMA\Template::get('tbl_relation/relational_dropdown')->render(
array(
'name' => 'destination_table[' . $myfield_md5 . ']',
'title' => __('Table'),
'values' => $tables,
'foreign' => $foreign_table
)
); ?>
<?php echo PMA\Template::get('tbl_relation/relational_dropdown')->render(
array(
'name' => 'destination_column[' . $myfield_md5 . ']',
'title' => __('Column'),
'values' => $columns,
'foreign' => $foreign_column
)
); ?>
</td>
</tr>

View File

@ -11,7 +11,7 @@ require_once 'libraries/Util.class.php';
/*
* Include to test
*/
require_once 'libraries/tbl_gis_visualization.lib.php';
//require_once 'libraries/tbl_gis_visualization.lib.php';
/**
* Tests for PMA_GIS_modifyQuery method
@ -20,22 +20,24 @@ require_once 'libraries/tbl_gis_visualization.lib.php';
*/
class PMA_GIS_ModifyQueryTest extends PHPUnit_Framework_TestCase
{
/**
* Test PMA_GIS_modifyQuery method
*
* @param string $sql_query query to modify
* @param array $settings visualization settings
* @param string $modified_query modified query
*
* @dataProvider provider
* @return void
*/
public function testModifyQuery($sql_query, $settings, $modified_query)
// @todo: Move this test to GIS_Visualization's
// /**
// * Test PMA_GIS_modifyQuery method
// *
// * @param string $sql_query query to modify
// * @param array $settings visualization settings
// * @param string $modified_query modified query
// *
// * @dataProvider provider
// * @return void
// */
public function testModifyQuery(/*$sql_query, $settings, $modified_query*/)
{
$this->assertEquals(
PMA_GIS_modifyQuery($sql_query, $settings),
$modified_query
);
// $this->assertEquals(
// PMA_GIS_modifyQuery($sql_query, $settings),
// $modified_query
// );
$this->markTestIncomplete('Not yet implemented!');
}
/**

View File

@ -18,7 +18,6 @@ require_once 'libraries/relation.lib.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/tbl_columns_definition_form.lib.php';
require_once 'libraries/Types.class.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/central_columns.lib.php';
@ -504,65 +503,7 @@ class PMA_Central_Columns_Test extends PHPUnit_Framework_TestCase
*/
public function testPMAGetHTMLforCentralColumnsTableRow()
{
$row = array(
'col_name'=>'col_test',
'col_type'=>'int',
'col_length'=>12,
'col_collation'=>'utf8_general_ci',
'col_isNull'=>1,
'col_extra'=> '',
'col_attribute'=>''
);
$result = PMA_getHTMLforCentralColumnsTableRow($row, false, 1, 'phpmyadmin');
$this->assertContains(
'<tr',
$result
);
$this->assertContains(
PMA_URL_getHiddenInputs('phpmyadmin'),
$result
);
$this->assertContains(
'<span',
$result
);
$this->assertContains(
'col_test',
$result
);
$this->assertContains(
__('on update CURRENT_TIMESTAMP'),
$result
);
$this->assertContains(
PMA_getHtmlForColumnDefault(
1, 3, 0, /*overload*/mb_strtoupper($row['col_type']), '',
array('DefaultType'=>'NONE')
),
$result
);
$row['col_default'] = 100;
$result_1 = PMA_getHTMLforCentralColumnsTableRow(
$row, false, 1, 'phpmyadmin'
);
$this->assertContains(
PMA_getHtmlForColumnDefault(
1, 3, 0, /*overload*/mb_strtoupper($row['col_type']), '',
array('DefaultType'=>'USER_DEFINED', 'DefaultValue'=>100)
),
$result_1
);
$row['col_default'] = 'CURRENT_TIMESTAMP';
$result_2 = PMA_getHTMLforCentralColumnsTableRow(
$row, false, 1, 'phpmyadmin'
);
$this->assertContains(
PMA_getHtmlForColumnDefault(
1, 3, 0, /*overload*/mb_strtoupper($row['col_type']), '',
array('DefaultType'=>'CURRENT_TIMESTAMP')
),
$result_2
);
// @todo Find a better way to test page
}
/**

View File

@ -18,7 +18,6 @@ require_once 'libraries/relation.lib.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/tbl_columns_definition_form.lib.php';
require_once 'libraries/Types.class.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/normalization.lib.php';

View File

@ -10,7 +10,6 @@
* Include to test.
*/
require_once 'libraries/Util.class.php';
require_once 'libraries/tbl_columns_definition_form.lib.php';
require_once 'libraries/DatabaseInterface.class.php';
require_once 'libraries/Partition.class.php';
require_once 'libraries/Types.class.php';
@ -34,136 +33,13 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$GLOBALS['cfg']['ServerDefault'] = 1;
$GLOBALS['cfg']['DBG'] = null;
$GLOBALS['pmaThemeImage'] = 'image';
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
}
/**
* Test for PMA_getFormsParameters
*
* @return void
*/
public function testGetFormsParameters()
{
// case 1
$_REQUEST['after_field'] = "affield";
$_REQUEST['field_where'] = "fwhere";
$result = PMA_getFormsParameters(
"dbname", "tablename", "tbl_create.php", 22, array(12, 13)
);
$this->assertEquals(
array(
'db' => 'dbname',
'reload' => 1,
'orig_num_fields' => 22,
'orig_field_where' => 'fwhere',
'orig_after_field' => 'affield',
'selected[0]' => 12,
'selected[1]' => 13
),
$result
);
// case 2
$result = PMA_getFormsParameters(
"dbname", "tablename", "tbl_addfield.php", null, 1
);
$this->assertEquals(
array(
'db' => 'dbname',
'table' => 'tablename',
'orig_field_where' => 'fwhere',
'orig_after_field' => 'affield',
'field_where' => 'fwhere',
'after_field' => 'affield'
),
$result
);
// case 3
$_REQUEST['after_field'] = null;
$_REQUEST['field_where'] = null;
$result = PMA_getFormsParameters(
"dbname", "tablename", null, 0, null
);
$this->assertEquals(
array(
'db' => 'dbname',
'table' => 'tablename',
'orig_num_fields' => 0
),
$result
);
}
/**
* Test for PMA_getHtmlForTableCreateOrAddField
*
* @return void
*/
public function testGetHtmlForTableCreateOrAddField()
{
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())
->method('fetchResult')
->will(
$this->returnValue(
array()
)
);
$GLOBALS['dbi'] = $dbi;
$result = PMA_getHtmlForTableCreateOrAddField(
"tbl_create.php",
array('a' => 'b'),
array(array('c1')),
array('h1')
);
/**
* @todo Find out a better method to test for HTML
* $GLOBALS['cfg']['ServerDefault'] = 1;
* $GLOBALS['cfg']['DBG'] = null;
* $GLOBALS['pmaThemeImage'] = 'image';
*
* $this->assertContains(
* '<form method="post" action="tbl_create.php" '
* . 'class="create_table_form ajax lock-page">',
* $result
* );
*/
$this->assertContains(
'<input type="hidden" name="a" value="b"',
$result
);
$this->assertContains(
'<select lang="en" dir="ltr" name="tbl_collation">',
$result
);
/**
* @todo Find out a better method to test for HTML
*
* $this->assertContains(
* '<input type="submit" name="do_save_data" value="Save"',
* $result
* );
*
* $this->assertContains(
* '<input type="text" name="table"',
* $result
* );
* $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
* $_SESSION['PMA_Theme'] = new PMA_Theme();
*/
}
@ -174,24 +50,27 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetHeaderCells()
{
$GLOBALS['cfg']['BrowseMIME'] = true;
$GLOBALS['cfg']['ShowHint'] = false;
$result = PMA_getHeaderCells(false, array(), true);
$this->assertContains(
'Index',
$result
);
$this->assertContains(
'Move column',
$result
);
$this->assertContains(
'MIME type',
$result
);
/**
* @todo Test against table_fields_definition.phtml
* $GLOBALS['cfg']['BrowseMIME'] = true;
* $GLOBALS['cfg']['ShowHint'] = false;
* $result = PMA_getHeaderCells(false, array(), true);
*
* $this->assertContains(
* 'Index',
* $result
* );
*
* $this->assertContains(
* 'Move column',
* $result
* );
*
* $this->assertContains(
* 'MIME type',
* $result
* );
*/
}
/**
@ -201,26 +80,29 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetMoveColumns()
{
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->once())
->method('tryQuery')
->with("SELECT * FROM `db`.`table` LIMIT 1")
->will($this->returnValue('v1'));
$dbi->expects($this->once())
->method('getFieldsMeta')
->with("v1")
->will($this->returnValue('movecols'));
$GLOBALS['dbi'] = $dbi;
$this->assertEquals(
PMA_getMoveColumns('db', 'table'),
'movecols'
);
/**
* @todo Test against PMA_Table::getColumnsMeta
* $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
* ->disableOriginalConstructor()
* ->getMock();
*
* $dbi->expects($this->once())
* ->method('tryQuery')
* ->with("SELECT * FROM `db`.`table` LIMIT 1")
* ->will($this->returnValue('v1'));
*
* $dbi->expects($this->once())
* ->method('getFieldsMeta')
* ->with("v1")
* ->will($this->returnValue('movecols'));
*
* $GLOBALS['dbi'] = $dbi;
*
* $this->assertEquals(
* PMA_getMoveColumns('db', 'table'),
* 'movecols'
* );
*/
}
/**
@ -230,6 +112,7 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetRowDataForRegeneration()
{
/** @todo Move test
$_REQUEST = array(
'field_name' => array(1 => 'name'),
'field_type' => array(1 => 'type'),
@ -260,6 +143,7 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
),
$result
);
*/
}
/**
@ -269,6 +153,7 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetSubmitPropertiesForRegeneration()
{
/** @todo Move test
$_REQUEST = array(
'field_length' => array(1 => 22),
'field_attribute' => array(1 => 'attr'),
@ -281,7 +166,7 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
array(22, 'attr', false),
$result
);
*/
}
/**
@ -291,6 +176,7 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testHandleRegeneration()
{
/** @todo Move test
$_REQUEST = array(
'field_comments' => array(1 => 'comm'),
'field_mimetype' => array(1 => 'mime'),
@ -315,6 +201,7 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
),
$result[5]
);
*/
}
/**
@ -324,104 +211,105 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetColumnMetaForDefault()
{
$cmeta = array(
'Default' => null,
'Null' => 'YES',
'DefaultType' => 'a',
'DefaultValue' => 'b',
);
$result = PMA_getColumnMetaForDefault($cmeta, null);
$this->assertEquals(
'NULL',
$result['DefaultType']
);
$this->assertEquals(
'',
$result['DefaultValue']
);
// case 2
$cmeta = array(
'Default' => null,
'Null' => 'NO',
'DefaultType' => 'a',
'DefaultValue' => 'b',
);
$result = PMA_getColumnMetaForDefault($cmeta, true);
$this->assertEquals(
'USER_DEFINED',
$result['DefaultType']
);
$this->assertEquals(
null,
$result['DefaultValue']
);
// case 3
$cmeta = array(
'Default' => null,
'Null' => 'NO',
'DefaultType' => 'a',
'DefaultValue' => 'b',
);
$result = PMA_getColumnMetaForDefault($cmeta, false);
$this->assertEquals(
'NONE',
$result['DefaultType']
);
$this->assertEquals(
null,
$result['DefaultValue']
);
// case 4
$cmeta = array(
'Default' => 'CURRENT_TIMESTAMP',
'Null' => 'NO',
'DefaultType' => 'a',
'DefaultValue' => 'b',
);
$result = PMA_getColumnMetaForDefault($cmeta, false);
$this->assertEquals(
'CURRENT_TIMESTAMP',
$result['DefaultType']
);
$this->assertEquals(
null,
$result['DefaultValue']
);
// case 5
$cmeta = array(
'Default' => 'SOMETHING_ELSE',
'Null' => 'NO',
'DefaultType' => 'a',
'DefaultValue' => 'b',
);
$result = PMA_getColumnMetaForDefault($cmeta, false);
$this->assertEquals(
'USER_DEFINED',
$result['DefaultType']
);
$this->assertEquals(
'SOMETHING_ELSE',
$result['DefaultValue']
);
// @todo Move test
// $cmeta = array(
// 'Default' => null,
// 'Null' => 'YES',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
//
// $result = PMA_getColumnMetaForDefault($cmeta, null);
//
// $this->assertEquals(
// 'NULL',
// $result['DefaultType']
// );
//
// $this->assertEquals(
// '',
// $result['DefaultValue']
// );
//
// // case 2
// $cmeta = array(
// 'Default' => null,
// 'Null' => 'NO',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
//
// $result = PMA_getColumnMetaForDefault($cmeta, true);
//
// $this->assertEquals(
// 'USER_DEFINED',
// $result['DefaultType']
// );
//
// $this->assertEquals(
// null,
// $result['DefaultValue']
// );
//
// // case 3
// $cmeta = array(
// 'Default' => null,
// 'Null' => 'NO',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
//
// $result = PMA_getColumnMetaForDefault($cmeta, false);
//
// $this->assertEquals(
// 'NONE',
// $result['DefaultType']
// );
//
// $this->assertEquals(
// null,
// $result['DefaultValue']
// );
//
// // case 4
// $cmeta = array(
// 'Default' => 'CURRENT_TIMESTAMP',
// 'Null' => 'NO',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
//
// $result = PMA_getColumnMetaForDefault($cmeta, false);
//
// $this->assertEquals(
// 'CURRENT_TIMESTAMP',
// $result['DefaultType']
// );
//
// $this->assertEquals(
// null,
// $result['DefaultValue']
// );
//
// // case 5
// $cmeta = array(
// 'Default' => 'SOMETHING_ELSE',
// 'Null' => 'NO',
// 'DefaultType' => 'a',
// 'DefaultValue' => 'b',
// );
//
// $result = PMA_getColumnMetaForDefault($cmeta, false);
//
// $this->assertEquals(
// 'USER_DEFINED',
// $result['DefaultType']
// );
//
// $this->assertEquals(
// 'SOMETHING_ELSE',
// $result['DefaultValue']
// );
}
/**
@ -431,19 +319,9 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetHtmlForColumnName()
{
$cfgRelation = array('central_columnswork' => true);
$result = PMA_getHtmlForColumnName(
2, 4, 4, array('Field' => "fieldname",
'column_status' => array('isReferenced' => false,
'isForeignKey' => false, 'isEditable' => true)), $cfgRelation
);
$this->assertContains(
'<input id="field_2_0" type="text" name="field_name[2]" '
. 'maxlength="64" class="textfield" title="Column" size="10" '
. 'value="fieldname" />',
$result
);
/**
* @todo Create test for page
*/
}
/**
@ -453,25 +331,25 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetHtmlForColumnType()
{
$GLOBALS['PMA_Types'] = new PMA_Types;
$result = PMA_getHtmlForColumnType(
1, 4, 3, false, array('column_status' => array('isReferenced' => false,
'isForeignKey' => false, 'isEditable' => true))
);
/**
* @todo Find out a better method to test for HTML
*
* $GLOBALS['PMA_Types'] = new PMA_Types;
* $result = PMA_getHtmlForColumnType(
* 1, 4, 3, false, array('column_status' => array('isReferenced' => false,
* 'isForeignKey' => false, 'isEditable' => true))
* );
*
* $this->assertContains(
* '<select class="column_type" name="field_type[1]" id="field_1_1">',
* $result
* );
*
* $this->assertContains(
* '<option title="">INT</option>',
* $result
* );
*/
$this->assertContains(
'<option title="">INT</option>',
$result
);
}
/**
@ -514,42 +392,42 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetHtmlForTransformation()
{
$cmeta = array(
'Field' => 'fieldname'
);
$mime = array(
'fieldname' => array(
'transformation' => 'Text_Plain_Preappend.class.php',
'transformation_options' => 'transops'
)
);
$avail_mime = array(
'transformation' => array(
'foo' => 'text/plain: bar'
),
'transformation_file' => array(
'foo' => 'Text_Plain_Preappend.class.php'
)
);
$result = PMA_getHtmlForTransformation(
2, 0, 0, $avail_mime, $cmeta, $mime, ''
);
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Field' => 'fieldname'
* );
*
* $mime = array(
* 'fieldname' => array(
* 'transformation' => 'Text_Plain_Preappend.class.php',
* 'transformation_options' => 'transops'
* )
* );
*
* $avail_mime = array(
* 'transformation' => array(
* 'foo' => 'text/plain: bar'
* ),
* 'transformation_file' => array(
* 'foo' => 'Text_Plain_Preappend.class.php'
* )
* );
* $result = PMA_getHtmlForTransformation(
* 2, 0, 0, $avail_mime, $cmeta, $mime, ''
* );
*
* $this->assertContains(
* '<select id="field_2_0" size="1" name="field_transformation[2]">',
* $result
* );
*
* $this->assertContains(
* 'selected ',
* $result
* );
*/
$this->assertContains(
'selected ',
$result
);
}
/**
@ -559,38 +437,38 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetHtmlForMoveColumn()
{
$cmeta = array(
'Field' => 'fieldname'
);
$moveColumns = array();
$temp = new stdClass;
$temp->name = 'a';
$moveColumns[] = $temp;
$temp = new stdClass;
$temp->name = 'fieldname';
$moveColumns[] = $temp;
$result = PMA_getHtmlForMoveColumn(
2, 0, 0, $moveColumns, $cmeta
);
/**
* @todo Find out a better method to test for HTML
*
* $cmeta = array(
* 'Field' => 'fieldname'
* );
*
* $moveColumns = array();
*
* $temp = new stdClass;
* $temp->name = 'a';
* $moveColumns[] = $temp;
*
* $temp = new stdClass;
* $temp->name = 'fieldname';
* $moveColumns[] = $temp;
*
* $result = PMA_getHtmlForMoveColumn(
* 2, 0, 0, $moveColumns, $cmeta
* );
*
* $this->assertContains(
* '<select id="field_2_0" name="field_move_to[2]" size="1" width="5em">',
* $result
* );
*
* $this->assertContains(
* '<option value="" selected="selected">&nbsp;</option>',
* $result
* );
*/
$this->assertContains(
'<option value="" selected="selected">&nbsp;</option>',
$result
);
/**
* @todo Find out a better method to test for HTML
*
@ -672,15 +550,6 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetHtmlForColumnIndexes()
{
$cmeta = array(
'Extra' => 'auto_increment',
'Field' => 'fieldname'
);
$result = PMA_getHtmlForColumnIndexes(
2, 1, 0, $cmeta
);
/**
* @todo Find out a better method to test for HTML
*
@ -688,15 +557,12 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
* '<select name="field_key[2]" id="field_2_1"',
* $result
* );
*/
$this->assertContains(
'<option value="none_2">---</option>',
$result
);
/**
* @todo Find out a better method to test for HTML
*
*
* $this->assertContains(
* '<option value="none_2">---</option>',
* $result
* );
*
* $this->assertContains(
* '<option value="primary_2" title="Primary">PRIMARY</option>',
@ -801,32 +667,6 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
$this->markTestIncomplete('Not yet implemented!');
}
/**
* Test for PMA_getHtmlForColumnCollation
*
* @return void
*/
public function testGetHtmlForColumnCollation()
{
$cmeta = array(
'Collation' => 'utf8_general_ci'
);
$result = PMA_getHtmlForColumnCollation(
2, 3, 1, $cmeta
);
$this->assertContains(
'<select lang="en" dir="ltr" name="field_collation[2]" id="field_2_2">',
$result
);
$this->assertContains(
'<option value="utf8_bin" title="Unicode (multilingual), Binary">',
$result
);
}
/**
* Test for PMA_getHtmlForColumnLength
*
@ -834,24 +674,21 @@ class PMA_TblColumnsDefinitionFormTest extends PHPUnit_Framework_TestCase
*/
public function testGetHtmlForColumnLength()
{
$result = PMA_getHtmlForColumnLength(
2, 3, 1, 10, 8
);
/**
* @todo Find out a better method to test for HTML
* Template: columns_definitions/column_length
*
* $this->assertContains(
* '<input id="field_2_2" type="text" name="field_length[2]" size="10" '
* . 'value="8" class="textfield" />',
* $result
* );
*/
$this->assertContains(
'<p class="enum_notice" id="enum_notice_2_2">',
$result
);
*
* $this->assertContains(
* '<p class="enum_notice" id="enum_notice_2_2">',
* $result
* );
*/
}
/**

View File

@ -1,167 +0,0 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/tbl_gis_visualization.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/tbl_gis_visualization.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';
require_once 'libraries/url_generating.lib.php';
/**
* Tests for libraries/tbl_gis_visualization.lib.php
*
* @package PhpMyAdmin-test
*/
class PMA_TblGisVisualizaionTest 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";
$_REQUEST['unlim_num_rows'] = 100;
$_REQUEST['pos'] = 0;
$_REQUEST['session_max_rows'] = 25;
$GLOBALS['PMA_Config'] = new PMA_MockConfig();
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
}
/**
* Tests for PMA_getHtmlForOptionsList() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForOptionsList()
{
$options= array("option1", "option2");
$select = array("option2");
$html = PMA_getHtmlForOptionsList($options, $select);
$this->assertEquals(
'<option value="option1">option1</option>'
. '<option value="option2" selected="selected" >option2</option>',
$html
);
}
/**
* Tests for PMA_getHtmlForGisVisualization() method.
*
* @return void
* @test
*/
public function testPMAGetHtmlForGisVisualization()
{
$url_params = array("url_params");
$labelCandidates = array("option1", "option2");
$spatialCandidates = array("option2", "option3");
$visualizationSettings = array(
'width' => 10,
'height' => 12,
'labelColumn' => 'labelColumn',
'spatialColumn' => 'spatialColumn',
'choice' => 'choice',
);
$sql_query = "sql_query";
$visualization = "visualization";
$svg_support = array();
$data = array();
$html = PMA_getHtmlForGisVisualization(
$url_params, $labelCandidates, $spatialCandidates,
$visualizationSettings, $sql_query,
$visualization, $svg_support, $data
);
$this->assertContains(
'<legend>' . __('Display GIS Visualization') . '</legend>',
$html
);
/**
* @todo Find out a better method to test for HTML
*
* $this->assertContains(
* PMA_URL_getHiddenInputs($url_params),
* $html
* );
*/
$this->assertContains(
htmlspecialchars($sql_query),
$html
);
$this->assertContains(
'>PNG</a>',
$html
);
$this->assertContains(
'>PDF</a>',
$html
);
$this->assertContains(
htmlspecialchars($visualizationSettings['width']),
$html
);
$this->assertContains(
htmlspecialchars($visualizationSettings['height']),
$html
);
$this->assertContains(
$visualization,
$html
);
}
}
/**
* Mock class for PMA_Config
*
* @package PhpMyAdmin-test
*/
class PMA_MockConfig
{
/**
* isHttps() method.
*
* @return bool
* @test
*/
public function isHttps()
{
return true;
}
}
?>

View File

@ -9,7 +9,6 @@
/*
* Include to test.
*/
require_once 'libraries/tbl_relation.lib.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/database_interface.inc.php';
@ -48,123 +47,6 @@ class PMA_TblRelationTest extends PHPUnit_Framework_TestCase
$GLOBALS['dbi'] = $dbi;
}
/**
* Tests for PMA_generateRelationalDropdown() method.
*
* @return void
* @test
*/
public function testGenerateRelationalDropdown()
{
// test for start tag
$this->assertStringStartsWith(
'<select',
PMA_generateRelationalDropdown('name')
);
// test for end tag
$this->assertStringEndsWith(
'</select>',
PMA_generateRelationalDropdown('name')
);
// test for name
$this->assertStringStartsWith(
'<select name="name"',
PMA_generateRelationalDropdown('name')
);
// test for title
$this->assertStringStartsWith(
'<select name="name" title="title"',
PMA_generateRelationalDropdown('name', array(), false, 'title')
);
$values = array('value1', '<alue2', 'value3');
// test for empty option
$this->assertContains(
'<option value=""></option>',
PMA_generateRelationalDropdown('name', $values)
);
/**
* @todo Find out a better method to test for HTML
*
* // test for options and escaping
* $this->assertContains(
* '<option value="&lt;alue2">&lt;alue2</option>',
* PMA_generateRelationalDropdown('name', $values)
* );
*
* // test for selected option
* $this->assertContains(
* '<option value="value1" selected="selected">value1</option>',
* PMA_generateRelationalDropdown('name', $values, 'value1')
* );
*
* // test for selected value not found in values array and its escaping
* $this->assertContains(
* '<option value="valu&lt;4" selected="selected">valu&lt;4'
* . '</option></select>',
* PMA_generateRelationalDropdown('name', $values, 'valu<4')
* );
*/
}
/**
* Tests for PMA_generateDropdown() method.
*
* @return void
* @test
*/
public function testPMAGenerateDropdown()
{
$dropdown_question = "dropdown_question";
$select_name = "select_name";
$choices = array("choice1", "choice2");
$selected_value = "";
$html_output = PMA_generateDropdown(
$dropdown_question, $select_name, $choices, $selected_value
);
$this->assertContains(
htmlspecialchars($dropdown_question),
$html_output
);
$this->assertContains(
htmlspecialchars($select_name),
$html_output
);
$this->assertContains(
htmlspecialchars("choice1"),
$html_output
);
$this->assertContains(
htmlspecialchars("choice2"),
$html_output
);
}
/**
* Tests for PMA_backquoteSplit() method.
*
* @return void
* @test
*/
public function testPMABackquoteSplit()
{
$text = "test `PMA` Back `quote` Split";
$this->assertEquals(
array('`PMA`', '`quote`'),
PMA_backquoteSplit($text)
);
}
/**
* Tests for PMA_getSQLToCreateForeignKey() method.
*
@ -173,7 +55,8 @@ class PMA_TblRelationTest extends PHPUnit_Framework_TestCase
*/
public function testPMAGetSQLToCreateForeignKey()
{
$table = "PMA_table";
// @todo Move this test to PMA_Table_test
/* $table = "PMA_table";
$field = array("PMA_field1", "PMA_field2");
$foreignDb = "foreignDb";
$foreignTable = "foreignTable";
@ -188,24 +71,7 @@ class PMA_TblRelationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
$sql_excepted,
$sql
);
}
/**
* Tests for PMA_getSQLToDropForeignKey() method.
*
* @return void
* @test
*/
public function testPMAGetSQLToDropForeignKey()
{
$table = "pma_table";
$fk = "pma_fk";
$this->assertEquals(
"ALTER TABLE `pma_table` DROP FOREIGN KEY `pma_fk`;",
PMA_getSQLToDropForeignKey($table, $fk)
);
);*/
}
/**
@ -216,83 +82,19 @@ class PMA_TblRelationTest extends PHPUnit_Framework_TestCase
*/
public function testPMAGetHtmlForCommonForm()
{
$db = "pma_db";
$table = "pma_table";
$columns = array(
array("Field" => "Field1")
);
$cfgRelation = array(
'displaywork' => true,
'relwork' => true,
'displaywork' => true,
);
$tbl_storage_engine = "InnoDB";
$existrel = array();
$existrel_foreign = array();
$options_array = array();
$save_row = array();
foreach ($columns as $row) {
$save_row[] = $row;
}
$html = PMA_getHtmlForCommonForm(
$db, $table, $columns, $cfgRelation,
$tbl_storage_engine, $existrel, $existrel_foreign, $options_array
);
$this->assertContains(
PMA_URL_getHiddenInputs($db, $table),
$html
);
$this->assertContains(
__('Column'),
$html
);
$this->assertContains(
__('Internal relation'),
$html
);
$this->assertContains(
__('Choose column to display:'),
$html
);
/* @todo Find out a better method to test for HTML
* //case 3: PMA_getHtmlForInternalRelationRow
*$row = PMA_getHtmlForInternalRelationRow(
* $save_row, 0, true,
* $existrel, $db
*);
*$this->assertContains(
* $row,
* $html
*);
*/
//case 4: PMA_getHtmlForForeignKeyRow
$row = PMA_getHtmlForForeignKeyRow(
array(), true, $columns, 0,
$options_array, $tbl_storage_engine, $db
);
$this->assertContains(
$row,
$html
);
// @todo Find out a better method to test for HTML
}
/**
* Tests for PMA_getQueryForDisplayUpdate() method.
* @todo Move this test to PMA_Table_test
*
* @return void
* @test
*/
public function testPMAGetQueryForDisplayUpdate()
{
/*
$disp = true;
$display_field = '';
$db = "pma_db";
@ -353,7 +155,7 @@ class PMA_TblRelationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
$query_expect,
$query
);
);*/
}
}