Esempio n. 1
0
 function getPage($id)
 {
     global $cfg;
     switch ($id) {
         case 'bufferpool':
             if (PMA_MYSQL_INT_VERSION < 50002) {
                 return FALSE;
             }
             // rabus: The following query is only possible because we know
             // that we are on MySQL 5 here (checked above)!
             // side note: I love MySQL 5 for this. :-)
             $res = PMA_DBI_query('SHOW STATUS WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\' OR Variable_name = \'Innodb_page_size\';');
             $status = array();
             while ($row = PMA_DBI_fetch_row($res)) {
                 $status[$row[0]] = $row[1];
             }
             PMA_DBI_free_result($res);
             unset($res, $row);
             $output = '<table>' . "\n" . '    <thead>' . "\n" . '        <tr>' . "\n" . '            <th colspan="4">' . "\n" . '                ' . $GLOBALS['strBufferPoolUsage'] . "\n" . '            </th>' . "\n" . '        </tr>' . "\n" . '    </thead>' . "\n" . '    <tfoot>' . "\n" . '        <tr>' . "\n" . '            <th>' . "\n" . '                ' . $GLOBALS['strTotalUC'] . "\n" . '            </th>' . "\n" . '            <th colspan="3">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_pages_total']) . '&nbsp;' . $GLOBALS['strInnoDBPages'] . '&nbsp;/ ' . join('&nbsp;', PMA_formatByteDown($status['Innodb_buffer_pool_pages_total'] * $status['Innodb_page_size'])) . "\n" . '            </th>' . "\n" . '        </tr>' . "\n" . '    </tfoot>' . "\n" . '    <tbody>' . "\n" . '        <tr>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strFreePages'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_pages_free']) . "\n" . '            </td>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strDirtyPages'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_pages_dirty']) . "\n" . '            </td>' . "\n" . '        </tr>' . "\n" . '        <tr>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strDataPages'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_pages_data']) . "\n" . '            </td>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strPagesToBeFlushed'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_pages_flushed']) . "\n" . '            </td>' . "\n" . '        </tr>' . "\n" . '        <tr>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strBusyPages'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_pages_misc']) . "\n" . '            </td>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strLatchedPages'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_pages_latched']) . "\n" . '            </td>' . "\n" . '        </tr>' . "\n" . '    </tbody>' . "\n" . '</table>' . "\n\n" . '<br />' . "\n\n" . '<table>' . "\n" . '    <thead>' . "\n" . '        <tr>' . "\n" . '            <th colspan="4">' . "\n" . '                ' . $GLOBALS['strBufferPoolActivity'] . "\n" . '            </th>' . "\n" . '        </tr>' . "\n" . '    </thead>' . "\n" . '    <tbody>' . "\n" . '        <tr>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strReadRequests'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_read_requests']) . "\n" . '            </td>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strWriteRequests'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_write_requests']) . "\n" . '            </td>' . "\n" . '        </tr>' . "\n" . '        <tr>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strBufferReadMisses'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_reads']) . "\n" . '            </td>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strBufferWriteWaits'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                ' . htmlspecialchars($status['Innodb_buffer_pool_wait_free']) . "\n" . '            </td>' . "\n" . '        </tr>' . "\n" . '        <tr>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strBufferReadMissesInPercent'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                ' . ($status['Innodb_buffer_pool_read_requests'] == 0 ? '---' : htmlspecialchars(number_format($status['Innodb_buffer_pool_reads'] * 100 / $status['Innodb_buffer_pool_read_requests'], 2, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator'])) . '&nbsp;%') . "\n" . '            </td>' . "\n" . '            <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n" . '                &nbsp;' . $GLOBALS['strBufferWriteWaitsInPercent'] . '&nbsp;' . "\n" . '            </td>' . "\n" . '            <td align="right" bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . '                ' . ($status['Innodb_buffer_pool_write_requests'] == 0 ? '---' : htmlspecialchars(number_format($status['Innodb_buffer_pool_wait_free'] * 100 / $status['Innodb_buffer_pool_write_requests'], 2, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator'])) . '&nbsp;%') . "\n" . '            </td>' . "\n" . '        </tr>' . "\n" . '    </tbody>' . "\n" . '</table>' . "\n";
             return $output;
         case 'status':
             $res = PMA_DBI_query('SHOW INNODB STATUS;');
             $row = PMA_DBI_fetch_row($res);
             PMA_DBI_free_result($res);
             return '<pre>' . "\n" . htmlspecialchars($row[0]) . "\n" . '</pre>' . "\n";
         default:
             return FALSE;
     }
 }
Esempio n. 2
0
/**
 * Executes a query as controluser if possible, otherwise as normal user
 *
 * @param   string    the query to execute
 * @param   boolean   whether to display SQL error messages or not
 *
 * @return  integer   the result id
 *
 * @access  public
 *
 * @author  Mike Beck <*****@*****.**>
 */
function PMA_query_as_cu($sql, $show_error = true, $options = 0)
{
    // Comparing resource ids works on PHP 5 because, when no controluser
    // is defined, connecting with the same user for controllink does
    // not create a new connection. However a new connection is created
    // on PHP 4, so we cannot directly compare resource ids.
    if ($GLOBALS['controllink'] == $GLOBALS['userlink'] || PMA_MYSQL_INT_VERSION < 50000) {
        PMA_DBI_select_db($GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink']);
    }
    if ($show_error) {
        $result = PMA_DBI_query($sql, $GLOBALS['controllink'], $options);
    } else {
        $result = @PMA_DBI_try_query($sql, $GLOBALS['controllink'], $options);
    }
    // end if... else...
    // It makes no sense to restore database on control user
    if ($GLOBALS['controllink'] == $GLOBALS['userlink'] || PMA_MYSQL_INT_VERSION < 50000) {
        PMA_DBI_select_db($GLOBALS['db'], $GLOBALS['controllink']);
    }
    if ($result) {
        return $result;
    } else {
        return false;
    }
}
Esempio n. 3
0
function PMA_generateEngineDetails($variables, $like = NULL, $indent = 0)
{
    global $cfg;
    $spaces = '';
    for ($i = 0; $i < $indent; $i++) {
        $spaces .= '    ';
    }
    /**
     * Get the variables!
     */
    if (!empty($variables)) {
        $sql_query = 'SHOW ' . (PMA_MYSQL_INT_VERSION >= 40102 ? 'GLOBAL ' : '') . 'VARIABLES' . (empty($like) ? '' : ' LIKE \'' . $like . '\'') . ';';
        $res = PMA_DBI_query($sql_query);
        $mysql_vars = array();
        while ($row = PMA_DBI_fetch_row($res)) {
            if (isset($variables[$row[0]])) {
                $mysql_vars[$row[0]] = $row[1];
            }
        }
        PMA_DBI_free_result($res);
        unset($res, $row, $sql_query);
    }
    if (empty($mysql_vars)) {
        return $spaces . '<p>' . "\n" . $spaces . '    ' . $GLOBALS['strNoDetailsForEngine'] . "\n" . $spaces . '</p>' . "\n";
    }
    $dt_table = $spaces . '<table>' . "\n";
    $useBgcolorOne = TRUE;
    $has_content = FALSE;
    foreach ($variables as $var => $details) {
        if (!isset($mysql_vars[$var])) {
            continue;
        }
        if (!isset($details['type'])) {
            $details['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
        }
        $is_num = $details['type'] == PMA_ENGINE_DETAILS_TYPE_SIZE || $details['type'] == PMA_ENGINE_DETAILS_TYPE_NUMERIC;
        $bgcolor = $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
        $dt_table .= $spaces . '    <tr>' . "\n" . $spaces . '        <td bgcolor="' . $bgcolor . '">' . "\n";
        if (!empty($variables[$var]['desc'])) {
            $dt_table .= $spaces . '            ' . PMA_showHint($details['desc']) . "\n";
        }
        $dt_table .= $spaces . '        </td>' . "\n" . $spaces . '        <td bgcolor="' . $bgcolor . '">' . "\n" . $spaces . '            &nbsp;' . $details['title'] . '&nbsp;' . "\n" . $spaces . '        </td>' . "\n" . $spaces . '        <td bgcolor="' . $bgcolor . '"' . ($is_num ? ' align="right"' : '') . '>' . "\n" . $spaces . '            &nbsp;';
        switch ($details['type']) {
            case PMA_ENGINE_DETAILS_TYPE_SIZE:
                $parsed_size = PMA_formatByteDown($mysql_vars[$var]);
                $dt_table .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
                unset($parsed_size);
                break;
            default:
                $dt_table .= htmlspecialchars($mysql_vars[$var]);
        }
        $dt_table .= '&nbsp;' . "\n" . $spaces . '        </td>' . "\n" . $spaces . '    </tr>' . "\n";
        $useBgcolorOne = !$useBgcolorOne;
        $has_content = TRUE;
    }
    if (!$has_content) {
        return '';
    }
    return $dt_table;
}
Esempio n. 4
0
 /**
  * Builds the SQL search query
  *
  * @param   string   the table name
  * @param   string   the string to search
  * @param   integer  type of search (1 -> 1 word at least, 2 -> all words,
  *                                   3 -> exact string, 4 -> regexp)
  *
  * @return  array    3 SQL querys (for count, display and delete results)
  *
  * @global  string   the url to return to in case of errors
  */
 function PMA_getSearchSqls($table, $search_str, $search_option)
 {
     global $err_url, $charset_connection;
     // Statement types
     $sqlstr_select = 'SELECT';
     $sqlstr_delete = 'DELETE';
     // Fields to select
     $res = PMA_DBI_query('SHOW ' . (PMA_MYSQL_INT_VERSION >= 40100 ? 'FULL ' : '') . 'FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']) . ';');
     while ($current = PMA_DBI_fetch_assoc($res)) {
         if (PMA_MYSQL_INT_VERSION >= 40100) {
             list($current['Charset']) = explode('_', $current['Collation']);
         }
         $current['Field'] = PMA_backquote($current['Field']);
         $tblfields[] = $current;
     }
     // while
     PMA_DBI_free_result($res);
     unset($current, $res);
     $tblfields_cnt = count($tblfields);
     // Table to use
     $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table);
     // Beginning of WHERE clause
     $sqlstr_where = ' WHERE';
     $search_words = $search_option > 2 ? array($search_str) : explode(' ', $search_str);
     $search_wds_cnt = count($search_words);
     $like_or_regex = $search_option == 4 ? 'REGEXP' : 'LIKE';
     $automatic_wildcard = $search_option < 3 ? '%' : '';
     for ($i = 0; $i < $search_wds_cnt; $i++) {
         // Eliminates empty values
         // In MySQL 4.1, if a field has no collation we get NULL in Charset
         // but in MySQL 5.0.x we get ''
         if (!empty($search_words[$i])) {
             for ($j = 0; $j < $tblfields_cnt; $j++) {
                 if (PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != $charset_connection && $tblfields[$j]['Charset'] != 'NULL' && $tblfields[$j]['Charset'] != '') {
                     $prefix = 'CONVERT(_utf8 ';
                     $suffix = ' USING ' . $tblfields[$j]['Charset'] . ') COLLATE ' . $tblfields[$j]['Collation'];
                 } else {
                     $prefix = $suffix = '';
                 }
                 $thefieldlikevalue[] = $tblfields[$j]['Field'] . ' ' . $like_or_regex . ' ' . $prefix . '\'' . $automatic_wildcard . $search_words[$i] . $automatic_wildcard . '\'' . $suffix;
             }
             // end for
             $fieldslikevalues[] = $search_wds_cnt > 1 ? '(' . implode(' OR ', $thefieldlikevalue) . ')' : implode(' OR ', $thefieldlikevalue);
             unset($thefieldlikevalue);
         }
         // end if
     }
     // end for
     $implode_str = $search_option == 1 ? ' OR ' : ' AND ';
     $sqlstr_where .= ' ' . implode($implode_str, $fieldslikevalues);
     unset($fieldslikevalues);
     // Builds complete queries
     $sql['select_fields'] = $sqlstr_select . ' * ' . $sqlstr_from . $sqlstr_where;
     // here, I think we need to still use the COUNT clause, even for
     // VIEWs, anyway we have a WHERE clause that should limit results
     $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS count' . $sqlstr_from . $sqlstr_where;
     $sql['delete'] = $sqlstr_delete . $sqlstr_from . $sqlstr_where;
     return $sql;
 }
