Beispiel #1
0
 /**
  * Returns the message for demo server to error messages
  *
  * @return string
  */
 private function _getDemoMessage()
 {
     $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: ';
     if (file_exists('./revision-info.php')) {
         include './revision-info.php';
         $message .= sprintf(__('Currently running Git revision %1$s from the %2$s branch.'), '<a target="_blank" href="' . $repobase . $fullrevision . '">' . $revision . '</a>', '<a target="_blank" href="' . $repobranchbase . $branch . '">' . $branch . '</a>');
     } else {
         $message .= __('Git information missing!');
     }
     return PMA_Message::notice($message)->getDisplay();
 }
/**
 * Prints html for auto refreshing processes list
 *
 * @return string
 */
function PMA_getHtmlForProcessListAutoRefresh()
{
    $notice = PMA_Message::notice(__('Note: Enabling the auto refresh here might cause ' . 'heavy traffic between the web server and the MySQL server.'))->getDisplay();
    $retval = $notice . '<div class="tabLinks">';
    $retval .= '<label>' . __('Refresh rate') . ': ';
    $retval .= PMA_ServerStatusData::getHtmlForRefreshList('refreshRate', 5, array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200));
    $retval .= '</label>';
    $retval .= '<a id="toggleRefresh" href="#">';
    $retval .= PMA_Util::getImage('play.png') . __('Start auto refresh');
    $retval .= '</a>';
    $retval .= '</div>';
    return $retval;
}
/**
 * Get HTML for the Change password dialog
 *
 * @param string $mode     where is the function being called?
 *                         values : 'change_pw' or 'edit_other'
 * @param string $username username
 * @param string $hostname hostname
 *
 * @return string html snippet
 */
function PMA_getHtmlForChangePassword($mode, $username, $hostname)
{
    /**
     * autocomplete feature of IE kills the "onchange" event handler and it
     * must be replaced by the "onpropertychange" one in this case
     */
    $chg_evt_handler = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7 ? 'onpropertychange' : 'onchange';
    $is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php';
    $html = '<form method="post" id="change_password_form" ' . 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" ' . 'name="chgPassword" ' . 'class="' . ($is_privileges ? 'submenu-item' : '') . '">';
    $html .= PMA_URL_getHiddenInputs();
    if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) {
        $html .= '<input type="hidden" name="username" ' . 'value="' . htmlspecialchars($username) . '" />' . '<input type="hidden" name="hostname" ' . 'value="' . htmlspecialchars($hostname) . '" />';
    }
    $html .= '<fieldset id="fieldset_change_password">' . '<legend' . ($is_privileges ? ' data-submenu-label="' . __('Change password') . '"' : '') . '>' . __('Change password') . '</legend>' . '<table class="data noclick">' . '<tr class="odd">' . '<td colspan="2">' . '<input type="radio" name="nopass" value="1" id="nopass_1" ' . 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; ' . 'this.checked = true" />' . '<label for="nopass_1">' . __('No Password') . '</label>' . '</td>' . '</tr>' . '<tr class="even vmiddle">' . '<td>' . '<input type="radio" name="nopass" value="0" id="nopass_0" ' . 'onclick="document.getElementById(\'text_pma_pw\').focus();" ' . 'checked="checked" />' . '<label for="nopass_0">' . __('Password:'******'&nbsp;</label>' . '</td>' . '<td>' . '<input type="password" name="pma_pw" id="text_pma_pw" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . '&nbsp;&nbsp;' . __('Re-type:') . '&nbsp;' . '<input type="password" name="pma_pw2" id="text_pma_pw2" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . '</td>' . '</tr>';
    $serverType = PMA_Util::getServerType();
    $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin('change', $username, $hostname);
    $is_superuser = $GLOBALS['dbi']->isSuperuser();
    if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50507 || $serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200) {
        // Provide this option only for 5.7.6+
        // OR for privileged users in 5.5.7+
        if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706 || $is_superuser && $mode == 'edit_other') {
            $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown($username, $hostname, $orig_auth_plugin, 'change_pw', 'new');
            $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td><td>';
            $html .= $auth_plugin_dropdown;
            $html .= '</td></tr>' . '<tr id="tr_element_before_generate_password"></tr>' . '</table>';
            $html .= '<div ' . ($orig_auth_plugin != 'sha256_password' ? 'style="display:none"' : '') . ' id="ssl_reqd_warning_cp">' . PMA_Message::notice(__('This method requires using an \'<i>SSL connection</i>\' ' . 'or an \'<i>unencrypted connection that encrypts the password ' . 'using RSA</i>\'; while connecting to the server.') . PMA_Util::showMySQLDocu('sha256-authentication-plugin'))->getDisplay() . '</div>';
        } else {
            $html .= '<tr id="tr_element_before_generate_password"></tr>' . '</table>';
        }
    } else {
        $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown($username, $hostname, $orig_auth_plugin, 'change_pw', 'old');
        $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td><td>';
        $html .= $auth_plugin_dropdown . '</td></tr>' . '<tr id="tr_element_before_generate_password"></tr>' . '</table>';
    }
    $html .= '</fieldset>' . '<fieldset id="fieldset_change_password_footer" class="tblFooters">' . '<input type="hidden" name="change_pw" value="1" />' . '<input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . '</form>';
    return $html;
}
/**
 * Get HTML for the Change password dialog
 *
 * @param string $username username
 * @param string $hostname hostname
 *
 * @return string html snippet
 */
function PMA_getHtmlForChangePassword($username, $hostname)
{
    /**
     * autocomplete feature of IE kills the "onchange" event handler and it
     * must be replaced by the "onpropertychange" one in this case
     */
    $chg_evt_handler = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7 ? 'onpropertychange' : 'onchange';
    $is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php';
    $html = '<form method="post" id="change_password_form" ' . 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" ' . 'name="chgPassword" ' . 'class="' . ($is_privileges ? 'submenu-item' : '') . '">';
    $html .= PMA_URL_getHiddenInputs();
    if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) {
        $html .= '<input type="hidden" name="username" ' . 'value="' . htmlspecialchars($username) . '" />' . '<input type="hidden" name="hostname" ' . 'value="' . htmlspecialchars($hostname) . '" />';
    }
    $html .= '<fieldset id="fieldset_change_password">' . '<legend' . ($is_privileges ? ' data-submenu-label="' . __('Change password') . '"' : '') . '>' . __('Change password') . '</legend>' . '<table class="data noclick">' . '<tr class="odd">' . '<td colspan="2">' . '<input type="radio" name="nopass" value="1" id="nopass_1" ' . 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; ' . 'this.checked = true" />' . '<label for="nopass_1">' . __('No Password') . '</label>' . '</td>' . '</tr>' . '<tr class="even vmiddle">' . '<td>' . '<input type="radio" name="nopass" value="0" id="nopass_0" ' . 'onclick="document.getElementById(\'text_pma_pw\').focus();" ' . 'checked="checked" />' . '<label for="nopass_0">' . __('Password:'******'&nbsp;</label>' . '</td>' . '<td>' . '<input type="password" name="pma_pw" id="text_pma_pw" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . '&nbsp;&nbsp;' . __('Re-type:') . '&nbsp;' . '<input type="password" name="pma_pw2" id="text_pma_pw2" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . '</td>' . '</tr>';
    $default_auth_plugin = PMA_getCurrentAuthenticationPlugin('change', $username, $hostname);
    // See http://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-5.html
    if (PMA_MYSQL_INT_VERSION >= 50705) {
        $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_mysql_native" ' . 'value="mysql_native_password"';
        if ($default_auth_plugin == 'mysql_native_password') {
            $html .= '" checked="checked"';
        }
        $html .= ' />' . '<label for="radio_pw_hash_mysql_native">' . __('MySQL native password') . '</label>' . '</td>' . '</tr>' . '<tr id="tr_element_before_generate_password">' . '<td>&nbsp;</td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_sha256" ' . 'value="sha256_password"';
        if ($default_auth_plugin == 'sha256_password') {
            $html .= '" checked="checked"';
        }
        $html .= ' />' . '<label for="radio_pw_hash_sha256">' . __('SHA256 password') . '</label>' . '</td>' . '</tr>';
    } elseif (PMA_MYSQL_INT_VERSION >= 50606) {
        $html .= '<tr class="vmiddle" id="tr_element_before_generate_password">' . '<td>' . __('Password Hashing:') . '</td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_new" ' . 'value="' . $default_auth_plugin . '" checked="checked" />' . '<label for="radio_pw_hash_new">' . $default_auth_plugin . '</label>' . '</td>' . '</tr>';
    } else {
        $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_new" ' . 'value="mysql_native_password" checked="checked" />' . '<label for="radio_pw_hash_new">mysql_native_password</label>' . '</td>' . '</tr>' . '<tr id="tr_element_before_generate_password" >' . '<td>&nbsp;</td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_old" ' . 'value="old" />' . '<label for="radio_pw_hash_old">' . __('MySQL 4.0 compatible') . '</label>' . '</td>' . '</tr>';
    }
    $html .= '</table>';
    $html .= '<div ' . ($default_auth_plugin != 'sha256_password' ? 'style="display:none"' : '') . ' id="ssl_reqd_warning">' . PMA_Message::notice(__('This method requires using an \'<i>SSL connection</i>\' ' . 'or an \'<i>unencrypted connection that encrypts the password ' . 'using RSA</i>\'; while connecting to the server.') . PMA_Util::showMySQLDocu('sha256-authentication-plugin'))->getDisplay() . '</div>';
    $html .= '</fieldset>' . '<fieldset id="fieldset_change_password_footer" class="tblFooters">' . '<input type="hidden" name="change_pw" value="1" />' . '<input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . '</form>';
    return $html;
}
    $tabs['tracking']['icon'] = 'eye.png';
    $tabs['tracking']['text'] = __('Tracking');
    $tabs['tracking']['link'] = 'tbl_tracking.php';
}
if (!$tbl_is_view && !(isset($db_is_information_schema) && $db_is_information_schema)) {
}
/**
 * Views support a limited number of operations
 */
