Esempio n. 1
0
/**
 * Inserts existing entries in a PMA_* table by reading a value from an old entry
 *
 * @param   string  The array index, which Relation feature to check
 *                  ('relwork', 'commwork', ...)
 * @param   string  The array index, which PMA-table to update
 *                  ('bookmark', 'relation', ...)
 * @param   array   Which fields will be SELECT'ed from the old entry
 * @param   array   Which fields will be used for the WHERE query
 *                  (array('FIELDNAME' => 'FIELDVALUE'))
 * @param   array   Which fields will be used as new VALUES. These are the important
 *                  keys which differ from the old entry.
 *                  (array('FIELDNAME' => 'NEW FIELDVALUE'))
 * @global  string  relation variable
 *
 * @author          Garvin Hicking <*****@*****.**>
 */
function PMA_duplicate_table($work, $pma_table, $get_fields, $where_fields, $new_fields)
{
    global $cfgRelation;
    $last_id = -1;
    if ($cfgRelation[$work]) {
        $select_parts = array();
        $row_fields = array();
        foreach ($get_fields as $nr => $get_field) {
            $select_parts[] = PMA_backquote($get_field);
            $row_fields[$get_field] = 'cc';
        }
        $where_parts = array();
        foreach ($where_fields as $_where => $_value) {
            $where_parts[] = PMA_backquote($_where) . ' = \'' . PMA_sqlAddslashes($_value) . '\'';
        }
        $new_parts = array();
        $new_value_parts = array();
        foreach ($new_fields as $_where => $_value) {
            $new_parts[] = PMA_backquote($_where);
            $new_value_parts[] = PMA_sqlAddslashes($_value);
        }
        $table_copy_query = 'SELECT ' . implode(', ', $select_parts) . ' FROM ' . PMA_backquote($cfgRelation[$pma_table]) . ' WHERE ' . implode(' AND ', $where_parts);
        $table_copy_rs = PMA_query_as_cu($table_copy_query);
        while ($table_copy_row = @PMA_mysql_fetch_array($table_copy_rs)) {
            $value_parts = array();
            foreach ($table_copy_row as $_key => $_val) {
                if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') {
                    $value_parts[] = PMA_sqlAddslashes($_val);
                }
            }
            $new_table_query = 'INSERT IGNORE INTO ' . PMA_backquote($cfgRelation[$pma_table]) . ' (' . implode(', ', $select_parts) . ', ' . implode(', ', $new_parts) . ')' . ' VALUES ' . ' (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')';
            $new_table_rs = PMA_query_as_cu($new_table_query);
            $last_id = @function_exists('mysql_insert_id') ? @mysql_insert_id() : -1;
        }
        // end while
        return $last_id;
    }
    return true;
}
Esempio n. 2
0
/**
 * Displays the privileges form table
 *
 * @param   string     the database
 * @param   string     the table
 * @param   boolean    wheather to display the submit button or not
 * @param   int        the indenting level of the code
 *
 * @global  array      the phpMyAdmin configuration
 * @global  ressource  the database connection
 *
 * @return  void
 */
function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0)
{
    global $cfg, $userlink;
    if ($db == '*') {
        $table = '*';
    }
    $spaces = '';
    for ($i = 0; $i < $indent; $i++) {
        $spaces .= '    ';
    }
    if (isset($GLOBALS['username'])) {
        $username = $GLOBALS['username'];
        $hostname = $GLOBALS['hostname'];
        if ($db == '*') {
            $sql_query = 'SELECT * FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";';
        } else {
            if ($table == '*') {
                $sql_query = 'SELECT * FROM `db` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '";';
            } else {
                $sql_query = 'SELECT `Table_priv` FROM `tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";';
            }
        }
        $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
        if ($res) {
            $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
        }
        @mysql_free_result($res);
    }
    if (empty($row)) {
        if ($table == '*') {
            if ($db == '*') {
                $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
            } else {
                if ($table == '*') {
                    $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
                }
            }
            $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
            while ($row1 = PMA_mysql_fetch_row($res)) {
                if (substr($row1[0], 0, 4) == 'max_') {
                    $row[$row1[0]] = 0;
                } else {
                    $row[$row1[0]] = 'N';
                }
            }
            mysql_free_result($res);
        } else {
            $row = array('Table_priv' => '');
        }
    }
    if (isset($row['Table_priv'])) {
        $sql_query = 'SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";';
        $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
        unset($sql_query);
        $row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC);
        mysql_free_result($res);
        $av_grants = explode('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
        unset($row1);
        $users_grants = explode(',', $row['Table_priv']);
        foreach ($av_grants as $current_grant) {
            $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N';
        }
        unset($row['Table_priv']);
        unset($current_grant);
        unset($av_grants);
        unset($users_grants);
        if ($res = PMA_mysql_query('SHOW COLUMNS FROM `' . $db . '`.`' . $table . '`;', $userlink)) {
            $columns = array();
            while ($row1 = PMA_mysql_fetch_row($res)) {
                $columns[$row1[0]] = array('Select' => FALSE, 'Insert' => FALSE, 'Update' => FALSE, 'References' => FALSE);
            }
            mysql_free_result($res);
            unset($res);
            unset($row1);
        }
    }
    if (!empty($columns)) {
        $sql_query = 'SELECT `Column_name`, `Column_priv` FROM `columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";';
        $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query);
        while ($row1 = PMA_mysql_fetch_row($res)) {
            $row1[1] = explode(',', $row1[1]);
            foreach ($row1[1] as $current) {
                $columns[$row1[0]][$current] = TRUE;
            }
        }
        mysql_free_result($res);
        unset($res);
        unset($row1);
        unset($current);
        echo $spaces . '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n" . $spaces . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n" . $spaces . '<table border="0">' . "\n" . $spaces . '    <tr>' . "\n" . $spaces . '        <th colspan="6">&nbsp;' . $GLOBALS['strTblPrivileges'] . '&nbsp;</th>' . "\n" . $spaces . '    </tr>' . "\n" . $spaces . '    <tr>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></td>' . "\n" . $spaces . '    </tr>' . "\n" . $spaces . '    <tr>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescSelect'] . '">SELECT</dfn></tt>&nbsp;</td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescInsert'] . '">INSERT</dfn></tt>&nbsp;</td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescUpdate'] . '">UPDATE</dfn></tt>&nbsp;</td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '">&nbsp;<tt><dfn title="' . $GLOBALS['strPrivDescReferences'] . '">REFERENCES</dfn></tt>&nbsp;</td>' . "\n";
        list($current_grant, $current_grant_value) = each($row);
        while (in_array(substr($current_grant, 0, strlen($current_grant) - 5), array('Select', 'Insert', 'Update', 'References'))) {
            list($current_grant, $current_grant_value) = each($row);
        }
        echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5) . 'Tbl']) . '"/></td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n" . $spaces . '    </tr>' . "\n" . $spaces . '    <tr>' . "\n";
        $rowspan = count($row) - 5;
        echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n" . $spaces . '            <select name="Select_priv[]" multiple="multiple">' . "\n";
        foreach ($columns as $current_column => $current_column_privileges) {
            echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
            if ($row['Select_priv'] == 'Y' || $current_column_privileges['Select']) {
                echo ' selected="selected"';
            }
            echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
        }
        echo $spaces . '            </select><br />' . "\n" . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n" . $spaces . '            <input type="checkbox" name="Select_priv_none" id="checkbox_Select_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n" . $spaces . '            <label for="checkbox_Select_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n" . $spaces . '        </td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n" . $spaces . '            <select name="Insert_priv[]" multiple="multiple">' . "\n";
        foreach ($columns as $current_column => $current_column_privileges) {
            echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
            if ($row['Insert_priv'] == 'Y' || $current_column_privileges['Insert']) {
                echo ' selected="selected"';
            }
            echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
        }
        echo $spaces . '            </select><br />' . "\n" . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n" . $spaces . '            <input type="checkbox" name="Insert_priv_none" id="checkbox_Insert_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n" . $spaces . '            <label for="checkbox_Insert_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n" . $spaces . '        </td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n" . $spaces . '            <select name="Update_priv[]" multiple="multiple">' . "\n";
        foreach ($columns as $current_column => $current_column_privileges) {
            echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
            if ($row['Update_priv'] == 'Y' || $current_column_privileges['Update']) {
                echo ' selected="selected"';
            }
            echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
        }
        echo $spaces . '            </select><br />' . "\n" . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n" . $spaces . '            <input type="checkbox" name="Update_priv_none" id="checkbox_Update_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n" . $spaces . '            <label for="checkbox_Update_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n" . $spaces . '        </td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" rowspan="' . $rowspan . '" valign="top">' . "\n" . $spaces . '            <select name="References_priv[]" multiple="multiple">' . "\n";
        foreach ($columns as $current_column => $current_column_privileges) {
            echo $spaces . '                <option value="' . htmlspecialchars($current_column) . '"';
            if ($row['References_priv'] == 'Y' || $current_column_privileges['References']) {
                echo ' selected="selected"';
            }
            echo '>' . htmlspecialchars($current_column) . '</option>' . "\n";
        }
        echo $spaces . '            </select><br />' . "\n" . $spaces . '            <i>' . $GLOBALS['strOr'] . '</i><br />' . "\n" . $spaces . '            <input type="checkbox" name="References_priv_none" id="checkbox_References_priv_none" title="' . $GLOBALS['strNone'] . '" />' . "\n" . $spaces . '            <label for="checkbox_References_priv_none">' . $GLOBALS['strNone'] . '</label>' . "\n" . $spaces . '        </td>' . "\n";
        unset($rowspan);
        list($current_grant, $current_grant_value) = each($row);
        while (in_array(substr($current_grant, 0, strlen($current_grant) - 5), array('Select', 'Insert', 'Update', 'References'))) {
            list($current_grant, $current_grant_value) = each($row);
        }
        echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5) . 'Tbl']) . '"/></td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n" . $spaces . '    </tr>' . "\n";
        while (list($current_grant, $current_grant_value) = each($row)) {
            if (in_array(substr($current_grant, 0, strlen($current_grant) - 5), array('Select', 'Insert', 'Update', 'References'))) {
                continue;
            }
            echo $spaces . '    <tr>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $current_grant . '" id="checkbox_' . $current_grant . '" value="Y" ' . ($current_grant_value == 'Y' ? 'checked="checked" ' : '') . 'title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5) . 'Tbl']) . '"/></td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)]) ? $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5)] : $GLOBALS['strPrivDesc' . substr($current_grant, 0, strlen($current_grant) - 5) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label></td>' . "\n" . $spaces . '    </tr>' . "\n";
        }
    } else {
        $privTable[0] = array(array('Select', 'SELECT', $GLOBALS['strPrivDescSelect']), array('Insert', 'INSERT', $GLOBALS['strPrivDescInsert']), array('Update', 'UPDATE', $GLOBALS['strPrivDescUpdate']), array('Delete', 'DELETE', $GLOBALS['strPrivDescDelete']));
        if ($db == '*') {
            $privTable[0][] = array('File', 'FILE', $GLOBALS['strPrivDescFile']);
        }
        $privTable[1] = array(array('Create', 'CREATE', $table == '*' ? $GLOBALS['strPrivDescCreateDb'] : $GLOBALS['strPrivDescCreateTbl']), array('Alter', 'ALTER', $GLOBALS['strPrivDescAlter']), array('Index', 'INDEX', $GLOBALS['strPrivDescIndex']), array('Drop', 'DROP', $table == '*' ? $GLOBALS['strPrivDescDropDb'] : $GLOBALS['strPrivDescDropTbl']));
        if (isset($row['Create_tmp_table_priv'])) {
            $privTable[1][] = array('Create_tmp_table', 'CREATE&nbsp;TEMPORARY&nbsp;TABLES', $GLOBALS['strPrivDescCreateTmpTable']);
        }
        $privTable[2] = array();
        if (isset($row['Grant_priv'])) {
            $privTable[2][] = array('Grant', 'GRANT', $GLOBALS['strPrivDescGrant']);
        }
        if ($db == '*') {
            if (isset($row['Super_priv'])) {
                $privTable[2][] = array('Super', 'SUPER', $GLOBALS['strPrivDescSuper']);
                $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess4']);
            } else {
                $privTable[2][] = array('Process', 'PROCESS', $GLOBALS['strPrivDescProcess3']);
            }
            $privTable[2][] = array('Reload', 'RELOAD', $GLOBALS['strPrivDescReload']);
            $privTable[2][] = array('Shutdown', 'SHUTDOWN', $GLOBALS['strPrivDescShutdown']);
            if (isset($row['Show_db_priv'])) {
                $privTable[2][] = array('Show_db', 'SHOW&nbsp;DATABASES', $GLOBALS['strPrivDescShowDb']);
            }
        }
        if (isset($row['Lock_tables_priv'])) {
            $privTable[2][] = array('Lock_tables', 'LOCK&nbsp;TABLES', $GLOBALS['strPrivDescLockTables']);
        }
        $privTable[2][] = array('References', 'REFERENCES', $GLOBALS['strPrivDescReferences']);
        if ($db == '*') {
            if (isset($row['Execute_priv'])) {
                $privTable[2][] = array('Execute', 'EXECUTE', $GLOBALS['strPrivDescExecute']);
            }
            if (isset($row['Repl_client_priv'])) {
                $privTable[2][] = array('Repl_client', 'REPLICATION&nbsp;CLIENT', $GLOBALS['strPrivDescReplClient']);
            }
            if (isset($row['Repl_slave_priv'])) {
                $privTable[2][] = array('Repl_slave', 'REPLICATION&nbsp;SLAVE', $GLOBALS['strPrivDescReplSlave']);
            }
        }
        echo $spaces . '<input type="hidden" name="grant_count" value="' . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0)) . '" />' . "\n" . $spaces . '<table border="0">' . "\n" . $spaces . '    <tr>' . "\n" . $spaces . '        <th colspan="6">&nbsp;' . ($db == '*' ? $GLOBALS['strGlobalPrivileges'] : ($table == '*' ? $GLOBALS['strDbPrivileges'] : $GLOBALS['strTblPrivileges'])) . '&nbsp;</th>' . "\n" . $spaces . '    </tr>' . "\n" . $spaces . '    <tr>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="6"><small><i>' . $GLOBALS['strEnglishPrivileges'] . '</i></small></td>' . "\n" . $spaces . '    </tr>' . "\n" . $spaces . '    <tr>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2">&nbsp;<b><i>' . $GLOBALS['strData'] . '</i></b>&nbsp;</td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2">&nbsp;<b><i>' . $GLOBALS['strStructure'] . '</i></b>&nbsp;</td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="2">&nbsp;<b><i>' . $GLOBALS['strAdministration'] . '</i></b>&nbsp;</td>' . "\n" . $spaces . '    </tr>' . "\n";
        $limitTable = FALSE;
        for ($i = 0; isset($privTable[0][$i]) || isset($privTable[1][$i]) || isset($privTable[2][$i]); $i++) {
            echo $spaces . '    <tr>' . "\n";
            for ($j = 0; $j < 3; $j++) {
                if (isset($privTable[$j][$i])) {
                    echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="checkbox" name="' . $privTable[$j][$i][0] . '_priv" id="checkbox_' . $privTable[$j][$i][0] . '_priv" value="Y" ' . ($row[$privTable[$j][$i][0] . '_priv'] == 'Y' ? 'checked="checked" ' : '') . 'title="' . $privTable[$j][$i][2] . '"/></td>' . "\n" . $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="checkbox_' . $privTable[$j][$i][0] . '_priv"><tt><dfn title="' . $privTable[$j][$i][2] . '">' . $privTable[$j][$i][1] . '</dfn></tt></label></td>' . "\n";
                } else {
                    if ($db == '*' && !isset($privTable[0][$i]) && !isset($privTable[1][$i]) && isset($row['max_questions']) && isset($row['max_updates']) && isset($row['max_connections']) && !$limitTable) {
                        echo $spaces . '        <td colspan="4" rowspan="' . (count($privTable[2]) - $i) . '">' . "\n" . $spaces . '            <table border="0">' . "\n" . $spaces . '                <tr>' . "\n" . $spaces . '                    <th colspan="2">&nbsp;' . $GLOBALS['strResourceLimits'] . '&nbsp;</th>' . "\n" . $spaces . '                </tr>' . "\n" . $spaces . '                <tr>' . "\n" . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2"><small><i>' . $GLOBALS['strZeroRemovesTheLimit'] . '</i></small></td>' . "\n" . $spaces . '                </tr>' . "\n" . $spaces . '                <tr>' . "\n" . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_questions"><tt><dfn title="' . $GLOBALS['strPrivDescMaxQuestions'] . '">MAX&nbsp;QUERIES&nbsp;PER&nbsp;HOUR</dfn></tt></label></td>' . "\n" . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_questions" id="text_max_questions" value="' . $row['max_questions'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxQuestions'] . '" /></td>' . "\n" . $spaces . '                </tr>' . "\n" . $spaces . '                <tr>' . "\n" . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_updates"><tt><dfn title="' . $GLOBALS['strPrivDescMaxUpdates'] . '">MAX&nbsp;UPDATES&nbsp;PER&nbsp;HOUR</dfn></tt></label></td>' . "\n" . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_updates" id="text_max_updates" value="' . $row['max_updates'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxUpdates'] . '" /></td>' . "\n" . $spaces . '                </tr>' . "\n" . $spaces . '                <tr>' . "\n" . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><label for="text_max_connections"><tt><dfn title="' . $GLOBALS['strPrivDescMaxConnections'] . '">MAX&nbsp;CONNECTIONS&nbsp;PER&nbsp;HOUR</dfn></tt></label></td>' . "\n" . $spaces . '                    <td bgcolor="' . $cfg['BgcolorTwo'] . '"><input type="text" class="textfield" name="max_connections" id="text_max_connections" value="' . $row['max_connections'] . '" size="11" maxlength="11" title="' . $GLOBALS['strPrivDescMaxConnections'] . '" /></td>' . "\n" . $spaces . '                </tr>' . "\n" . $spaces . '            </table>' . "\n" . $spaces . '        </td>' . "\n";
                        $limitTable = TRUE;
                    } else {
                        if (!$limitTable) {
                            echo $spaces . '        <td bgcolor="' . $cfg['BgcolorTwo'] . '" colspan="2">&nbsp;</td>' . "\n";
                        }
                    }
                }
            }
        }
        echo $spaces . '    </tr>' . "\n";
    }
    if ($submit) {
        echo $spaces . '    <tr>' . "\n" . $spaces . '        <td colspan="6" align="center">' . "\n" . $spaces . '            <input type="submit" name="update_privs" value="' . $GLOBALS['strGo'] . '" />' . "\n" . $spaces . '        </td>' . "\n" . $spaces . '    </tr>' . "\n";
    }
    echo $spaces . '</table>' . "\n";
}
Esempio n. 3
0
            ?>
                    </select>
                </td>
                <td bgcolor="<?php 
            echo $bgcolor;
            ?>
