Example #1
0
     if ($indexes) {
         echo "<table cellspacing='0'>\n";
         foreach ($indexes as $name => $index) {
             ksort($index["columns"]);
             // enforce correct columns order
             $print = array();
             foreach ($index["columns"] as $key => $val) {
                 $print[] = "<i>" . h($val) . "</i>" . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "") . ($index["descs"][$key] ? " DESC" : "");
             }
             echo "<tr title='" . h($name) . "'><th>{$index['type']}<td>" . implode(", ", $print) . "\n";
         }
         echo "</table>\n";
     }
     echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
 }
 if (fk_support($table_status)) {
     echo "<h3 id='foreign-keys'>" . lang('Foreign keys') . "</h3>\n";
     $foreign_keys = foreign_keys($TABLE);
     if ($foreign_keys) {
         echo "<table cellspacing='0'>\n";
         echo "<thead><tr><th>" . lang('Source') . "<td>" . lang('Target') . "<td>" . lang('ON DELETE') . "<td>" . lang('ON UPDATE') . "<td>&nbsp;</thead>\n";
         foreach ($foreign_keys as $name => $foreign_key) {
             echo "<tr title='" . h($name) . "'>";
             echo "<th><i>" . implode("</i>, <i>", array_map('h', $foreign_key["source"])) . "</i>";
             echo "<td><a href='" . h($foreign_key["db"] != "" ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), ME) : ($foreign_key["ns"] != "" ? preg_replace('~ns=[^&]*~', "ns=" . urlencode($foreign_key["ns"]), ME) : ME)) . "table=" . urlencode($foreign_key["table"]) . "'>" . ($foreign_key["db"] != "" ? "<b>" . h($foreign_key["db"]) . "</b>." : "") . ($foreign_key["ns"] != "" ? "<b>" . h($foreign_key["ns"]) . "</b>." : "") . h($foreign_key["table"]) . "</a>";
             echo "(<i>" . implode("</i>, <i>", array_map('h', $foreign_key["target"])) . "</i>)";
             echo "<td>" . nbsp($foreign_key["on_delete"]) . "\n";
             echo "<td>" . nbsp($foreign_key["on_update"]) . "\n";
             echo '<td><a href="' . h(ME . 'foreign=' . urlencode($TABLE) . '&name=' . urlencode($name)) . '">' . lang('Alter') . '</a>';
         }
         echo "</table>\n";
Example #2
0
/** Get referencable tables with single column primary key except self
* @param string
* @return array ($table_name => $field)
*/
function referencable_primary($self)
{
    $return = array();
    // table_name => field
    foreach (table_status('', true) as $table_name => $table) {
        if ($table_name != $self && fk_support($table)) {
            foreach (fields($table_name) as $field) {
                if ($field["primary"]) {
                    if ($return[$table_name]) {
                        // multi column primary key
                        unset($return[$table_name]);
                        break;
                    }
                    $return[$table_name] = $field;
                }
            }
        }
    }
    return $return;
}