if ($tbl_is_view && !(isset($db_is_information_schema) && $db_is_information_schema)) {
    $tabs['operation']['icon'] = 'b_tblops.png';
    $tabs['operation']['link'] = 'view_operations.php';
    $tabs['operation']['text'] = __('Operations');
}
if ($table_info_num_rows == 0 && !$tbl_is_view) {
    $tabs['browse']['warning'] = __('Table seems to be empty!');
    $tabs['search']['warning'] = __('Table seems to be empty!');
}
echo PMA_generate_html_tabs($tabs, $url_params);
unset($tabs);
if (PMA_Tracker::isActive() and PMA_Tracker::isTracked($GLOBALS["db"], $GLOBALS["table"])) {
    $msg = PMA_Message::notice('<a href="tbl_tracking.php?' . $url_query . '">' . sprintf(__('Tracking of %s.%s is activated.'), htmlspecialchars($GLOBALS["db"]), htmlspecialchars($GLOBALS["table"])) . '</a>');
    $msg->display();
}
/**
 * Displays a message
 */
if (!empty($message)) {
    PMA_showMessage($message);
    unset($message);
}
/**
 * Parses the SQL queries
 *
 * @param string $sql The SQL query list
 *
 * @return mixed Most of times, nothing...
 *
 * @global array    The current PMA configuration
 * @global array    MySQL column attributes
 * @global array    MySQL reserved words
 * @global array    MySQL column types
 * @global array    MySQL function names
 * @global array    List of available character sets
 * @global array    List of available collations
 *
 * @access public
 */