">
            <?php 
            // <*****@*****.**>
            $field = $fields_list[$i];
            // do not use require_once here
            require './libraries/get_foreign.lib.php';
            echo "\n";
            // we got a bug report: in some cases, even if $disp is true,
            // there are no rows, so we add a fetch_array
            if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp && @PMA_mysql_fetch_array($disp)) {
                // f o r e i g n    k e y s
                echo '                    <select name="fields[]">' . "\n";
                // go back to first row
                mysql_data_seek($disp, 0);
                echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100);
                echo '                    </select>' . "\n";
            } else {
                if (isset($foreign_link) && $foreign_link == true) {
                    ?>
            <input type="text"   name="fields[]" id="field_<?php 
                    echo md5($field);
                    ?>
[]" class="textfield" />
            <script type="text/javascript" language="javascript">
                document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php?<?php 
Esempio n. 4
0
            foreach ($array_sh_page as $key => $temp_sh_page) {
                $drag_x = $temp_sh_page['x'];
                $drag_y = $temp_sh_page['y'];
                $draginit .= '    Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
                $draginit .= '    getElement("table_' . $i . '").onDrag = function (x, y) { document.edcoord.elements["c_table_' . $i . '[x]"].value = parseInt(x); document.edcoord.elements["c_table_' . $i . '[y]"].value = parseInt(y) }' . "\n";
                $draginit .= '    getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
                $draginit .= '    getElement("table_' . $i . '").style.top  = "' . $drag_y . 'px";' . "\n";
                $reset_draginit .= '    getElement("table_' . $i . '").style.left = "2px";' . "\n";
                $reset_draginit .= '    getElement("table_' . $i . '").style.top  = "' . 15 * $i . 'px";' . "\n";
                $reset_draginit .= '    document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
                $reset_draginit .= '    document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . 15 * $i . '"' . "\n";
                $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($temp_sh_page['table_name']) . ' FROM ' . PMA_backquote($db);
                $fields_rs = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
                $fields_cnt = mysql_num_rows($fields_rs);
                echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
                while ($row = PMA_mysql_fetch_array($fields_rs)) {
                    echo "<br>" . htmlspecialchars($row['Field']) . "\n";
                }
                echo '</div>' . "\n";
                mysql_free_result($fields_rs);
                $i++;
            }
            ?>
</div>
<script type="text/javascript">
<!--
function init() {
    refreshLayout();
    myid = getElement('pdflayout');
    <?php 
            echo $draginit;
Esempio n. 5
0
/**
 * Displays the body of the results table
 *
 * @param   integer  the link id associated to the query which results have
 *                   to be displayed
 * @param   array    which elements to display
 * @param   array    the list of relations
 * @param   array    the analyzed query
 *
 * @return  boolean  always true
 *
 * @global  string   the current language
 * @global  string   the current charset for MySQL
 * @global  integer  the server to use (refers to the number in the
 *                   configuration file)
 * @global  string   the database name
 * @global  string   the table name
 * @global  string   the sql query
 * @global  string   the url to go back in case of errors
 * @global  integer  the current position in results
 * @global  integer  the maximum number of rows per page
 * @global  array    the list of fields properties
 * @global  integer  the total number of fields returned by the sql query
 * @global  array    informations used with vertical display mode
 * @global  string   the display mode (horizontal/vertical/horizontalflipped)
 * @global  integer  the number of row to display between two table headers
 * @global  boolean  whether to limit the number of displayed characters of
 *                   text type fields or not
 *
 * @access  private
 *
 * @see     PMA_displayTable()
 */
function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
{
    global $lang, $convcharset, $server, $db, $table;
    global $goto;
    global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
    global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
    global $dontlimitchars;
    global $row;
    // mostly because of browser transformations, to make the row-data accessible in a plugin
    if (!is_array($map)) {
        $map = array();
    }
    ?>
<!-- Results table body -->
    <?php 
    echo "\n";
    $row_no = 0;
    $vertical_display['edit'] = array();
    $vertical_display['delete'] = array();
    $vertical_display['data'] = array();
    $vertical_display['row_delete'] = array();
    // Correction uva 19991216 in the while below
    // Previous code assumed that all tables have keys, specifically that
    // the phpMyAdmin GUI should support row delete/edit only for such
    // tables.
    // Although always using keys is arguably the prescribed way of
    // defining a relational table, it is not required. This will in
    // particular be violated by the novice.
    // We want to encourage phpMyAdmin usage by such novices. So the code
    // below has been changed to conditionally work as before when the
    // table being displayed has one or more keys; but to display
    // delete/edit options correctly for tables without keys.
    // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
    //        to get the NULL values
    while ($row = PMA_mysql_fetch_array($dt_result)) {
        // lem9: "vertical display" mode stuff
        if ($row_no != 0 && $repeat_cells != 0 && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
            echo '<tr>' . "\n";
            for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
                echo '    <td>&nbsp;</td>' . "\n";
            }
            foreach ($vertical_display['desc'] as $key => $val) {
                echo $val;
            }
            for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
                echo '    <td>&nbsp;</td>' . "\n";
            }
            echo '</tr>' . "\n";
        }
        // end if
        if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
            $bgcolor = '#ffffff';
        } else {
            $bgcolor = $row_no % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
        }
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            // loic1: pointer code part
            $on_mouse = '';
            if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
                if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
                    $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"' . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
                }
                if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
                    $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
                }
            }
            // end if
            ?>
