1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<tr>
{# Drop key anchor #}
<td>
{% set js_msg = '' %}
{% set this_params = null %}
{% if one_key['constraint'] is defined %}
{% set drop_fk_query = 'ALTER TABLE ' ~ Util_backquote(db) ~ '.' ~ Util_backquote(table)
~ ' DROP FOREIGN KEY '
~ Util_backquote(one_key['constraint']) ~ ';'
%}
{% set this_params = url_params %}
{% set this_params = {
'goto': 'tbl_relation.php',
'back': 'tbl_relation.php',
'sql_query': drop_fk_query,
'message_to_show': 'Foreign key constraint %s has been dropped'|trans|format(
one_key['constraint']
)
} %}
{% set js_msg = Sanitize_jsFormat(
'ALTER TABLE ' ~ db ~ '.' ~ table
~ ' DROP FOREIGN KEY '
~ one_key['constraint'] ~ ';'
) %}
{% endif %}
{% if one_key['constraint'] is defined %}
<input type="hidden" class="drop_foreign_key_msg" value="
{{- js_msg }}" />
{% set drop_url = 'sql.php' ~ Url_getCommon(this_params) %}
{% set drop_str = Util_getIcon('b_drop', 'Drop'|trans) %}
{{ Util_linkOrButton(drop_url, drop_str, {'class': 'drop_foreign_key_anchor ajax'}) }}
{% endif %}
</td>
<td>
<span class="formelement clearfloat">
<input type="text" name="constraint_name[{{ i }}]" value="
{{- one_key['constraint'] is defined ? one_key['constraint'] -}}
" placeholder="{% trans 'Constraint name' %}" maxlength="64" />
</span>
<div class="floatleft">
{# 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. #}
{% set on_delete = one_key['on_delete'] is defined
? one_key['on_delete'] : 'RESTRICT' %}
{% set on_update = one_key['on_update'] is defined
? one_key['on_update'] : 'RESTRICT' %}
<span class="formelement">
{% include 'table/relation/dropdown_generate.twig' with {
'dropdown_question': 'ON DELETE',
'select_name': 'on_delete[' ~ i ~ ']',
'choices': options_array,
'selected_value': on_delete
} only %}
</span>
<span class="formelement">
{% include 'table/relation/dropdown_generate.twig' with {
'dropdown_question': 'ON UPDATE',
'select_name': 'on_update[' ~ i ~ ']',
'choices': options_array,
'selected_value': on_update
} only %}
</span>
</div>
</td>
<td>
{% if one_key['index_list'] is defined %}
{% for key, column in one_key['index_list'] %}
<span class="formelement clearfloat">
{% include 'table/relation/dropdown_generate.twig' with {
'dropdown_question': '',
'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
'choices': column_array,
'selected_value': column
} only %}
</span>
{% endfor %}
{% else %}
<span class="formelement clearfloat">
{% include 'table/relation/dropdown_generate.twig' with {
'dropdown_question': '',
'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
'choices': column_array,
'selected_value': ''
} only %}
</span>
{% endif %}
<a class="formelement clearfloat add_foreign_key_field" data-index="
{{- i }}" href="">
{% trans '+ Add column' %}
</a>
</td>
{% set tables = [] %}
{% if foreign_db %}
{% set tables = Relation_getTables(foreign_db, tbl_storage_engine) %}
{% endif %}
<td>
<span class="formelement clearfloat">
{% include 'table/relation/relational_dropdown.twig' with {
'name': 'destination_foreign_db[' ~ i ~ ']',
'title': 'Database'|trans,
'values': databases,
'foreign': foreign_db
} only %}
</span>
</td>
<td>
<span class="formelement clearfloat">
{% include 'table/relation/relational_dropdown.twig' with {
'name': 'destination_foreign_table[' ~ i ~ ']',
'title': 'Table'|trans,
'values': tables,
'foreign': foreign_table
} only %}
</span>
</td>
<td>
{% if foreign_db and foreign_table %}
{% for foreign_column in one_key['ref_index_list'] %}
<span class="formelement clearfloat">
{% include 'table/relation/relational_dropdown.twig' with {
'name': 'destination_foreign_column[' ~ i ~ '][]',
'title': 'Column'|trans,
'values': unique_columns,
'foreign': foreign_column
} only %}
</span>
{% endfor %}
{% else %}
<span class="formelement clearfloat">
{% include 'table/relation/relational_dropdown.twig' with {
'name': 'destination_foreign_column[' ~ i ~ '][]',
'title': 'Column'|trans,
'values': [],
'foreign': ''
} only %}
</span>
{% endif %}
</td>
</tr>