function PMA_SQP_parse($sql)
{
    static $PMA_SQPdata_column_attrib, $PMA_SQPdata_reserved_word;
    static $PMA_SQPdata_column_type;
    static $PMA_SQPdata_function_name, $PMA_SQPdata_forbidden_word;
    global $mysql_charsets, $mysql_collations_flat;
    /* @var $pmaString PMA_String */
    $pmaString = $GLOBALS['PMA_String'];
    // Convert all line feeds to Unix style
    $sql = str_replace("\r\n", "\n", $sql);
    $sql = str_replace("\r", "\n", $sql);
    $len = mb_strlen($sql);
    if ($len == 0) {
        return array();
    }
    // Create local hashtables
    if (!isset($PMA_SQPdata_column_attrib)) {
        $PMA_SQPdata_column_attrib = array_flip($GLOBALS['PMA_SQPdata_column_attrib']);
        $PMA_SQPdata_function_name = array_flip($GLOBALS['PMA_SQPdata_function_name']);
        $PMA_SQPdata_reserved_word = array_flip($GLOBALS['PMA_SQPdata_reserved_word']);
        $PMA_SQPdata_forbidden_word = array_flip($GLOBALS['PMA_SQPdata_forbidden_word']);
        $PMA_SQPdata_column_type = array_flip($GLOBALS['PMA_SQPdata_column_type']);
    }
    $sql_array = array();
    $sql_array['raw'] = $sql;
    $count2 = 0;
    $punct_queryend = ';';
    $punct_qualifier = '.';
    $punct_listsep = ',';
    $bracket_list = '()[]{}';
    $allpunct_list = '-,;:!?/.^~\\*&%+<=>|';
    $allpunct_list_pair = array('!=' => 1, '&&' => 1, ':=' => 1, '<<' => 1, '<=' => 1, '<=>' => 1, '<>' => 1, '>=' => 1, '>>' => 1, '||' => 1, '==' => 1);
    $quote_list = '\'"`';
    $arraysize = 0;
    $this_was_space = false;
    $this_was_bracket = false;
    $this_was_punct = false;
    $this_was_listsep = false;
    $this_was_quote = false;
    while ($count2 < $len) {
        $c = mb_substr($sql, $count2, 1);
        $count1 = $count2;
        $previous_was_space = $this_was_space;
        $this_was_space = false;
        $previous_was_bracket = $this_was_bracket;
        $this_was_bracket = false;
        $previous_was_punct = $this_was_punct;
        $this_was_punct = false;
        $previous_was_listsep = $this_was_listsep;
        $this_was_listsep = false;
        $previous_was_quote = $this_was_quote;
        $this_was_quote = false;
        if ($c === "\n") {
            $this_was_space = true;
            $count2++;
            PMA_SQP_arrayAdd($sql_array, 'white_newline', "\n", $arraysize, $count2);
            continue;
        }
        // Checks for white space
        if ($pmaString->isSpace($c)) {
            $this_was_space = true;
            $count2++;
            continue;
        }
        // Checks for comment lines.
        // MySQL style #
        // C style /* */
        // ANSI style --
        $next_c = mb_substr($sql, $count2 + 1, 1);
        if ($c == '#' || $count2 + 1 < $len && $c == '/' && $next_c == '*' || $count2 + 2 == $len && $c == '-' && $next_c == '-' || $count2 + 2 < $len && $c == '-' && $next_c == '-' && mb_substr($sql, $count2 + 2, 1) <= ' ') {
            $count2++;
            $pos = 0;
            $type = 'bad';
            switch ($c) {
                case '#':
                    $type = 'mysql';
                    $pos = mb_strpos($sql, "\n", $count2);
                    break;
                case '-':
                    $type = 'ansi';
                    $pos = mb_strpos($sql, "\n", $count2);
                    break;
                case '/':
                    $type = 'c';
                    $pos = mb_strpos($sql, '*/', $count2);
                    $pos += 2;
                    break;
                default:
                    break;
            }
            // end switch
            $count2 = $pos < $count2 ? $len : $pos;
            $str = mb_substr($sql, $count1, $count2 - $count1);
            PMA_SQP_arrayAdd($sql_array, 'comment_' . $type, $str, $arraysize, $count2);
            continue;
        }
        // end if
        // Checks for something inside quotation marks
        if (mb_strpos($quote_list, $c) !== false) {
            $startquotepos = $count2;
            $quotetype = $c;
            $count2++;
            $pos = $count2;
            do {
                $oldpos = $pos;
                $pos = mb_strpos(' ' . $sql, $quotetype, $oldpos + 1) - 1;
                // ($pos === false)
                if ($pos < 0) {
                    if ($c != '`') {
                        $debugstr = __('Unclosed quote') . ' @ ' . $startquotepos . "\n" . 'STR: ' . htmlspecialchars($quotetype);
                        PMA_SQP_throwError($debugstr, $sql);
                        return $sql_array;
                    }
                    /*
                     * Behave same as MySQL and accept end of query as end
                     * of backtick.
                     * I know this is sick, but MySQL behaves like this:
                     *
                     * SELECT * FROM `table
                     *
                     * is treated like
                     *
                     * SELECT * FROM `table`
                     */
                    $pos_quote_separator = mb_strpos(' ' . $sql, $GLOBALS['sql_delimiter'], $oldpos + 1) - 1;
                    if ($pos_quote_separator < 0) {
                        $len += 1;
                        $sql .= '`';
                        $sql_array['raw'] .= '`';
                        $pos = $len;
                    } else {
                        $len += 1;
                        $sql = mb_substr($sql, 0, $pos_quote_separator) . '`' . mb_substr($sql, $pos_quote_separator);
                        $sql_array['raw'] = $sql;
                        $pos = $pos_quote_separator;
                    }
                    if (class_exists('PMA_Message') && $GLOBALS['is_ajax_request'] != true) {
                        PMA_Message::notice(__('Automatically appended backtick to the end of query!'))->display();
                    }
                }
                // If the quote is the first character, it can't be
                // escaped, so don't do the rest of the code
                if ($pos == 0) {
                    break;
                }
                // Checks for MySQL escaping using a \
                // And checks for ANSI escaping using the $quotetype character
                if ($pos < $len && $pmaString->charIsEscaped($sql, $pos) && $c != '`') {
                    $pos++;
                    continue;
                } elseif ($pos + 1 < $len && mb_substr($sql, $pos, 1) == $quotetype && mb_substr($sql, $pos + 1, 1) == $quotetype) {
                    $pos = $pos + 2;
                    continue;
                } else {
                    break;
                }
            } while ($len > $pos);
            // end do
            $count2 = $pos;
            $count2++;
            $type = 'quote_';
            switch ($quotetype) {
                case '\'':
                    $type .= 'single';
                    $this_was_quote = true;
                    break;
                case '"':
                    $type .= 'double';
                    $this_was_quote = true;
                    break;
                case '`':
                    $type .= 'backtick';
                    $this_was_quote = true;
                    break;
                default:
                    break;
            }
            // end switch
            $data = mb_substr($sql, $count1, $count2 - $count1);
            PMA_SQP_arrayAdd($sql_array, $type, $data, $arraysize, $count2);
            continue;
        }
        // Checks for brackets
        if (mb_strpos($bracket_list, $c) !== false) {
            // All bracket tokens are only one item long
            $this_was_bracket = true;
            $count2++;
            if (mb_strpos('([{', $c) !== false) {
                $type_type = 'open';
            } else {
                $type_type = 'close';
            }
            if (mb_strpos('()', $c) !== false) {
                $type_style = 'round';
            } elseif (mb_strpos('[]', $c) !== false) {
                $type_style = 'square';
            } else {
                $type_style = 'curly';
            }
            $type = 'punct_bracket_' . $type_type . '_' . $type_style;
            PMA_SQP_arrayAdd($sql_array, $type, $c, $arraysize, $count2);
            continue;
        }
        /* DEBUG
           echo '<pre>1';
           var_dump($pmaString->isSqlIdentifier($c, false));
           var_dump($c == '@');
           var_dump($c == '.');
           var_dump(
               $pmaString->isDigit(
                   $pmaString->substr($sql, $count2 + 1, 1)
               )
           );
           var_dump($previous_was_space);
           var_dump($previous_was_bracket);
           var_dump($previous_was_listsep);
           echo '</pre>';
           */
        // Checks for identifier (alpha or numeric)
        if ($pmaString->isSqlIdentifier($c, false) || $c == '@' || $c == '.' && $pmaString->isDigit(mb_substr($sql, $count2 + 1, 1)) && ($previous_was_space || $previous_was_bracket || $previous_was_listsep)) {
            /* DEBUG
               echo $pmaString->substr($sql, $count2);
               echo '<hr />';
               */
            $count2++;
            /**
             * @todo a @ can also be present in expressions like
             * FROM 'user'@'%' or  TO 'user'@'%'
             * in this case, the @ is wrongly marked as alpha_variable
             */
            $is_identifier = $previous_was_punct;
            $is_sql_variable = $c == '@' && !$previous_was_quote;
            $is_user = $c == '@' && $previous_was_quote;
            $is_digit = !$is_identifier && !$is_sql_variable && $pmaString->isDigit($c);
            $is_hex_digit = $is_digit && $c == '0' && $count2 < $len && mb_substr($sql, $count2, 1) == 'x';
            $is_float_digit = $c == '.';
            $is_float_digit_exponent = false;
            /* DEBUG
               echo '<pre>2';
               var_dump($is_identifier);
               var_dump($is_sql_variable);
               var_dump($is_digit);
               var_dump($is_float_digit);
               echo '</pre>';
                */
            // Fast skip is especially needed for huge BLOB data
            if ($is_hex_digit) {
                $count2++;
                $pos = strspn($sql, '0123456789abcdefABCDEF', $count2);
                if ($pos > $count2) {
                    $count2 = $pos;
                }
                unset($pos);
            } elseif ($is_digit) {
                $pos = strspn($sql, '0123456789', $count2);
                if ($pos > $count2) {
                    $count2 = $pos;
                }
                unset($pos);
            }
            while ($count2 < $len && $pmaString->isSqlIdentifier(mb_substr($sql, $count2, 1), $is_sql_variable || $is_digit)) {
                $c2 = mb_substr($sql, $count2, 1);
                if ($is_sql_variable && $c2 == '.') {
                    $count2++;
                    continue;
                }
                if ($is_digit && !$is_hex_digit && $c2 == '.') {
                    $count2++;
                    if (!$is_float_digit) {
                        $is_float_digit = true;
                        continue;
                    } else {
                        $debugstr = __('Invalid Identifer') . ' @ ' . ($count1 + 1) . "\n" . 'STR: ' . htmlspecialchars(mb_substr($sql, $count1, $count2 - $count1));
                        PMA_SQP_throwError($debugstr, $sql);
                        return $sql_array;
                    }
                }
                if ($is_digit && !$is_hex_digit && ($c2 == 'e' || $c2 == 'E')) {
                    if (!$is_float_digit_exponent) {
                        $is_float_digit_exponent = true;
                        $is_float_digit = true;
                        $count2++;
                        continue;
                    } else {
                        $is_digit = false;
                        $is_float_digit = false;
                    }
                }
                if ($is_hex_digit && $pmaString->isHexDigit($c2) || $is_digit && $pmaString->isDigit($c2)) {
                    $count2++;
                    continue;
                } else {
                    $is_digit = false;
                    $is_hex_digit = false;
                }
                $count2++;
            }
            // end while
            $l = $count2 - $count1;
            $str = mb_substr($sql, $count1, $l);
            if ($is_digit || $is_float_digit || $is_hex_digit) {
                $type = 'digit';
                if ($is_float_digit) {
                    $type .= '_float';
                } elseif ($is_hex_digit) {
                    $type .= '_hex';
                } else {
                    $type .= '_integer';
                }
            } elseif ($is_user) {
                $type = 'punct_user';
            } elseif ($is_sql_variable != false) {
                $type = 'alpha_variable';
            } else {
                $type = 'alpha';
            }
            // end if... else....
            PMA_SQP_arrayAdd($sql_array, $type, $str, $arraysize, $count2);
            continue;
        }
        // Checks for punct
        if (mb_strpos($allpunct_list, $c) !== false) {
            while ($count2 < $len && mb_strpos($allpunct_list, mb_substr($sql, $count2, 1)) !== false) {
                $count2++;
            }
            $l = $count2 - $count1;
            if ($l == 1) {
                $punct_data = $c;
            } else {
                $punct_data = mb_substr($sql, $count1, $l);
            }
            // Special case, sometimes, although two characters are
            // adjacent directly, they ACTUALLY need to be separate
            /* DEBUG
               echo '<pre>';
               var_dump($l);
               var_dump($punct_data);
               echo '</pre>';
               */
            if ($l == 1) {
                $t_suffix = '';
                switch ($punct_data) {
                    case $punct_queryend:
                        $t_suffix = '_queryend';
                        break;
                    case $punct_qualifier:
                        $t_suffix = '_qualifier';
                        $this_was_punct = true;
                        break;
                    case $punct_listsep:
                        $this_was_listsep = true;
                        $t_suffix = '_listsep';
                        break;
                    default:
                        break;
                }
                PMA_SQP_arrayAdd($sql_array, 'punct' . $t_suffix, $punct_data, $arraysize, $count2);
            } elseif ($punct_data == $GLOBALS['sql_delimiter'] || isset($allpunct_list_pair[$punct_data])) {
                // Ok, we have one of the valid combined punct expressions
                PMA_SQP_arrayAdd($sql_array, 'punct', $punct_data, $arraysize, $count2);
            } else {
                // Bad luck, lets split it up more
                $first = $punct_data[0];
                $last2 = $punct_data[$l - 2] . $punct_data[$l - 1];
                $last = $punct_data[$l - 1];
                if ($first == ',' || $first == ';' || $first == '.' || $first == '*') {
                    $count2 = $count1 + 1;
                    $punct_data = $first;
                } elseif ($last2 == '/*' || $last2 == '--' && ($count2 == $len || mb_substr($sql, $count2, 1) <= ' ')) {
                    $count2 -= 2;
                    $punct_data = mb_substr($sql, $count1, $count2 - $count1);
                } elseif ($last == '-' || $last == '+' || $last == '!') {
                    $count2--;
                    $punct_data = mb_substr($sql, $count1, $count2 - $count1);
                } elseif ($last != '~') {
                    /**
                     * @todo for negation operator, split in 2 tokens ?
                     * "select x&~1 from t"
                     * becomes "select x & ~ 1 from t" ?
                     */
                    $debugstr = __('Unknown Punctuation String') . ' @ ' . ($count1 + 1) . "\n" . 'STR: ' . htmlspecialchars($punct_data);
                    PMA_SQP_throwError($debugstr, $sql);
                    return $sql_array;
                }
                PMA_SQP_arrayAdd($sql_array, 'punct', $punct_data, $arraysize, $count2);
                continue;
            }
            // end if... elseif... else
            continue;
        }
        // DEBUG
        $count2++;
        $debugstr = 'C1 C2 LEN: ' . $count1 . ' ' . $count2 . ' ' . $len . "\n" . 'STR: ' . mb_substr($sql, $count1, $count2 - $count1) . "\n";
        PMA_SQP_bug($debugstr, $sql);
        return $sql_array;
    }
    // end while ($count2 < $len)
    /*
    echo '<pre>';
    print_r($sql_array);
    echo '</pre>';
    */
    if ($arraysize > 0) {
        $t_next = $sql_array[0]['type'];
        $t_prev = '';
        $t_cur = '';
        $d_next = $sql_array[0]['data'];
        $d_prev = '';
        $d_cur = '';
        $d_next_upper = $t_next == 'alpha' ? mb_strtoupper($d_next) : $d_next;
        $d_prev_upper = '';
        $d_cur_upper = '';
    }
    for ($i = 0; $i < $arraysize; $i++) {
        $t_prev = $t_cur;
        $t_cur = $t_next;
        $d_prev = $d_cur;
        $d_cur = $d_next;
        $d_bef_prev_upper = $d_prev_upper;
        $d_prev_upper = $d_cur_upper;
        $d_cur_upper = $d_next_upper;
        if ($i + 1 < $arraysize) {
            $t_next = $sql_array[$i + 1]['type'];
            $d_next = $sql_array[$i + 1]['data'];
            $d_next_upper = $t_next == 'alpha' ? mb_strtoupper($d_next) : $d_next;
        } else {
            $t_next = '';
            $d_next = '';
            $d_next_upper = '';
        }
        /* DEBUG
           echo "[prev: <strong>".$d_prev."</strong> ".$t_prev."][cur: <strong>"
               . $d_cur."</strong> ".$t_cur."][next: <strong>".$d_next."</strong> "
               . $t_next."]<br />";
           */
        if ($t_cur == 'alpha') {
            $t_suffix = '_identifier';
            // for example: `thebit` bit(8) NOT NULL DEFAULT b'0'
            if ($t_prev == 'alpha' && $d_prev == 'DEFAULT' && $d_cur == 'b' && $t_next == 'quote_single') {
                $t_suffix = '_bitfield_constant_introducer';
            } elseif ($t_next == 'punct_qualifier' || $t_prev == 'punct_qualifier') {
                $t_suffix = '_identifier';
            } elseif ($t_next == 'punct_bracket_open_round' && isset($PMA_SQPdata_function_name[$d_cur_upper])) {
                /**
                 * @todo 2005-10-16: in the case of a CREATE TABLE containing
                 * a TIMESTAMP, since TIMESTAMP() is also a function, it's
                 * found here and the token is wrongly marked as alpha_functionName.
                 * But we compensate for this when analysing for timestamp_not_null
                 * later in this script.
                 *
                 * Same applies to CHAR vs. CHAR() function.
                 */
                $t_suffix = '_functionName';
                /* There are functions which might be as well column types */
            } elseif (isset($PMA_SQPdata_column_type[$d_cur_upper])) {
                $t_suffix = '_columnType';
                /**
                 * Temporary fix for bugs #621357 and #2027720
                 *
                 * @todo FIX PROPERLY NEEDS OVERHAUL OF SQL TOKENIZER
                 */
                if (($d_cur_upper == 'SET' || $d_cur_upper == 'BINARY') && $t_next != 'punct_bracket_open_round') {
                    $t_suffix = '_reservedWord';
                }
                //END OF TEMPORARY FIX
                // CHARACTER is a synonym for CHAR, but can also be meant as
                // CHARACTER SET. In this case, we have a reserved word.
                if ($d_cur_upper == 'CHARACTER' && $d_next_upper == 'SET') {
                    $t_suffix = '_reservedWord';
                }
                // experimental
                // current is a column type, so previous must not be
                // a reserved word but an identifier
                // CREATE TABLE SG_Persons (first varchar(64))
                //if ($sql_array[$i-1]['type'] =='alpha_reservedWord') {
                //    $sql_array[$i-1]['type'] = 'alpha_identifier';
                //}
            } elseif (isset($PMA_SQPdata_reserved_word[$d_cur_upper])) {
                $t_suffix = '_reservedWord';
            } elseif (isset($PMA_SQPdata_column_attrib[$d_cur_upper])) {
                $t_suffix = '_columnAttrib';
                // INNODB is a MySQL table type, but in "SHOW ENGINE INNODB STATUS",
                // it should be regarded as a reserved word.
                if ($d_cur_upper == 'INNODB' && $d_prev_upper == 'SHOW' && $d_next_upper == 'STATUS') {
                    $t_suffix = '_reservedWord';
                }
                if ($d_cur_upper == 'DEFAULT' && $d_next_upper == 'CHARACTER') {
                    $t_suffix = '_reservedWord';
                }
                // Binary as character set
                if ($d_cur_upper == 'BINARY' && ($d_bef_prev_upper == 'CHARACTER' && $d_prev_upper == 'SET' || $d_bef_prev_upper == 'SET' && $d_prev_upper == '=' || $d_bef_prev_upper == 'CHARSET' && $d_prev_upper == '=' || $d_prev_upper == 'CHARSET') && in_array($d_cur, $mysql_charsets)) {
                    $t_suffix = '_charset';
                }
            } elseif (in_array($d_cur, $mysql_charsets) || in_array($d_cur, $mysql_collations_flat) || $d_cur[0] == '_' && in_array(mb_substr($d_cur, 1), $mysql_charsets)) {
                $t_suffix = '_charset';
            } else {
                // Do nothing
            }
            // check if present in the list of forbidden words
            if ($t_suffix == '_reservedWord' && isset($PMA_SQPdata_forbidden_word[$d_cur_upper])) {
                $sql_array[$i]['forbidden'] = true;
            } else {
                $sql_array[$i]['forbidden'] = false;
            }
            $sql_array[$i]['type'] .= $t_suffix;
        }
    }
    // end for
    // Stores the size of the array inside the array, as count() is a slow
    // operation.
    $sql_array['len'] = $arraysize;
    // DEBUG echo 'After parsing<pre>'; print_r($sql_array); echo '</pre>';
    // Sends the data back
    return $sql_array;
}
Beispiel #7
0
/**
 * Function to get html for tracking report and tracking report export
 *
 * @param string  $url_query        url query
 * @param array   $data             data
 * @param array   $url_params       url params
 * @param boolean $selection_schema selection schema
 * @param boolean $selection_data   selection data
 * @param boolean $selection_both   selection both
 * @param int     $filter_ts_to     filter time stamp from
 * @param int     $filter_ts_from   filter time stamp tp
 * @param array   $filter_users     filter users
 *
 * @return string
 */