<tr<?php 
            echo $on_mouse;
            ?>
>
            <?php 
            echo "\n";
        }
        // 1. Prepares the row (gets primary keys to use)
        if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
            $primary_key = '';
            $unique_key = '';
            $uva_nonprimary_condition = '';
            // 1.1 Results from a "SELECT" statement -> builds the
            //     "primary" key to use in links
            if ($is_display['edit_lnk'] == 'ur') {
                for ($i = 0; $i < $fields_cnt; ++$i) {
                    $field_flags = PMA_mysql_field_flags($dt_result, $i);
                    $meta = $fields_meta[$i];
                    // do not use an alias in a condition
                    $column_for_condition = $meta->name;
                    if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
                        foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) {
                            $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
                            if (!empty($alias)) {
                                $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
                                if ($alias == $meta->name) {
                                    $column_for_condition = $true_column;
                                }
                                // end if
                            }
                            // end if
                        }
                        // end while
                    }
                    // to fix the bug where float fields (primary or not)
                    // can't be matched because of the imprecision of
                    // floating comparison, use CONCAT
                    // (also, the syntax "CONCAT(field) IS NULL"
                    // that we need on the next "if" will work)
                    if ($meta->type == 'real') {
                        $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') ';
                    } else {
                        $condition = ' ' . PMA_backquote($column_for_condition) . ' ';
                    }
                    // end if... else...
                    // loic1: To fix bug #474943 under php4, the row
                    //        pointer will depend on whether the "is_null"
                    //        php4 function is available or not
                    $pointer = function_exists('is_null') ? $i : $meta->name;
                    if (!isset($row[$meta->name]) || function_exists('is_null') && is_null($row[$pointer])) {
                        $condition .= 'IS NULL AND';
                    } else {
                        if ($meta->type == 'blob' && stristr($field_flags, 'BINARY') && !empty($row[$pointer])) {
                            $condition .= 'LIKE 0x' . bin2hex($row[$pointer]) . ' AND';
                        } else {
                            $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer], FALSE, TRUE) . '\' AND';
                        }
                    }
                    if ($meta->primary_key > 0) {
                        $primary_key .= $condition;
                    } else {
                        if ($meta->unique_key > 0) {
                            $unique_key .= $condition;
                        }
                    }
                    $uva_nonprimary_condition .= $condition;
                }
                // end for
                // Correction uva 19991216: prefer primary or unique keys
                // for condition, but use conjunction of all values if no
                // primary key
                if ($primary_key) {
                    $uva_condition = $primary_key;
                } else {
                    if ($unique_key) {
                        $uva_condition = $unique_key;
                    } else {
                        $uva_condition = $uva_nonprimary_condition;
                    }
                }
                $uva_condition = urlencode(preg_replace('|\\s?AND$|', '', $uva_condition));
            }
            // end if (1.1)
            // 1.2 Defines the urls for the modify/delete link(s)
            $url_query = PMA_generate_common_url($db, $table) . '&amp;pos=' . $pos . '&amp;session_max_rows=' . $session_max_rows . '&amp;disp_direction=' . $disp_direction . '&amp;repeat_cells=' . $repeat_cells . '&amp;dontlimitchars=' . $dontlimitchars;
            // We need to copy the value or else the == 'both' check will always return true
            $propicon = (string) $GLOBALS['cfg']['PropertiesIconic'];
            if ($propicon == 'both') {
                $iconic_spacer = '<nobr>';
            } else {
                $iconic_spacer = '';
            }
            // 1.2.1 Modify link(s)
            if ($is_display['edit_lnk'] == 'ur') {
                // update row case
                //                    $lnk_goto = 'sql.php'
                //                             . '?' . str_replace('&amp;', '&', $url_query)
                //                              . '&sql_query=' . urlencode($sql_query)
                //                              . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
                // to reduce the length of the URL, because of some browsers limitations:
                $lnk_goto = 'sql.php';
                $edit_url = 'tbl_change.php' . '?' . $url_query . '&amp;primary_key=' . $uva_condition . '&amp;sql_query=' . urlencode($sql_query) . '&amp;goto=' . urlencode($lnk_goto);
                if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
                    $edit_str = $GLOBALS['strEdit'];
                } else {
                    $edit_str = $iconic_spacer . '<img width="12" height="13" src="images/button_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" border="0" />';
                    if ($propicon == 'both') {
                        $edit_str .= '&nbsp;' . $GLOBALS['strEdit'] . '</nobr>';
                    }
                }
            }
            // end if (1.2.1)
            if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db']) {
                $bookmark_go = '<a href="read_dump.php?' . PMA_generate_common_url($row['dbase'], '') . '&amp;id_bookmark=' . $row['id'] . '&amp;action_bookmark=0' . '&amp;action_bookmark_all=1' . '&amp;SQL=' . $GLOBALS['strExecuteBookmarked'] . ' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
                if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
                    $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
                } else {
                    $bookmark_go .= $iconic_spacer . '<img width="12" height="13" src="images/button_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" border="0" />';
                    if ($propicon == 'both') {
                        $bookmark_go .= '&nbsp;' . $GLOBALS['strExecuteBookmarked'] . '</nobr>';
                    }
                }
                $bookmark_go .= '</a>';
            } else {
                $bookmark_go = '';
            }
            // 1.2.2 Delete/Kill link(s)
            if ($is_display['del_lnk'] == 'dr') {
                // delete row case
                $lnk_goto = 'sql.php' . '?' . str_replace('&amp;', '&', $url_query) . '&sql_query=' . urlencode($sql_query) . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
                $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . '+LIMIT+1';
                $del_url = 'sql.php' . '?' . $url_query . '&amp;sql_query=' . $del_query . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&amp;goto=' . urlencode($lnk_goto);
                $js_conf = 'DELETE FROM ' . PMA_jsFormat($table) . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE)) . ' LIMIT 1';
                if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
                    $del_str = $GLOBALS['strDelete'];
                } else {
                    $del_str = $iconic_spacer . '<img width="12" height="13" src="images/button_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" border="0" />';
                    if ($propicon == 'both') {
                        $del_str .= '&nbsp;' . $GLOBALS['strDelete'] . '</nobr>';
                    }
                }
            } else {
                if ($is_display['del_lnk'] == 'kp') {
                    // kill process case
                    $lnk_goto = 'sql.php' . '?' . str_replace('&amp;', '&', $url_query) . '&sql_query=' . urlencode($sql_query) . '&goto=main.php';
                    $del_url = 'sql.php?' . PMA_generate_common_url('mysql') . '&amp;sql_query=' . urlencode('KILL ' . $row['Id']) . '&amp;goto=' . urlencode($lnk_goto);
                    $del_query = urlencode('KILL ' . $row['Id']);
                    $js_conf = 'KILL ' . $row['Id'];
                    if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
                        $del_str = $GLOBALS['strKill'];
                    } else {
                        $del_str = $iconic_spacer . '<img width="12" height="13" src="images/button_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" border="0" />';
                        if ($propicon == 'both') {
                            $del_str .= '&nbsp;' . $GLOBALS['strKill'] . '</nobr>';
                        }
                    }
                }
            }
            // end if (1.2.2)
            // 1.3 Displays the links at left if required
            if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
                require './libraries/display_tbl_links.lib.php';
            }
            // end if (1.3)
            echo $disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped' ? "\n" : '';
        }
        // end if (1)
        // 2. Displays the rows' values
        for ($i = 0; $i < $fields_cnt; ++$i) {
            $meta = $fields_meta[$i];
            // loic1: To fix bug #474943 under php4, the row pointer will
            //        depend on whether the "is_null" php4 function is
            //        available or not
            $pointer = function_exists('is_null') ? $i : $meta->name;
            // garvin: See if this column should get highlight because it's used in the
            //  where-query.
            if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
                $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
            } else {
                $column_style = '';
            }
            // garvin: Wrap MIME-transformations. [MIME]
            $default_function = 'default_function';
            // default_function
            $transform_function = $default_function;
            $transform_options = array();
            if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
                if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
                    $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
                    if (file_exists('./libraries/transformations/' . $include_file)) {
                        $transformfunction_name = preg_replace('@(\\.inc\\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
                        require_once './libraries/transformations/' . $include_file;
                        if (function_exists('PMA_transformation_' . $transformfunction_name)) {
                            $transform_function = 'PMA_transformation_' . $transformfunction_name;
                            $transform_options = PMA_transformation_getOptions(isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : '');
                            $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
                        }
                    }
                    // end if file_exists
                }
                // end if transformation is set
            }
            // end if mime/transformation works.
            $transform_options['wrapper_link'] = '?' . (isset($url_query) ? $url_query : '') . '&amp;primary_key=' . (isset($uva_condition) ? $uva_condition : '') . '&amp;sql_query=' . (isset($sql_query) ? urlencode($sql_query) : '') . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '') . '&amp;transform_key=' . urlencode($meta->name);
            // n u m e r i c
            if ($meta->numeric == 1) {
                // lem9: if two fields have the same name (this is possible
                //       with self-join queries, for example), using $meta->name
                //       will show both fields NULL even if only one is NULL,
                //       so use the $pointer
                //      (works only if function_exists('is_null')
                // PS:   why not always work with the number ($i), since
                //       the default second parameter of
                //       mysql_fetch_array() is MYSQL_BOTH, so we always get
                //       associative and numeric indices?
                //if (!isset($row[$meta->name])
                if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) {
                    $vertical_display['data'][$row_no][$i] = '    <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
                } else {
                    if ($row[$pointer] != '') {
                        $vertical_display['data'][$row_no][$i] = '    <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '" nowrap="nowrap">';
                        if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
                            foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) {
                                $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
                                if (!empty($alias)) {
                                    $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
                                    if ($alias == $meta->name) {
                                        $meta->name = $true_column;
                                    }
                                    // end if
                                }
                                // end if
                            }
                            // end while
                        }
                        if (isset($map[$meta->name])) {
                            // Field to display from the foreign table?
                            if (!empty($map[$meta->name][2])) {
                                $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer];
                                $dispresult = PMA_mysql_query($dispsql);
                                if ($dispresult && mysql_num_rows($dispresult) > 0) {
                                    $dispval = PMA_mysql_result($dispresult, 0);
                                } else {
                                    $dispval = $GLOBALS['strLinkNotFound'];
                                }
                            } else {
                                $dispval = '';
                            }
                            // end if... else...
                            if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
                                $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
                            } else {
                                $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : '';
                                $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?' . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>' . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . '</a>';
                            }
                        } else {
                            $vertical_display['data'][$row_no][$i] .= $transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta);
                        }
                        $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
                    } else {
                        $vertical_display['data'][$row_no][$i] = '    <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '" nowrap="nowrap">&nbsp;</td>' . "\n";
                    }
                }
                //  b l o b
            } else {
                if ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) {
                    // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
                    // TEXT fields type, however TEXT fields must be displayed
                    // even if $cfg['ShowBlob'] is false -> get the true type
                    // of the fields.
                    $field_flags = PMA_mysql_field_flags($dt_result, $i);
                    if (stristr($field_flags, 'BINARY')) {
                        $blobtext = '[BLOB';
                        if (isset($row[$pointer])) {
                            $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1);
                            $blobtext .= ' - ' . $blob_size[0] . ' ' . $blob_size[1];
                            unset($blob_size);
                        }
                        $blobtext .= ']';
                        $blobtext = $default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta);
                        $vertical_display['data'][$row_no][$i] = '    <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
                    } else {
                        //if (!isset($row[$meta->name])
                        if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) {
                            $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
                        } else {
                            if ($row[$pointer] != '') {
                                // garvin: if a transform function for blob is set, none of these replacements will be made
                                if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && $dontlimitchars != 1) {
                                    $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
                                }
                                // loic1: displays all space characters, 4 space
                                // characters for tabulations and <cr>/<lf>
                                $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta);
                                $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
                            } else {
                                $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
                            }
                        }
                    }
                } else {
                    //if (!isset($row[$meta->name])
                    if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) {
                        $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
                    } else {
                        if ($row[$pointer] != '') {
                            // loic1: support blanks in the key
                            $relation_id = $row[$pointer];
                            // nijel: Cut all fields to $cfg['LimitChars']
                            if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && $dontlimitchars != 1) {
                                $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
                            }
                            // loic1: displays special characters from binaries
                            $field_flags = PMA_mysql_field_flags($dt_result, $i);
                            if (stristr($field_flags, 'BINARY')) {
                                $row[$pointer] = str_replace("", '\\0', $row[$pointer]);
                                $row[$pointer] = str_replace("", '\\b', $row[$pointer]);
                                $row[$pointer] = str_replace("\n", '\\n', $row[$pointer]);
                                $row[$pointer] = str_replace("\r", '\\r', $row[$pointer]);
                                $row[$pointer] = str_replace("", '\\Z', $row[$pointer]);
                                $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta);
                            } else {
                                $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta);
                            }
                            // garvin: transform functions may enable nowrapping:
                            $function_nowrap = $transform_function . '_nowrap';
                            $bool_nowrap = $default_function != $transform_function && function_exists($function_nowrap) ? $function_nowrap($transform_options) : false;
                            // loic1: do not wrap if date field type
                            $nowrap = preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap ? ' nowrap="nowrap"' : '';
                            $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
                            if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
                                foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) {
                                    $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
                                    if (!empty($alias)) {
                                        $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
                                        if ($alias == $meta->name) {
                                            $meta->name = $true_column;
                                        }
                                        // end if
                                    }
                                    // end if
                                }
                                // end while
                            }
                            if (isset($map[$meta->name])) {
                                // Field to display from the foreign table?
                                if (!empty($map[$meta->name][2])) {
                                    $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\'';
                                    $dispresult = @PMA_mysql_query($dispsql);
                                    if ($dispresult && mysql_num_rows($dispresult) > 0) {
                                        $dispval = PMA_mysql_result($dispresult, 0);
                                    } else {
                                        $dispval = $GLOBALS['strLinkNotFound'];
                                    }
                                } else {
                                    $dispval = '';
                                }
                                $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : '';
                                $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?' . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>' . $row[$pointer] . '</a>';
                            } else {
                                $vertical_display['data'][$row_no][$i] .= $row[$pointer];
                            }
                            $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
                        } else {
                            $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
                        }
                    }
                }
            }
            // lem9: output stored cell
            if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
                echo $vertical_display['data'][$row_no][$i];
            }
            if (isset($vertical_display['rowdata'][$i][$row_no])) {
                $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
            } else {
                $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
            }
        }
        // end for (2)
        // 3. Displays the modify/delete links on the right if required
        if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
            require './libraries/display_tbl_links.lib.php';
        }
        // end if (3)
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            echo "\n";
            ?>