Esempio n. 5
0
/**
 * returns JavaScript code for intializing vars
 *
 * @return string   JavaScript code
 */
function get_script_contr()
{
    PMA_DBI_select_db($GLOBALS['db']);
    $con["C_NAME"] = array();
    $i = 0;
    $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($GLOBALS['db']), null, PMA_DBI_QUERY_STORE);
    while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
        $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal');
        //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - ";
        //print_r($row);
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
        $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign');
        //echo "<br> INNO ";
        //print_r($row);
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
    }
    $ti = 0;
    $script_contr = '<script type="text/javascript">' . "\n" . '// <![CDATA[' . "\n" . 'var contr = new Array();' . "\n";
    for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
        $js_var = ' contr[' . $ti . ']';
        $script_contr .= $js_var . " = new Array();\n";
        $js_var .= "['" . $con['C_NAME'][$i] . "']";
        $script_contr .= $js_var . " = new Array();\n";
        if (in_array($con['DTN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"]) && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) {
            $js_var .= "['" . $con['DTN'][$i] . "']";
            $script_contr .= $js_var . " = new Array();\n";
            $m_col = array();
            //}
            $js_var .= "['" . $con['DCN'][$i] . "']";
            $script_contr .= $js_var . " = new Array();\n";
            //}
            $script_contr .= $js_var . "[0] = '" . $con['STN'][$i] . "';\n";
            //
            $script_contr .= $js_var . "[1] = '" . $con['SCN'][$i] . "';\n";
            //
        }
        $ti++;
    }
    $script_contr .= '// ]]>' . "\n" . '</script>' . "\n";
    return $script_contr;
}
Esempio n. 6
0
/**
 * Function for displaying the table of an engine's parameters
 *
 * @param   array   List of MySQL variables and corresponding localized descriptions.
 *                  The array elements should have the following format:
 *                      $variable => array('title' => $title, 'desc' => $description);
 * @param   string  Prefix for the SHOW VARIABLES query.
 * @return  string  The table that was generated based on the given information.
 */