function PMA_getHtmlForTrackingReport($url_query, $data, $url_params, $selection_schema, $selection_data, $selection_both, $filter_ts_to, $filter_ts_from, $filter_users)
{
    $html = '<h3>' . __('Tracking report') . '  [<a href="tbl_tracking.php' . $url_query . '">' . __('Close') . '</a>]</h3>';
    $html .= '<small>' . __('Tracking statements') . ' ' . htmlspecialchars($data['tracking']) . '</small><br/>';
    $html .= '<br/>';
    list($str1, $str2, $str3, $str4, $str5) = PMA_getHtmlForElementsOfTrackingReport($selection_schema, $selection_data, $selection_both);
    // Prepare delete link content here
    $drop_image_or_text = '';
    if (PMA_Util::showIcons('ActionLinksMode')) {
        $drop_image_or_text .= PMA_Util::getImage('b_drop.png', __('Delete tracking data row from report'));
    }
    if (PMA_Util::showText('ActionLinksMode')) {
        $drop_image_or_text .= __('Delete');
    }
    /*
     *  First, list tracked data definition statements
     */
    if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
        $msg = PMA_Message::notice(__('No data'));
        $msg->display();
    }
    $html .= PMA_getHtmlForTrackingReportExportForm1($data, $url_params, $selection_schema, $selection_data, $selection_both, $filter_ts_to, $filter_ts_from, $filter_users, $str1, $str2, $str3, $str4, $str5, $drop_image_or_text);
    $html .= PMA_getHtmlForTrackingReportExportForm2($url_params, $str1, $str2, $str3, $str4, $str5);
    $html .= "<br/><br/><hr/><br/>\n";
    return $html;
}
 /**
  * add another string to be concatenated on displaying
  *
  * @uses    PMA_Message::$_added_messages to fill
  * @uses    PMA_Message::notice()
  * @param   string  $string    to be added
  * @param   string  $separator to use between this and previous string/message
  */
 public function addString($string, $separator = ' ')
 {
     $this->_added_messages[] = $separator;
     $this->_added_messages[] = PMA_Message::notice($string);
 }
/**
 * Executes the sql query and get the result, then move back to the calling page
 *
 * @param array $url_params url parameters array
 * @param array $query      built query from PMA_buildSqlQuery()
 *
 * @return array            $url_params, $total_affected_rows, $last_messages
 *                          $warning_messages, $error_messages, $return_to_sql_query
 */
function PMA_executeSqlQuery($url_params, $query)
{
    $return_to_sql_query = '';
    if (!empty($GLOBALS['sql_query'])) {
        $url_params['sql_query'] = $GLOBALS['sql_query'];
        $return_to_sql_query = $GLOBALS['sql_query'];
    }
    $GLOBALS['sql_query'] = implode('; ', $query) . ';';
    // to ensure that the query is displayed in case of
    // "insert as new row" and then "insert another new row"
    $GLOBALS['display_query'] = $GLOBALS['sql_query'];
    $total_affected_rows = 0;
    $last_messages = array();
    $warning_messages = array();
    $error_messages = array();
    foreach ($query as $single_query) {
        if ($_REQUEST['submit_type'] == 'showinsert') {
            $last_messages[] = PMA_Message::notice(__('Showing SQL query'));
            continue;
        }
        if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) {
            $result = $GLOBALS['dbi']->tryQuery($single_query);
        } else {
            $result = $GLOBALS['dbi']->query($single_query);
        }
        if (!$result) {
            $error_messages[] = PMA_Message::sanitize($GLOBALS['dbi']->getError());
        } else {
            // The next line contains a real assignment, it's not a typo
            if ($tmp = @$GLOBALS['dbi']->affectedRows()) {
                $total_affected_rows += $tmp;
            }
            unset($tmp);
            $insert_id = $GLOBALS['dbi']->insertId();
            if ($insert_id != 0) {
                // insert_id is id of FIRST record inserted in one insert, so if we
                // inserted multiple rows, we had to increment this
                if ($total_affected_rows > 0) {
                    $insert_id = $insert_id + $total_affected_rows - 1;
                }
                $last_message = PMA_Message::notice(__('Inserted row id: %1$d'));
                $last_message->addParam($insert_id);
                $last_messages[] = $last_message;
            }
            $GLOBALS['dbi']->freeResult($result);
        }
        $warning_messages = PMA_getWarningMessages();
    }
    return array($url_params, $total_affected_rows, $last_messages, $warning_messages, $error_messages, $return_to_sql_query);
}
Beispiel #10
0
 /**
  * Set the content that needs to be shown in message
  *
  * @param string  $sorted_column_message the message for sorted column
  * @param string  $limit_clause          the limit clause of analyzed query
  * @param integer $total                 the total number of rows returned by
  *                                       the SQL query without any
  *                                       programmatically appended LIMIT clause
  * @param integer $pos_next              the offset for next page
  * @param string  $pre_count             the string renders before row count
  * @param string  $after_count           the string renders after row count
  *
  * @return PMA_Message $message an object of PMA_Message
  *
  * @access  private
  *
  * @see     getTable()
  */
 private function _setMessageInformation($sorted_column_message, $limit_clause, $total, $pos_next, $pre_count, $after_count)
 {
     $unlim_num_rows = $this->__get('unlim_num_rows');
     // To use in isset()
     if (!empty($limit_clause)) {
         $limit_data = PMA_Util::analyzeLimitClause($limit_clause);
         $first_shown_rec = $limit_data['start'];
         if ($limit_data['length'] < $total) {
             $last_shown_rec = $limit_data['start'] + $limit_data['length'] - 1;
         } else {
             $last_shown_rec = $limit_data['start'] + $total - 1;
         }
     } elseif ($_SESSION['tmpval']['max_rows'] == self::ALL_ROWS || $pos_next > $total) {
         $first_shown_rec = $_SESSION['tmpval']['pos'];
         $last_shown_rec = $total - 1;
     } else {
         $first_shown_rec = $_SESSION['tmpval']['pos'];
         $last_shown_rec = $pos_next - 1;
     }
     if (PMA_Table::isView($this->__get('db'), $this->__get('table')) && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
         $message = PMA_Message::notice(__('This view has at least this number of rows. ' . 'Please refer to %sdocumentation%s.'));
         $message->addParam('[doc@cfg_MaxExactCount]');
         $message->addParam('[/doc]');
         $message_view_warning = PMA_Util::showHint($message);
     } else {
         $message_view_warning = false;
     }
     $message = PMA_Message::success(__('Showing rows %1s - %2s'));
     $message->addParam($first_shown_rec);
     if ($message_view_warning) {
         $message->addParam('... ' . $message_view_warning, false);
     } else {
         $message->addParam($last_shown_rec);
     }
     $message->addMessage('(');
     if (!$message_view_warning) {
         if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
             $message_total = PMA_Message::notice($pre_count . __('%1$d total, %2$d in query'));
             $message_total->addParam($total);
             $message_total->addParam($unlim_num_rows);
         } else {
             $message_total = PMA_Message::notice($pre_count . __('%d total'));
             $message_total->addParam($total);
         }
         if (!empty($after_count)) {
             $message_total->addMessage($after_count);
         }
         $message->addMessage($message_total, '');
         $message->addMessage(', ', '');
     }
     $message_qt = PMA_Message::notice(__('Query took %01.4f seconds.') . ')');
     $message_qt->addParam($this->__get('querytime'));
     $message->addMessage($message_qt, '');
     if (!is_null($sorted_column_message)) {
         $message->addMessage($sorted_column_message, '');
     }
     return $message;
 }
Beispiel #11
0
/**
 * Get Html for PMA tables fixing anchor.
 *
 * @param boolean $allTables whether to create all tables
 *
 * @return string Html
 */
