foreign_key_row.twig 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_str = Util_getIcon('b_drop', 'Drop'|trans) %}
  30. {{ Util_linkOrButton('sql.php', this_params, drop_str, {'class': 'drop_foreign_key_anchor ajax'}) }}
  31. {% endif %}
  32. </td>
  33. <td>
  34. <span class="formelement clearfloat">
  35. <input type="text" name="constraint_name[{{ i }}]" value="
  36. {{- one_key['constraint'] is defined ? one_key['constraint'] -}}
  37. " placeholder="{% trans 'Constraint name' %}" maxlength="64" />
  38. </span>
  39. <div class="floatleft">
  40. {# For ON DELETE and ON UPDATE, the default action
  41. is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE
  42. won't display the clause if it's set as RESTRICT. #}
  43. {% set on_delete = one_key['on_delete'] is defined
  44. ? one_key['on_delete'] : 'RESTRICT' %}
  45. {% set on_update = one_key['on_update'] is defined
  46. ? one_key['on_update'] : 'RESTRICT' %}
  47. <span class="formelement">
  48. {% include 'table/relation/dropdown_generate.twig' with {
  49. 'dropdown_question': 'ON DELETE',
  50. 'select_name': 'on_delete[' ~ i ~ ']',
  51. 'choices': options_array,
  52. 'selected_value': on_delete
  53. } only %}
  54. </span>
  55. <span class="formelement">
  56. {% include 'table/relation/dropdown_generate.twig' with {
  57. 'dropdown_question': 'ON UPDATE',
  58. 'select_name': 'on_update[' ~ i ~ ']',
  59. 'choices': options_array,
  60. 'selected_value': on_update
  61. } only %}
  62. </span>
  63. </div>
  64. </td>
  65. <td>
  66. {% if one_key['index_list'] is defined %}
  67. {% for key, column in one_key['index_list'] %}
  68. <span class="formelement clearfloat">
  69. {% include 'table/relation/dropdown_generate.twig' with {
  70. 'dropdown_question': '',
  71. 'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
  72. 'choices': column_array,
  73. 'selected_value': column
  74. } only %}
  75. </span>
  76. {% endfor %}
  77. {% else %}
  78. <span class="formelement clearfloat">
  79. {% include 'table/relation/dropdown_generate.twig' with {
  80. 'dropdown_question': '',
  81. 'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
  82. 'choices': column_array,
  83. 'selected_value': ''
  84. } only %}
  85. </span>
  86. {% endif %}
  87. <a class="formelement clearfloat add_foreign_key_field" data-index="
  88. {{- i }}" href="">
  89. {% trans '+ Add column' %}
  90. </a>
  91. </td>
  92. {% set tables = [] %}
  93. {% if foreign_db %}
  94. {% set tables = Relation_getTables(foreign_db, tbl_storage_engine) %}
  95. {% endif %}
  96. <td>
  97. <span class="formelement clearfloat">
  98. {% include 'table/relation/relational_dropdown.twig' with {
  99. 'name': 'destination_foreign_db[' ~ i ~ ']',
  100. 'title': 'Database'|trans,
  101. 'values': databases,
  102. 'foreign': foreign_db
  103. } only %}
  104. </span>
  105. </td>
  106. <td>
  107. <span class="formelement clearfloat">
  108. {% include 'table/relation/relational_dropdown.twig' with {
  109. 'name': 'destination_foreign_table[' ~ i ~ ']',
  110. 'title': 'Table'|trans,
  111. 'values': tables,
  112. 'foreign': foreign_table
  113. } only %}
  114. </span>
  115. </td>
  116. <td>
  117. {% if foreign_db and foreign_table %}
  118. {% for foreign_column in one_key['ref_index_list'] %}
  119. <span class="formelement clearfloat">
  120. {% include 'table/relation/relational_dropdown.twig' with {
  121. 'name': 'destination_foreign_column[' ~ i ~ '][]',
  122. 'title': 'Column'|trans,
  123. 'values': unique_columns,
  124. 'foreign': foreign_column
  125. } only %}
  126. </span>
  127. {% endfor %}
  128. {% else %}
  129. <span class="formelement clearfloat">
  130. {% include 'table/relation/relational_dropdown.twig' with {
  131. 'name': 'destination_foreign_column[' ~ i ~ '][]',
  132. 'title': 'Column'|trans,
  133. 'values': [],
  134. 'foreign': ''
  135. } only %}
  136. </span>
  137. {% endif %}
  138. </td>
  139. </tr>