function PMA_generateEngineDetails($variables, $like = null)
{
    /**
     * Get the variables!
     */
    if (!empty($variables)) {
        $sql_query = 'SHOW ' . (PMA_MYSQL_INT_VERSION >= 40102 ? 'GLOBAL ' : '') . 'VARIABLES' . (empty($like) ? '' : ' LIKE \'' . $like . '\'') . ';';
        $res = PMA_DBI_query($sql_query);
        $mysql_vars = array();
        while ($row = PMA_DBI_fetch_row($res)) {
            if (isset($variables[$row[0]])) {
                $mysql_vars[$row[0]] = $row[1];
            }
        }
        PMA_DBI_free_result($res);
        unset($res, $row, $sql_query);
    }
    if (empty($mysql_vars)) {
        return '<p>' . "\n" . '    ' . $GLOBALS['strNoDetailsForEngine'] . "\n" . '</p>' . "\n";
    }
    $dt_table = '<table class="data" cellspacing="1">' . "\n";
    $odd_row = false;
    $has_content = false;
    foreach ($variables as $var => $details) {
        if (!isset($mysql_vars[$var])) {
            continue;
        }
        if (!isset($details['type'])) {
            $details['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
        }
        $is_num = $details['type'] == PMA_ENGINE_DETAILS_TYPE_SIZE || $details['type'] == PMA_ENGINE_DETAILS_TYPE_NUMERIC;
        $dt_table .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n" . '    <td>' . "\n";
        if (!empty($variables[$var]['desc'])) {
            $dt_table .= '        ' . PMA_showHint($details['desc']) . "\n";
        }
        $dt_table .= '    </td>' . "\n" . '    <th>' . htmlspecialchars(empty($details['title']) ? $var : $details['title']) . "\n" . '    </th>' . "\n" . '    <td class="value">';
        switch ($details['type']) {
            case PMA_ENGINE_DETAILS_TYPE_SIZE:
                $parsed_size = PMA_formatByteDown($mysql_vars[$var]);
                $dt_table .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
                unset($parsed_size);
                break;
            case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
                $dt_table .= PMA_formatNumber($mysql_vars[$var]) . ' ';
                break;
            default:
                $dt_table .= htmlspecialchars($mysql_vars[$var]) . '   ';
        }
        $dt_table .= '</td>' . "\n" . '</tr>' . "\n";
        $odd_row = !$odd_row;
        $has_content = true;
    }
    if (!$has_content) {
        return '';
    }
    $dt_table .= '</table>' . "\n";
    return $dt_table;
}
function get_script_contr()
{
    global $db;
    PMA_DBI_select_db($db);
    $con["C_NAME"] = array();
    $i = 0;
    $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db), NULL, PMA_DBI_QUERY_STORE);
    while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
        $row = PMA_getForeigners($db, $val[0], '', 'internal');
        //echo "<br> internal ".$db." - ".$val[0]." - ";
        //print_r($row );
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($db . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
        $row = PMA_getForeigners($db, $val[0], '', 'innodb');
        //echo "<br> INNO ";
        //print_r($row );
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($db . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
    }
    $ti = 0;
    $script_contr = "<script>\n var contr = new Array();\n";
    for ($i = 0; $i < sizeof($con["C_NAME"]); $i++) {
        $script_contr .= " contr[{$ti}] = new Array();\n";
        $script_contr .= "  contr[{$ti}]['" . $con['C_NAME'][$i] . "'] = new Array();\n";
        if (in_array($con['DTN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"]) && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) {
            $script_contr .= "  contr[{$ti}]['" . $con['C_NAME'][$i] . "']['" . $con['DTN'][$i] . "'] = new Array();\n";
            $m_col = array();
            //}
            $script_contr .= "  contr[{$ti}]['" . $con['C_NAME'][$i] . "']['" . $con['DTN'][$i] . "']['" . $con['DCN'][$i] . "'] = new Array();\n";
            //}
            $script_contr .= "    contr[{$ti}]['" . $con['C_NAME'][$i] . "']['" . $con['DTN'][$i] . "']['" . $con['DCN'][$i] . "'][0] = '" . $con['STN'][$i] . "';\n";
            //
            $script_contr .= "    contr[{$ti}]['" . $con['C_NAME'][$i] . "']['" . $con['DTN'][$i] . "']['" . $con['DCN'][$i] . "'][1] = '" . $con['SCN'][$i] . "';\n";
            //
        }
        $ti++;
    }
    $script_contr .= "</script>\n";
    return $script_contr;
}
/**
 * Function to get all index information from a certain table
 *
 * @param   string      Table name
 * @param   string      Error URL
 *
 * @access  public
 * @return  array       Index keys
 */
function PMA_get_indexes($tbl_name, $err_url_0 = '')
{
    $tbl_local_query = 'SHOW KEYS FROM ' . PMA_backquote($tbl_name);
    $tbl_result = PMA_DBI_query($tbl_local_query) or PMA_mysqlDie('', $tbl_local_query, '', $err_url_0);
    $tbl_ret_keys = array();
    while ($tbl_row = PMA_DBI_fetch_assoc($tbl_result)) {
        $tbl_ret_keys[] = $tbl_row;
    }
    PMA_DBI_free_result($tbl_result);
    return $tbl_ret_keys;
}
Esempio n. 9
0
/**
 * returns JavaScript code for intializing vars
 *
 * @return string   JavaScript code
 */
function get_script_contr()
{
    PMA_DBI_select_db($GLOBALS['db']);
    $con["C_NAME"] = array();
    $i = 0;
    $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_Util::backquote($GLOBALS['db']), null, PMA_DBI_QUERY_STORE);
    while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
        $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal');
        //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - ";
        //print_r($row);
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
        $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign');
        //echo "<br> INNO ";
        //print_r($row);
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
    }
    $ti = 0;
    $retval = array();
    for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
        $c_name_i = $con['C_NAME'][$i];
        $dtn_i = $con['DTN'][$i];
        $retval[$ti] = array();
        $retval[$ti][$c_name_i] = array();
        if (in_array($dtn_i, $GLOBALS['PMD_URL']["TABLE_NAME"]) && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) {
            $retval[$ti][$c_name_i][$dtn_i] = array();
            $retval[$ti][$c_name_i][$dtn_i][$con['DCN'][$i]] = array(0 => $con['STN'][$i], 1 => $con['SCN'][$i]);
        }
        $ti++;
    }
    return $retval;
}
Esempio n. 10
0
/**
 * retrieves table column info
 *
 * @uses    $GLOBALS['db']
 * @uses    PMA_DBI_QUERY_STORE
 * @uses    PMA_DBI_select_db()
 * @uses    PMA_DBI_query()
 * @uses    PMA_DBI_num_rows()
 * @uses    PMA_backquote()
 * @uses    count()
 * @return  array   table column nfo
 */
function get_tab_info()
{
    PMA_DBI_select_db($GLOBALS['db']);
    $tab_column = array();
    for ($i = 0, $cnt = count($GLOBALS['PMD']["TABLE_NAME"]); $i < $cnt; $i++) {
        $fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($GLOBALS['PMD']["TABLE_NAME_SMALL"][$i]), NULL, PMA_DBI_QUERY_STORE);
        $j = 0;
        while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
            $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_ID'][$j] = $j;
            $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_NAME'][$j] = $row['Field'];
            $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['TYPE'][$j] = $row['Type'];
            $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['NULLABLE'][$j] = $row['Null'];
            $j++;
        }
    }
    return $tab_column;
}
Esempio n. 11
0
 /**
  * renames table
  *
  * @param string $new_name new table name
  * @param string $new_db   new database name
  * @param bool   $is_view  is this for a VIEW rename?
  * @todo    remove the $is_view parameter (also in callers)
  *
  * @return bool success
  */
 function rename($new_name, $new_db = null, $is_view = false)
 {
     if (null !== $new_db && $new_db !== $this->getDbName()) {
         // Ensure the target is valid
         if (!$GLOBALS['pma']->databases->exists($new_db)) {
             $this->errors[] = __('Invalid database') . ': ' . $new_db;
             return false;
         }
     } else {
         $new_db = $this->getDbName();
     }
     $new_table = new PMA_Table($new_name, $new_db);
     if ($this->getFullName() === $new_table->getFullName()) {
         return true;
     }
     if (!PMA_Table::isValidName($new_name)) {
         $this->errors[] = __('Invalid table name') . ': ' . $new_table->getFullName();
         return false;
     }
     // If the table is moved to a different database drop its triggers first
     $triggers = PMA_DBI_get_triggers($this->getDbName(), $this->getName(), '');
     $handle_triggers = $this->getDbName() != $new_db && $triggers;
     if ($handle_triggers) {
         foreach ($triggers as $trigger) {
             $sql = 'DROP TRIGGER IF EXISTS ' . PMA_backquote($this->getDbName()) . '.' . PMA_backquote($trigger['name']) . ';';
             PMA_DBI_query($sql);
         }
     }
     /*
      * tested also for a view, in MySQL 5.0.92, 5.1.55 and 5.5.13
      */
     $GLOBALS['sql_query'] = '
         RENAME TABLE ' . $this->getFullName(true) . '
               TO ' . $new_table->getFullName(true) . ';';
     // I don't think a specific error message for views is necessary
     if (!PMA_DBI_query($GLOBALS['sql_query'])) {
         // Restore triggers in the old database
         if ($handle_triggers) {
             PMA_DBI_select_db($this->getDbName());
             foreach ($triggers as $trigger) {
                 PMA_DBI_query($trigger['create']);
             }
         }
         $this->errors[] = sprintf(__('Error renaming table %1$s to %2$s'), $this->getFullName(), $new_table->getFullName());
         return false;
     }
     $old_name = $this->getName();
     $old_db = $this->getDbName();
     $this->setName($new_name);
     $this->setDbName($new_db);
     /**
      * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db)
      */
     // Move old entries from comments to new table
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     if ($GLOBALS['cfgRelation']['commwork']) {
         $remove_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($remove_query);
         unset($remove_query);
     }
     if ($GLOBALS['cfgRelation']['displaywork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['relwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `foreign_db`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `foreign_table` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `foreign_db`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `foreign_table` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `master_db`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `master_table` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `master_db`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `master_table` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['pdfwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['designerwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     $this->messages[] = sprintf(__('Table %1$s has been renamed to %2$s.'), htmlspecialchars($old_name), htmlspecialchars($new_name));
     return true;
 }
            echo "\n";
            require_once './libraries/footer.inc.php';
        } else {
            // end if (no row returned)
            $meta = PMA_DBI_get_fields_meta($result[$key_id]);
            list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true);
            if (!empty($unique_condition)) {
                $found_unique_key = true;
            }
            unset($unique_condition, $tmp_clause_is_unique);
        }
    }
} else {
    // no primary key given, just load first row - but what happens if table is empty?
    $insert_mode = true;
    $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);
    $rows = array_fill(0, $cfg['InsertRows'], false);
}
// <*****@*****.**>
// retrieve keys into foreign fields, if any
$foreigners = PMA_getForeigners($db, $table);
/**
 * Displays the form
 */
// loic1: 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';
// Had to put the URI because when hosted on an https server,
// some browsers send wrongly this form to the http server.
if ($cfg['CtrlArrowsMoving']) {
    ?>
Esempio n. 13
0
        $message .= PMA_DBI_query($sql_query) ? $strSuccess : $strError;
        $reread_info = true;
        unset($table_alters);
    }
}
/**
 * Reordering the table has been requested by the user
 */