function PMA_getHtmlFixPMATables($allTables)
{
    $retval = '';
    $url_query = PMA_URL_getCommon(array('db' => $GLOBALS['db']));
    if ($allTables) {
        $url_query .= '&amp;goto=db_operations.php&amp;create_pmadb=1';
        $message = PMA_Message::notice(__('%sCreate%s the phpMyAdmin configuration storage in the ' . 'current database.'));
    } else {
        $url_query .= '&amp;goto=db_operations.php&amp;fix_pmadb=1';
        $message = PMA_Message::notice(__('%sCreate%s missing phpMyAdmin configuration storage tables.'));
    }
    $message->addParam('<a href="' . $GLOBALS['cfg']['PmaAbsoluteUri'] . 'chk_rel.php' . $url_query . '">', false);
    $message->addParam('</a>', false);
    $retval .= $message->getDisplay();
    return $retval;
}
/**
 * Displays a table of results returned by a SQL query.
 * This function is called by the "sql.php" script.
 *
 * @param   integer the link id associated to the query which results have
 *                  to be displayed
 * @param   array   the display mode
 * @param   array   the analyzed query
 *
 * @uses    $_SESSION['tmp_user_values']['pos']
 * @global  string   $db                the database name
 * @global  string   $table             the table name
 * @global  string   $goto              the URL to go back in case of errors
 * @global  string   $sql_query         the current SQL query
 * @global  integer  $num_rows          the total number of rows returned by the
 *                                      SQL query
 * @global  integer  $unlim_num_rows    the total number of rows returned by the
 *                                      SQL query without any programmatically
 *                                      appended "LIMIT" clause
 * @global  array    $fields_meta       the list of fields properties
 * @global  integer  $fields_cnt        the total number of fields returned by
 *                                      the SQL query
 * @global  array    $vertical_display  informations used with vertical display
 *                                      mode
 * @global  array    $highlight_columns column names to highlight
 * @global  array    $cfgRelation       the relation settings
 *
 * @access  private
 *
 * @see     PMA_showMessage(), PMA_setDisplayMode(),
 *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
 *          PMA_displayTableBody(), PMA_displayResultsOperations()
 */
function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
{
    global $db, $table, $goto;
    global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
    global $vertical_display, $highlight_columns;
    global $cfgRelation;
    global $showtable;
    // why was this called here? (already called from sql.php)
    //PMA_displayTable_checkConfigParams();
    /**
     * @todo move this to a central place
     * @todo for other future table types
     */
    $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB';
    if ($is_innodb && !isset($analyzed_sql[0]['queryflags']['union']) && !isset($analyzed_sql[0]['table_ref'][1]['table_name']) && (empty($analyzed_sql[0]['where_clause']) || $analyzed_sql[0]['where_clause'] == '1 ')) {
        // "j u s t   b r o w s i n g"
        $pre_count = '~';
        $after_count = PMA_showHint(PMA_sanitize($GLOBALS['strApproximateCount']), true);
    } else {
        $pre_count = '';
        $after_count = '';
    }
    // 1. ----- Prepares the work -----
    // 1.1 Gets the informations about which functionalities should be
    //     displayed
    $total = '';
    $is_display = PMA_setDisplayMode($the_disp_mode, $total);
    // 1.2 Defines offsets for the next and previous pages
    if ($is_display['nav_bar'] == '1') {
        if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
            $pos_next = 0;
            $pos_prev = 0;
        } else {
            $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
            $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
            if ($pos_prev < 0) {
                $pos_prev = 0;
            }
        }
    }
    // end if
    // 1.3 Find the sort expression
    // we need $sort_expression and $sort_expression_nodirection
    // even if there are many table references
    if (!empty($analyzed_sql[0]['order_by_clause'])) {
        $sort_expression = trim(str_replace('  ', ' ', $analyzed_sql[0]['order_by_clause']));
        /**
         * Get rid of ASC|DESC
         */
        preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
        $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
        $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
        unset($matches);
    } else {
        $sort_expression = $sort_expression_nodirection = $sort_direction = '';
    }
    // 1.4 Prepares display of first and last value of the sorted column
    if (!empty($sort_expression_nodirection)) {
        list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
        $sort_table = PMA_unQuote($sort_table);
        $sort_column = PMA_unQuote($sort_column);
        // find the sorted column index in row result
        // (this might be a multi-table query)
        $sorted_column_index = false;
        foreach ($fields_meta as $key => $meta) {
            if ($meta->table == $sort_table && $meta->name == $sort_column) {
                $sorted_column_index = $key;
                break;
            }
        }
        if ($sorted_column_index !== false) {
            // fetch first row of the result set
            $row = PMA_DBI_fetch_row($dt_result);
            $column_for_first_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
            // fetch last row of the result set
            PMA_DBI_data_seek($dt_result, $num_rows - 1);
            $row = PMA_DBI_fetch_row($dt_result);
            $column_for_last_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
            // reset to first row for the loop in PMA_displayTableBody()
            PMA_DBI_data_seek($dt_result, 0);
            // we could also use here $sort_expression_nodirection
            $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
            unset($row, $column_for_first_row, $column_for_last_row);
        }
        unset($sorted_column_index, $sort_table, $sort_column);
    }
    // 2. ----- Displays the top of the page -----
    // 2.1 Displays a messages with position informations
    if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
        if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
            $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
        } else {
            $selectstring = '';
        }
        $last_shown_rec = $_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total ? $total - 1 : $pos_next - 1;
        if (PMA_Table::isView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
            $message = PMA_Message::notice('strViewHasAtLeast');
            $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
            $message->addParam('[/a]');
            $message_view_warning = PMA_showHint($message);
        } else {
            $message_view_warning = false;
        }
        $message = PMA_Message::success('strShowingRecords');
        $message->addMessage($_SESSION['tmp_user_values']['pos']);
        if ($message_view_warning) {
            $message->addMessage('...', ' - ');
            $message->addMessage($message_view_warning);
            $message->addMessage('(');
        } else {
            $message->addMessage($last_shown_rec, ' - ');
            $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' (');
            $message->addString('strTotal');
            $message->addMessage($selectstring, '');
            $message->addMessage(', ', '');
        }
        $messagge_qt = PMA_Message::notice('strQueryTime');
        $messagge_qt->addParam($GLOBALS['querytime']);
        $message->addMessage($messagge_qt, '');
        $message->addMessage(')', '');
        $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
        PMA_showMessage($message, $sql_query, 'success');
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success');
    }
    // 2.3 Displays the navigation bars
    if (!strlen($table)) {
        if (isset($analyzed_sql[0]['query_type']) && $analyzed_sql[0]['query_type'] == 'SELECT') {
            // table does not always contain a real table name,
            // for example in MySQL 5.0.x, the query SHOW STATUS
            // returns STATUS as a table name
            $table = $fields_meta[0]->table;
        } else {
            $table = '';
        }
    }
    if ($is_display['nav_bar'] == '1') {
        PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
        echo "\n";
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        echo "\n" . '<br /><br />' . "\n";
    }
    // 2b ----- Get field references from Database -----
    // (see the 'relation' configuration variable)
    // loic1, 2002-03-02: extended to php3
    // initialize map
    $map = array();
    // find tables
    $target = array();
    if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
        foreach ($analyzed_sql[0]['table_ref'] as $table_ref_position => $table_ref) {
            $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
        }
    }
    $tabs = '(\'' . join('\',\'', $target) . '\')';
    if ($cfgRelation['displaywork']) {
        if (!strlen($table)) {
            $exist_rel = false;
        } else {
            $exist_rel = PMA_getForeigners($db, $table, '', 'both');
            if ($exist_rel) {
                foreach ($exist_rel as $master_field => $rel) {
                    $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
                    $map[$master_field] = array($rel['foreign_table'], $rel['foreign_field'], $display_field, $rel['foreign_db']);
                }
                // end while
            }
            // end if
        }
        // end if
    }
    // end if
    // end 2b
    // 3. ----- Displays the results table -----
    PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
    $url_query = '';
    echo '<tbody>' . "\n";
    $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
    // vertical output case
    if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
        PMA_displayVerticalTable();
    }
    // end if
    unset($vertical_display);
    echo '</tbody>' . "\n";
    ?>
