common_form.twig
8.8 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<form method="post" action="tbl_relation.php">
{{ Url_getHiddenInputs(db, table) }}
{# InnoDB #}
{% if Util_isForeignKeySupported(tbl_storage_engine) %}
<fieldset>
<legend>{% trans 'Foreign key constraints' %}</legend>
<div class="responsivetable jsresponsive">
<table id="foreign_keys" class="relationalTable">
<thead><tr>
<th>{% trans 'Actions' %}</th>
<th>{% trans 'Constraint properties' %}</th>
{% if tbl_storage_engine|upper == 'INNODB' %}
<th>
{% trans 'Column' %}
{{ 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.'|trans) }}
</th>
{% else %}
<th>
{% trans 'Column' %}
{{ Util_showHint('Only columns with index will be displayed. You can define an index below.'|trans) }}
</th>
{% endif %}
<th colspan="3">
{% trans 'Foreign key constraint' %}
({{ tbl_storage_engine }})
</th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th>{% trans 'Database' %}</th>
<th>{% trans 'Table' %}</th>
<th>{% trans 'Column' %}</th>
</tr></thead>
{% set i = 0 %}
{% if existrel_foreign is not empty %}
{% for key, one_key in existrel_foreign %}
{# Foreign database dropdown #}
{% set foreign_db = one_key['ref_db_name'] is defined
and one_key['ref_db_name'] is not null
? one_key['ref_db_name'] : db %}
{% set foreign_table = false %}
{% if foreign_db %}
{% set foreign_table = one_key['ref_table_name'] is defined
and one_key['ref_table_name'] is not null
? one_key['ref_table_name'] : false %}
{% endif %}
{% set unique_columns = [] %}
{% if foreign_db and foreign_table %}
{% set table_obj = Table_get(foreign_table, foreign_db) %}
{% set unique_columns = table_obj.getUniqueColumns(false, false) %}
{% endif %}
{% include 'table/relation/foreign_key_row.twig' with {
'i': i,
'one_key': one_key,
'column_array': column_array,
'options_array': options_array,
'tbl_storage_engine': tbl_storage_engine,
'db': db,
'table': table,
'url_params': url_params,
'databases': databases,
'foreign_db': foreign_db,
'foreign_table': foreign_table,
'unique_columns': unique_columns
} only %}
{% set i = i + 1 %}
{% endfor %}
{% endif %}
{% include 'table/relation/foreign_key_row.twig' with {
'i': i,
'one_key': [],
'column_array': column_array,
'options_array': options_array,
'tbl_storage_engine': tbl_storage_engine,
'db': db,
'table': table,
'url_params': url_params,
'databases': databases,
'foreign_db': foreign_db,
'foreign_table': foreign_table,
'unique_columns': unique_columns
} only %}
{% set i = i + 1 %}
<tr>
<th colspan="6">
<a class="formelement clearfloat add_foreign_key" href="">
{% trans '+ Add constraint' %}
</td>
</tr>
</table>
</div>
</fieldset>
{% endif %}
{% if cfg_relation['relwork'] %}
{% if Util_isForeignKeySupported(tbl_storage_engine) %}
{{ Util_getDivForSliderEffect('ir_div', 'Internal relationships'|trans) }}
{% endif %}
<fieldset>
<legend>
{% trans 'Internal relationships' %}
{{ Util_showDocu('config', 'cfg_Servers_relation') }}
</legend>
<table id="internal_relations" class="relationalTable">
<tr>
<th>{% trans 'Column' %}</th>
<th>{% trans 'Internal relation' %}
{% if Util_isForeignKeySupported(tbl_storage_engine) %}
{{ Util_showHint('An internal relation is not necessary when a corresponding FOREIGN KEY relation exists.'|trans) }}
{% endif %}
</th>
{% set saved_row_cnt = save_row|length - 1 %}
{% for i in 0..saved_row_cnt %}
{% set myfield = save_row[i]['Field'] %}
{# Use an md5 as array index to avoid having special characters
in the name attribute (see bug #1746964 ) #}
{% set myfield_md5 = md5(myfield) %}
{% set foreign_table = false %}
{% set foreign_column = false %}
{# Database dropdown #}
{% if existrel[myfield] is defined %}
{% set foreign_db = existrel[myfield]['foreign_db'] %}
{% else %}
{% set foreign_db = db %}
{% endif %}
{# Table dropdown #}
{% set tables = [] %}
{% if foreign_db %}
{% if existrel[myfield] is defined %}
{% set foreign_table = existrel[myfield]['foreign_table'] %}
{% endif %}
{% set tables = dbi.getTables(foreign_db) %}
{% endif %}
{# Column dropdown #}
{% set unique_columns = [] %}
{% if foreign_db and foreign_table %}
{% if existrel[myfield] is defined %}
{% set foreign_column = existrel[myfield]['foreign_field'] %}
{% endif %}
{% set table_obj = Table_get(foreign_table, foreign_db) %}
{% set unique_columns = table_obj.getUniqueColumns(false, false) %}
{% endif %}
{% include 'table/relation/internal_relational_row.twig' with {
'myfield': myfield,
'myfield_md5': myfield_md5,
'databases': databases,
'tables': tables,
'columns': unique_columns,
'foreign_db': foreign_db,
'foreign_table': foreign_table,
'foreign_column': foreign_column
} only %}
{% endfor %}
</table>
</fieldset>
{% if Util_isForeignKeySupported(tbl_storage_engine) %}
</div>
{% endif %}
{% endif %}
{% if cfg_relation['displaywork'] %}
{% set disp = Relation_getDisplayField(db, table) %}
<fieldset>
<label>{% trans 'Choose column to display:' %}</label>
<select name="display_field">
<option value="">---</option>
{% for row in save_row %}
<option value="{{ row['Field'] }}"
{%- if disp is defined and row['Field'] == disp %}
selected="selected"
{%- endif %}>
{{ row['Field'] }}
</option>
{% endfor %}
</select>
</fieldset>
{% endif %}
<fieldset class="tblFooters">
<input type="button" class="preview_sql" value="{% trans 'Preview SQL' %}" />
<input type="submit" value="{% trans 'Save' %}" />
</fieldset>
</form>