if (isset($_REQUEST['submitorderby']) && !empty($_REQUEST['order_field'])) {
    $sql_query = '
        ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
        ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
    if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
        $sql_query .= ' DESC';
    }
    $message = PMA_DBI_query($sql_query) ? $strSuccess : $strError;
}
// end if
if ($reread_info) {
    $checksum = $delay_key_write = 0;
    require './libraries/tbl_info.inc.php';
}
unset($reread_info);
/**
 * Displays top menu links
 */
require_once './libraries/tbl_links.inc.php';
$url_params['goto'] = 'tbl_operations.php';
$url_params['back'] = 'tbl_operations.php';
/**
 * Get columns names
Esempio n. 14
0
     $message = $strDatabaseEmpty;
 } else {
     $local_query = 'CREATE DATABASE ' . PMA_backquote($newname) . ';';
     $sql_query = $local_query;
     PMA_DBI_query($local_query);
     $tables = PMA_DBI_get_tables($db);
     foreach ($tables as $table) {
         $back = $sql_query;
         $sql_query = '';
         PMA_table_move_copy($db, $table, $newname, $table, isset($what) ? $what : 'data', $move);
         $sql_query = $back . $sql_query;
     }
     if ($move) {
         $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
         $sql_query .= "\n" . $local_query;
         PMA_DBI_query($local_query);
         $message = sprintf($strRenameDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
     } else {
         $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
     }
     $reload = TRUE;
     /* Change database to be used */
     if ($move) {
         $db = $newname;
     } else {
         $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
         if (isset($switch_to_new) && $switch_to_new == 'true') {
             setcookie('pma_switch_to_new', 'true', 0, substr($pma_uri_parts['path'], 0, strrpos($pma_uri_parts['path'], '/')), '', $pma_uri_parts['scheme'] == 'https');
             $db = $newname;
         } else {
             setcookie('pma_switch_to_new', '', 0, substr($pma_uri_parts['path'], 0, strrpos($pma_uri_parts['path'], '/')), '', $pma_uri_parts['scheme'] == 'https');
Esempio n. 15
0
 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy)
 {
     global $cfgRelation;
     /**
      * Get the unique keys in the table
      */
     $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
     $keys_result = PMA_DBI_query($keys_query);
     $unique_keys = array();
     while ($key = PMA_DBI_fetch_assoc($keys_result)) {
         if ($key['Non_unique'] == 0) {
             $unique_keys[] = $key['Column_name'];
         }
     }
     PMA_DBI_free_result($keys_result);
     /**
      * Gets fields properties
      */
     PMA_DBI_select_db($db);
     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
     $result = PMA_DBI_query($local_query);
     $fields_cnt = PMA_DBI_num_rows($result);
     // Check if we can use Relations (Mike Beck)
     if ($do_relation && !empty($cfgRelation['relation'])) {
         // Find which tables are related with the current one and write it in
         // an array
         $res_rel = PMA_getForeigners($db, $table);
         if ($res_rel && count($res_rel) > 0) {
             $have_rel = TRUE;
         } else {
             $have_rel = FALSE;
         }
     } else {
         $have_rel = FALSE;
     }
     // end if
     /**
      * Displays the table structure
      */
     $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{';
     if (!PMA_exportOutputHandler($buffer)) {
         return FALSE;
     }
     $columns_cnt = 4;
     $alignment = '|l|c|c|c|';
     if ($do_relation && $have_rel) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     $buffer = $alignment . '} ' . $crlf;
     $header = ' \\hline ';
     $header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}';
     if ($do_relation && $have_rel) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}';
     }
     if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}';
         $comments = PMA_getComments($db, $table);
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
         $mime_map = PMA_getMIME($db, $table, true);
     }
     $local_buffer = PMA_texEscape($table);
     // Table caption for first page and label
     if (isset($GLOBALS['latex_caption'])) {
         $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption']) . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label']) . '} \\\\' . $crlf;
     }
     $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
     // Table caption on next pages
     if (isset($GLOBALS['latex_caption'])) {
         $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption']) . '} \\\\ ' . $crlf;
     }
     $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf;
     if (!PMA_exportOutputHandler($buffer)) {
         return FALSE;
     }
     while ($row = PMA_DBI_fetch_assoc($result)) {
         $type = $row['Type'];
         // reformat mysql query output - staybyte - 9. June 2001
         // loic1: set or enum types: slashes single quotes inside options
         if (eregi('^(set|enum)\\((.+)\\)$', $type, $tmp)) {
             $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
             $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
             $type_nowrap = '';
             $binary = 0;
             $unsigned = 0;
             $zerofill = 0;
         } else {
             $type_nowrap = ' nowrap="nowrap"';
             $type = eregi_replace('BINARY', '', $type);
             $type = eregi_replace('ZEROFILL', '', $type);
             $type = eregi_replace('UNSIGNED', '', $type);
             if (empty($type)) {
                 $type = '&nbsp;';
             }
             $binary = eregi('BINARY', $row['Type']);
             $unsigned = eregi('UNSIGNED', $row['Type']);
             $zerofill = eregi('ZEROFILL', $row['Type']);
         }
         if (!isset($row['Default'])) {
             if ($row['Null'] != '') {
                 $row['Default'] = 'NULL';
             }
         } else {
             $row['Default'] = $row['Default'];
         }
         $field_name = $row['Field'];
         $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "" . (isset($row['Default']) ? $row['Default'] : '');
         if ($do_relation && $have_rel) {
             $local_buffer .= "";
             if (isset($res_rel[$field_name])) {
                 $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')';
             }
         }
         if ($do_comments && $cfgRelation['commwork']) {
             $local_buffer .= "";
             if (isset($comments[$field_name])) {
                 $local_buffer .= $comments[$field_name];
             }
         }
         if ($do_mime && $cfgRelation['mimework']) {
             $local_buffer .= "";
             if (isset($mime_map[$field_name])) {
                 $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
             }
         }
         $local_buffer = PMA_texEscape($local_buffer);
         if ($row['Key'] == 'PRI') {
             $pos = strpos($local_buffer, "");
             $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
         }
         if (in_array($field_name, $unique_keys)) {
             $pos = strpos($local_buffer, "");
             $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
         }
         $buffer = str_replace("", ' & ', $local_buffer);
         $buffer .= ' \\\\ \\hline ' . $crlf;
         if (!PMA_exportOutputHandler($buffer)) {
             return FALSE;
         }
     }
     // end while
     PMA_DBI_free_result($result);
     $buffer = ' \\end{longtable}' . $crlf;
     return PMA_exportOutputHandler($buffer);
 }
Esempio n. 16
0
//Set default datalabel if not selected
if (!isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
    $dataLabel = PMA_getDisplayField($db, $table);
}
// Displays the zoom search form
$response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
/*
 * Handle the input criteria and generate the query result
 * Form for displaying query results
 */
