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
) {
$html_output = htmlspecialchars($dropdown_question) . ' '
. '' . "\n";
return $html_output;
}
/**
* 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 = strlen($text) - 1;
$pos = 0;
while ($pos <= $final_pos) {
$first_backquote = strpos($text, '`', $pos);
$second_backquote = 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 = strpos($text, '`', $second_backquote + 2);
}
if (false === $first_backquote || false === $second_backquote) {
break;
}
$elements[] = 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 string $field field name
* @param string $foreignDb foreign database name
* @param string $foreignTable foreign table name
* @param string $foreignField foreign field name
* @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);
}
$sql_query .= ' FOREIGN KEY (' . PMA_Util::backquote($field) . ')'
. ' REFERENCES ' . PMA_Util::backquote($foreignDb)
. '.' . PMA_Util::backquote($foreignTable)
. '(' . PMA_Util::backquote($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 = ''
) {
$html_output = '';
return $html_output;
}
/**
* 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
) {
$html_output = PMA_getHtmlForCommonFormHeader($db, $table);
if (count($columns) > 0) {
$html_output .= PMA_getHtmlForCommonFormRows(
$columns, $cfgRelation, $tbl_storage_engine,
$existrel, $existrel_foreign, $options_array, $db, $table
);
} // end if (we have columns in this table)
$html_output .= PMA_getHtmlForCommonFormFooter();
return $html_output;
}
/**
* Function to get html for the common form rows
*
* @param array $columns columns
* @param array $cfgRelation configuration relation
* @param string $tbl_storage_engine table storage engine
* @param array $existrel existed relations
* @param array $existrel_foreign existed relations for foreign keys
* @param array $options_array options array
* @param string $db current database
* @param string $table current table
*
* @return string
*/
function PMA_getHtmlForCommonFormRows($columns, $cfgRelation, $tbl_storage_engine,
$existrel, $existrel_foreign, $options_array, $db, $table
) {
foreach ($columns as $row) {
$save_row[] = $row;
}
$saved_row_cnt = count($save_row);
$html_output = '
' . "\n";
if ($cfgRelation['displaywork']) {
$html_output .= PMA_getHtmlForDisplayFieldInfos($db, $table, $save_row);
}
return $html_output;
}
/**
* 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 $cfgRelation configuration relation
* @param array $existrel db, table, column
* @param string $db current db
* @param string $tbl_storage_engine table storage engine
* @param array $existrel_foreign db, table, column
* @param array $options_array options array
*
* @return string
*/
function PMA_getHtmlForRow($save_row, $i, $odd_row, $cfgRelation, $existrel, $db,
$tbl_storage_engine, $existrel_foreign, $options_array
) {
$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);
$html_output = '
'
. '
'
. '' . $myfield_html . ''
. ''
. '
';
if ($cfgRelation['relwork']) {
$html_output .= '
';
} // end if (internal relations)
if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
$html_output .= PMA_getHtmlForForeignKey(
$save_row, $i, $existrel_foreign, $myfield, $db,
$myfield_md5, $tbl_storage_engine, $options_array
);
} // end if (InnoDB)
$html_output .= '
';
return $html_output;
}
/**
* Function to get html for the common form header
*
* @param string $db current database
* @param string $table current table
*
* @return string
*/
function PMA_getHtmlForCommonFormHeader($db, $table)
{
return '';
}
/**
* Function to get html for display field infos
*
* @param string $db current database
* @param string $table current table
* @param array $save_row save row
*
* @return string
*/
function PMA_getHtmlForDisplayFieldInfos($db, $table, $save_row)
{
$disp = PMA_getDisplayField($db, $table);
$html_output = '';
return $html_output;
}
/**
* Function to get html for the common form title headers
*
* @param array $cfgRelation configuration relation
* @param string $tbl_storage_engine table storage engine
*
* @return string
*/
function PMA_getHtmlForCommonFormTableHeaders($cfgRelation, $tbl_storage_engine)
{
$html_output = '
' . __('Column') . '
';
if ($cfgRelation['relwork']) {
$html_output .= '
' . __('Internal relation');
if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
$html_output .= PMA_Util::showHint(
__(
'An internal relation is not necessary when a corresponding'
. ' FOREIGN KEY relation exists.'
)
);
}
$html_output .= '
';
}
if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
// this does not have to be translated, it's part of the MySQL syntax
$html_output .= '