Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,138 @@
<form method="post" action="tbl_relation.php">
<?= PMA_URL_getHiddenInputs($db, $table); ?>
<!-- InnoDB -->
<?php if (PMA\libraries\Util::isForeignKeySupported($tbl_storage_engine)): ?>
<fieldset>
<legend><?= __('Foreign key constraints'); ?></legend>
<table id="foreign_keys" class="relationalTable">
<tr>
<th><?= __('Actions'); ?></th>
<th><?= __('Constraint properties'); ?></th>
<?php if (strtoupper($tbl_storage_engine) == 'INNODB'): ?>
<th><?= __('Column') , PMA\libraries\Util::showHint(__(
'Creating a foreign key over a non-indexed column would automatically create'
. ' an index on it. Alternatively, you can define an index below, before creating'
. ' the foreign key.'
)) ?>
</th>
<?php else: ?>
<th><?= __('Column') , PMA\libraries\Util::showHint(__(
'Only columns with index will be displayed. You can define an'
. ' index below.'
)) ?>
</th>
<?php endif; ?>
<th colspan="3">
<?= __('Foreign key constraint'); ?> (<?= $tbl_storage_engine; ?>)
</th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th><?= __('Database'); ?></th>
<th><?= __('Table'); ?></th>
<th><?= __('Column'); ?></th>
</tr>
<?php $odd_row = true; $i = 0; ?>
<?php if (! empty($existrel_foreign)): ?>
<?php foreach ($existrel_foreign as $key => $one_key): ?>
<?= PMA\libraries\Template::get('table/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 endif; ?>
<?= PMA\libraries\Template::get('table/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">
<a class="formelement clearfloat add_foreign_key" href="">
<?= __('+ Add constraint'); ?>
</td>
</tr>
</table>
</fieldset>
<?php endif; ?>
<?php if ($cfgRelation['relwork']): ?>
<?php if (PMA\libraries\Util::isForeignKeySupported($tbl_storage_engine)): ?>
<br/>
<?= PMA\libraries\Util::getDivForSliderEffect('ir_div', __('Internal relations')) ?>
<?php endif; ?>
<?php $save_row = array_values($columns);
$saved_row_cnt = count($save_row);?>
<fieldset>
<legend><?= __('Internal relations') , PMA\libraries\Util::showDocu('config', 'cfg_Servers_relation'); ?></legend>
<table id="internal_relations" class="relationalTable">
<tr>
<th><?= __('Column'); ?></th>
<th><?= __('Internal relation'); ?>
<?php if (PMA\libraries\Util::isForeignKeySupported($tbl_storage_engine)): ?>
<?= PMA\libraries\Util::showHint(__(
'An internal relation is not necessary when a corresponding'
. ' FOREIGN KEY relation exists.')); ?>
<?php endif; ?>
</th>
<?php $odd_row = true; ?>
<?php for ($i = 0; $i < $saved_row_cnt; $i++): ?>
<?= PMA\libraries\Template::get('table/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>
</fieldset>
<?php if (PMA\libraries\Util::isForeignKeySupported($tbl_storage_engine)): ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if ($cfgRelation['displaywork']): ?>
<?php $save_row = array_values($columns);?>
<?php $disp = PMA_getDisplayField($db, $table); ?>
<fieldset>
<label><?= __('Choose column to display:'); ?></label>
<select name="display_field">
<option value="">---</option>
<?php foreach ($save_row as $row): ?>
<option value="<?= htmlspecialchars($row['Field']); ?>"
<?php if (isset($disp) && $row['Field'] == $disp): ?>
selected="selected"
<?php endif; ?>>
<?= htmlspecialchars($row['Field']); ?>
</option>
<?php endforeach; ?>
</select>
</fieldset>
<?php endif; ?>
<fieldset class="tblFooters">
<input type="button" class="preview_sql" value="<?= __('Preview SQL'); ?>" />
<input type="submit" value="<?= __('Save'); ?>" />
</fieldset>
</form>

View File

@ -0,0 +1,12 @@
<?= (! empty($dropdown_question)
? htmlspecialchars($dropdown_question) . '&nbsp;&nbsp;'
: ''); ?><select name="<?= htmlspecialchars($select_name); ?>">
<?php foreach ($choices as $one_value => $one_label): ?>
<option value="<?= htmlspecialchars($one_value); ?>"
<?php if ($selected_value == $one_value): ?>
selected="selected"
<?php endif; ?>>
<?= htmlspecialchars($one_label); ?>
</option>
<?php endforeach; ?>
</select>

View File

@ -0,0 +1,200 @@
<?php
use PMA\libraries\DatabaseInterface;
use PMA\libraries\Table;
use PMA\libraries\Util;
$js_msg = '';
$this_params = null;
if (isset($one_key['constraint'])) {
$drop_fk_query = 'ALTER TABLE ' . PMA\libraries\Util::backquote($GLOBALS['table'])
. ' DROP FOREIGN KEY '
. PMA\libraries\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 (strtoupper($tbl_storage_engine) == 'INNODB'
|| ! 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'] : '';
$tables_rs = $GLOBALS['dbi']->query(
'SHOW TABLE STATUS FROM ' . Util::backquote($foreign_db),
null,
DatabaseInterface::QUERY_STORE
);
while ($row = $GLOBALS['dbi']->fetchRow($tables_rs)) {
if (isset($row[1])
&& mb_strtoupper($row[1]) == $tbl_storage_engine
) {
$tables[] = $row[0];
}
}
}
?>
<tr class="<?= ($odd_row ? 'odd' : 'even'); ?>">
<!-- Drop key anchor -->
<td>
<?php if (isset($one_key['constraint'])): ?>
<input type="hidden"
class="drop_foreign_key_msg"
value="<?= $js_msg; ?>" />
<a class="drop_foreign_key_anchor ajax"
href="sql.php<?= PMA_URL_getCommon($this_params); ?>" >
<?= PMA\libraries\Util::getIcon('b_drop.png', __('Drop')); ?>
</a>
<?php endif; ?>
</td>
<td>
<span class="formelement clearfloat">
<input type="text" name="constraint_name[<?= $i; ?>]"
value="<?= (isset($one_key['constraint'])) ?
htmlspecialchars($one_key['constraint'])
: ''
?>"
placeholder="<?= __('Constraint name'); ?>"
maxlength="64" />
</span>
<div class="floatleft">
<span class="formelement">
<?= PMA\libraries\Template::get('table/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">
<?= PMA\libraries\Template::get('table/relation/dropdown_generate')->render(
array(
'dropdown_question' => 'ON UPDATE',
'select_name' => 'on_update[' . $i . ']',
'choices' => $options_array,
'selected_value' => $on_update
)
); ?>
</span>
</div>
</td>
<td>
<?php if (isset($one_key['index_list'])): ?>
<?php foreach ($one_key['index_list'] as $key => $column): ?>
<span class="formelement clearfloat">
<?= PMA\libraries\Template::get('table/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">
<?= PMA\libraries\Template::get('table/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"
href=""
data-index="<?= $i; ?>">
<?= __('+ Add column'); ?>
</a>
</td>
<td>
<span class="formelement clearfloat">
<?= PMA\libraries\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_db[' . $i . ']',
'title' => __('Database'),
'values' => $GLOBALS['dblist']->databases,
'foreign' => $foreign_db
)
); ?>
</td>
<td>
<span class="formelement clearfloat">
<?= PMA\libraries\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_table[' . $i . ']',
'title' => __('Table'),
'values' => $tables,
'foreign' => $foreign_table
)
); ?>
</span>
</td>
<td>
<?php if ($foreign_db && $foreign_table): ?>
<?php foreach ($one_key['ref_index_list'] as $foreign_column): ?>
<?php
$table_obj = new Table($foreign_table, $foreign_db);
$columns = $table_obj->getUniqueColumns(false, false);
?>
<span class="formelement clearfloat">
<?= PMA\libraries\Template::get('table/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">
<?= PMA\libraries\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_foreign_column[' . $i . '][]',
'title' => __('Column'),
'values' => array(),
'foreign' => ''
)
); ?>
</span>
<?php endif; ?>
</td>
</tr>

View File

@ -0,0 +1,79 @@
<?php
use PMA\libraries\Table;
$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\libraries\Util::backquote($foreign_db),
null,
PMA\libraries\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 Table($foreign_table, $foreign_db);
$columns = $table_obj->getUniqueColumns(false, false);
}
?>
<tr class="<?= ($odd_row ? 'odd' : 'even'); ?>">
<td class="vmiddle">
<strong><?= $myfield_html; ?></strong>
<input type="hidden" name="fields_name[<?= $myfield_md5; ?>]"
value="<?= $myfield_html; ?>"/>
</td>
<td>
<?= PMA\libraries\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_db[' . $myfield_md5 . ']',
'title' => __('Database'),
'values' => $GLOBALS['dblist']->databases,
'foreign' => $foreign_db
)
); ?>
<?= PMA\libraries\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_table[' . $myfield_md5 . ']',
'title' => __('Table'),
'values' => $tables,
'foreign' => $foreign_table
)
); ?>
<?= PMA\libraries\Template::get('table/relation/relational_dropdown')->render(
array(
'name' => 'destination_column[' . $myfield_md5 . ']',
'title' => __('Column'),
'values' => $columns,
'foreign' => $foreign_column
)
); ?>
</td>
</tr>

View File

@ -0,0 +1,18 @@
<select name="<?= $name; ?>" title="<?= $title; ?>">
<option value=""></option>
<?php $seen_key = false; ?>
<?php foreach ($values as $value): ?>
<option value="<?= htmlspecialchars($value); ?>"
<?php if ($foreign && $value == $foreign): ?>
selected="selected"
<?php $seen_key = true; ?>
<?php endif; ?>>
<?= htmlspecialchars($value); ?>
</option>
<?php endforeach; ?>
<?php if (is_string($foreign) && ! $seen_key): ?>
<option value="<?= htmlspecialchars($foreign); ?>" selected="selected">
<?= htmlspecialchars($foreign); ?>
</option>
<?php endif; ?>
</select>