if (isset($zoom_submit) && $_POST['criteriaColumnNames'][0] != 'pma_null' && $_POST['criteriaColumnNames'][1] != 'pma_null' && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]) {
    //Query generation part
    $sql_query = $table_search->buildSqlQuery();
    $sql_query .= ' LIMIT ' . $maxPlotLimit;
    //Query execution part
    $result = PMA_DBI_query($sql_query . ";", null, PMA_DBI_QUERY_STORE);
    $fields_meta = PMA_DBI_get_fields_meta($result);
    while ($row = PMA_DBI_fetch_assoc($result)) {
        //Need a row with indexes as 0,1,2 for the getUniqueCondition
        // hence using a temporary array
        $tmpRow = array();
        foreach ($row as $val) {
            $tmpRow[] = $val;
        }
        //Get unique conditon on each row (will be needed for row update)
        $uniqueCondition = PMA_Util::getUniqueCondition($result, count($table_search->getColumnNames()), $fields_meta, $tmpRow, true);
        //Append it to row array as where_clause
        $row['where_clause'] = $uniqueCondition[0];
        $tmpData = array($_POST['criteriaColumnNames'][0] => $row[$_POST['criteriaColumnNames'][0]], $_POST['criteriaColumnNames'][1] => $row[$_POST['criteriaColumnNames'][1]], 'where_clause' => $uniqueCondition[0]);
        $tmpData[$dataLabel] = $dataLabel ? $row[$dataLabel] : '';
        $data[] = $tmpData;
            <td bgcolor="<?php 
echo $cfg['BgcolorOne'];
?>
" align="right">
                <input type="submit" name="submitcomment" value="<?php 
echo $strGo;
?>
" style="vertical-align: middle" />
            </td>
        </tr>
    </form>
        <tr><td colspan="2" height="5"></td></tr>
    <!-- Table type -->
    <?php 
// modify robbat2 code - staybyte - 11. June 2001
$result = PMA_DBI_query('SHOW VARIABLES LIKE \'have_%\';');
if ($result) {
    while ($tmp = PMA_DBI_fetch_assoc($result)) {
        if (isset($tmp['Variable_name'])) {
            switch ($tmp['Variable_name']) {
                case 'have_bdb':
                    if ($tmp['Value'] == 'YES') {
                        $tbl_bdb = TRUE;
                    }
                    break;
                case 'have_gemini':
                    if ($tmp['Value'] == 'YES') {
                        $tbl_gemini = TRUE;
                    }
                    break;
                case 'have_innodb':
Esempio n. 18
0
/**
 * Displays the privileges form table
 *
 * @param string  $db     the database
 * @param string  $table  the table
 * @param boolean $submit wheather to display the submit button or not
 *
 * @global  array      $cfg         the phpMyAdmin configuration
 * @global  ressource  $user_link   the database connection
 *
 * @return void
 */
function PMA_displayPrivTable($db = '*', $table = '*', $submit = true)
{
    global $random_n;

    if ($db == '*') {
        $table = '*';
    }

    if (isset($GLOBALS['username'])) {
        $username = $GLOBALS['username'];
        $hostname = $GLOBALS['hostname'];
        if ($db == '*') {
            $sql_query = "SELECT * FROM `mysql`.`user`"
                ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'"
                ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "';";
        } elseif ($table == '*') {
            $sql_query = "SELECT * FROM `mysql`.`db`"
                ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'"
                ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "'"
                ." AND '" . PMA_unescape_mysql_wildcards($db) . "'"
                ." LIKE `Db`;";
        } else {
            $sql_query = "SELECT `Table_priv`"
                ." FROM `mysql`.`tables_priv`"
                ." WHERE `User` = '" . PMA_sqlAddSlashes($username) . "'"
                ." AND `Host` = '" . PMA_sqlAddSlashes($hostname) . "'"
                ." AND `Db` = '" . PMA_unescape_mysql_wildcards($db) . "'"
                ." AND `Table_name` = '" . PMA_sqlAddSlashes($table) . "';";
        }
        $row = PMA_DBI_fetch_single_row($sql_query);
    }
    if (empty($row)) {
        if ($table == '*') {
            if ($db == '*') {
                $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
            } elseif ($table == '*') {
                $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;';
            }
            $res = PMA_DBI_query($sql_query);
            while ($row1 = PMA_DBI_fetch_row($res)) {
                if (substr($row1[0], 0, 4) == 'max_') {
                    $row[$row1[0]] = 0;
                } else {
                    $row[$row1[0]] = 'N';
                }
            }
            PMA_DBI_free_result($res);
        } else {
            $row = array('Table_priv' => '');
        }
    }
    if (isset($row['Table_priv'])) {
        $row1 = PMA_DBI_fetch_single_row(
            'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';',
            'ASSOC', $GLOBALS['userlink']
        );
        // note: in MySQL 5.0.3 we get "Create View', 'Show view';
        // the View for Create is spelled with uppercase V
        // the view for Show is spelled with lowercase v
        // and there is a space between the words

        $av_grants = explode(
            '\',\'',
            substr(
                $row1['Type'],
                strpos($row1['Type'], '(') + 2,
                strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3
            )
        );
        unset($row1);
        $users_grants = explode(',', $row['Table_priv']);

        foreach ($av_grants as $current_grant) {
            $row[$current_grant . '_priv']
                = in_array($current_grant, $users_grants) ? 'Y' : 'N';
        }
        unset($row['Table_priv'], $current_grant, $av_grants, $users_grants);

        // get collumns
        $res = PMA_DBI_try_query(
            'SHOW COLUMNS FROM '
            . PMA_backquote(PMA_unescape_mysql_wildcards($db))
            . '.' . PMA_backquote($table) . ';'
        );
        $columns = array();
        if ($res) {
            while ($row1 = PMA_DBI_fetch_row($res)) {
                $columns[$row1[0]] = array(
                    'Select' => false,
                    'Insert' => false,
                    'Update' => false,
                    'References' => false
                );
            }
            PMA_DBI_free_result($res);
        }
        unset($res, $row1);
    }
    // t a b l e - s p e c i f i c    p r i v i l e g e s
    if (! empty($columns)) {
        $res = PMA_DBI_query(
            'SELECT `Column_name`, `Column_priv`'
            .' FROM `mysql`.`columns_priv`'
            .' WHERE `User`'
            .' = \'' . PMA_sqlAddSlashes($username) . "'"
            .' AND `Host`'
            .' = \'' . PMA_sqlAddSlashes($hostname) . "'"
            .' AND `Db`'
            .' = \'' . PMA_sqlAddSlashes(PMA_unescape_mysql_wildcards($db)) . "'"
            .' AND `Table_name`'
            .' = \'' . PMA_sqlAddSlashes($table) . '\';'
        );

        while ($row1 = PMA_DBI_fetch_row($res)) {
            $row1[1] = explode(',', $row1[1]);
            foreach ($row1[1] as $current) {
                $columns[$row1[0]][$current] = true;
            }
        }
        PMA_DBI_free_result($res);
        unset($res, $row1, $current);

        echo '<input type="hidden" name="grant_count" value="' . count($row) . '" />' . "\n"
           . '<input type="hidden" name="column_count" value="' . count($columns) . '" />' . "\n"
           . '<fieldset id="fieldset_user_priv">' . "\n"
           . '    <legend>' . __('Table-specific privileges')
           . PMA_showHint(__('Note: MySQL privilege names are expressed in English'))
           . '</legend>' . "\n";



        // privs that are attached to a specific column
        PMA_displayColumnPrivs(
            $columns, $row, 'Select_priv', 'SELECT',
            'select', __('Allows reading data.'), 'Select'
        );

        PMA_displayColumnPrivs(
            $columns, $row, 'Insert_priv', 'INSERT',
            'insert', __('Allows inserting and replacing data.'), 'Insert'
        );

        PMA_displayColumnPrivs(
            $columns, $row, 'Update_priv', 'UPDATE',
            'update', __('Allows changing data.'), 'Update'
        );

        PMA_displayColumnPrivs(
            $columns, $row, 'References_priv', 'REFERENCES', 'references',
            __('Has no effect in this MySQL version.'), 'References'
        );

        // privs that are not attached to a specific column

        echo '    <div class="item">' . "\n";
        foreach ($row as $current_grant => $current_grant_value) {
            $grant_type = substr($current_grant, 0, (strlen($current_grant) - 5));
            if (in_array($grant_type, array('Select', 'Insert', 'Update', 'References'))) {
                continue;
            }
            // make a substitution to match the messages variables;
            // also we must substitute the grant we get, because we can't generate
            // a form variable containing blanks (those would get changed to
            // an underscore when receiving the POST)
            if ($current_grant == 'Create View_priv') {
                $tmp_current_grant = 'CreateView_priv';
                $current_grant = 'Create_view_priv';
            } elseif ($current_grant == 'Show view_priv') {
                $tmp_current_grant = 'ShowView_priv';
                $current_grant = 'Show_view_priv';
            } else {
                $tmp_current_grant = $current_grant;
            }

            echo '        <div class="item">' . "\n"
               . '            <input type="checkbox"'
               . (empty($GLOBALS['checkall']) ?  '' : ' checked="checked"')
               . ' name="' . $current_grant . '" id="checkbox_' . $current_grant
               . '" value="Y" '
               . ($current_grant_value == 'Y' ? 'checked="checked" ' : '')
               . 'title="';

            echo (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
                ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
                : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '"/>' . "\n";

            echo '            <label for="checkbox_' . $current_grant
                . '"><code><dfn title="'
                . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))])
                    ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]
                    : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl'])
               . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></code></label>' . "\n"
               . '        </div>' . "\n";
        } // end foreach ()

        echo '    </div>' . "\n";
        // for Safari 2.0.2
        echo '    <div class="clearfloat"></div>' . "\n";

    } else {

        // g l o b a l    o r    d b - s p e c i f i c
        //
        $privTable_names = array(0 => __('Data'), 1 => __('Structure'), 2 => __('Administration'));

        // d a t a
        $privTable[0] = array(
            array('Select', 'SELECT', __('Allows reading data.')),
            array('Insert', 'INSERT', __('Allows inserting and replacing data.')),
            array('Update', 'UPDATE', __('Allows changing data.')),
            array('Delete', 'DELETE', __('Allows deleting data.'))
        );
        if ($db == '*') {
            $privTable[0][] = array('File', 'FILE', __('Allows importing data from and exporting data into files.'));
        }

        // s t r u c t u r e
        $privTable[1] = array(
            array('Create', 'CREATE', ($table == '*' ? __('Allows creating new databases and tables.') : __('Allows creating new tables.'))),
            array('Alter', 'ALTER', __('Allows altering the structure of existing tables.')),
            array('Index', 'INDEX', __('Allows creating and dropping indexes.')),
            array('Drop', 'DROP', ($table == '*' ? __('Allows dropping databases and tables.') : __('Allows dropping tables.'))),
            array('Create_tmp_table', 'CREATE TEMPORARY TABLES', __('Allows creating temporary tables.')),
            array('Show_view', 'SHOW VIEW', __('Allows performing SHOW CREATE VIEW queries.')),
            array('Create_routine', 'CREATE ROUTINE', __('Allows creating stored routines.')),
            array('Alter_routine', 'ALTER ROUTINE', __('Allows altering and dropping stored routines.')),
            array('Execute', 'EXECUTE', __('Allows executing stored routines.')),
        );
        // this one is for a db-specific priv: Create_view_priv
        if (isset($row['Create_view_priv'])) {
            $privTable[1][] = array('Create_view', 'CREATE VIEW', __('Allows creating new views.'));
        }
        // this one is for a table-specific priv: Create View_priv
        if (isset($row['Create View_priv'])) {
            $privTable[1][] = array('Create View', 'CREATE VIEW', __('Allows creating new views.'));
        }
        if (isset($row['Event_priv'])) {
            // MySQL 5.1.6
            $privTable[1][] = array('Event', 'EVENT', __('Allows to set up events for the event scheduler'));
            $privTable[1][] = array('Trigger', 'TRIGGER', __('Allows creating and dropping triggers'));
        }

        // a d m i n i s t r a t i o n
        $privTable[2] = array(
            array('Grant', 'GRANT', __('Allows adding users and privileges without reloading the privilege tables.')),
        );
        if ($db == '*') {
            $privTable[2][] = array('Super', 'SUPER', __('Allows connecting, even if maximum number of connections is reached; required for most administrative operations like setting global variables or killing threads of other users.'));
            $privTable[2][] = array('Process', 'PROCESS', __('Allows viewing processes of all users'));
            $privTable[2][] = array('Reload', 'RELOAD', __('Allows reloading server settings and flushing the server\'s caches.'));
            $privTable[2][] = array('Shutdown', 'SHUTDOWN', __('Allows shutting down the server.'));
            $privTable[2][] = array('Show_db', 'SHOW DATABASES', __('Gives access to the complete list of databases.'));
        }
        $privTable[2][] = array('Lock_tables', 'LOCK TABLES', __('Allows locking tables for the current thread.'));
        $privTable[2][] = array('References', 'REFERENCES', __('Has no effect in this MySQL version.'));
        if ($db == '*') {
            $privTable[2][] = array('Repl_client', 'REPLICATION CLIENT', __('Allows the user to ask where the slaves / masters are.'));
            $privTable[2][] = array('Repl_slave', 'REPLICATION SLAVE', __('Needed for the replication slaves.'));
            $privTable[2][] = array('Create_user', 'CREATE USER', __('Allows creating, dropping and renaming user accounts.'));
        }
        echo '<input type="hidden" name="grant_count" value="'
            . (count($privTable[0]) + count($privTable[1]) + count($privTable[2]) - (isset($row['Grant_priv']) ? 1 : 0))
            . '" />' . "\n"
           . '<fieldset id="fieldset_user_global_rights">' . "\n"
           . '    <legend>' . "\n"
           . '        '
            . ($db == '*'
                ? __('Global privileges')
                : ($table == '*'
                    ? __('Database-specific privileges')
                    : __('Table-specific privileges'))) . "\n"
           . '        (<a href="server_privileges.php?'
            . $GLOBALS['url_query'] . '&amp;checkall=1" onclick="setCheckboxes(\'addUsersForm_' . $random_n . '\', true); return false;">'
            . __('Check All') . '</a> /' . "\n"
           . '        <a href="server_privileges.php?'
            . $GLOBALS['url_query'] . '" onclick="setCheckboxes(\'addUsersForm_' . $random_n . '\', false); return false;">'
            . __('Uncheck All') . '</a>)' . "\n"
           . '    </legend>' . "\n"
           . '    <p><small><i>' . __('Note: MySQL privilege names are expressed in English') . '</i></small></p>' . "\n";

        // Output the Global privilege tables with checkboxes
        foreach ($privTable as $i => $table) {
            echo '    <fieldset>' . "\n"
                . '        <legend>' . __($privTable_names[$i]) . '</legend>' . "\n";
            foreach ($table as $priv) {
                echo '        <div class="item">' . "\n"
                    . '            <input type="checkbox"'
                    .                   ' name="' . $priv[0] . '_priv" id="checkbox_' . $priv[0] . '_priv"'
                    .                   ' value="Y" title="' . $priv[2] . '"'
                    .                   ((! empty($GLOBALS['checkall']) || $row[$priv[0] . '_priv'] == 'Y') ?  ' checked="checked"' : '')
                    .               '/>' . "\n"
                    . '            <label for="checkbox_' . $priv[0] . '_priv"><code><dfn title="' . $priv[2] . '">'
                    .                    $priv[1] . '</dfn></code></label>' . "\n"
                    . '        </div>' . "\n";
            }
            echo '    </fieldset>' . "\n";
        }

        // The "Resource limits" box is not displayed for db-specific privs
        if ($db == '*') {
            echo '    <fieldset>' . "\n"
               . '        <legend>' . __('Resource limits') . '</legend>' . "\n"
               . '        <p><small><i>' . __('Note: Setting these options to 0 (zero) removes the limit.') . '</i></small></p>' . "\n"
               . '        <div class="item">' . "\n"
               . '            <label for="text_max_questions"><code><dfn title="'
                . __('Limits the number of queries the user may send to the server per hour.') . '">MAX QUERIES PER HOUR</dfn></code></label>' . "\n"
               . '            <input type="text" name="max_questions" id="text_max_questions" value="'
                . $row['max_questions'] . '" size="11" maxlength="11" title="' . __('Limits the number of queries the user may send to the server per hour.') . '" />' . "\n"
               . '        </div>' . "\n"
               . '        <div class="item">' . "\n"
               . '            <label for="text_max_updates"><code><dfn title="'
                . __('Limits the number of commands that change any table or database the user may execute per hour.') . '">MAX UPDATES PER HOUR</dfn></code></label>' . "\n"
               . '            <input type="text" name="max_updates" id="text_max_updates" value="'
                . $row['max_updates'] . '" size="11" maxlength="11" title="' . __('Limits the number of commands that change any table or database the user may execute per hour.') . '" />' . "\n"
               . '        </div>' . "\n"
               . '        <div class="item">' . "\n"
               . '            <label for="text_max_connections"><code><dfn title="'
                . __('Limits the number of new connections the user may open per hour.') . '">MAX CONNECTIONS PER HOUR</dfn></code></label>' . "\n"
               . '            <input type="text" name="max_connections" id="text_max_connections" value="'
                . $row['max_connections'] . '" size="11" maxlength="11" title="' . __('Limits the number of new connections the user may open per hour.') . '" />' . "\n"
               . '        </div>' . "\n"
               . '        <div class="item">' . "\n"
               . '            <label for="text_max_user_connections"><code><dfn title="'
                . __('Limits the number of simultaneous connections the user may have.') . '">MAX USER_CONNECTIONS</dfn></code></label>' . "\n"
               . '            <input type="text" name="max_user_connections" id="text_max_user_connections" value="'
                . $row['max_user_connections'] . '" size="11" maxlength="11" title="' . __('Limits the number of simultaneous connections the user may have.') . '" />' . "\n"
               . '        </div>' . "\n"
               . '    </fieldset>' . "\n";
        }
        // for Safari 2.0.2
        echo '    <div class="clearfloat"></div>' . "\n";
    }
    echo '</fieldset>' . "\n";
    if ($submit) {
        echo '<fieldset id="fieldset_user_privtable_footer" class="tblFooters">' . "\n"
           . '    <input type="submit" name="update_privs" value="' . __('Go') . '" />' . "\n"
           . '</fieldset>' . "\n";
    }
} // end of the 'PMA_displayPrivTable()' function
 /**
  * Outputs the content of a table in YAML format
  *
  * @param string  $db         database name
  * @param string  $table      table name
  * @param string  $crlf       the end of line sequence
  * @param string  $error_url  the url to go back in case of error
  * @param string  $sql_query  SQL query for obtaining data
  * @return  bool        Whether it succeeded
  *
  * @access  public
  */
 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
 {
     $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
     $columns_cnt = PMA_DBI_num_fields($result);
     for ($i = 0; $i < $columns_cnt; $i++) {
         $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
     }
     unset($i);
     $buffer = '';
     $record_cnt = 0;
     while ($record = PMA_DBI_fetch_row($result)) {
         $record_cnt++;
         // Output table name as comment if this is the first record of the table
         if ($record_cnt == 1) {
             $buffer = '# ' . $db . '.' . $table . $crlf;
             $buffer .= '-' . $crlf;
         } else {
             $buffer = '-' . $crlf;
         }
         for ($i = 0; $i < $columns_cnt; $i++) {
             if (!isset($record[$i])) {
                 continue;
             }
             $column = $columns[$i];
             if (is_null($record[$i])) {
                 $buffer .= '  ' . $column . ': null' . $crlf;
                 continue;
             }
             if (is_numeric($record[$i])) {
                 $buffer .= '  ' . $column . ': ' . $record[$i] . $crlf;
                 continue;
             }
             $record[$i] = str_replace(array('\\', '"', "\n", "\r"), array('\\\\', '\\"', '\\n', '\\r'), $record[$i]);
             $buffer .= '  ' . $column . ': "' . $record[$i] . '"' . $crlf;
         }
         if (!PMA_exportOutputHandler($buffer)) {
             return false;
         }
     }
     PMA_DBI_free_result($result);
     return true;
 }
Esempio n. 20
0
                        // disable BLOB repository monitoring
                    // disable BLOB repository monitoring
                    case "disable":
                        // if at least one blobstreaming table exists, execute drop
                        if ($oneBSTableExists) {
                            PMA_BS_DropTables($db);
                        }
                        break;
                        // repair BLOB repository
                    // repair BLOB repository
                    case "repair":
                        // check if a blobstreaming table is missing
                        foreach ($bs_tables as $table_key => $tbl) {
                            if (!$bs_tables[$table_key]['Exists']) {
                                PMA_DBI_select_db($db);
                                PMA_DBI_query(PMA_BS_GetTableStruct($table_key));
                            }
                        }
                }
                // refresh side menu
                PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'db_operations.php?' . PMA_generate_common_url('', '', '&') . (isset($db) ? '&db=' . urlencode($db) : '') . (isset($token) ? '&token=' . urlencode($token) : '') . (isset($goto) ? '&goto=' . urlencode($goto) : '') . 'reload=1&purge=1');
            }
            // end  if ($PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST'))
        }
        // end if ($PMA_Config->get('PBXT_NAME') !== strtolower($db))
    }
}
/**
 * Settings for relations stuff
 */