</tr>
            <?php 
        }
        // end if
        // 4. Gather links of del_urls and edit_urls in an array for later
        //    output
        if (!isset($vertical_display['edit'][$row_no])) {
            $vertical_display['edit'][$row_no] = '';
            $vertical_display['delete'][$row_no] = '';
            $vertical_display['row_delete'][$row_no] = '';
        }
        if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
            $vertical_display['row_delete'][$row_no] .= '    <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . '        <input type="checkbox" id="id_rows_to_delete' . $row_no . '" name="rows_to_delete[' . $uva_condition . ']" value="' . $del_query . '" />' . "\n" . '    </td>' . "\n";
        } else {
            unset($vertical_display['row_delete'][$row_no]);
        }
        if (isset($edit_url)) {
            $vertical_display['edit'][$row_no] .= '    <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . PMA_linkOrButton($edit_url, $edit_str, '') . $bookmark_go . '    </td>' . "\n";
        } else {
            unset($vertical_display['edit'][$row_no]);
        }
        if (isset($del_url)) {
            $vertical_display['delete'][$row_no] .= '    <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . PMA_linkOrButton($del_url, $del_str, isset($js_conf) ? $js_conf : '') . '    </td>' . "\n";
        } else {
            unset($vertical_display['delete'][$row_no]);
        }
        echo $disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped' ? "\n" : '';
        $row_no++;
    }
    // end while
    if (isset($url_query)) {
        $GLOBALS['url_query'] = $url_query;
    }
    return TRUE;
}
Esempio n. 6
0
 if ($num_dbs == 1) {
     $db = $dblist[0];
     $tables = @PMA_mysql_list_tables($db);
     $num_tables = $tables ? @mysql_numrows($tables) : 0;
     $common_url_query = PMA_generate_common_url($db);
     if ($num_tables) {
         $num_tables_disp = $num_tables;
     } else {
         $num_tables_disp = '-';
     }
     // Get additional infomation about tables for tooltip
     if ($cfg['ShowTooltip'] && PMA_MYSQL_INT_VERSION >= 32303 && $num_tables) {
         $tooltip = array();
         $tooltip_name = array();
         $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db));
         while ($tmp = PMA_mysql_fetch_array($result)) {
             $tooltip_name[$tmp['Name']] = !empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '';
             $tmp['Comment'] = $cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : $tmp['Comment'];
             $tooltip[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '') . '(' . (isset($tmp['Rows']) ? $tmp['Rows'] : '0') . ' ' . $strRows . ')';
         }
         // end while
     }
     // end if
     // garvin: Get comments from PMA comments table
     $db_tooltip = '';
     if ($cfg['ShowTooltip'] && $cfgRelation['commwork']) {
         $tmp_db_tooltip = PMA_getComments($db);
         if (is_array($tmp_db_tooltip)) {
             $db_tooltip = implode(' ', $tmp_db_tooltip);
         }
     }
/**
* Set a single mimetype to a certain value.
*
* @param   string   the name of the db
* @param   string   the name of the table
* @param   string   the name of the column
* @param   string   the mimetype of the column
* @param   string   the transformation of the column
* @param   string   the transformation options of the column
* @param   string   (optional) force delete, will erase any existing comments for this column
*
* @return  boolean  true, if comment-query was made.
*
* @global  array    the list of relations settings
*
* @access  public
*/
function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false)
{
    global $cfgRelation;
    $test_qry = 'SELECT mimetype, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
    $test_rs = PMA_query_as_cu($test_qry);
    if ($test_rs && mysql_num_rows($test_rs) > 0) {
        $row = @PMA_mysql_fetch_array($test_rs);
        if (!$forcedelete && (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0 || strlen($row['comment']) > 0)) {
            $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) . ' SET mimetype = \'' . PMA_sqlAddslashes($mimetype) . '\',' . '     transformation = \'' . PMA_sqlAddslashes($transformation) . '\',' . '     transformation_options = \'' . PMA_sqlAddslashes($transformation_options) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
        } else {
            $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
        }
    } else {
        if (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) {
            $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($key) . '\',' . '\'' . PMA_sqlAddslashes($mimetype) . '\',' . '\'' . PMA_sqlAddslashes($transformation) . '\',' . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
        }
    }
    if (isset($upd_query)) {
        $upd_rs = PMA_query_as_cu($upd_query);
        unset($upd_query);
        return true;
    } else {
        return false;
    }
}
                        $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\'';
                        $sts_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
                        $sts_tmp = PMA_mysql_fetch_array($sts_result);
                        $tables[] = $sts_tmp;
                    } else {
                        // table in use
                        $tables[] = array('Name' => $tmp[0]);
                    }
                }
                mysql_free_result($db_info_result);
                $sot_ready = TRUE;
            }
        }
    }
}
if (!isset($sot_ready)) {
    $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db);
    $db_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
    if ($db_info_result != FALSE && mysql_num_rows($db_info_result) > 0) {
        while ($sts_tmp = PMA_mysql_fetch_array($db_info_result)) {
            $tables[] = $sts_tmp;
        }
        mysql_free_result($db_info_result);
    }
}
$num_tables = isset($tables) ? count($tables) : 0;
/**
 * Displays top menu links
 */