</table>

    <?php 
    // 4. ----- Displays the link for multi-fields edit and delete
    if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
        $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
        $_url_params = array('db' => $db, 'table' => $table, 'sql_query' => $sql_query, 'goto' => $goto);
        $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
        $_url_params['checkall'] = '1';
        $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
        if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
            $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
            $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
        } else {
            $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
            $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
        }
        $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
        $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
        if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
            echo '<img class="selectallarrow" width="38" height="22"' . ' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"' . ' alt="' . $GLOBALS['strWithChecked'] . '" />';
        }
        echo $checkall_link . "\n" . ' / ' . "\n" . $uncheckall_link . "\n" . '<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
        PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
        PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_delete', $delete_text, 'b_drop.png');
        if ($analyzed_sql[0]['querytype'] == 'SELECT') {
            PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', $GLOBALS['strExport'], 'b_tblexport.png');
        }
        echo "\n";
        echo '<input type="hidden" name="sql_query"' . ' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
        echo '<input type="hidden" name="url_query"' . ' value="' . $GLOBALS['url_query'] . '" />' . "\n";
        echo '<input type="hidden" name="clause_is_unique"' . ' value="' . $clause_is_unique . '" />' . "\n";
        echo '</form>' . "\n";
    }
    // 5. ----- Displays the navigation bar at the bottom if required -----
    if ($is_display['nav_bar'] == '1') {
        echo '<br />' . "\n";
        PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        echo "\n" . '<br /><br />' . "\n";
    }
    // 6. ----- Displays "Query results operations"
    if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
    }
}
Beispiel #13
0
        $result = PMA_DBI_query($single_query);
    }
    if (!$result) {
        $error_messages[] = PMA_DBI_getError();
    } else {
        if (@PMA_DBI_affected_rows()) {
            $total_affected_rows += @PMA_DBI_affected_rows();
        }
        $insert_id = PMA_DBI_insert_id();
        if ($insert_id != 0) {
            // insert_id is id of FIRST record inserted in one insert, so if we
            // inserted multiple rows, we had to increment this
            if ($total_affected_rows > 0) {
                $insert_id = $insert_id + $total_affected_rows - 1;
            }
            $last_message = PMA_Message::notice('strInsertedRowId');
            $last_message->addParam($insert_id);
            $last_messages[] = $last_message;
        }
        PMA_DBI_free_result($result);
    }
    // end if
    foreach (PMA_DBI_get_warnings() as $warning) {
        $warning_messages[] = $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message'];
    }
    unset($result);
}
unset($single_query, $query);
$message->addParam($total_affected_rows);
$message->addMessages($last_messages, '<br />');
if (!empty($warning_messages)) {
Beispiel #14
0
        // the form should not have priority over errors
    } elseif (! empty($message_to_show) && ! $is_select) {
        $message = PMA_Message::rawSuccess(htmlspecialchars($message_to_show));
    } elseif (! empty($GLOBALS['show_as_php'])) {
        $message = PMA_Message::success(__('Showing as PHP code'));
    } elseif (isset($GLOBALS['show_as_php'])) {
        /* User disable showing as PHP, query is only displayed */
        $message = PMA_Message::notice(__('Showing SQL query'));
    } elseif (! empty($GLOBALS['validatequery'])) {
        $message = PMA_Message::notice(__('Validated SQL'));
    } else {
        $message = PMA_Message::success(__('MySQL returned an empty result set (i.e. zero rows).'));
    }

    if (isset($GLOBALS['querytime'])) {
        $_querytime = PMA_Message::notice(__('Query took %01.4f sec'));
        $_querytime->addParam($GLOBALS['querytime']);
        $message->addMessage('(');
        $message->addMessage($_querytime);
        $message->addMessage(')');
    }

    if ($GLOBALS['is_ajax_request'] == true) {
        if ($cfg['ShowSQL']) {
            $extra_data['sql_query'] = PMA_showMessage($message, $GLOBALS['sql_query'], 'success');
        }
        if (isset($GLOBALS['reload']) && $GLOBALS['reload'] == 1) {
            $extra_data['reload'] = 1;
            $extra_data['db'] = $GLOBALS['db'];
        }
        PMA_ajaxResponse($message, $message->isSuccess(), (isset($extra_data) ? $extra_data : ''));
Beispiel #15
0
if ($file_to_unlink != '') {
    unlink($file_to_unlink);
}
// Reset charset back, if we did some changes
if ($reset_charset) {
    PMA_DBI_query('SET CHARACTER SET utf8');
    PMA_DBI_query('SET SESSION collation_connection =\'' . $collation_connection . '\'');
}
// Show correct message
if (!empty($id_bookmark) && $action_bookmark == 2) {
    $message = PMA_Message::success(__('The bookmark has been deleted.'));
    $display_query = $import_text;
    $error = FALSE;
    // unset error marker, it was used just to skip processing
} elseif (!empty($id_bookmark) && $action_bookmark == 1) {
    $message = PMA_Message::notice(__('Showing bookmark'));
} elseif ($bookmark_created) {
    $special_message = '[br]' . sprintf(__('Bookmark %s created'), htmlspecialchars($bkm_label));
} elseif ($finished && !$error) {
    if ($import_type == 'query') {
        $message = PMA_Message::success();
    } else {
        if ($import_notice) {
            $message = PMA_Message::success('<em>' . __('Import has been successfully finished, %d queries executed.') . '</em>');
            $message->addParam($executed_queries);
            $message->addString($import_notice);
            $message->addString('(' . $_FILES['import_file']['name'] . ')');
        } else {
            $message = PMA_Message::success(__('Import has been successfully finished, %d queries executed.'));
            $message->addParam($executed_queries);
            $message->addString('(' . $_FILES['import_file']['name'] . ')');
/**
 * Function to get html for displaying the index form
 *
 * @param array     $fields      fields
 * @param PMA_Index $index       index
 * @param array     $form_params form parameters
 * @param int       $add_fields  number of fields in the form
 *
 * @return string
 */
function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields)
{
    $html = "";
    $html .= '<form action="tbl_indexes.php" method="post" name="index_frm" id="' . 'index_frm" class="ajax"' . 'onsubmit="if (typeof(this.elements[\'index[Key_name]\'].disabled) !=' . ' \'undefined\') {' . 'this.elements[\'index[Key_name]\'].disabled = false}">';
    $html .= PMA_URL_getHiddenInputs($form_params);
    $html .= '<fieldset id="index_edit_fields">';
    $html .= '<div class="index_info">';
    $html .= '<div>' . '<div class="label">' . '<strong>' . '<label for="input_index_name">' . __('Index name:') . PMA_Util::showHint(PMA_Message::notice(__('"PRIMARY" <b>must</b> be the name of' . ' and <b>only of</b> a primary key!'))) . '</label>' . '</strong>' . '</div>' . '<input type="text" name="index[Key_name]" id="input_index_name"' . ' size="25"' . 'value="' . htmlspecialchars($index->getName()) . '"' . 'onfocus="this.select()" />' . '</div>';
    $html .= '<div>' . '<div class="label">' . '<strong>' . '<label for="input_index_comment">' . __('Comment:') . '</label>' . '</strong>' . '</div>' . '<input type="text" name="index[Index_comment]" ' . 'id="input_index_comment" size="30"' . 'value="' . htmlspecialchars($index->getComment()) . '"' . 'onfocus="this.select()" />' . '</div>';
    $html .= '<div>' . '<div class="label">' . '<strong>' . '<label for="select_index_type">' . __('Index type:') . PMA_Util::showMySQLDocu('ALTER_TABLE') . '</label>' . '</strong>' . '</div>' . '<select name="index[Index_type]" id="select_index_type" ' . (isset($_REQUEST['create_edit_table']) ? 'disabled="disabled"' : '') . '>' . $index->generateIndexSelector() . '</select>' . '</div>';
    $html .= '<div class="clearfloat"></div>';
    $html .= '</div>';
    $html .= '<table id="index_columns">';
    $html .= '<thead>' . '<tr>' . '<th>' . __('Column') . '</th>' . '<th>' . __('Size') . '</th>' . '</tr>' . '</thead>';
    $odd_row = true;
    $spatial_types = array('geometry', 'point', 'linestring', 'polygon', 'multipoint', 'multilinestring', 'multipolygon', 'geomtrycollection');
    $html .= '<tbody>';
    /* @var $column PMA_Index_Column */
    foreach ($index->getColumns() as $column) {
        $html .= '<tr class="';
        $html .= $odd_row ? 'odd' : 'even';
        $html .= 'noclick">';
        $html .= '<td><span class="drag_icon" title="' . __('Drag to reorder') . '"' . '></span>';
        $html .= '<select name="index[columns][names][]">';
        $html .= '<option value="">-- ' . __('Ignore') . ' --</option>';
        foreach ($fields as $field_name => $field_type) {
            if (($index->getType() != 'FULLTEXT' || preg_match('/(char|text)/i', $field_type)) && ($index->getType() != 'SPATIAL' || in_array($field_type, $spatial_types))) {
                $html .= '<option value="' . htmlspecialchars($field_name) . '"' . ($field_name == $column->getName() ? ' selected="selected"' : '') . '>' . htmlspecialchars($field_name) . ' [' . htmlspecialchars($field_type) . ']' . '</option>' . "\n";
            }
        }
        // end foreach $fields
        $html .= '</select>';
        $html .= '</td>';
        $html .= '<td>';
        $html .= '<input type="text" size="5" onfocus="this.select()"' . 'name="index[columns][sub_parts][]" value="';
        if ($index->getType() != 'SPATIAL') {
            $html .= $column->getSubPart();
        }
        $html .= '"/>';
        $html .= '</td>';
        $html .= '</tr>';
        $odd_row = !$odd_row;
    }
    // end foreach $edited_index_info['Sequences']
    for ($i = 0; $i < $add_fields; $i++) {
        $html .= '<tr class="';
        $html .= $odd_row ? 'odd' : 'even';
        $html .= 'noclick">';
        $html .= '<td><span class="drag_icon" title="' . __('Drag to reorder') . '"' . '></span>';
        $html .= '<select name="index[columns][names][]">';
        $html .= '<option value="">-- ' . __('Ignore') . ' --</option>';
        $j = 0;
        foreach ($fields as $field_name => $field_type) {
            if (isset($_REQUEST['create_edit_table'])) {
                $col_index = $field_type[1];
                $field_type = $field_type[0];
            }
            $html .= '<option value="' . htmlspecialchars(isset($col_index) ? $col_index : $field_name) . '" ' . ($j++ == $i ? 'selected="selected"' : '') . '>' . htmlspecialchars($field_name) . ' [' . htmlspecialchars($field_type) . ']' . '</option>' . "\n";
        }
        // end foreach $fields
        $html .= '</select>';
        $html .= '</td>';
        $html .= '<td>' . '<input type="text" size="5" onfocus="this.select()"' . 'name="index[columns][sub_parts][]" value="" />' . '</td>';
        $html .= '</tr>';
        $odd_row = !$odd_row;
    }
    // end foreach $edited_index_info['Sequences']
    $html .= '</tbody>';
    $html .= '</table>';
    $html .= '</fieldset>';
    $html .= '<fieldset class="tblFooters">';
    $btn_value = sprintf(__('Add %s column(s) to index'), 1);
    $html .= '<div class="slider"></div>';
    $html .= '<div class="add_fields">';
    $html .= '<input type="submit" value="' . $btn_value . '" />';
    $html .= '</div>';
    $html .= '</fieldset>';
    $html .= '</form>';
    return $html;
}
Beispiel #17
0
        $message = PMA_Message::notice(__('The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. To find out why click %shere%s.'));
        $message->addParam('<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $common_url_query . '">', false);
        $message->addParam('</a>', false);
        /* Show error if user has configured something, notice elsewhere */
        if (!empty($cfg['Servers'][$server]['pmadb'])) {
            $message->isError(true);
        }
        $message->display();
    }
    // end if
}
/**
 * Show notice when javascript support is missing.
 */
echo '<noscript>';
$message = PMA_Message::notice(__('Javascript support is missing or disabled in your browser, some phpMyAdmin functionality will be missing. For example navigation frame will not refresh automatically.'));
$message->isError(true);
$message->display();
echo '</noscript>';
/**
 * Warning about different MySQL library and server version
 * (a difference on the third digit does not count).
 * If someday there is a constant that we can check about mysqlnd, we can use it instead
 * of strpos().
 * If no default server is set, PMA_DBI_get_client_info() is not defined yet.
 */
if (function_exists('PMA_DBI_get_client_info')) {
    $_client_info = PMA_DBI_get_client_info();
    if ($server > 0 && strpos($_client_info, 'mysqlnd') === false && substr(PMA_MYSQL_CLIENT_API, 0, 3) != substr(PMA_MYSQL_INT_VERSION, 0, 3)) {
        trigger_error(PMA_sanitize(sprintf(__('Your PHP MySQL library version %s differs from your MySQL server version %s. This may cause unpredictable behavior.'), $_client_info, substr(PMA_MYSQL_STR_VERSION, 0, strpos(PMA_MYSQL_STR_VERSION . '-', '-')))), E_USER_NOTICE);
    }
/**
 * returns html code for table with slave users connected to this master
 *
 * @param boolean $hidden - if true, then default style is set to hidden,
 *                        - default value false
 *
 * @return string
 */
function PMA_getHtmlForReplicationSlavesTable($hidden = false)
{
    $html = '';
    // Fetch data
    $data = $GLOBALS['dbi']->fetchResult('SHOW SLAVE HOSTS', null, null);
    $html .= '  <br />';
    $html .= '  <div id="replication_slaves_section" style="';
    $html .= ($hidden ? 'display: none;' : '') . '"> ';
    $html .= '    <table class="data">';
    $html .= '    <thead>';
    $html .= '      <tr>';
    $html .= '        <th>' . __('Server ID') . '</th>';
    $html .= '        <th>' . __('Host') . '</th>';
    $html .= '      </tr>';
    $html .= '    </thead>';
    $html .= '    <tbody>';
    $odd_row = true;
    foreach ($data as $slave) {
        $html .= '    <tr class="' . ($odd_row ? 'odd' : 'even') . '">';
        $html .= '      <td class="value">' . $slave['Server_id'] . '</td>';
        $html .= '      <td class="value">' . $slave['Host'] . '</td>';
        $html .= '    </tr>';
        $odd_row = !$odd_row;
    }
    $html .= '    </tbody>';
    $html .= '    </table>';
    $html .= '    <br />';
    $html .= PMA_Message::notice(__('Only slaves started with the ' . '--report-host=host_name option are visible in this list.'))->getDisplay();
    $html .= '    <br />';
    $html .= '  </div>';
    return $html;
}
Beispiel #19
0
     // the form should not have priority over
     // errors like $strEmptyResultSet
 } elseif (!empty($zero_rows) && !$is_select) {
     $message = PMA_Message::rawSuccess(htmlspecialchars($zero_rows));
 } elseif (!empty($GLOBALS['show_as_php'])) {
     $message = PMA_Message::success('strShowingPhp');
 } elseif (isset($GLOBALS['show_as_php'])) {
     /* User disable showing as PHP, query is only displayed */
     $message = PMA_Message::notice('strShowingSQL');
 } elseif (!empty($GLOBALS['validatequery'])) {
     $message = PMA_Message::notice('strValidateSQL');
 } else {
     $message = PMA_Message::success('strEmptyResultSet');
 }
 if (isset($GLOBALS['querytime'])) {
     $_querytime = PMA_Message::notice('strQueryTime');
     $_querytime->addParam($GLOBALS['querytime']);
     $message->addMessage('(');
     $message->addMessage($_querytime);
     $message->addMessage(')');
 }
 if ($is_gotofile) {
     $goto = PMA_securePath($goto);
     // Checks for a valid target script
     $is_db = $is_table = false;
     include 'libraries/db_table_exists.lib.php';
     if (strpos($goto, 'tbl_') === 0 && !$is_table) {
         if (strlen($table)) {
             $table = '';
         }
         $goto = 'db_sql.php';
Beispiel #20
0
                </div>
                <div id="opts_export_local_storage" class="prefsmanage_opts disabled">
                    <span class="localStorage-supported">
                        <?php 
echo __('Settings will be saved in your browser\'s local storage.');
?>
                        <span class="localStorage-exists">
                            <br /><b><?php 
echo __('Existing settings will be overwritten!');
?>
</b>
                        </span>
                    </span>
                    <div class="localStorage-unsupported">
                        <?php 
PMA_Message::notice(__('This feature is not supported by your web browser'))->display();
?>
                    </div>
                </div>
                <br />
                <input type="submit" name="submit_export" value="<?php 
echo __('Go');
?>
" />
            </form>
        </div>
        <div class="group">
            <h2><?php 
echo __('Reset');
?>
</h2>
Beispiel #21
0
                <?php 
            }
            // end  if ($PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST'))
        }
        // end if ($PMA_Config->get('PBXT_NAME') !== strtolower($db))
    }
    /**
     * Change database charset
     */
    echo '<form method="post" action="./db_operations.php">' . "\n" . PMA_generate_common_hidden_inputs($db, $table) . '<fieldset>' . "\n" . '    <legend>';
    if ($cfg['PropertiesIconic']) {
        echo '<img class="icon" src="' . $pmaThemeImage . 's_asci.png"' . ' alt="" width="16" height="16" />';
    }
    echo '    <label for="select_db_collation">' . $strCollation . ':</label>' . "\n" . '    </legend>' . "\n" . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, false, 3) . '    <input type="submit" name="submitcollation"' . ' value="' . $strGo . '" style="vertical-align: middle" />' . "\n" . '</fieldset>' . "\n" . '</form>' . "\n";
    if ($num_tables > 0 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false) {
        $message = PMA_Message::notice('strRelationNotWorking');
        $message->addParam('<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">', false);
        $message->addParam('</a>', false);
        /* Show error if user has configured something, notice elsewhere */
        if (!empty($cfg['Servers'][$server]['pmadb'])) {
            $message->isError(true);
        }
        $message->display();
    }
    // end if
}
// end if (!$is_information_schema)
// not sure about displaying the PDF dialog in case db is information_schema
if ($cfgRelation['pdfwork'] && $num_tables > 0) {
    ?>
    <!-- Work on PDF Pages -->
Beispiel #22
0
 * Check for existence of config directory which should not exist in
 * production environment.
 */
if (file_exists('config')) {
    trigger_error(
        __('Directory [code]config[/code], which is used by the setup script, still exists in your phpMyAdmin directory. You should remove it once phpMyAdmin has been configured.'),
        E_USER_WARNING
    );
}

if ($server > 0) {
    $cfgRelation = PMA_getRelationsParam();
    if (! $cfgRelation['allworks']
        && $cfg['PmaNoRelation_DisableWarning'] == false
    ) {
        $msg = PMA_Message::notice(__('The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. To find out why click %shere%s.'));
        $msg->addParam(
            '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $common_url_query . '">',
            false
        );
        $msg->addParam('</a>', false);
        /* Show error if user has configured something, notice elsewhere */
        if (!empty($cfg['Servers'][$server]['pmadb'])) {
            $msg->isError(true);
        }
        $msg->display();
    } // end if
}

/**
 * Warning about different MySQL library and server version
Beispiel #23
0
/**
 * Function to get the message for the no rows returned case
 *
 * @param string $message_to_show      message to show
 * @param array  $analyzed_sql_results analyzed sql results
 * @param int    $num_rows             number of rows
 *
 * @return string $message
 */
function PMA_getMessageForNoRowsReturned($message_to_show, $analyzed_sql_results, $num_rows)
{
    if ($analyzed_sql_results['is_delete']) {
        $message = PMA_Message::getMessageForDeletedRows($num_rows);
    } elseif ($analyzed_sql_results['is_insert']) {
        if ($analyzed_sql_results['is_replace']) {
            // For replace we get DELETED + INSERTED row count,
            // so we have to call it affected
            $message = PMA_Message::getMessageForAffectedRows($num_rows);
        } else {
            $message = PMA_Message::getMessageForInsertedRows($num_rows);
        }
        $insert_id = $GLOBALS['dbi']->insertId();
        if ($insert_id != 0) {
            // insert_id is id of FIRST record inserted in one insert,
            // so if we inserted multiple rows, we had to increment this
            $message->addMessage('[br]');
            // need to use a temporary because the Message class
            // currently supports adding parameters only to the first
            // message
            $_inserted = PMA_Message::notice(__('Inserted row id: %1$d'));
            $_inserted->addParam($insert_id + $num_rows - 1);
            $message->addMessage($_inserted);
        }
    } elseif ($analyzed_sql_results['is_affected']) {
        $message = PMA_Message::getMessageForAffectedRows($num_rows);
        // Ok, here is an explanation for the !$is_select.
        // The form generated by sql_query_form.lib.php
        // and db_sql.php has many submit buttons
        // on the same form, and some confusion arises from the
        // fact that $message_to_show is sent for every case.
        // The $message_to_show containing a success message and sent with
        // the form should not have priority over errors
    } elseif (!empty($message_to_show) && !$analyzed_sql_results['is_select']) {
        $message = PMA_Message::rawSuccess(htmlspecialchars($message_to_show));
    } elseif (!empty($GLOBALS['show_as_php'])) {
        $message = PMA_Message::success(__('Showing as PHP code'));
    } elseif (isset($GLOBALS['show_as_php'])) {
        /* User disable showing as PHP, query is only displayed */
        $message = PMA_Message::notice(__('Showing SQL query'));
    } else {
        $message = PMA_Message::success(__('MySQL returned an empty result set (i.e. zero rows).'));
    }
    if (isset($GLOBALS['querytime'])) {
        $_querytime = PMA_Message::notice('(' . __('Query took %01.4f seconds.') . ')');
        $_querytime->addParam($GLOBALS['querytime']);
        $message->addMessage($_querytime);
    }
    // In case of ROLLBACK, notify the user.
    if (isset($_REQUEST['rollback_query'])) {
        $message->addMessage(__('[ROLLBACK occurred.]'));
    }
    return $message;
}
    unlink($file_to_unlink);
}