require_once './libraries/relation.lib.php';
 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
 // Blending out tables in use
 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
     while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
         // if in use memorize tablename
         if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
             $sot_cache[$tmp[0]] = true;
         }
     }
     PMA_DBI_free_result($db_info_result);
     if (isset($sot_cache)) {
         $db_info_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', null, PMA_DBI_QUERY_STORE);
         if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
             while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
                 if (!isset($sot_cache[$tmp[0]])) {
                     $sts_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\';');
                     $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
                     PMA_DBI_free_result($sts_result);
                     unset($sts_result);
                     if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
                         $sts_tmp['Type'] =& $sts_tmp['Engine'];
                     }
                     if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB'] && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
                         continue;
                     }
                     if ($cfg['ShowTooltip']) {
                         PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
                     }
                     $tables[$sts_tmp['Name']] = $sts_tmp;
                 } else {
                     // table in use
Esempio n. 22
0
 /**
  * Outputs the content of a table in CSV format
  *
  * @param string  $db         database name
  * @param string  $table      table name
  * @param string  $crlf       the end of line sequence
  * @param string  $error_url  the url to go back in case of error
  * @param string  $sql_query  SQL query for obtaining data
  * @return  bool        Whether it succeeded
  *
  * @access  public
  */
 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
 {
     global $what;
     global $csv_terminated;
     global $csv_separator;
     global $csv_enclosed;
     global $csv_escaped;
     // Gets the data from the database
     $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
     $fields_cnt = PMA_DBI_num_fields($result);
     // If required, get fields name at the first line
     if (isset($GLOBALS['csv_columns'])) {
         $schema_insert = '';
         for ($i = 0; $i < $fields_cnt; $i++) {
             if ($csv_enclosed == '') {
                 $schema_insert .= stripslashes(PMA_DBI_field_name($result, $i));
             } else {
                 $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(PMA_DBI_field_name($result, $i))) . $csv_enclosed;
             }
             $schema_insert .= $csv_separator;
         }
         // end for
         $schema_insert = trim(substr($schema_insert, 0, -1));
         if (!PMA_exportOutputHandler($schema_insert . $csv_terminated)) {
             return false;
         }
     }
     // end if
     // Format the data
     while ($row = PMA_DBI_fetch_row($result)) {
         $schema_insert = '';
         for ($j = 0; $j < $fields_cnt; $j++) {
             if (!isset($row[$j]) || is_null($row[$j])) {
                 $schema_insert .= $GLOBALS[$what . '_null'];
             } elseif ($row[$j] == '0' || $row[$j] != '') {
                 // always enclose fields
                 if ($what == 'excel') {
                     $row[$j] = preg_replace("/\r(\n)?/", "\n", $row[$j]);
                 }
                 // remove CRLF characters within field
                 if (isset($GLOBALS[$what . '_removeCRLF']) && $GLOBALS[$what . '_removeCRLF']) {
                     $row[$j] = str_replace("\n", "", str_replace("\r", "", $row[$j]));
                 }
                 if ($csv_enclosed == '') {
                     $schema_insert .= $row[$j];
                 } else {
                     // also double the escape string if found in the data
                     if ($csv_escaped != $csv_enclosed) {
                         $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, str_replace($csv_escaped, $csv_escaped . $csv_escaped, $row[$j])) . $csv_enclosed;
                     } else {
                         // avoid a problem when escape string equals enclose
                         $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
                     }
                 }
             } else {
                 $schema_insert .= '';
             }
             if ($j < $fields_cnt - 1) {
                 $schema_insert .= $csv_separator;
             }
         }
         // end for
         if (!PMA_exportOutputHandler($schema_insert . $csv_terminated)) {
             return false;
         }
     }
     // end while
     PMA_DBI_free_result($result);
     return true;
 }
