query("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = " . $dbh->quote($this->database()) . " AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote($this->database()) . " AND REFERENCED_TABLE_NAME = " . $dbh->quote($table) . " ORDER BY ORDINAL_POSITION"); //! requires MySQL 5 if ($result) { while ($row = $result->fetch_assoc()) { $return[$row["TABLE_NAME"]][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"]; } $result->free(); } return $return; } function selectQuery($query) { return "\n"; } function rowDescription($table) { $return = ""; // first varchar column foreach (fields($table) as $field) { if ($field["type"] == "varchar") { $return = idf_escape($field["field"]); break; } } return $return; } function rowDescriptions($rows, $foreignKeys) { global $dbh; $return = $rows; foreach ($rows[0] as $key => $val) { foreach ((array) $foreignKeys[$key] as $foreignKey) { if (count($foreignKey["source"]) == 1) { $id = idf_escape($foreignKey["target"][0]); $name = $this->rowDescription($foreignKey["table"]); if (strlen($name)) { // find all used ids $ids = array(); foreach ($rows as $row) { $ids[$row[$key]] = $dbh->quote($row[$key]); } // uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow $descriptions = array(); $result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")"); while ($row = $result->fetch_row()) { $descriptions[$row[0]] = $row[1]; } $result->free(); // use the descriptions foreach ($rows as $n => $row) { $return[$n][$key] = $descriptions[$row[$key]]; } break; } } } } return $return; } function selectVal($val, $link, $field) { $return = ($val == "NULL" ? " " : $val); if (ereg('blob|binary', $field["type"]) && !is_utf8($val)) { $return = lang('%d byte(s)', strlen($val)); if (ereg("^(GIF|\xFF\xD8\xFF|\x89\x50\x4E\x47\x0D\x0A\x1A\x0A)", $val)) { // GIF|JPG|PNG, getimagetype() works with filename $return = "$return"; } } return ($link ? "$return" : $return); } function selectExtraDisplay($emailFields) { global $confirm; if ($emailFields) { echo '
' . lang('E-mail') . "
\n"; } } function selectExtraProcess($where) { global $dbh; if ($_POST["email"]) { $sent = 0; if ($_POST["all"] || $_POST["check"]) { $field = idf_escape($_POST["email_field"]); $result = $dbh->query("SELECT DISTINCT $field FROM " . idf_escape($_GET["select"]) . " WHERE $field IS NOT NULL AND $field != ''" . ($where ? " AND " . implode(" AND ", $where) : "") . ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . "))") ); while ($row = $result->fetch_row()) { if (is_email($row[0]) && mail($row[0], email_header($_POST["email_subject"]), $_POST["email_message"], "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit" . (is_email($_POST["email_from"]) ? "\nFrom: $_POST[email_from]" : "") //! should allow address with a name but simple application of email_header() adds the default server domain )) { $sent++; } } $result->free(); } redirect(remove_from_uri(), lang('%d e-mail(s) have been sent.', $sent)); } return false; } function messageQuery($query) { return ""; } function editFunctions($field) { return (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + array(""); } function editInput($table, $field) { global $dbh; $return = null; $foreign_keys = column_foreign_keys($table); foreach ((array) $foreign_keys[$field["field"]] as $foreign_key) { if (count($foreign_key["source"]) == 1) { $id = idf_escape($foreign_key["target"][0]); $name = $this->rowDescription($foreign_key["table"]); if (strlen($name) && $dbh->result($dbh->query("SELECT COUNT(*) FROM " . idf_escape($foreign_key["table"]))) <= 1000) { // optionlist with more than 1000 options would be too big if ($field["null"]) { $return[""] = ""; } $result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " ORDER BY 2"); while ($row = $result->fetch_row()) { $return[$row[0]] = $row[1]; } $result->free(); break; } } } return $return; } /** Process sent input * @param string field name * @param array single field from fields() * @return string expression to use in a query */ function processInput($name, $field) { global $dbh; $idf = bracket_escape($name); $value = $_POST["fields"][$idf]; $return = $dbh->quote($value); if (!ereg('varchar|text', $field["type"]) && !strlen($value)) { $return = "NULL"; } elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") { $return = $value; } return $return; } function navigation($missing) { global $SELF; if ($missing != "auth") { ?>

">

" . lang('No tables.') . "\n"; } else { echo "

\n"; foreach ($table_status as $row) { $name = $this->tableName($row); if (isset($row["Engine"]) && strlen($name)) { // ignore views and tables without name echo '$name
\n"; } } } } } } }