// Reset charset back, if we did some changes
if ($reset_charset) {
    PMA_DBI_query('SET CHARACTER SET utf8');
    PMA_DBI_query('SET SESSION collation_connection =\'' . $collation_connection . '\'');
}

// Show correct message
if (!empty($id_bookmark) && $action_bookmark == 2) {
    $message = PMA_Message::success('strBookmarkDeleted');
    $display_query = $import_text;
    $error = FALSE; // unset error marker, it was used just to skip processing
} elseif (!empty($id_bookmark) && $action_bookmark == 1) {
    $message = PMA_Message::notice('strShowingBookmark');
} elseif ($bookmark_created) {
    $special_message = '[br]' . sprintf($strBookmarkCreated, htmlspecialchars($bkm_label));
} elseif ($finished && !$error) {
    if ($import_type == 'query') {
        $message = PMA_Message::success();
    } else {
        $message = PMA_Message::success('strImportSuccessfullyFinished');
        $message->addParam($executed_queries);
    }
}

// Did we hit timeout? Tell it user.
if ($timeout_passed) {
    $message = PMA_Message::error('strTimeoutPassed');
    if ($offset == 0 || (isset($original_skip) && $original_skip == $offset)) {
Beispiel #25
0
        /* ]]> */
        </style>
        <![endif]-->
    </head>

    <body>
        <?php 
        // Include possible custom headers
        if (file_exists(CUSTOM_HEADER_FILE)) {
            require CUSTOM_HEADER_FILE;
        }
        // message of "Cookies required" displayed for auth_type http or config
        // note: here, the decoration won't work because without cookies,
        // our standard CSS is not operational
        if (empty($_COOKIE)) {
            PMA_Message::notice(__('Cookies must be enabled past this point.'))->display();
        }
        // offer to load user preferences from localStorage
        if ($userprefs_offer_import) {
            require_once './libraries/user_preferences.lib.php';
            PMA_userprefs_autoload_header();
        }
        if (!defined('PMA_DISPLAY_HEADING')) {
            define('PMA_DISPLAY_HEADING', 1);
        }
        /**
         * Display heading if needed. Design can be set in css file.
         */
        if (PMA_DISPLAY_HEADING && $GLOBALS['server'] > 0) {
            $server_info = !empty($GLOBALS['cfg']['Server']['verbose']) ? $GLOBALS['cfg']['Server']['verbose'] : $GLOBALS['cfg']['Server']['host'] . (empty($GLOBALS['cfg']['Server']['port']) ? '' : ':' . $GLOBALS['cfg']['Server']['port']);
            $item = '<a href="%1$s?%2$s" class="item">';
Beispiel #26
0
}
/**
 * Check for existence of config directory which should not exist in
 * production environment.
 */
if (file_exists('config')) {
    trigger_error(__('Directory [code]config[/code], which is used by the setup script, still exists in your phpMyAdmin directory. It is strongly recommended to remove it once phpMyAdmin has been configured. Otherwise the security of your server may be compromised by unauthorized people downloading your configuration.'), E_USER_WARNING);
}
if ($server > 0) {
    $cfgRelation = PMA_getRelationsParam();
    if (!$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false) {
        $msg_text = __('The phpMyAdmin configuration storage is not completely ' . 'configured, some extended features have been deactivated. ' . '%sFind out why%s. ');
        if ($cfg['ZeroConf'] == true) {
            $msg_text .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . __('Or alternately go to \'Operations\' tab of any database ' . 'to set it up there.');
        }
        $msg = PMA_Message::notice($msg_text);
        $msg->addParam('<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php' . $common_url_query . '">', false);
        $msg->addParam('</a>', false);
        /* Show error if user has configured something, notice elsewhere */
        if (!empty($cfg['Servers'][$server]['pmadb'])) {
            $msg->isError(true);
        }
        $msg->display();
    }
    // end if
}
/**
 * Warning about different MySQL library and server version
 * (a difference on the third digit does not count).
 * If someday there is a constant that we can check about mysqlnd,
 * we can use it instead of strpos().
        $response .= $one_grant . ";\n\n";
    }
    return $response;
} // end of the 'PMA_getGrants()' function

/**
 * Changes / copies a user, part I
 */
if (isset($_REQUEST['change_copy'])) {
    $user_host_condition = ' WHERE `User`'
        .' = \'' . PMA_sqlAddSlashes($old_username) . "'"
        .' AND `Host`'
        .' = \'' . PMA_sqlAddSlashes($old_hostname) . '\';';
    $row = PMA_DBI_fetch_single_row('SELECT * FROM `mysql`.`user` ' . $user_host_condition);
    if (! $row) {
        PMA_Message::notice(__('No user found.'))->display();
        unset($_REQUEST['change_copy']);
    } else {
        extract($row, EXTR_OVERWRITE);
        // Recent MySQL versions have the field "Password" in mysql.user,
        // so the previous extract creates $Password but this script
        // uses $password
        if (! isset($password) && isset($Password)) {
            $password = $Password;
        }
        $queries = array();
    }
}


/**
/**
 * Get HTML snippet for display user overview page
 *
 * @param string $pmaThemeImage a image source link
 * @param string $text_dir      text directory
 *
 * @return string $html_output
 */
function PMA_getHtmlForUserOverview($pmaThemeImage, $text_dir)
{
    $html_output = '<h2>' . "\n" . PMA_Util::getIcon('b_usrlist.png') . __('User accounts overview') . "\n" . '</h2>' . "\n";
    $password_column = 'Password';
    if (PMA_Util::getServerType() == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706) {
        $password_column = 'authentication_string';
    }
    // $sql_query is for the initial-filtered,
    // $sql_query_all is for counting the total no. of users
    $sql_query = $sql_query_all = 'SELECT *,' . " IF(`" . $password_column . "` = _latin1 '', 'N', 'Y') AS 'Password'" . ' FROM `mysql`.`user`';
    $sql_query .= isset($_REQUEST['initial']) ? PMA_rangeOfUsers($_REQUEST['initial']) : '';
    $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;';
    $sql_query_all .= ' ;';
    $res = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DatabaseInterface::QUERY_STORE);
    $res_all = $GLOBALS['dbi']->tryQuery($sql_query_all, null, PMA_DatabaseInterface::QUERY_STORE);
    if (!$res) {
        // the query failed! This may have two reasons:
        // - the user does not have enough privileges
        // - the privilege tables use a structure of an earlier version.
        // so let's try a more simple query
        $GLOBALS['dbi']->freeResult($res);
        $GLOBALS['dbi']->freeResult($res_all);
        $sql_query = 'SELECT * FROM `mysql`.`user`';
        $res = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DatabaseInterface::QUERY_STORE);
        if (!$res) {
            $html_output .= PMA_getHtmlForViewUsersError();
            $html_output .= PMA_getAddUserHtmlFieldset();
        } else {
            // This message is hardcoded because I will replace it by
            // a automatic repair feature soon.
            $raw = 'Your privilege table structure seems to be older than' . ' this MySQL version!<br />' . 'Please run the <code>mysql_upgrade</code> command' . '(<code>mysql_fix_privilege_tables</code> on older systems)' . ' that should be included in your MySQL server distribution' . ' to solve this problem!';
            $html_output .= PMA_Message::rawError($raw)->getDisplay();
        }
        $GLOBALS['dbi']->freeResult($res);
    } else {
        $db_rights = PMA_getDbRightsForUserOverview();
        // for all initials, even non A-Z
        $array_initials = array();
        foreach ($db_rights as $right) {
            foreach ($right as $account) {
                if (empty($account['User']) && $account['Host'] == 'localhost') {
                    $html_output .= PMA_Message::notice(__('A user account allowing any user from localhost to ' . 'connect is present. This will prevent other users ' . 'from connecting if the host part of their account ' . 'allows a connection from any (%) host.') . PMA_Util::showMySQLDocu('problems-connecting'))->getDisplay();
                    break 2;
                }
            }
        }
        /**
         * Displays the initials
         * Also not necessary if there is less than 20 privileges
         */
        if ($GLOBALS['dbi']->numRows($res_all) > 20) {
            $html_output .= PMA_getHtmlForInitials($array_initials);
        }
        /**
         * Display the user overview
         * (if less than 50 users, display them immediately)
         */
        if (isset($_REQUEST['initial']) || isset($_REQUEST['showall']) || $GLOBALS['dbi']->numRows($res) < 50) {
            $html_output .= PMA_getUsersOverview($res, $db_rights, $pmaThemeImage, $text_dir);
        } else {
            $html_output .= PMA_getAddUserHtmlFieldset();
        }
        // end if (display overview)
        if (!$GLOBALS['is_ajax_request'] || !empty($_REQUEST['ajax_page_request'])) {
            if (isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv']) {
                $flushnote = new PMA_Message(__('Note: phpMyAdmin gets the users\' privileges directly ' . 'from MySQL\'s privilege tables. The content of these ' . 'tables may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'you should %sreload the privileges%s before you continue.'), PMA_Message::NOTICE);
                $flushLink = '<a href="server_privileges.php' . PMA_URL_getCommon(array('flush_privileges' => 1)) . '" id="reload_privileges_anchor">';
                $flushnote->addParam($flushLink, false);
                $flushnote->addParam('</a>', false);
            } else {
                $flushnote = new PMA_Message(__('Note: phpMyAdmin gets the users\' privileges directly ' . 'from MySQL\'s privilege tables. The content of these ' . 'tables may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'the privileges have to be reloaded but currently, you ' . 'don\'t have the RELOAD privilege.') . PMA_Util::showMySQLDocu('privileges-provided', false, 'priv_reload'), PMA_Message::NOTICE);
            }
            $html_output .= $flushnote->getDisplay();
        }
    }
    return $html_output;
}
/**
 * Get HTML header for display User's properties
 *
 * @param boolean $dbname_is_wildcard whether database name is wildcard or not
 * @param string  $url_dbname         url database name that urlencode() string
 * @param string  $dbname             database name
 * @param string  $username           username
 * @param string  $hostname           host name
 * @param string  $tablename          table name
 *
 * @return string $html_output
 */
function PMA_getHtmlHeaderForUserProperties($dbname_is_wildcard, $url_dbname, $dbname, $username, $hostname, $tablename)
{
    $html_output = '<h2>' . "\n" . PMA_Util::getIcon('b_usredit.png') . __('Edit Privileges:') . ' ' . __('User');
    if (!empty($dbname)) {
        $html_output .= ' <i><a class="edit_user_anchor"' . ' href="server_privileges.php' . PMA_URL_getCommon(array('username' => $username, 'hostname' => $hostname, 'dbname' => '', 'tablename' => '')) . '">\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'</a></i>' . "\n";
        $html_output .= ' - ';
        $html_output .= $dbname_is_wildcard || is_array($dbname) && count($dbname) > 1 ? __('Databases') : __('Database');
        if (!empty($_REQUEST['tablename'])) {
            $html_output .= ' <i><a href="server_privileges.php' . PMA_URL_getCommon(array('username' => $username, 'hostname' => $hostname, 'dbname' => $url_dbname, 'tablename' => '')) . '">' . htmlspecialchars($dbname) . '</a></i>';
            $html_output .= ' - ' . __('Table') . ' <i>' . htmlspecialchars($tablename) . '</i>';
        } else {
            if (!is_array($dbname)) {
                $dbname = array($dbname);
            }
            $html_output .= ' <i>' . htmlspecialchars(implode(', ', $dbname)) . '</i>';
        }
    } else {
        $html_output .= ' <i>\'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'</i>' . "\n";
    }
    $html_output .= '</h2>' . "\n";
    $cur_user = htmlspecialchars($GLOBALS['dbi']->getCurrentUser());
    $user = htmlspecialchars($username . '@' . $hostname);
    // Add a short notice for the user
    // to remind him that he is editing his own privileges
    if ($user === $cur_user) {
        $html_output .= PMA_Message::notice(__('Note: You are attempting to edit privileges of the ' . 'user with which you are currently logged in.'))->getDisplay();
    }
    return $html_output;
}
Beispiel #30
0
 /**
  * Returns the message with corresponding image icon
  *
  * @param string $message the message(s)
  *
  * @return string message with icon
  */
 public function getMessageWithIcon($message)
 {
     $image = '';
     if ('error' == $this->getLevel()) {
         $image = 's_error.png';
     } elseif ('success' == $this->getLevel()) {
         $image = 's_success.png';
     } else {
         $image = 's_notice.png';
     }
     $message = PMA_Message::notice(PMA_Util::getImage($image)) . " " . $message;
     return $message;
 }