foreign_key_row.twig 5.8 KB

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