Esempio n. 23
0
</form>
<div id="pdflayout" class="pdflayout" style="visibility: hidden;">
<?php 
            foreach ($array_sh_page as $key => $temp_sh_page) {
                $drag_x = $temp_sh_page['x'];
                $drag_y = $temp_sh_page['y'];
                $draginit .= '    Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
                $draginit .= '    getElement("table_' . $i . '").onDrag = function (x, y) { document.edcoord.elements["c_table_' . $i . '[x]"].value = parseInt(x); document.edcoord.elements["c_table_' . $i . '[y]"].value = parseInt(y) }' . "\n";
                $draginit .= '    getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
                $draginit .= '    getElement("table_' . $i . '").style.top  = "' . $drag_y . 'px";' . "\n";
                $reset_draginit .= '    getElement("table_' . $i . '").style.left = "2px";' . "\n";
                $reset_draginit .= '    getElement("table_' . $i . '").style.top  = "' . 15 * $i . 'px";' . "\n";
                $reset_draginit .= '    document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
                $reset_draginit .= '    document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . 15 * $i . '"' . "\n";
                $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($temp_sh_page['table_name']) . ' FROM ' . PMA_backquote($db);
                $fields_rs = PMA_DBI_query($local_query);
                unset($local_query);
                $fields_cnt = PMA_DBI_num_rows($fields_rs);
                echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
                if (isset($with_field_names)) {
                    while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
                        echo '<br />' . htmlspecialchars($row['Field']) . "\n";
                    }
                }
                echo '</div>' . "\n";
                PMA_DBI_free_result($fields_rs);
                unset($fields_rs);
                $i++;
            }
            ?>
