common_form.twig 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. {% extends 'table/page_with_secondary_tabs.twig' %}
  2. {% block content %}
  3. <form method="post" action="{{ url('/table/relation') }}">
  4. {{ get_hidden_inputs(db, table) }}
  5. {# InnoDB #}
  6. {% if is_foreign_key_supported(tbl_storage_engine) %}
  7. <fieldset>
  8. <legend>{% trans 'Foreign key constraints' %}</legend>
  9. <div class="table-responsive-md jsresponsive">
  10. <table class="relationalTable table table-light table-striped w-auto">
  11. <thead class="thead-light">
  12. <tr>
  13. <th>{% trans 'Actions' %}</th>
  14. <th>{% trans 'Constraint properties' %}</th>
  15. {% if tbl_storage_engine|upper == 'INNODB' %}
  16. <th>
  17. {% trans 'Column' %}
  18. {{ show_hint('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) }}
  19. </th>
  20. {% else %}
  21. <th>
  22. {% trans 'Column' %}
  23. {{ show_hint('Only columns with index will be displayed. You can define an index below.'|trans) }}
  24. </th>
  25. {% endif %}
  26. <th colspan="3">
  27. {% trans 'Foreign key constraint' %}
  28. ({{ tbl_storage_engine }})
  29. </th>
  30. </tr>
  31. <tr>
  32. <th></th>
  33. <th></th>
  34. <th></th>
  35. <th>{% trans 'Database' %}</th>
  36. <th>{% trans 'Table' %}</th>
  37. <th>{% trans 'Column' %}</th>
  38. </tr></thead>
  39. {% set i = 0 %}
  40. {% if existrel_foreign is not empty %}
  41. {% for key, one_key in existrel_foreign %}
  42. {# Foreign database dropdown #}
  43. {% set foreign_db = one_key['ref_db_name'] is defined
  44. and one_key['ref_db_name'] is not null
  45. ? one_key['ref_db_name'] : db %}
  46. {% set foreign_table = false %}
  47. {% if foreign_db %}
  48. {% set foreign_table = one_key['ref_table_name'] is defined
  49. and one_key['ref_table_name'] is not null
  50. ? one_key['ref_table_name'] : false %}
  51. {% endif %}
  52. {% set unique_columns = [] %}
  53. {% if foreign_db and foreign_table %}
  54. {% set table_obj = table_get(foreign_table, foreign_db) %}
  55. {% set unique_columns = table_obj.getUniqueColumns(false, false) %}
  56. {% endif %}
  57. {% include 'table/relation/foreign_key_row.twig' with {
  58. 'i': i,
  59. 'one_key': one_key,
  60. 'column_array': column_array,
  61. 'options_array': options_array,
  62. 'tbl_storage_engine': tbl_storage_engine,
  63. 'db': db,
  64. 'table': table,
  65. 'url_params': url_params,
  66. 'databases': databases,
  67. 'foreign_db': foreign_db,
  68. 'foreign_table': foreign_table,
  69. 'unique_columns': unique_columns
  70. } only %}
  71. {% set i = i + 1 %}
  72. {% endfor %}
  73. {% endif %}
  74. {% include 'table/relation/foreign_key_row.twig' with {
  75. 'i': i,
  76. 'one_key': [],
  77. 'column_array': column_array,
  78. 'options_array': options_array,
  79. 'tbl_storage_engine': tbl_storage_engine,
  80. 'db': db,
  81. 'table': table,
  82. 'url_params': url_params,
  83. 'databases': databases,
  84. 'foreign_db': foreign_db,
  85. 'foreign_table': foreign_table,
  86. 'unique_columns': unique_columns
  87. } only %}
  88. {% set i = i + 1 %}
  89. <tr>
  90. <th colspan="6">
  91. <a class="formelement clearfloat add_foreign_key" href="">
  92. {% trans '+ Add constraint' %}
  93. </a>
  94. </th>
  95. </tr>
  96. </table>
  97. </div>
  98. </fieldset>
  99. {% endif %}
  100. {% if cfg_relation['relwork'] %}
  101. {% if is_foreign_key_supported(tbl_storage_engine) %}
  102. <div id="ir_div"{% if default_sliders_state != 'disabled' -%}
  103. {{- default_sliders_state == 'closed' ? ' style="display: none; overflow:auto;"' }} class="pma_auto_slider" title="{% trans 'Internal relationships' %}"
  104. {%- endif %}>
  105. {% endif %}
  106. <fieldset>
  107. <legend>
  108. {% trans 'Internal relationships' %}
  109. {{ show_docu('config', 'cfg_Servers_relation') }}
  110. </legend>
  111. <table class="relationalTable table table-light table-striped table-hover table-sm w-auto">
  112. <thead class="thead-light">
  113. <tr>
  114. <th>{% trans 'Column' %}</th>
  115. <th>
  116. {% trans 'Internal relation' %}
  117. {% if is_foreign_key_supported(tbl_storage_engine) %}
  118. {{ show_hint('An internal relation is not necessary when a corresponding FOREIGN KEY relation exists.'|trans) }}
  119. {% endif %}
  120. </th>
  121. </tr>
  122. </thead>
  123. <tbody>
  124. {% set saved_row_cnt = save_row|length - 1 %}
  125. {% for i in 0..saved_row_cnt %}
  126. {% set myfield = save_row[i]['Field'] %}
  127. {# Use an md5 as array index to avoid having special characters
  128. in the name attribute (see bug #1746964 ) #}
  129. {% set myfield_md5 = column_hash_array[myfield] %}
  130. {% set foreign_table = false %}
  131. {% set foreign_column = false %}
  132. {# Database dropdown #}
  133. {% if existrel[myfield] is defined %}
  134. {% set foreign_db = existrel[myfield]['foreign_db'] %}
  135. {% else %}
  136. {% set foreign_db = db %}
  137. {% endif %}
  138. {# Table dropdown #}
  139. {% set tables = [] %}
  140. {% if foreign_db %}
  141. {% if existrel[myfield] is defined %}
  142. {% set foreign_table = existrel[myfield]['foreign_table'] %}
  143. {% endif %}
  144. {% set tables = dbi.getTables(foreign_db) %}
  145. {% endif %}
  146. {# Column dropdown #}
  147. {% set unique_columns = [] %}
  148. {% if foreign_db and foreign_table %}
  149. {% if existrel[myfield] is defined %}
  150. {% set foreign_column = existrel[myfield]['foreign_field'] %}
  151. {% endif %}
  152. {% set table_obj = table_get(foreign_table, foreign_db) %}
  153. {% set unique_columns = table_obj.getUniqueColumns(false, false) %}
  154. {% endif %}
  155. <tr>
  156. <td class="vmiddle">
  157. <strong>{{ myfield }}</strong>
  158. <input type="hidden" name="fields_name[{{ myfield_md5 }}]"
  159. value="{{ myfield }}">
  160. </td>
  161. <td>
  162. {% include 'table/relation/relational_dropdown.twig' with {
  163. 'name': 'destination_db[' ~ myfield_md5 ~ ']',
  164. 'title': 'Database'|trans,
  165. 'values': databases,
  166. 'foreign': foreign_db
  167. } only %}
  168. {% include 'table/relation/relational_dropdown.twig' with {
  169. 'name': 'destination_table[' ~ myfield_md5 ~ ']',
  170. 'title': 'Table'|trans,
  171. 'values': tables,
  172. 'foreign': foreign_table
  173. } only %}
  174. {% include 'table/relation/relational_dropdown.twig' with {
  175. 'name': 'destination_column[' ~ myfield_md5 ~ ']',
  176. 'title': 'Column'|trans,
  177. 'values': unique_columns,
  178. 'foreign': foreign_column
  179. } only %}
  180. </td>
  181. </tr>
  182. {% endfor %}
  183. </tbody>
  184. </table>
  185. </fieldset>
  186. {% if is_foreign_key_supported(tbl_storage_engine) %}
  187. </div>
  188. {% endif %}
  189. {% endif %}
  190. {% if cfg_relation['displaywork'] %}
  191. {% set disp = get_display_field(db, table) %}
  192. <fieldset>
  193. <label>{% trans 'Choose column to display:' %}</label>
  194. <select name="display_field">
  195. <option value="">---</option>
  196. {% for row in save_row %}
  197. <option value="{{ row['Field'] }}"
  198. {%- if disp is defined and row['Field'] == disp %}
  199. selected="selected"
  200. {%- endif %}>
  201. {{ row['Field'] }}
  202. </option>
  203. {% endfor %}
  204. </select>
  205. </fieldset>
  206. {% endif %}
  207. <fieldset class="tblFooters">
  208. <input class="btn btn-secondary preview_sql" type="button" value="{% trans 'Preview SQL' %}">
  209. <input class="btn btn-primary" type="submit" value="{% trans 'Save' %}">
  210. </fieldset>
  211. </form>
  212. {% endblock %}