common_form.twig 8.8 KB

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