common_form.twig 10 KB

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