PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/adminer/inc/adminer/foreign.inc.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 78 lines | 74 code | 4 blank | 0 comment | 23 complexity | c08d4c41c9a70e29e01be4d7e6ec8379 MD5 | raw file
  1. <?php
  2. $TABLE = $_GET["foreign"];
  3. if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) {
  4. if ($_POST["drop"]) {
  5. query_redirect("ALTER TABLE " . table($TABLE) . "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($_GET["name"]), ME . "table=" . urlencode($TABLE), lang('Foreign key has been dropped.'));
  6. } else {
  7. $source = array_filter($_POST["source"], 'strlen');
  8. ksort($source); // enforce input order
  9. $target = array();
  10. foreach ($source as $key => $val) {
  11. $target[$key] = $_POST["target"][$key];
  12. }
  13. query_redirect("ALTER TABLE " . table($TABLE)
  14. . ($_GET["name"] != "" ? "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($_GET["name"]) . "," : "")
  15. . "\nADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . table($_POST["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")" //! reuse $_GET["name"] - check in older MySQL versions
  16. . (ereg("^($on_actions)\$", $_POST["on_delete"]) ? " ON DELETE $_POST[on_delete]" : "")
  17. . (ereg("^($on_actions)\$", $_POST["on_update"]) ? " ON UPDATE $_POST[on_update]" : "")
  18. , ME . "table=" . urlencode($TABLE), ($_GET["name"] != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.')));
  19. $error = lang('Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.') . "<br>$error"; //! no partitioning
  20. }
  21. }
  22. page_header(lang('Foreign key'), $error, array("table" => $TABLE), $TABLE);
  23. $row = array("table" => $TABLE, "source" => array(""));
  24. if ($_POST) {
  25. $row = $_POST;
  26. ksort($row["source"]);
  27. if ($_POST["add"]) {
  28. $row["source"][] = "";
  29. } elseif ($_POST["change"] || $_POST["change-js"]) {
  30. $row["target"] = array();
  31. }
  32. } elseif ($_GET["name"] != "") {
  33. $foreign_keys = foreign_keys($TABLE);
  34. $row = $foreign_keys[$_GET["name"]];
  35. $row["source"][] = "";
  36. }
  37. $source = array_keys(fields($TABLE)); //! no text and blob
  38. $target = ($TABLE === $row["table"] ? $source : array_keys(fields($row["table"])));
  39. $referencable = array();
  40. foreach (table_status() as $name => $table_status) {
  41. if (fk_support($table_status)) {
  42. $referencable[] = $name;
  43. }
  44. }
  45. ?>
  46. <form action="" method="post">
  47. <p>
  48. <?php if ($row["db"] == "" && $row["ns"] == "") { ?>
  49. <?php echo lang('Target table'); ?>:
  50. <?php echo html_select("table", $referencable, $row["table"], "this.form['change-js'].value = '1'; this.form.submit();"); ?>
  51. <input type="hidden" name="change-js" value="">
  52. <noscript><p><input type="submit" name="change" value="<?php echo lang('Change'); ?>"></noscript>
  53. <table cellspacing="0">
  54. <thead><tr><th><?php echo lang('Source'); ?><th><?php echo lang('Target'); ?></thead>
  55. <?php
  56. $j = 0;
  57. foreach ($row["source"] as $key => $val) {
  58. echo "<tr>";
  59. echo "<td>" . html_select("source[" . (+$key) . "]", array(-1 => "") + $source, $val, ($j == count($row["source"]) - 1 ? "foreignAddRow(this);" : 1));
  60. echo "<td>" . html_select("target[" . (+$key) . "]", $target, $row["target"][$key]);
  61. $j++;
  62. }
  63. ?>
  64. </table>
  65. <p>
  66. <?php echo lang('ON DELETE'); ?>: <?php echo html_select("on_delete", array(-1 => "") + explode("|", $on_actions), $row["on_delete"]); ?>
  67. <?php echo lang('ON UPDATE'); ?>: <?php echo html_select("on_update", array(-1 => "") + explode("|", $on_actions), $row["on_update"]); ?>
  68. <p>
  69. <input type="submit" value="<?php echo lang('Save'); ?>">
  70. <noscript><p><input type="submit" name="add" value="<?php echo lang('Add column'); ?>"></noscript>
  71. <?php } ?>
  72. <?php if ($_GET["name"] != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo confirm(); ?>><?php } ?>
  73. <input type="hidden" name="token" value="<?php echo $token; ?>">
  74. </form>