</div>
Esempio n. 24
0
 /**
  * renames table
  *
  * @param   string  new table name
  * @param   string  new database name
  * @return  boolean success
  */
 function rename($new_name, $new_db = null)
 {
     if (null !== $new_db && $new_db !== $this->getDbName()) {
         // Ensure the target is valid
         if (!$GLOBALS['PMA_List_Database']->exists($new_db)) {
             $this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db;
             return false;
         }
     } else {
         $new_db = $this->getDbName();
     }
     $new_table = new PMA_Table($new_name, $new_db);
     if ($this->getFullName() === $new_table->getFullName()) {
         return true;
     }
     if (!PMA_Table::isValidName($new_name)) {
         $this->errors[] = $GLOBALS['strInvalidTableName'] . ': ' . $new_table->getFullName();
         return false;
     }
     $GLOBALS['sql_query'] = '
         RENAME TABLE ' . $this->getFullName(true) . '
                   TO ' . $new_table->getFullName(true) . ';';
     if (!PMA_DBI_query($GLOBALS['sql_query'])) {
         $this->errors[] = sprintf($GLOBALS['strErrorRenamingTable'], $this->getFullName(), $new_table->getFullName());
         return false;
     }
     $old_name = $this->getName();
     $old_db = $this->getDbName();
     $this->setName($new_name);
     $this->setDbName($new_db);
     /**
      * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db)
      */
     // garvin: Move old entries from comments to new table
     require_once './libraries/relation.lib.php';
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     if ($GLOBALS['cfgRelation']['commwork']) {
         $remove_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($remove_query);
         unset($remove_query);
     }
     if ($GLOBALS['cfgRelation']['displaywork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['relwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `foreign_db`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `foreign_table` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `foreign_db`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `foreign_table` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `master_db`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `master_table` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `master_db`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `master_table` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['pdfwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['designerwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddslashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddslashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddslashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddslashes($old_name) . '\'';
         PMA_query_as_cu($table_query);
         unset($table_query);
     }
     $this->messages[] = sprintf($GLOBALS['strRenameTableOK'], htmlspecialchars($old_name), htmlspecialchars($new_name));
     return true;
 }
Esempio n. 25
0
File: csv.php Progetto: lifecom/test
/**
 * Outputs the content of a table in CSV format
 *
 * @param   string      the database name
 * @param   string      the table name
 * @param   string      the end of line sequence
 * @param   string      the url to go back in case of error
 * @param   string      SQL query for obtaining data
 *
 * @return  bool        Whether it suceeded
 *
 * @access  public
 */
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
    global $what;
    global $add_character;
    global $separator;
    global $enclosed;
    global $escaped;
    // Gets the data from the database
    $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED);
    $fields_cnt = PMA_DBI_num_fields($result);
    // If required, get fields name at the first line
    if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') {
        $schema_insert = '';
        for ($i = 0; $i < $fields_cnt; $i++) {
            if ($enclosed == '') {
                $schema_insert .= stripslashes(PMA_DBI_field_name($result, $i));
            } else {
                $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, stripslashes(PMA_DBI_field_name($result, $i))) . $enclosed;
            }
            $schema_insert .= $separator;
        }
        // end for
        $schema_insert = trim(substr($schema_insert, 0, -1));
        if (!PMA_exportOutputHandler($schema_insert . $add_character)) {
            return FALSE;
        }
    }
    // end if
    // Format the data
    while ($row = PMA_DBI_fetch_row($result)) {
        $schema_insert = '';
        for ($j = 0; $j < $fields_cnt; $j++) {
            if (!isset($row[$j]) || is_null($row[$j])) {
                $schema_insert .= $GLOBALS[$what . '_replace_null'];
            } else {
                if ($row[$j] == '0' || $row[$j] != '') {
                    // loic1 : always enclose fields
                    if ($what == 'excel') {
                        $row[$j] = ereg_replace("\r(\n)?", "\n", $row[$j]);
                    }
                    if ($enclosed == '') {
                        $schema_insert .= $row[$j];
                    } else {
                        $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, $row[$j]) . $enclosed;
                    }
                } else {
                    $schema_insert .= '';
                }
            }
            if ($j < $fields_cnt - 1) {
                $schema_insert .= $separator;
            }
        }
        // end for
        if (!PMA_exportOutputHandler($schema_insert . $add_character)) {
            return FALSE;
        }
    }
    // end while
    PMA_DBI_free_result($result);
    return TRUE;
}
    // Not a valid db name -> back to the welcome page
    if (strlen($db)) {
        $is_db = PMA_DBI_select_db($db);
    }
    if (! strlen($db) || !$is_db) {
        PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php?' . PMA_generate_common_url('', '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1');
        exit;
    }
} // end if (ensures db exists)

/**
 * Changes database charset if requested by the user
 */
if (isset($submitcollation) && !empty($db_collation)) {
    list($db_charset) = explode('_', $db_collation);
    $sql_query        = 'ALTER DATABASE ' . PMA_backquote($db) . ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
    $result           = PMA_DBI_query($sql_query);
    $message          = PMA_Message::success();
    unset($db_charset, $db_collation);
}

$GLOBALS['js_include'][] = 'functions.js';
require_once './libraries/header.inc.php';

/**
 * Set parameters for links
 */
$url_query = PMA_generate_common_url($db);

?>
/**
 * Adds a bookmark
 *
 * @uses    PMA_backquote()
 * @uses    PMA_sqlAddslashes()
 * @uses    PMA_DBI_query()
 * @uses    PMA_Bookmark_getParams()
 * @global  resource  the controluser db connection handle
 *
 * @param   array     the properties of the bookmark to add; here,
 *                    $fields['query'] is urlencoded
 * @param   boolean   whether to make the bookmark available for all users
 *
 * @return  boolean   whether the INSERT succeeds or not
 *
 * @access  public
 */
function PMA_Bookmark_save($fields, $all_users = false)
{
    global $controllink;
    $cfgBookmark = PMA_Bookmark_getParams();
    if (empty($cfgBookmark)) {
        return false;
    }
    $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' (id, dbase, user, query, label) VALUES (NULL, \'' . PMA_sqlAddslashes($fields['dbase']) . '\', \'' . ($all_users ? '' : PMA_sqlAddslashes($fields['user'])) . '\', \'' . PMA_sqlAddslashes(urldecode($fields['query'])) . '\', \'' . PMA_sqlAddslashes($fields['label']) . '\')';
    return PMA_DBI_query($query, $controllink);
}
Esempio n. 28
0
 /**
  * Counts and displays the number of records in a table
  *
  * Last revision 13 July 2001: Patch for limiting dump size from
  * vinay@sanisoft.com & girish@sanisoft.com
  *
  * @param   string   the current database name
  * @param   string   the current table name
  * @param   boolean  whether to retain or to displays the result
  *
  * @return  mixed    the number of records if retain is required, true else
  *
  * @access  public
  */
 function PMA_countRecords($db, $table, $ret = FALSE)
 {
     global $err_url, $cfg;
     $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';');
     $showtable = PMA_DBI_fetch_assoc($result);
     $num = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
     if ($num < $cfg['MaxExactCount']) {
         unset($num);
     }
     PMA_DBI_free_result($result);
     if (!isset($num)) {
         $result = PMA_DBI_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table));
         list($num) = $result ? PMA_DBI_fetch_row($result) : array(0);
         PMA_DBI_free_result($result);
     }
     if ($ret) {
         return $num;
     } else {
         echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
         return TRUE;
     }
 }
Esempio n. 29
0
    if (PMA_Tracker::deactivateTracking($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'])) {
        $msg = PMA_Message::success(sprintf($strTrackingVersionDeactivated, $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']));
        $msg->display();
    }
}
// Activate tracking
if (isset($_REQUEST['submit_activate_now'])) {
    if (PMA_Tracker::activateTracking($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version'])) {
        $msg = PMA_Message::success(sprintf($strTrackingVersionActivated, $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']));
        $msg->display();
    }
}
// Export as SQL execution
if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'execution') {
    foreach ($entries as $entry) {
        $sql_result = PMA_DBI_query("/*NOTRACK*/\n" . $entry['statement']);
    }
    $msg = PMA_Message::success($strTrackingSQLExecuted);
    $msg->display();
}
// Export as SQL dump
if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'sqldump') {
    $new_query = "# " . $strTrackingYouCanExecute . "\n" . "# " . $strTrackingCommentOut . "\n" . "\n" . "CREATE database IF NOT EXISTS pma_temp_db; \n" . "USE pma_temp_db; \n" . "\n";
    foreach ($entries as $entry) {
        $new_query .= $entry['statement'];
    }
    $msg = PMA_Message::success($strTrackingSQLExported);
    $msg->display();
    $db_temp = $db;
    $table_temp = $table;
    $db = $table = '';
Esempio n. 30
0
    }
    exit;
}
/**
 * Executes the sql query and get the result, then move back to the calling
 * page
 */
$sql_query = implode(';', $query) . ';';
$total_affected_rows = 0;
$last_message = '';
$warning_message = '';
foreach ($query as $query_index => $single_query) {
    if ($cfg['IgnoreMultiSubmitErrors']) {
        $result = PMA_DBI_try_query($single_query);
    } else {
        $result = PMA_DBI_query($single_query);
    }
    if (isset($GLOBALS['warning'])) {
        $warning_message .= $GLOBALS['warning'] . '[br]';
    }
    if (!$result) {
        $message .= 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) {
            $last_message .= '[br]' . $strInsertedRowId . '&nbsp;' . $insert_id;
        }
    }