echo '<!-- Top menu links -->' . "\n";
require './db_details_links.php';
Esempio n. 9
0
/**
 * Outputs the content of a table
 *
 * @param   string      the database name
 * @param   string      the table name
 * @param   string      the end of line sequence
 * @param   string      the url to go back in case of error
 * @param   string      SQL query for obtaining data
 *
 * @return  bool        Whether it suceeded
 *
 * @access  public
 */
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
    $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
    $columns_cnt = mysql_num_fields($result);
    for ($i = 0; $i < $columns_cnt; $i++) {
        $columns[$i] = stripslashes(mysql_field_name($result, $i));
    }
    unset($i);
    $buffer = '  <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
    if (!PMA_exportOutputHandler($buffer)) {
        return FALSE;
    }
    while ($record = PMA_mysql_fetch_array($result, MYSQL_ASSOC)) {
        $buffer = '    <' . $table . '>' . $crlf;
        for ($i = 0; $i < $columns_cnt; $i++) {
            // There is no way to dectect a "NULL" value with PHP3
            if (isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) {
                $buffer .= '        <' . $columns[$i] . '>' . htmlspecialchars(stripslashes($record[$columns[$i]])) . '</' . $columns[$i] . '>' . $crlf;
            }
        }
        $buffer .= '    </' . $table . '>' . $crlf;
        if (!PMA_exportOutputHandler($buffer)) {
            return FALSE;
        }
    }
    mysql_free_result($result);
    return TRUE;
}
Esempio n. 10
0
        ?>
<form method="post" action="tbl_relation.php">
    <?php 
        echo PMA_generate_common_hidden_inputs($db, $table);
        ?>
    <input type="hidden" name="submit_show" value="true" />

    <p><?php 
        echo $strChangeDisplay . ': ';
        ?>
    <select name="display_field" onchange="this.form.submit();">
        <option value="">---</option>
        <?php 
        echo "\n";
        mysql_data_seek($col_rs, 0);
        while ($row = @PMA_mysql_fetch_array($col_rs)) {
            echo '        <option value="' . htmlspecialchars($row['Field']) . '"';
            if (isset($disp) && $row['Field'] == $disp) {
                echo ' selected="selected"';
            }
            echo '>' . htmlspecialchars($row['Field']) . '</option>' . "\n";
        }
        // end while
        ?>
    </select>
    <script type="text/javascript" language="javascript">
    <!--
    // Fake js to allow the use of the <noscript> tag
    //-->
    </script>
    <noscript>
    <li>
        <form method="post" action="pdf_schema.php">
            <?php 
        echo PMA_generate_common_hidden_inputs($db);
        ?>
            <?php 
        echo $strDisplayPDF;
        ?>
&nbsp;:<br />
            <?php 
        echo $strPageNumber;
        ?>
&nbsp;
            <select name="pdf_page_number">
        <?php 
        while ($pages = @PMA_mysql_fetch_array($test_rs)) {
            echo "\n" . '                ' . '<option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>';
        }
        // end while
        echo "\n";
        ?>
            </select><br />
            <input type="checkbox" name="show_grid" id="show_grid_opt" />
            <label for="show_grid_opt"><?php 
        echo $strShowGrid;
        ?>
</label><br />
            <input type="checkbox" name="show_color" id="show_color_opt" checked="checked" />
            <label for="show_color_opt"><?php 
        echo $strShowColor;
        ?>
Esempio n. 12
0
/**
 * Returns $table's CREATE definition
 *
 * @param   string   the database name
 * @param   string   the table name
 * @param   string   the end of line sequence
 * @param   string   the url to go back in case of error
 * @param   boolean  whether to include creation/update/check dates
 *
 * @return  string   resulting schema
 *
 * @global  boolean  whether to add 'drop' statements or not
 * @global  boolean  whether to use backquotes to allow the use of special
 *                   characters in database, table and fields names or not
 *
 * @access  public
 */
function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false)
{
    global $drop;
    global $use_backquotes;
    global $cfgRelation;
    global $sql_constraints;
    $schema_create = '';
    $auto_increment = '';
    $new_crlf = $crlf;
    $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\'');
    if ($result != FALSE) {
        if (mysql_num_rows($result) > 0) {
            $tmpres = PMA_mysql_fetch_array($result);
            if (isset($GLOBALS['auto_increment']) && !empty($tmpres['Auto_increment'])) {
                $auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
            }
            if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
                $schema_create .= '# ' . $GLOBALS['strStatCreateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])) . $crlf;
                $new_crlf = '#' . $crlf . $crlf;
            }
            if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
                $schema_create .= '# ' . $GLOBALS['strStatUpdateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])) . $crlf;
                $new_crlf = '#' . $crlf . $crlf;
            }
            if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
                $schema_create .= '# ' . $GLOBALS['strStatCheckTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])) . $crlf;
                $new_crlf = '#' . $crlf . $crlf;
            }
            mysql_free_result($result);
        }
    }
    $schema_create .= $new_crlf;
    if (!empty($drop)) {
        $schema_create .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table, $use_backquotes) . ';' . $crlf;
    }
    // Steve Alberty's patch for complete table dump,
    // Whether to quote table and fields names or not
    if ($use_backquotes) {
        PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
    } else {
        PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 0');
    }
    $result = PMA_mysql_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table));
    if ($result != FALSE && mysql_num_rows($result) > 0) {
        $tmpres = PMA_mysql_fetch_array($result);
        // Fix for case problems with winwin, thanks to
        // Pawe³ Szczepañski <pauluz at users.sourceforge.net>
        $pos = strpos($tmpres[1], ' (');
        // Fix a problem with older versions of mysql
        // Find the first opening parenthesys, i.e. that after the name
        // of the table
        $pos2 = strpos($tmpres[1], '(');
        // Old mysql did not insert a space after table name
        // in query "show create table ..."!
        if ($pos2 != $pos + 1) {
            // This is the real position of the first character after
            // the name of the table
            $pos = $pos2;
            // Old mysql did not even put newlines and indentation...
            $tmpres[1] = str_replace(",", ",\n     ", $tmpres[1]);
        }
        $tmpres[1] = substr($tmpres[1], 0, 13) . ($use_backquotes ? PMA_backquote($tmpres[0]) : $tmpres[0]) . substr($tmpres[1], $pos);
        $tmpres[1] = str_replace("\n", $crlf, $tmpres[1]);
        if (preg_match_all('((,\\r?\\n[\\s]*(CONSTRAINT|FOREIGN[\\s]*KEY)[^\\r\\n,]+)+)', $tmpres[1], $regs)) {
            if (!isset($sql_constraints)) {
                if (isset($GLOBALS['no_constraints_comments'])) {
                    $sql_constraints = '';
                } else {
                    $sql_constraints = $crlf . '#' . $crlf . '# ' . $GLOBALS['strConstraintsForDumped'] . $crlf . '#' . $crlf;
                }
            }
            if (!isset($GLOBALS['no_constraints_comments'])) {
                $sql_constraints .= $crlf . '#' . $crlf . '# ' . $GLOBALS['strConstraintsForTable'] . ' ' . PMA_backquote($table) . $crlf . '#' . $crlf;
            }
            $sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf . preg_replace('/(,\\r?\\n|^)([\\s]*)(CONSTRAINT|FOREIGN[\\s]*KEY)/', '\\1\\2ADD \\3', substr($regs[0][0], 2)) . ";\n";
            $tmpres[1] = preg_replace('((,\\r?\\n[\\s]*(CONSTRAINT|FOREIGN[\\s]*KEY)[^\\r\\n,]+)+)', '', $tmpres[1]);
        }
        $schema_create .= $tmpres[1];
    }
    $schema_create .= $auto_increment;
    mysql_free_result($result);
    return $schema_create;
}
Esempio n. 13
0
     // end if
 }
 // end if
 // If the user has Create priv on a inexistant db, show him in the dialog
 // the first inexistant db name that we find, in most cases it's probably
 // the one he just dropped :)
 if (!$is_create_priv) {
     $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = \'Y\' AND User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\'';
     $rs_usr = PMA_mysql_query($local_query, $dbh);
     // Debug: or PMA_mysqlDie('', $local_query, FALSE);
     if ($rs_usr) {
         $re0 = '(^|(\\\\\\\\)+|[^\\])';
         // non-escaped wildcards
         $re1 = '(^|[^\\])(\\\\)+';
         // escaped wildcards
         while ($row = PMA_mysql_fetch_array($rs_usr)) {
             if (ereg($re0 . '(%|_)', $row['Db']) || !PMA_mysql_select_db(ereg_replace($re1 . '(%|_)', '\\1\\3', $row['Db']), $userlink) && @mysql_errno() != 1044) {
                 $db_to_create = ereg_replace($re0 . '%', '\\1...', ereg_replace($re0 . '_', '\\1?', $row['Db']));
                 $db_to_create = ereg_replace($re1 . '(%|_)', '\\1\\3', $db_to_create);
                 $is_create_priv = TRUE;
                 break;
             }
             // end if
         }
         // end while
         mysql_free_result($rs_usr);
     } else {
         // Finally, let's try to get the user's privileges by using SHOW
         // GRANTS...
         // Maybe we'll find a little CREATE priv there :)
         $local_query = 'SHOW GRANTS FOR ' . $mysql_cur_user_and_host;
Esempio n. 14
0
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
{
    global $cfgRelation;
    /**
     * Gets fields properties
     */
    PMA_mysql_select_db($db);
    $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
    $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
    $fields_cnt = mysql_num_rows($result);
    // Check if we can use Relations (Mike Beck)
    if ($do_relation && !empty($cfgRelation['relation'])) {
        // Find which tables are related with the current one and write it in
        // an array
        $res_rel = PMA_getForeigners($db, $table);
        if ($res_rel && count($res_rel) > 0) {
            $have_rel = TRUE;
        } else {
            $have_rel = FALSE;
        }
    } else {
        $have_rel = FALSE;
    }
    // end if
    /**
     * Get the unique keys in the table
     */
    $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
    $keys_result = PMA_mysql_query($keys_query) or PMA_mysqlDie('', $keys_query, '', $error_url);
    $unique_keys = array();
    while ($key = PMA_mysql_fetch_array($keys_result)) {
        if ($key['Non_unique'] == 0) {
            $unique_keys[] = $key['Column_name'];
        }
    }
    /**
     * Displays the table structure
     */
    $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{';
    if (!PMA_exportOutputHandler($buffer)) {
        return FALSE;
    }
    $columns_cnt = 4;
    $alignment = '|l|c|c|c|';
    if ($do_relation && $have_rel) {
        $columns_cnt++;
        $alignment .= 'l|';
    }
    if ($do_comments && $cfgRelation['commwork']) {
        $columns_cnt++;
        $alignment .= 'l|';
    }
    if ($do_mime && $cfgRelation['mimework']) {
        $columns_cnt++;
        $alignment .= 'l|';
    }
    $buffer = $alignment . '} ' . $crlf;
    $header .= ' \\hline ';
    $header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}';
    if ($do_relation && $have_rel) {
        $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}';
    }
    if ($do_comments && $cfgRelation['commwork']) {
        $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}';
        $comments = PMA_getComments($db, $table);
    }
    if ($do_mime && $cfgRelation['mimework']) {
        $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
        $mime_map = PMA_getMIME($db, $table, true);
    }
    $local_buffer = PMA_texEscape($table);
    // Table caption for first page and label
    if (isset($GLOBALS['latex_caption'])) {
        $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption']) . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label']) . '} \\\\' . $crlf;
    }
    $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
    // Table caption on next pages
    if (isset($GLOBALS['latex_caption'])) {
        $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption']) . '} \\\\ ' . $crlf;
    }
    $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ';
    if (!PMA_exportOutputHandler($buffer)) {
        return FALSE;
    }
    while ($row = PMA_mysql_fetch_array($result)) {
        $type = $row['Type'];
        // reformat mysql query output - staybyte - 9. June 2001
        // loic1: set or enum types: slashes single quotes inside options
        if (eregi('^(set|enum)\\((.+)\\)$', $type, $tmp)) {
            $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
            $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
            $type_nowrap = '';
            $binary = 0;
            $unsigned = 0;
            $zerofill = 0;
        } else {
            $type_nowrap = ' nowrap="nowrap"';
            $type = eregi_replace('BINARY', '', $type);
            $type = eregi_replace('ZEROFILL', '', $type);
            $type = eregi_replace('UNSIGNED', '', $type);
            if (empty($type)) {
                $type = '&nbsp;';
            }
            $binary = eregi('BINARY', $row['Type'], $test);
            $unsigned = eregi('UNSIGNED', $row['Type'], $test);
            $zerofill = eregi('ZEROFILL', $row['Type'], $test);
        }
        $strAttribute = '&nbsp;';
        if ($binary) {
            $strAttribute = 'BINARY';
        }
        if ($unsigned) {
            $strAttribute = 'UNSIGNED';
        }
        if ($zerofill) {
            $strAttribute = 'UNSIGNED ZEROFILL';
        }
        if (!isset($row['Default'])) {
            if ($row['Null'] != '') {
                $row['Default'] = 'NULL';
            }
        } else {
            $row['Default'] = $row['Default'];
        }
        $field_name = $row['Field'];
        $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "" . (isset($row['Default']) ? $row['Default'] : '');
        if ($do_relation && $have_rel) {
            $local_buffer .= "";
            if (isset($res_rel[$field_name])) {
                $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')';
            }
        }
        if ($do_comments && $cfgRelation['commwork']) {
            $local_buffer .= "";
            if (isset($comments[$field_name])) {
                $local_buffer .= $comments[$field_name];
            }
        }
        if ($do_mime && $cfgRelation['mimework']) {
            $local_buffer .= "";
            if (isset($mime_map[$field_name])) {
                $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
            }
        }
        $local_buffer = PMA_texEscape($local_buffer);
        if ($row['Key'] == 'PRI') {
            $pos = strpos($local_buffer, "");
            $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
        }
        if (in_array($field_name, $unique_keys)) {
            $pos = strpos($local_buffer, "");
            $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
        }
        $buffer = str_replace("", ' & ', $local_buffer);
        $buffer .= ' \\\\ \\hline ' . $crlf;
        if (!PMA_exportOutputHandler($buffer)) {
            return FALSE;
        }
    }
    // end while
    mysql_free_result($result);
    $buffer = ' \\end{longtable}' . $crlf;
    return PMA_exportOutputHandler($buffer);
}
<?php

/* $Id: tbl_properties_table_info.php,v 2.3 2003/12/29 17:15:14 rabus Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
// this should be recoded as functions, to avoid messing with global
// variables
// Check parameters
require_once './libraries/common.lib.php';
PMA_checkParameters(array('db', 'table'));
/**
 * Gets table informations
 */
// The 'show table' statement works correct since 3.23.03
$local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
$table_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
$showtable = PMA_mysql_fetch_array($table_info_result);
$tbl_type = strtoupper($showtable['Type']);
$tbl_charset = empty($showtable['Collation']) ? '' : $showtable['Collation'];
$table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
$show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
$auto_increment = isset($showtable['Auto_increment']) ? $showtable['Auto_increment'] : '';
$tmp = explode(' ', $showtable['Create_options']);
$tmp_cnt = count($tmp);
for ($i = 0; $i < $tmp_cnt; $i++) {
    $tmp1 = explode('=', $tmp[$i]);
    if (isset($tmp1[1])) {
        ${$tmp1}[0] = $tmp1[1];
    }
}
// end for
unset($tmp1, $tmp);
Esempio n. 16
0
if (PMA_MYSQL_INT_VERSION >= 40100) {
    $res = PMA_mysql_query('SHOW CHARACTER SET;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW CHARACTER SET;');
    $mysql_charsets = array();
    while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
        $mysql_charsets[] = $row['Charset'];
        $mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
        $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
    }
    @mysql_free_result($res);
    unset($res, $row);
    $res = PMA_mysql_query('SHOW COLLATION;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW COLLATION;');
    $mysql_charsets_count = count($mysql_charsets);
    sort($mysql_charsets, SORT_STRING);
    $mysql_collations = array_flip($mysql_charsets);
    $mysql_default_collations = $mysql_collations_flat = array();
    while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
        if (!is_array($mysql_collations[$row['Charset']])) {
            $mysql_collations[$row['Charset']] = array($row['Collation']);
        } else {
            $mysql_collations[$row['Charset']][] = $row['Collation'];
        }
        $mysql_collations_flat[] = $row['Collation'];
        if (isset($row['D']) && $row['D'] == 'Y' || isset($row['Default']) && $row['Default'] == 'Yes') {
            $mysql_default_collations[$row['Charset']] = $row['Collation'];
        }
    }
    $mysql_collations_count = count($mysql_collations_flat);
    sort($mysql_collations_flat, SORT_STRING);
    foreach ($mysql_collations as $key => $value) {
        sort($mysql_collations[$key], SORT_STRING);
        reset($mysql_collations[$key]);
Esempio n. 17
0
 * No modifications yet required -> displays the table fields
 */
if ($abort == FALSE) {
    if (!isset($selected)) {
        PMA_checkParameters(array('field'));
        $selected[] = $field;
        $selected_cnt = 1;
    } else {
        // from a multiple submit
        $selected_cnt = count($selected);
    }
    // TODO: optimize in case of multiple fields to modify
    for ($i = 0; $i < $selected_cnt; $i++) {
        if (!empty($submit_mult)) {
            $field = PMA_sqlAddslashes(urldecode($selected[$i]), TRUE);
        } else {
            $field = PMA_sqlAddslashes($selected[$i], TRUE);
        }
        $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . " LIKE '{$field}'";
        $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
        $fields_meta[] = PMA_mysql_fetch_array($result);
        mysql_free_result($result);
    }
    $num_fields = count($fields_meta);
    $action = 'tbl_alter.php';
    require './tbl_properties.inc.php';
}
/**
 * Displays the footer
 */
require_once './footer.inc.php';
Esempio n. 18
0
</tr>';
echo $header;
if (isset($disp) && $disp) {
    function dimsort($arrayA, $arrayB)
    {
        $keyA = key($arrayA);
        $keyB = key($arrayB);
        if ($arrayA[$keyA] == $arrayB[$keyB]) {
            return 0;
        }
        return $arrayA[$keyA] < $arrayB[$keyB] ? -1 : 1;
    }
    $mysql_key_relrow = array();
    $mysql_val_relrow = array();
    $count = 0;
    while ($relrow = @PMA_mysql_fetch_array($disp)) {
        if ($foreign_display != FALSE) {
            $val = $relrow[$foreign_display];
        } else {
            $val = '';
        }
        $mysql_key_relrow[$count] = array($relrow[$foreign_field] => $val);
        $mysql_val_relrow[$count] = array($val => $relrow[$foreign_field]);
        $count++;
    }
    usort($mysql_val_relrow, 'dimsort');
    $hcount = 0;
    for ($i = 0; $i < $count; $i++) {
        $hcount++;
        $bgcolor = $hcount % 2 ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
        if ($cfg['RepeatCells'] > 0 && $hcount > $cfg['RepeatCells']) {
Esempio n. 19
0
 /**
  * Finds all related tables
  *
  * @param   string   wether to go from master to foreign or vice versa
  *
  * @return  boolean  always TRUE
  *
  * @global  array    the list of tables that we still couldn't connect
  * @global  array    the list of allready connected tables
  * @global  string   the current databse name
  * @global  string   the super user connection id
  * @global  array    the list of relation settings
  *
  * @access  private
  */
 function PMA_getRelatives($from)
 {
     global $tab_left, $tab_know, $fromclause;
     global $dbh, $db, $cfgRelation;
     if ($from == 'master') {
         $to = 'foreign';
     } else {
         $to = 'master';
     }
     $in_know = '(\'' . implode('\', \'', $tab_know) . '\')';
     $in_left = '(\'' . implode('\', \'', $tab_left) . '\')';
     $rel_query = 'SELECT *' . ' FROM ' . PMA_backquote($cfgRelation['relation']) . ' WHERE ' . $from . '_db   = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $to . '_db   = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $from . '_table IN ' . $in_know . ' AND ' . $to . '_table IN ' . $in_left;
     if (isset($dbh)) {
         PMA_mysql_select_db($cfgRelation['db'], $dbh);
         $relations = @PMA_mysql_query($rel_query, $dbh) or PMA_mysqlDie(PMA_mysql_error($dbh), $rel_query, '', $err_url_0);
         PMA_mysql_select_db($db, $dbh);
     } else {
         PMA_mysql_select_db($cfgRelation['db']);
         $relations = @PMA_mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url_0);
         PMA_mysql_select_db($db);
     }
     while ($row = PMA_mysql_fetch_array($relations)) {
         $found_table = $row[$to . '_table'];
         if (isset($tab_left[$found_table])) {
             $fromclause .= "\n" . ' LEFT JOIN ' . PMA_backquote($row[$to . '_table']) . ' ON ' . PMA_backquote($row[$from . '_table']) . '.' . PMA_backquote($row[$from . '_field']) . ' = ' . PMA_backquote($row[$to . '_table']) . '.' . PMA_backquote($row[$to . '_field']) . ' ';
             $tab_know[$found_table] = $found_table;
             $tab_left = PMA_arrayShort($tab_left, $found_table);
         }
     }
     // end while
     return TRUE;
 }
Esempio n. 20
0
function PMA_mysql_list_fields_alternate($database_name, $table_name, $link_identifier = FALSE)
{
    if ($link_identifier != FALSE) {
        $result = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote(PMA_convert_charset($database_name)) . '.' . PMA_backquote(PMA_convert_charset($table_name)), $link_identifier);
    } else {
        $result = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote(PMA_convert_charset($database_name)) . '.' . PMA_backquote(PMA_convert_charset($table_name)));
    }
    $fields = array();
    while ($row = PMA_mysql_fetch_array($result)) {
        $fields[] = $row;
    }
    return $fields;
}
Esempio n. 21
0
    /**
     * Displays a message at the top of the "main" (right) frame
     *
     * @param   string  the message to display
     *
     * @global  array   the configuration array
     *
     * @access  public
     */
    function PMA_showMessage($message)
    {
        global $cfg;
        require_once './header.inc.php';
        // Reloads the navigation frame via JavaScript if required
        if (isset($GLOBALS['reload']) && $GLOBALS['reload']) {
            echo "\n";
            $reload_url = './left.php?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', '', '&');
            ?>
<script type="text/javascript" language="javascript1.2">
<!--
if (typeof(window.parent) != 'undefined'
    && typeof(window.parent.frames['nav']) != 'undefined') {
    window.parent.frames['nav'].location.replace('<?php 
            echo $reload_url;
            ?>
&hash=' + <?php 
            echo $cfg['QueryFrame'] && $cfg['QueryFrameJS'] ? 'window.parent.frames[\'queryframe\'].document.hashform.hash.value' : "'" . md5($cfg['PmaAbsoluteUri']) . "'";
            ?>
);
}
//-->
</script>
            <?php 
            unset($GLOBALS['reload']);
        } else {
            if (!empty($GLOBALS['table']) && $cfg['ShowTooltip']) {
                $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
                if ($result) {
                    $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC);
                    $tooltip = empty($tbl_status['Comment']) ? '' : $tbl_status['Comment'] . ' ';
                    $tooltip .= '(' . $tbl_status['Rows'] . ' ' . $GLOBALS['strRows'] . ')';
                    mysql_free_result($result);
                    $md5_tbl = md5($GLOBALS['table']);
                    echo "\n";
                    ?>
<script type="text/javascript" language="javascript1.2">
<!--
if (typeof(document.getElementById) != 'undefined'
    && typeof(window.parent.frames['nav']) != 'undefined'
    && typeof(window.parent.frames['nav'].document) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'unknown'
    && (window.parent.frames['nav'].document.getElementById('<?php 
                    echo 'tbl_' . $md5_tbl;
                    ?>
'))
    && typeof(window.parent.frames['nav'].document.getElementById('<?php 
                    echo 'tbl_' . $md5_tbl;
                    ?>
')) != 'undefined'
    && typeof(window.parent.frames['nav'].document.getElementById('<?php 
                    echo 'tbl_' . $md5_tbl;
                    ?>
').title) == 'string') {
    window.parent.frames['nav'].document.getElementById('<?php 
                    echo 'tbl_' . $md5_tbl;
                    ?>
').title = '<?php 
                    echo PMA_jsFormat($tooltip, FALSE);
                    ?>
';
}
//-->
</script>
                <?php 
                }
                // end if
            }
        }
        // end if... else if
        // Checks if the table needs to be repaired after a TRUNCATE query.
        if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
            if (!isset($tbl_status)) {
                $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\'');
                if ($result) {
                    $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC);
                    mysql_free_result($result);
                }
            }
            if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) {
                @PMA_mysql_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
            }
        }
        unset($tbl_status);
        echo "\n";
        ?>
<div align="<?php 
        echo $GLOBALS['cell_align_left'];
        ?>
">
    <table border="<?php 
        echo $cfg['Border'];
        ?>
" cellpadding="5">
    <tr>
        <td bgcolor="<?php 
        echo $cfg['ThBgcolor'];
        ?>
">
            <b><?php 
        echo $message;
        ?>
</b><br />
        </td>
    </tr>
        <?php 
        if ($cfg['ShowSQL'] == TRUE && (!empty($GLOBALS['sql_query']) || !empty($GLOBALS['display_query']))) {
            $local_query = !empty($GLOBALS['display_query']) ? $GLOBALS['display_query'] : ($cfg['SQP']['fmtType'] == 'none' && $GLOBALS['unparsed_sql'] != '' ? $GLOBALS['unparsed_sql'] : $GLOBALS['sql_query']);
            // Basic url query part
            $url_qpart = '?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : '');
            echo "\n";
            ?>
    <tr>
        <td bgcolor="<?php 
            echo $cfg['BgcolorOne'];
            ?>
">
            <?php 
            echo "\n";
            // Html format the query to be displayed
            // The nl2br function isn't used because its result isn't a valid
            // xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />")
            // If we want to show some sql code it is easiest to create it here
            /* SQL-Parser-Analyzer */
            $sqlnr = 1;
            if (!empty($GLOBALS['show_as_php'])) {
                $new_line = '\'<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;. \' ';
            }
            if (isset($new_line)) {
                /* SQL-Parser-Analyzer */
                $query_base = PMA_sqlAddslashes(htmlspecialchars($local_query));
                /* SQL-Parser-Analyzer */
                $query_base = preg_replace("@((\r\n)|(\r)|(\n))+@", $new_line, $query_base);
            } else {
                $query_base = $local_query;
            }
            if (!empty($GLOBALS['show_as_php'])) {
                $query_base = '$sql  = \'' . $query_base;
            } else {
                if (!empty($GLOBALS['validatequery'])) {
                    $query_base = PMA_validateSQL($query_base);
                } else {
                    $parsed_sql = PMA_SQP_parse($query_base);
                    $query_base = PMA_formatSql($parsed_sql, $query_base);
                }
            }
            // Prepares links that may be displayed to edit/explain the query
            // (don't go to default pages, we must go to the page
            // where the query box is available)
            // (also, I don't see why we should check the goto variable)
            //if (!isset($GLOBALS['goto'])) {
            //$edit_target = (isset($GLOBALS['table'])) ? $cfg['DefaultTabTable'] : $cfg['DefaultTabDatabase'];
            $edit_target = isset($GLOBALS['db']) ? isset($GLOBALS['table']) ? 'tbl_properties.php' : 'db_details.php' : '';
            //} else if ($GLOBALS['goto'] != 'main.php') {
            //    $edit_target = $GLOBALS['goto'];
            //} else {
            //    $edit_target = '';
            //}
            if (isset($cfg['SQLQuery']['Edit']) && $cfg['SQLQuery']['Edit'] == TRUE && !empty($edit_target)) {
                $onclick = '';
                if ($cfg['QueryFrameJS'] && $cfg['QueryFrame']) {
                    $onclick = 'onclick="focus_querywindow(\'' . urlencode($local_query) . '\'); return false;"';
                }
                $edit_link = '&nbsp;[<a href="' . $edit_target . $url_qpart . '&amp;sql_query=' . urlencode($local_query) . '&amp;show_query=1#querybox" ' . $onclick . '>' . $GLOBALS['strEdit'] . '</a>]';
            } else {
                $edit_link = '';
            }
            // Want to have the query explained (Mike Beck 2002-05-22)
            // but only explain a SELECT (that has not been explained)
            /* SQL-Parser-Analyzer */
            if (isset($cfg['SQLQuery']['Explain']) && $cfg['SQLQuery']['Explain'] == TRUE) {
                // Detect if we are validating as well
                // To preserve the validate uRL data
                if (!empty($GLOBALS['validatequery'])) {
                    $explain_link_validate = '&amp;validatequery=1';
                } else {
                    $explain_link_validate = '';
                }
                $explain_link = '&nbsp;[<a href="sql.php' . $url_qpart . $explain_link_validate . '&amp;sql_query=';
                if (preg_match('@^SELECT[[:space:]]+@i', $local_query)) {
                    $explain_link .= urlencode('EXPLAIN ' . $local_query) . '">' . $GLOBALS['strExplain'];
                } else {
                    if (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $local_query)) {
                        $explain_link .= urlencode(substr($local_query, 8)) . '">' . $GLOBALS['strNoExplain'];
                    } else {
                        $explain_link = '';
                    }
                }
                if (!empty($explain_link)) {
                    $explain_link .= '</a>]';
                }
            } else {
                $explain_link = '';
            }
            //show explain
            // Also we would like to get the SQL formed in some nice
            // php-code (Mike Beck 2002-05-22)
            if (isset($cfg['SQLQuery']['ShowAsPHP']) && $cfg['SQLQuery']['ShowAsPHP'] == TRUE) {
                $php_link = '&nbsp;[<a href="sql.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($local_query) . '&amp;show_as_php=';
                if (!empty($GLOBALS['show_as_php'])) {
                    $php_link .= '0">' . $GLOBALS['strNoPhp'];
                } else {
                    $php_link .= '1">' . $GLOBALS['strPhp'];
                }
                $php_link .= '</a>]';
                if (isset($GLOBALS['show_as_php']) && $GLOBALS['show_as_php'] == '1') {
                    $php_link .= '&nbsp;[<a href="sql.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($local_query) . '">' . $GLOBALS['strRunQuery'] . '</a>]';
                }
            } else {
                $php_link = '';
            }
            //show as php
            if (isset($cfg['SQLValidator']['use']) && $cfg['SQLValidator']['use'] == TRUE && isset($cfg['SQLQuery']['Validate']) && $cfg['SQLQuery']['Validate'] == TRUE) {
                $validate_link = '&nbsp;[<a href="sql.php' . $url_qpart . '&amp;show_query=1' . '&amp;sql_query=' . urlencode($local_query) . '&amp;validatequery=';
                if (!empty($GLOBALS['validatequery'])) {
                    $validate_link .= '0">' . $GLOBALS['strNoValidateSQL'];
                } else {
                    $validate_link .= '1">' . $GLOBALS['strValidateSQL'];
                }
                $validate_link .= '</a>]';
            } else {
                $validate_link = '';
            }
            //validator
            // Displays the message
            echo '            ' . $GLOBALS['strSQLQuery'] . '&nbsp;:';
            if (!empty($edit_target)) {
                echo $edit_link . $explain_link . $php_link . $validate_link;
            }
            echo '<br />' . "\n";
            echo '            ' . $query_base;
            // If a 'LIMIT' clause has been programatically added to the query
            // displays it
            if (!empty($GLOBALS['sql_limit_to_append'])) {
                if (!empty($GLOBALS['show_as_php'])) {
                    echo $GLOBALS['sql_limit_to_append'];
                } else {
                    if (!empty($GLOBALS['validatequery'])) {
                        // skip the extra bit here
                    } else {
                        echo '&nbsp;' . PMA_formatSql(PMA_SQP_parse($GLOBALS['sql_limit_to_append'], $GLOBALS['sql_limit_to_append']));
                    }
                }
            }
            unset($local_query);
            //Clean up the end of the PHP
            if (!empty($GLOBALS['show_as_php'])) {
                echo '\';';
            }
            echo "\n";
            ?>
        </td>
    </tr>
           <?php 
        }
        echo "\n";
        ?>
    </table>
</div><br />
        <?php 
    }
Esempio n. 22
0
    }
    $titles['Browse'] = $iconic_spacer . '<img width="12" height="13" src="images/button_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
    if ($propicon == 'both') {
        $titles['Browse'] .= '&nbsp;' . $strBrowseForeignValues . '</nobr>';
    }
} else {
    $titles['Browse'] = $strBrowseForeignValues;
}
// Set if we passed the first timestamp field
$timestamp_seen = 0;
$fields_cnt = mysql_num_rows($table_def);
// Set a flag here because the 'if' would not be valid in the loop
// if we set a value in some field
$insert_mode = !isset($row) ? TRUE : FALSE;
$loop_array = isset($row) ? $row : array(0 => FALSE);
while ($trow = PMA_mysql_fetch_array($table_def)) {
    $trow_table_def[] = $trow;
}
$o_rows = 0;
foreach ($loop_array as $vrowcount => $vrow) {
    if ($vrow === FALSE) {
        unset($vrow);
    }
    $vresult = isset($result) && is_array($result) && isset($result[$vrowcount]) ? $result[$vrowcount] : $result;
    ?>
    <table border="<?php 
    echo $cfg['Border'];
    ?>
">
        <tr>
            <th><?php 
Esempio n. 23
0
<?php

/* $Id: defines_mysql.lib.php,v 2.1 2003/11/26 22:52:23 rabus Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
 * DEFINES MYSQL RELATED VARIABLES & CONSTANTS
 * Overview:
 *    PMA_MYSQL_INT_VERSION    (int)    - eg: 32339 instead of 3.23.39
 */
if (!defined('PMA_MYSQL_INT_VERSION') && isset($userlink)) {
    if (!empty($server)) {
        $result = PMA_mysql_query('SELECT VERSION() AS version', $userlink);
        if ($result != FALSE && @mysql_num_rows($result) > 0) {
            $row = PMA_mysql_fetch_array($result);
            $match = explode('.', $row['version']);
            mysql_free_result($result);
        }
    }
    // end server id is defined case
    if (!isset($match) || !isset($match[0])) {
        $match[0] = 3;
    }
    if (!isset($match[1])) {
        $match[1] = 23;
    }
    if (!isset($match[2])) {
        $match[2] = 32;
    }
    if (!isset($row)) {
        $row['version'] = '3.23.32';
    }
Esempio n. 24
0
function PMA_DBI_fetch_row($result)
{
    return PMA_mysql_fetch_array($result, MYSQL_NUM);
}
Esempio n. 25
0
 $query = array();
 $message = '';
 PMA_mysql_select_db($db);
 foreach ($loop_array as $primary_key_index => $enc_primary_key) {
     $fieldlist = '';
     $valuelist = '';
     $me_fields = isset($fields['multi_edit']) && isset($fields['multi_edit'][$enc_primary_key]) ? $fields['multi_edit'][$enc_primary_key] : (isset($fields) ? $fields : null);
     $me_fields_prev = isset($fields_prev['multi_edit']) && isset($fields_prev['multi_edit'][$enc_primary_key]) ? $fields_prev['multi_edit'][$enc_primary_key] : (isset($fields_prev) ? $fields_prev : null);
     $me_funcs = isset($funcs['multi_edit']) && isset($funcs['multi_edit'][$enc_primary_key]) ? $funcs['multi_edit'][$enc_primary_key] : (isset($funcs) ? $funcs : null);
     $me_fields_type = isset($fields_type['multi_edit']) && isset($fields_type['multi_edit'][$enc_primary_key]) ? $fields_type['multi_edit'][$enc_primary_key] : (isset($fields_type) ? $fields_type : null);
     $me_fields_null = isset($fields_null['multi_edit']) && isset($fields_null['multi_edit'][$enc_primary_key]) ? $fields_null['multi_edit'][$enc_primary_key] : (isset($fields_null) ? $fields_null : null);
     // garvin: Get, if sent, any protected fields to insert them here:
     if (isset($me_fields_type) && is_array($me_fields_type) && isset($enc_primary_key)) {
         $prot_local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . urldecode($enc_primary_key);
         $prot_result = PMA_mysql_query($prot_local_query) or PMA_mysqlDie('', $prot_local_query, '', $err_url);
         $prot_row = PMA_mysql_fetch_array($prot_result);
     }
     foreach ($me_fields as $key => $val) {
         $encoded_key = $key;
         $key = urldecode($key);
         $fieldlist .= PMA_backquote($key) . ', ';
         require './tbl_replace_fields.php';
         if (empty($me_funcs[$encoded_key])) {
             $valuelist .= $val . ', ';
         } else {
             if ($val == '\'\'' && preg_match('@^(UNIX_TIMESTAMP|RAND|LAST_INSERT_ID)$@', $me_funcs[$encoded_key]) || preg_match('@^(NOW|CURDATE|CURTIME|USER)$@', $me_funcs[$encoded_key])) {
                 $valuelist .= $me_funcs[$encoded_key] . '(), ';
             } else {
                 $valuelist .= $me_funcs[$encoded_key] . '(' . $val . '), ';
             }
         }
Esempio n. 26
0
 /**
  * The "PMA_RT" constructor
  *
  * @param   mixed    The scaling factor
  * @param   integer  The page number to draw (from the
  *                   $cfg['Servers'][$i]['table_coords'] table)
  * @param   boolean  Whether to display table position or not
  * @param   boolean  Was originally whether to use one color per
  *                   relation or not, now enables/disables color
  *                   everywhere, due to some problems printing with color
  * @param   boolean  Whether to draw grids or not
  * @param   boolean  Whether all tables should have the same width or not
  *
  * @global  object   The current PDF document
  * @global  string   The current db name
  * @global  array    The relations settings
  *
  * @access  private
  *
  * @see     PMA_PDF
  */
 function PMA_RT($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4')
 {
     global $pdf, $db, $cfgRelation, $with_doc;
     // Font face depends on the current language
     $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
     $this->same_wide = $all_tab_same_wide;
     // Initializes a new document
     $pdf = new PMA_PDF('L', 'mm', $paper);
     $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
     $pdf->cMargin = 0;
     $pdf->Open();
     $pdf->SetTitle($pdf->title);
     $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $pdf->AliasNbPages();
     // fonts added to phpMyAdmin and considered non-standard by fpdf
     // (Note: those tahoma fonts are iso-8859-2 based)
     if ($this->ff == 'tahoma') {
         $pdf->AddFont('tahoma', '', 'tahoma.php');
         $pdf->AddFont('tahoma', 'B', 'tahomab.php');
     }
     $pdf->SetFont($this->ff, '', 14);
     $pdf->SetAutoPageBreak('auto');
     // Gets tables on this page
     $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel;
     $tab_rs = PMA_query_as_cu($tab_sql);
     if (!$tab_rs || !mysql_num_rows($tab_rs) > 0) {
         $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
         //            die('No tables');
     }
     while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
         $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
         //$intable     = '\'' . implode('\', \'', $alltables) . '\'';
     }
     //              make doc                    //
     if ($with_doc) {
         $pdf->SetAutoPageBreak('auto', 15);
         $pdf->cMargin = 1;
         PMA_RT_DOC($alltables);
         $pdf->SetAutoPageBreak('auto');
         $pdf->cMargin = 0;
     }
     $pdf->Addpage();
     if ($with_doc) {
         $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
         $pdf->Bookmark($GLOBALS['strRelationalSchema']);
         $pdf->SetAlias('{00}', $pdf->PageNo());
         $this->t_marg = 18;
         $this->b_marg = 18;
     }
     /* snip */
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
         }
         if ($this->same_wide) {
             $this->tables[$table]->width = $this->tablewidth;
         }
         $this->PMA_RT_setMinMax($this->tables[$table]);
     }
     // Defines the scale factor
     $this->scale = ceil(max(($this->x_max - $this->x_min) / ($pdf->fh - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->fw - $this->t_marg - $this->b_marg)) * 100) / 100;
     $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
     // Builds and save the PDF document
     $pdf->PMA_PDF_setLineWidthScale(0.1);
     if ($show_grid) {
         $pdf->SetFontSize(10);
         $this->PMA_RT_strokeGrid();
     }
     $pdf->PMA_PDF_setFontSizeScale(14);
     //        $sql    = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
     //                .   ' WHERE master_db   = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND foreign_db    = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND master_table  IN (' . $intable . ')'
     //                .   ' AND foreign_table IN (' . $intable . ')';
     //        $result =  PMA_query_as_cu($sql);
     //
     // lem9:
     // previous logic was checking master tables and foreign tables
     // but I think that looping on every table of the pdf page as a master
     // and finding its foreigns is OK (then we can support innodb)
     $seen_a_relation = FALSE;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
         if ($exist_rel) {
             $seen_a_relation = TRUE;
             foreach ($exist_rel as $master_field => $rel) {
                 // put the foreign table on the schema only if selected
                 // by the user
                 // (do not use array_search() because we would have to
                 // to do a === FALSE and this is not PHP3 compatible)
                 if (PMA_isInto($rel['foreign_table'], $alltables) > -1) {
                     $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
                 }
             }
             // end while
         }
         // end if
     }
     // end while
     // loic1: also show tables without relations
     //        $norelations     = TRUE;
     //        if ($result && mysql_num_rows($result) > 0) {
     //            $norelations = FALSE;
     //            while ($row = PMA_mysql_fetch_array($result)) {
     //                $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
     //            }
     //        }
     //        if ($norelations == FALSE) {
     if ($seen_a_relation) {
         $this->PMA_RT_drawRelations($change_color);
     }
     $this->PMA_RT_drawTables($show_info, $change_color);
     $this->PMA_RT_showRt();
 }
Esempio n. 27
0
/**
* Outputs dropdown with values of foreign fields
*
* @param   string   the query of the foreign keys
* @param   string   the foreign field
* @param   string   the foreign field to display
* @param   string   the current data of the dropdown
*
* @return  string   the <option value=""><option>s
*
* @access  public
*/
function PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, $max = 100)
{
    global $cfg;
    $ret = '<option value=""></option>' . "\n";
    $reloptions = array('content-id' => array(), 'id-content' => array());
    while ($relrow = @PMA_mysql_fetch_array($disp)) {
        $key = $relrow[$foreign_field];
        if (strlen($relrow[$foreign_display]) <= $cfg['LimitChars']) {
            $value = $foreign_display != FALSE ? htmlspecialchars($relrow[$foreign_display]) : '';
            $vtitle = '';
        } else {
            $vtitle = htmlspecialchars($relrow[$foreign_display]);
            $value = $foreign_display != FALSE ? htmlspecialchars(substr($vtitle, 0, $cfg['LimitChars']) . '...') : '';
        }
        $reloption = '<option value="' . htmlspecialchars($key) . '"';
        if ($vtitle != '') {
            $reloption .= ' title="' . $vtitle . '"';
        }
        if ($key == $data) {
            $reloption .= ' selected="selected"';
        }
        // end if
        $reloptions['id-content'][] = $reloption . '>' . $value . '&nbsp;-&nbsp;' . htmlspecialchars($key) . '</option>' . "\n";
        $reloptions['content-id'][] = $reloption . '>' . htmlspecialchars($key) . '&nbsp;-&nbsp;' . $value . '</option>' . "\n";
    }
    // end while
    if ($max == -1 || count($reloptions['content-id']) < $max) {
        $ret .= implode('', $reloptions['content-id']);
        if (count($reloptions['content-id']) > 0) {
            $ret .= '<option value=""></option>' . "\n";
            $ret .= '<option value=""></option>' . "\n";
        }
    }
    $ret .= implode('', $reloptions['id-content']);
    return $ret;
}