Esempio n. 1
0
// end if
$tables_cnt = count($the_tables);
$counter = 0;
foreach ($the_tables as $key => $table) {
    if ($counter + 1 >= $tables_cnt) {
        $breakstyle = '';
    } else {
        $breakstyle = ' style="page-break-after: always;"';
    }
    $counter++;
    echo '<div' . $breakstyle . '>' . "\n";
    echo '<h1>' . htmlspecialchars($table) . '</h1>' . "\n";
    /**
     * Gets table informations
     */
    $showtable = PMA_Table::sGetStatusInfo($db, $table);
    $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
    $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
    $tbl_is_view = PMA_Table::isView($db, $table);
    /**
     * Gets fields properties
     */
    $columns = PMA_DBI_get_columns($db, $table);
    // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
    // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
    // and SHOW CREATE TABLE says NOT NULL (tested
    // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
    $show_create_table = PMA_DBI_fetch_value('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0, 1);
    $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
    // Check if we can use Relations
    // Find which tables are related with the current one and write it in
Esempio n. 2
0
/**
 * Get HTML snippet for display table statistics
 *
 * @param array   $showtable           full table status info
 * @param integer $table_info_num_rows table info number of rows
 * @param boolean $tbl_is_view         whether table is view or not
 * @param boolean $db_is_system_schema whether db is information schema or not
 * @param string  $tbl_storage_engine  table storage engine
 * @param string  $url_query           url query
 * @param string  $tbl_collation       table collation
 *
 * @return string $html_output
 */
function PMA_getHtmlForDisplayTableStats($showtable, $table_info_num_rows, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $url_query, $tbl_collation)
{
    $html_output = '<div id="tablestatistics">';
    if (empty($showtable)) {
        $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
    }
    $nonisam = false;
    $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB';
    if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
        $nonisam = true;
    }
    // Gets some sizes
    $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
    // this is to display for example 261.2 MiB instead of 268k KiB
    $max_digits = 3;
    $decimals = 1;
    list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length'], $max_digits, $decimals);
    if ($mergetable == false) {
        list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length'], $max_digits, $decimals);
    }
    // InnoDB returns a huge value in Data_free, do not use it
    if (!$is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
        list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free'], $max_digits, $decimals);
        list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals);
    } else {
        list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
    }
    list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
    if ($table_info_num_rows > 0) {
        list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
    }
    // Displays them
    $odd_row = false;
    $html_output .= '<fieldset>' . '<legend>' . __('Information') . '</legend>' . '<a id="showusage"></a>';
    if (!$tbl_is_view && !$db_is_system_schema) {
        $html_output .= '<table id="tablespaceusage" class="data">' . '<caption class="tblHeaders">' . __('Space usage') . '</caption>' . '<tbody>';
        $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Data'), $data_size, $data_unit);
        $odd_row = !$odd_row;
        if (isset($index_size)) {
            $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Index'), $index_size, $index_unit);
            $odd_row = !$odd_row;
        }
        if (isset($free_size)) {
            $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Overhead'), $free_size, $free_unit);
            $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Effective'), $effect_size, $effect_unit);
            $odd_row = !$odd_row;
        }
        if (isset($tot_size) && $mergetable == false) {
            $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Total'), $tot_size, $tot_unit);
            $odd_row = !$odd_row;
        }
        // Optimize link if overhead
        if (isset($free_size) && !PMA_DRIZZLE && ($tbl_storage_engine == 'MYISAM' || $tbl_storage_engine == 'ARIA' || $tbl_storage_engine == 'MARIA' || $tbl_storage_engine == 'BDB')) {
            $html_output .= PMA_getHtmlForOptimizeLink($url_query);
        }
        $html_output .= '</tbody>' . '</table>';
    }
    $html_output .= getHtmlForRowStatsTable($showtable, $tbl_collation, $is_innodb, $mergetable, isset($avg_size) ? $avg_size : '', isset($avg_unit) ? $avg_unit : '');
    $html_output .= '</fieldset>' . '</div>';
    return $html_output;
}
Esempio n. 3
0
/**
 * Generate table html when SQL statement have multiple queries
 * which return displayable results
 *
 * @param PMA_DisplayResults $displayResultsObject object
 * @param string             $db                   database name
 * @param array              $sql_data             information about SQL statement
 * @param string             $goto                 the URL to go back in case of errors
 * @param string             $pmaThemeImage        path for theme images directory
 * @param string             $text_dir             
 * @param string             $printview            
 * @param string             $url_query            URL query
 * @param array              $disp_mode            the display mode
 *
 * @return string   $table_html   html content
 */
function getTableHtmlForMultipleQueries(
    $displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage,
    $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append
) {
    
    $table_html = '';
        
    $tables_array = PMA_DBI_get_tables($db);
    $databases_array = PMA_DBI_get_databases_full();
    $multi_sql = implode(";", $sql_data['valid_sql']);    
    $querytime_before = array_sum(explode(' ', microtime()));

    // Assignment for variable is not needed since the results are
    // looiping using the connection
    @PMA_DBI_try_multi_query($multi_sql);

    $querytime_after = array_sum(explode(' ', microtime()));
    $querytime = $querytime_after - $querytime_before;        
    $sql_no = 0;

    do {

        $analyzed_sql = array();
        $is_affected = false;
        
        $result = PMA_DBI_store_result();
        $fields_meta = ($result !== false) ? PMA_DBI_get_fields_meta($result) : array();
        $fields_cnt  = count($fields_meta);
        
        // Initialize needed params related to each query in multiquery statement
        if (isset($sql_data['valid_sql'][$sql_no])) {
            
            // 'Use' query can change the database
            if (stripos($sql_data['valid_sql'][$sql_no], "use ")) {
                $db = PMA_getNewDatabase($sql_data['valid_sql'][$sql_no], $databases_array);
            }
            $parsed_sql = PMA_SQP_parse($sql_data['valid_sql'][$sql_no]);
            $table = PMA_getTableNameBySQL($sql_data['valid_sql'][$sql_no], $tables_array);            
            
            $analyzed_sql = PMA_SQP_analyze($parsed_sql);
            $is_select = isset($analyzed_sql[0]['queryflags']['select_from']);        
            $unlim_num_rows = PMA_Table::countRecords($db, $table, $force_exact = true);
            $showtable = PMA_Table::sGetStatusInfo($db, $table, null, true);
            $url_query = PMA_generate_common_url($db, $table);
            
            list($is_group, $is_func, $is_count, $is_export, $is_analyse,
                $is_explain, $is_delete, $is_affected, $is_insert, $is_replace,
                $is_show, $is_maint)
                    = PMA_getDisplayPropertyParams(
                        $sql_data['valid_sql'][$sql_no], $is_select
                    );
            
            // Handle remembered sorting order, only for single table query
            if ($GLOBALS['cfg']['RememberSorting']
                && ! ($is_count || $is_export || $is_func || $is_analyse)
                && isset($analyzed_sql[0]['select_expr'])
                && (count($analyzed_sql[0]['select_expr']) == 0)
                && isset($analyzed_sql[0]['queryflags']['select_from'])
                && count($analyzed_sql[0]['table_ref']) == 1
            ) {
                PMA_handleSortOrder($db, $table, $analyzed_sql, $sql_data['valid_sql'][$sql_no]);
            }

            // Do append a "LIMIT" clause?
            if (($_SESSION['tmp_user_values']['max_rows'] != 'all')
                && ! ($is_count || $is_export || $is_func || $is_analyse)
                && isset($analyzed_sql[0]['queryflags']['select_from'])
                && ! isset($analyzed_sql[0]['queryflags']['offset'])
                && empty($analyzed_sql[0]['limit_clause'])
            ) {            
                $sql_data['valid_sql'][$sql_no] = PMA_getSqlWithLimitClause(
                    $sql_data['valid_sql'][$sql_no], $analyzed_sql, $sql_limit_to_append
                );            
            }
            
            // Set the needed properties related to executing sql query
            $displayResultsObject->__set('_db', $db);
            $displayResultsObject->__set('_table', $table);
            $displayResultsObject->__set('_goto', $goto);
            
        }
        
        if (! $is_affected) {
            $num_rows = ($result) ? @PMA_DBI_num_rows($result) : 0;
        } elseif (! isset($num_rows)) {
            $num_rows = @PMA_DBI_affected_rows();
        }

        if (isset($sql_data['valid_sql'][$sql_no])) {
            
            $displayResultsObject->__set('_sql_query', $sql_data['valid_sql'][$sql_no]);
            $displayResultsObject->setProperties(
                $unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func,
                $is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $text_dir,
                $is_maint, $is_explain, $is_show, $showtable, $printview, $url_query
            );
            
        }

        if ($num_rows == 0) {
            continue;
        }

        // With multiple results, operations are limied
        $disp_mode = 'nnnn000000';
        $is_limited_display = true;

        // Collect the tables
        $table_html .= $displayResultsObject->getTable(
            $result, $disp_mode, $analyzed_sql, $is_limited_display
        );

        // Free the result to save the memory
        PMA_DBI_free_result($result);
        
        $sql_no++;
        
    } while (PMA_DBI_more_results() && PMA_DBI_next_result());

    return $table_html;
    
}
Esempio n. 4
0
// Seems we need to do this in MySQL 5.0.2,
// otherwise error #1046, no database selected
PMA_DBI_select_db($GLOBALS['db']);
/**
 * Holds information about the current table
 *
 * @todo replace this by PMA_Table
 * @global array $GLOBALS['showtable']
 * @name $showtable
 */
$GLOBALS['showtable'] = array();
// PMA_Table::sGetStatusInfo() does caching by default, but here
// we force reading of the current table status
// if $reread_info is true (for example, coming from tbl_operations.php
// and we just changed the table's storage engine)
$GLOBALS['showtable'] = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, isset($reread_info) && $reread_info ? true : false);
// need this test because when we are creating a table, we get 0 rows
// from the SHOW TABLE query
// and we don't want to mess up the $tbl_storage_engine coming from the form
if ($showtable) {
    if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
        $tbl_is_view = true;
        $tbl_storage_engine = __('View');
        $show_comment = null;
    } else {
        $tbl_is_view = false;
        $tbl_storage_engine = isset($showtable['Engine']) ? strtoupper($showtable['Engine']) : '';
        // a new comment could be coming from tbl_operations.php
        // and we want to show it in the header
        if (isset($submitcomment) && isset($comment)) {
            $show_comment = $comment;
Esempio n. 5
0
/**
 * Generate table html when SQL statement have multiple queries
 * which return displayable results
 *
 * @param object $displayResultsObject PMA_DisplayResults object
 * @param string $db                   database name
 * @param array  $sql_data             information about SQL statement
 * @param string $goto                 URL to go back in case of errors
 * @param string $pmaThemeImage        path for theme images  directory
 * @param string $printview            whether printview is enabled
 * @param string $url_query            URL query
 * @param array  $disp_mode            the display mode
 * @param string $sql_limit_to_append  limit clause
 * @param bool   $editable             whether editable or not
 *
 * @return string   $table_html   html content
 */
function PMA_getTableHtmlForMultipleQueries($displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage, $printview, $url_query, $disp_mode, $sql_limit_to_append, $editable)
{
    $table_html = '';
    $tables_array = $GLOBALS['dbi']->getTables($db);
    $databases_array = $GLOBALS['dbi']->getDatabasesFull();
    $multi_sql = implode(";", $sql_data['valid_sql']);
    $querytime_before = array_sum(explode(' ', microtime()));
    // Assignment for variable is not needed since the results are
    // looping using the connection
    @$GLOBALS['dbi']->tryMultiQuery($multi_sql);
    $querytime_after = array_sum(explode(' ', microtime()));
    $querytime = $querytime_after - $querytime_before;
    $sql_no = 0;
    do {
        $analyzed_sql = array();
        $is_affected = false;
        $showtable = array();
        $result = $GLOBALS['dbi']->storeResult();
        $fields_meta = $result !== false ? $GLOBALS['dbi']->getFieldsMeta($result) : array();
        $fields_cnt = count($fields_meta);
        // Initialize needed params related to each query in multiquery statement
        if (isset($sql_data['valid_sql'][$sql_no])) {
            // 'Use' query can change the database
            if (mb_stripos($sql_data['valid_sql'][$sql_no], "use ")) {
                $db = PMA_getNewDatabase($sql_data['valid_sql'][$sql_no], $databases_array);
            }
            $table = PMA_getTableNameBySQL($sql_data['valid_sql'][$sql_no], $tables_array);
            // for the use of the parse_analyze.inc.php
            $sql_query = $sql_data['valid_sql'][$sql_no];
            // Parse and analyze the query
            include 'libraries/parse_analyze.inc.php';
            $unlim_num_rows = PMA_Table::countRecords($db, $table, true);
            $showtable = PMA_Table::sGetStatusInfo($db, $table, null, true);
            $url_query = PMA_URL_getCommon(array('db' => $db, 'table' => $table));
            // Handle remembered sorting order, only for single table query
            if ($GLOBALS['cfg']['RememberSorting'] && !($is_count || $is_export || $is_func || $is_analyse) && isset($analyzed_sql[0]['select_expr']) && count($analyzed_sql[0]['select_expr']) == 0 && isset($analyzed_sql[0]['queryflags']['select_from']) && count($analyzed_sql[0]['table_ref']) == 1) {
                PMA_handleSortOrder($db, $table, $analyzed_sql, $sql_data['valid_sql'][$sql_no]);
            }
            // Do append a "LIMIT" clause?
            if ($_SESSION['tmpval']['max_rows'] != 'all' && !($is_count || $is_export || $is_func || $is_analyse) && isset($analyzed_sql[0]['queryflags']['select_from']) && !isset($analyzed_sql[0]['queryflags']['offset']) && empty($analyzed_sql[0]['limit_clause'])) {
                $sql_limit_to_append = ' LIMIT ' . $_SESSION['tmpval']['pos'] . ', ' . $_SESSION['tmpval']['max_rows'] . " ";
                $sql_data['valid_sql'][$sql_no] = PMA_getSqlWithLimitClause($analyzed_sql, $sql_limit_to_append);
            }
            // Set the needed properties related to executing sql query
            $displayResultsObject->__set('db', $db);
            $displayResultsObject->__set('table', $table);
            $displayResultsObject->__set('goto', $goto);
        }
        if (!$is_affected) {
            $num_rows = $result ? @$GLOBALS['dbi']->numRows($result) : 0;
        } elseif (!isset($num_rows)) {
            $num_rows = @$GLOBALS['dbi']->affectedRows();
        }
        if (isset($sql_data['valid_sql'][$sql_no])) {
            $displayResultsObject->__set('sql_query', $sql_data['valid_sql'][$sql_no]);
            $displayResultsObject->setProperties($unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func, $is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $GLOBALS['text_dir'], $is_maint, $is_explain, $is_show, $showtable, $printview, $url_query, $editable);
        }
        if ($num_rows == 0) {
            continue;
        }
        // With multiple results, operations are limited
        $disp_mode = 'nnnn000000';
        $is_limited_display = true;
        // Collect the tables
        $table_html .= $displayResultsObject->getTable($result, $disp_mode, $analyzed_sql, $is_limited_display);
        // Free the result to save the memory
        $GLOBALS['dbi']->freeResult($result);
        $sql_no++;
    } while ($GLOBALS['dbi']->moreResults() && $GLOBALS['dbi']->nextResult());
    return $table_html;
}
Esempio n. 6
0
/**
 * Function to send html for table dropdown list
 *
 * @return void
 */
function PMA_sendHtmlForTableDropdownList()
{
    $response = PMA_Response::getInstance();
    $tables = array();
    $foreign = isset($_REQUEST['foreign']) && $_REQUEST['foreign'] === 'true';
    if ($foreign) {
        $tbl_storage_engine = strtoupper(PMA_Table::sGetStatusInfo($_REQUEST['db'], $_REQUEST['table'], 'Engine'));
    }
    // In Drizzle, 'SHOW TABLE STATUS' will show status only for the tables
    // which are currently in the table cache. Hence we have to use 'SHOW TABLES'
    // and manully retrieve table engine values.
    if ($foreign && !PMA_DRIZZLE) {
        $query = 'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($_REQUEST['foreignDb']);
        $tables_rs = $GLOBALS['dbi']->query($query, null, PMA_DatabaseInterface::QUERY_STORE);
        while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
            if (isset($row['Engine']) && strtoupper($row['Engine']) == $tbl_storage_engine) {
                $tables[] = htmlspecialchars($row['Name']);
            }
        }
    } else {
        $query = 'SHOW TABLES FROM ' . PMA_Util::backquote($_REQUEST['foreignDb']);
        $tables_rs = $GLOBALS['dbi']->query($query, null, PMA_DatabaseInterface::QUERY_STORE);
        while ($row = $GLOBALS['dbi']->fetchArray($tables_rs)) {
            if ($foreign && PMA_DRIZZLE) {
                $engine = strtoupper(PMA_Table::sGetStatusInfo($_REQUEST['foreignDb'], $row[0], 'Engine'));
                if (isset($engine) && $engine == $tbl_storage_engine) {
                    $tables[] = htmlspecialchars($row[0]);
                }
            } else {
                $tables[] = htmlspecialchars($row[0]);
            }
        }
    }
    $response->addJSON('tables', $tables);
}
 public function dataDictionaryDoc($alltables)
 {
     global $db, $pdf, $orientation, $paper;
     // TOC
     $pdf->addpage($GLOBALS['orientation']);
     $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
     $pdf->Ln(15);
     $i = 1;
     foreach ($alltables as $table) {
         $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
         $pdf->SetX(10);
         // $pdf->Ln(1);
         $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
         $pdf->SetX(10);
         $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
         // $pdf->Ln(1);
         $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
         while ($row = PMA_DBI_fetch_assoc($result)) {
             $pdf->SetX(20);
             $field_name = $row['Field'];
             $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
             // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]);
         }
         $lasttable = $table;
         $i++;
     }
     $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
     $pdf->SetX(10);
     $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['RT']['-']);
     $pdf->SetX(10);
     $pdf->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
     $z = 0;
     foreach ($alltables as $table) {
         $z++;
         $pdf->SetAutoPageBreak(true, 15);
         $pdf->addpage($GLOBALS['orientation']);
         $pdf->Bookmark($table);
         $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo());
         $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
         $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
         $pdf->SetFont($this->_ff, 'B', 18);
         $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
         $pdf->SetFont($this->_ff, '', 8);
         $pdf->ln();
         $cfgRelation = PMA_getRelationsParam();
         $comments = PMA_getComments($db, $table);
         if ($cfgRelation['mimework']) {
             $mime_map = PMA_getMIME($db, $table, true);
         }
         /**
          * Gets table informations
          */
         $showtable = PMA_Table::sGetStatusInfo($db, $table);
         $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
         $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
         $create_time = isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '';
         $update_time = isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '';
         $check_time = isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '';
         /**
          * Gets table keys and retains them
          */
         $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
         $primary = '';
         $indexes = array();
         $lastIndex = '';
         $indexes_info = array();
         $indexes_data = array();
         $pk_array = array();
         // will be use to emphasis prim. keys in the table
         // view
         while ($row = PMA_DBI_fetch_assoc($result)) {
             // Backups the list of primary keys
             if ($row['Key_name'] == 'PRIMARY') {
                 $primary .= $row['Column_name'] . ', ';
                 $pk_array[$row['Column_name']] = 1;
             }
             // Retains keys informations
             if ($row['Key_name'] != $lastIndex) {
                 $indexes[] = $row['Key_name'];
                 $lastIndex = $row['Key_name'];
             }
             $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
             $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
             if (isset($row['Cardinality'])) {
                 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
             }
             // I don't know what does following column mean....
             // $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
             $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
             if (isset($row['Sub_part'])) {
                 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
             }
         }
         // end while
         if ($result) {
             PMA_DBI_free_result($result);
         }
         /**
          * Gets fields properties
          */
         $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
         $fields_cnt = PMA_DBI_num_rows($result);
         // Check if we can use Relations (Mike Beck)
         if (!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 (count($res_rel) > 0) {
                 $have_rel = true;
             } else {
                 $have_rel = false;
             }
         } else {
             $have_rel = false;
         }
         // end if
         /**
          * Displays the comments of the table if MySQL >= 3.23
          */
         $break = false;
         if (!empty($show_comment)) {
             $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
             $break = true;
         }
         if (!empty($create_time)) {
             $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
             $break = true;
         }
         if (!empty($update_time)) {
             $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
             $break = true;
         }
         if (!empty($check_time)) {
             $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
             $break = true;
         }
         if ($break == true) {
             $pdf->Cell(0, 3, '', 0, 1);
             $pdf->Ln();
         }
         $pdf->SetFont($this->_ff, 'B');
         if (isset($orientation) && $orientation == 'L') {
             $pdf->Cell(25, 8, ucfirst(__('Column')), 1, 0, 'C');
             $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
             $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
             $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
             $pdf->Cell(20, 8, ucfirst(__('Default')), 1, 0, 'C');
             $pdf->Cell(25, 8, ucfirst(__('Extra')), 1, 0, 'C');
             $pdf->Cell(45, 8, ucfirst(__('Links to')), 1, 0, 'C');
             if ($paper == 'A4') {
                 $comments_width = 67;
             } else {
                 // this is really intended for 'letter'
                 /**
                  * @todo find optimal width for all formats
                  */
                 $comments_width = 50;
             }
             $pdf->Cell($comments_width, 8, ucfirst(__('Comments')), 1, 0, 'C');
             $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
         } else {
             $pdf->Cell(20, 8, ucfirst(__('Column')), 1, 0, 'C');
             $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C');
             $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C');
             $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C');
             $pdf->Cell(15, 8, ucfirst(__('Default')), 1, 0, 'C');
             $pdf->Cell(15, 8, ucfirst(__('Extra')), 1, 0, 'C');
             $pdf->Cell(30, 8, ucfirst(__('Links to')), 1, 0, 'C');
             $pdf->Cell(30, 8, ucfirst(__('Comments')), 1, 0, 'C');
             $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
         }
         $pdf->SetFont($this->_ff, '');
         while ($row = PMA_DBI_fetch_assoc($result)) {
             $type = $row['Type'];
             // reformat mysql query output
             // set or enum types: slashes single quotes inside options
             if (preg_match('@^(set|enum)\\((.+)\\)$@i', $type, $tmp)) {
                 $tmp[2] = substr(preg_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 = preg_replace('@BINARY@i', '', $type);
                 $type = preg_replace('@ZEROFILL@i', '', $type);
                 $type = preg_replace('@UNSIGNED@i', '', $type);
                 if (empty($type)) {
                     $type = '&nbsp;';
                 }
                 $binary = stristr($row['Type'], 'BINARY');
                 $unsigned = stristr($row['Type'], 'UNSIGNED');
                 $zerofill = stristr($row['Type'], 'ZEROFILL');
             }
             $attribute = ' ';
             if ($binary) {
                 $attribute = 'BINARY';
             }
             if ($unsigned) {
                 $attribute = 'UNSIGNED';
             }
             if ($zerofill) {
                 $attribute = 'UNSIGNED ZEROFILL';
             }
             if (!isset($row['Default'])) {
                 if ($row['Null'] != '' && $row['Null'] != 'NO') {
                     $row['Default'] = 'NULL';
                 }
             }
             $field_name = $row['Field'];
             // $pdf->Ln();
             $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
             $pdf->Bookmark($field_name, 1, -1);
             $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
             $pdf_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], isset($res_rel[$field_name]) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : '', isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '');
             $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
             if (isset($res_rel[$field_name]['foreign_table']) and isset($res_rel[$field_name]['foreign_field']) and isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])) {
                 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
             } else {
                 unset($links[6]);
             }
             $pdf->Row($pdf_row, $links);
         }
         // end while
         $pdf->SetFont($this->_ff, '', 14);
         PMA_DBI_free_result($result);
     }
     //end each
 }
Esempio n. 8
0
/**
 * displays the message and the query
 * usually the message is the result of the query executed
 *
 * @param string  $message   the message to display
 * @param string  $sql_query the query to display
 * @param string  $type      the type (level) of the message
 * @param boolean $is_view   is this a message after a VIEW operation?
 *
 * @return  string
 *
 * @access  public
 */
function PMA_showMessage($message, $sql_query = null, $type = 'notice', $is_view = false)
{
    /*
     * PMA_ajaxResponse uses this function to collect the string of HTML generated
     * for showing the message.  Use output buffering to collect it and return it
     * in a string.  In some special cases on sql.php, buffering has to be disabled
     * and hence we check with $GLOBALS['buffer_message']
     */
    if ($GLOBALS['is_ajax_request'] == true && !isset($GLOBALS['buffer_message'])) {
        ob_start();
    }
    global $cfg;
    if (null === $sql_query) {
        if (!empty($GLOBALS['display_query'])) {
            $sql_query = $GLOBALS['display_query'];
        } elseif ($cfg['SQP']['fmtType'] == 'none' && !empty($GLOBALS['unparsed_sql'])) {
            $sql_query = $GLOBALS['unparsed_sql'];
        } elseif (!empty($GLOBALS['sql_query'])) {
            $sql_query = $GLOBALS['sql_query'];
        } else {
            $sql_query = '';
        }
    }
    if (isset($GLOBALS['using_bookmark_message'])) {
        $GLOBALS['using_bookmark_message']->display();
        unset($GLOBALS['using_bookmark_message']);
    }
    // Corrects the tooltip text via JS if required
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (!$is_view && strlen($GLOBALS['table']) && $cfg['ShowTooltip']) {
        $tooltip = PMA_Table::sGetToolTip($GLOBALS['db'], $GLOBALS['table']);
        $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
        echo "\n";
        echo '<script type="text/javascript">' . "\n";
        echo '//<![CDATA[' . "\n";
        echo "if (window.parent.updateTableTitle) window.parent.updateTableTitle('" . $uni_tbl . "', '" . PMA_jsFormat($tooltip, false) . "');" . "\n";
        echo '//]]>' . "\n";
        echo '</script>' . "\n";
    }
    // end if ... elseif
    // Checks if the table needs to be repaired after a TRUNCATE query.
    // @todo what about $GLOBALS['display_query']???
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (strlen($GLOBALS['table']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
        if (PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Index_length') > 1024 && !PMA_DRIZZLE) {
            PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
        }
    }
    unset($tbl_status);
    // In an Ajax request, $GLOBALS['cell_align_left'] may not be defined. Hence,
    // check for it's presence before using it
    echo '<div id="result_query" align="' . (isset($GLOBALS['cell_align_left']) ? $GLOBALS['cell_align_left'] : '') . '">' . "\n";
    if ($message instanceof PMA_Message) {
        if (isset($GLOBALS['special_message'])) {
            $message->addMessage($GLOBALS['special_message']);
            unset($GLOBALS['special_message']);
        }
        $message->display();
        $type = $message->getLevel();
    } else {
        echo '<div class="' . $type . '">';
        echo PMA_sanitize($message);
        if (isset($GLOBALS['special_message'])) {
            echo PMA_sanitize($GLOBALS['special_message']);
            unset($GLOBALS['special_message']);
        }
        echo '</div>';
    }
    if ($cfg['ShowSQL'] == true && !empty($sql_query)) {
        // Html format the query to be displayed
        // If we want to show some sql code it is easiest to create it here
        /* SQL-Parser-Analyzer */
        if (!empty($GLOBALS['show_as_php'])) {
            $new_line = '\\n"<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;. "';
            $query_base = htmlspecialchars(addslashes($sql_query));
            $query_base = preg_replace('/((\\015\\012)|(\\015)|(\\012))/', $new_line, $query_base);
        } else {
            $query_base = $sql_query;
        }
        $query_too_big = false;
        if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
            // when the query is large (for example an INSERT of binary
            // data), the parser chokes; so avoid parsing the query
            $query_too_big = true;
            $shortened_query_base = nl2br(htmlspecialchars(substr($sql_query, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]'));
        } elseif (!empty($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
            // (here, use "! empty" because when deleting a bookmark,
            // $GLOBALS['parsed_sql'] is set but empty
            $parsed_sql = $GLOBALS['parsed_sql'];
        } else {
            // Parse SQL if needed
            $parsed_sql = PMA_SQP_parse($query_base);
        }
        // Analyze it
        if (isset($parsed_sql) && !PMA_SQP_isError()) {
            $analyzed_display_query = PMA_SQP_analyze($parsed_sql);
            // Same as below (append LIMIT), append the remembered ORDER BY
            if ($GLOBALS['cfg']['RememberSorting'] && isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_order_to_append'])) {
                $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_order_to_append'] . $analyzed_display_query[0]['limit_clause'] . ' ' . $analyzed_display_query[0]['section_after_limit'];
                // Need to reparse query
                $parsed_sql = PMA_SQP_parse($query_base);
                // update the $analyzed_display_query
                $analyzed_display_query[0]['section_before_limit'] .= $GLOBALS['sql_order_to_append'];
                $analyzed_display_query[0]['order_by_clause'] = $GLOBALS['sorted_col'];
            }
            // Here we append the LIMIT added for navigation, to
            // enable its display. Adding it higher in the code
            // to $sql_query would create a problem when
            // using the Refresh or Edit links.
            // Only append it on SELECTs.
            /**
             * @todo what would be the best to do when someone hits Refresh:
             * use the current LIMITs ?
             */
            if (isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_limit_to_append'])) {
                $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];
                // Need to reparse query
                $parsed_sql = PMA_SQP_parse($query_base);
            }
        }
        if (!empty($GLOBALS['show_as_php'])) {
            $query_base = '$sql  = "' . $query_base;
        } elseif (!empty($GLOBALS['validatequery'])) {
            try {
                $query_base = PMA_validateSQL($query_base);
            } catch (Exception $e) {
                PMA_Message::error(__('Failed to connect to SQL validator!'))->display();
            }
        } elseif (isset($parsed_sql)) {
            $query_base = PMA_formatSql($parsed_sql, $query_base);
        }
        // Prepares links that may be displayed to edit/explain the query
        // (don't go to default pages, we must go to the page
        // where the query box is available)
        // Basic url query part
        $url_params = array();
        if (!isset($GLOBALS['db'])) {
            $GLOBALS['db'] = '';
        }
        if (strlen($GLOBALS['db'])) {
            $url_params['db'] = $GLOBALS['db'];
            if (strlen($GLOBALS['table'])) {
                $url_params['table'] = $GLOBALS['table'];
                $edit_link = 'tbl_sql.php';
            } else {
                $edit_link = 'db_sql.php';
            }
        } else {
            $edit_link = 'server_sql.php';
        }
        // Want to have the query explained
        // but only explain a SELECT (that has not been explained)
        /* SQL-Parser-Analyzer */
        $explain_link = '';
        $is_select = false;
        if (!empty($cfg['SQLQuery']['Explain']) && !$query_too_big) {
            $explain_params = $url_params;
            // Detect if we are validating as well
            // To preserve the validate uRL data
            if (!empty($GLOBALS['validatequery'])) {
                $explain_params['validatequery'] = 1;
            }
            if (preg_match('@^SELECT[[:space:]]+@i', $sql_query)) {
                $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query;
                $_message = __('Explain SQL');
                $is_select = true;
            } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) {
                $explain_params['sql_query'] = substr($sql_query, 8);
                $_message = __('Skip Explain SQL');
            }
            if (isset($explain_params['sql_query'])) {
                $explain_link = 'import.php' . PMA_generate_common_url($explain_params);
                $explain_link = ' [' . PMA_linkOrButton($explain_link, $_message) . ']';
            }
        }
        //show explain
        $url_params['sql_query'] = $sql_query;
        $url_params['show_query'] = 1;
        // even if the query is big and was truncated, offer the chance
        // to edit it (unless it's enormous, see PMA_linkOrButton() )
        if (!empty($cfg['SQLQuery']['Edit'])) {
            if ($cfg['EditInWindow'] == true) {
                $onclick = 'window.parent.focus_querywindow(\'' . PMA_jsFormat($sql_query, false) . '\'); return false;';
            } else {
                $onclick = '';
            }
            $edit_link .= PMA_generate_common_url($url_params) . '#querybox';
            $edit_link = ' [' . PMA_linkOrButton($edit_link, __('Edit'), array('onclick' => $onclick)) . ']';
        } else {
            $edit_link = '';
        }
        $url_qpart = PMA_generate_common_url($url_params);
        // Also we would like to get the SQL formed in some nice
        // php-code
        if (!empty($cfg['SQLQuery']['ShowAsPHP']) && !$query_too_big) {
            $php_params = $url_params;
            if (!empty($GLOBALS['show_as_php'])) {
                $_message = __('Without PHP Code');
            } else {
                $php_params['show_as_php'] = 1;
                $_message = __('Create PHP Code');
            }
            $php_link = 'import.php' . PMA_generate_common_url($php_params);
            $php_link = ' [' . PMA_linkOrButton($php_link, $_message) . ']';
            if (isset($GLOBALS['show_as_php'])) {
                $runquery_link = 'import.php' . PMA_generate_common_url($url_params);
                $php_link .= ' [' . PMA_linkOrButton($runquery_link, __('Submit Query')) . ']';
            }
        } else {
            $php_link = '';
        }
        //show as php
        // Refresh query
        if (!empty($cfg['SQLQuery']['Refresh']) && !isset($GLOBALS['show_as_php']) && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) {
            $refresh_link = 'import.php' . PMA_generate_common_url($url_params);
            $refresh_link = ' [' . PMA_linkOrButton($refresh_link, __('Refresh')) . ']';
        } else {
            $refresh_link = '';
        }
        //refresh
        if (!empty($cfg['SQLValidator']['use']) && !empty($cfg['SQLQuery']['Validate'])) {
            $validate_params = $url_params;
            if (!empty($GLOBALS['validatequery'])) {
                $validate_message = __('Skip Validate SQL');
            } else {
                $validate_params['validatequery'] = 1;
                $validate_message = __('Validate SQL');
            }
            $validate_link = 'import.php' . PMA_generate_common_url($validate_params);
            $validate_link = ' [' . PMA_linkOrButton($validate_link, $validate_message) . ']';
        } else {
            $validate_link = '';
        }
        //validator
        if (!empty($GLOBALS['validatequery'])) {
            echo '<div class="sqlvalidate">';
        } else {
            echo '<code class="sql">';
        }
        if ($query_too_big) {
            echo $shortened_query_base;
        } else {
            echo $query_base;
        }
        //Clean up the end of the PHP
        if (!empty($GLOBALS['show_as_php'])) {
            echo '";';
        }
        if (!empty($GLOBALS['validatequery'])) {
            echo '</div>';
        } else {
            echo '</code>';
        }
        echo '<div class="tools">';
        // avoid displaying a Profiling checkbox that could
        // be checked, which would reexecute an INSERT, for example
        if (!empty($refresh_link)) {
            PMA_profilingCheckbox($sql_query);
        }
        // if needed, generate an invisible form that contains controls for the
        // Inline link; this way, the behavior of the Inline link does not
        // depend on the profiling support or on the refresh link
        if (empty($refresh_link) || !PMA_profilingSupported()) {
            echo '<form action="sql.php" method="post">';
            echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']);
            echo '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />';
            echo '</form>';
        }
        // in the tools div, only display the Inline link when not in ajax
        // mode because 1) it currently does not work and 2) we would
        // have two similar mechanisms on the page for the same goal
        if ($is_select || $GLOBALS['is_ajax_request'] === false && !$query_too_big) {
            // see in js/functions.js the jQuery code attached to id inline_edit
            // document.write conflicts with jQuery, hence used $().append()
            echo "<script type=\"text/javascript\">\n" . "//<![CDATA[\n" . "\$('.tools form').last().after('[<a href=\"#\" title=\"" . PMA_escapeJsString(__('Inline edit of this query')) . "\" class=\"inline_edit_sql\">" . PMA_escapeJsString(_pgettext('Inline edit query', 'Inline')) . "</a>]');\n" . "//]]>\n" . "</script>";
        }
        echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
        echo '</div>';
    }
    echo '</div>';
    if ($GLOBALS['is_ajax_request'] === false) {
        echo '<br class="clearfloat" />';
    }
    // If we are in an Ajax request, we have most probably been called in
    // PMA_ajaxResponse().  Hence, collect the buffer contents and return it
    // to PMA_ajaxResponse(), which will encode it for JSON.
    if ($GLOBALS['is_ajax_request'] == true && !isset($GLOBALS['buffer_message'])) {
        $buffer_contents = ob_get_contents();
        ob_end_clean();
        return $buffer_contents;
    }
    return null;
}
Esempio n. 9
0
            /**
             * if $submit_mult == 'change', execution will have stopped
             * at this point
             */
            if (empty($message)) {
                $message = PMA_Message::success();
            }
        }
    } else {
        $response = PMA_Response::getInstance();
        $response->isSuccess(false);
        $response->addJSON('message', __('No column selected.'));
    }
}
// display secondary level tabs if necessary
$engine = PMA_Table::sGetStatusInfo($db, $table, 'ENGINE');
$response->addHTML(PMA_getStructureSecondaryTabs($engine));
$response->addHTML('<div id="structure_content">');
/**
 * Modifications have been submitted -> updates the table
 */
if (isset($_REQUEST['do_save_data'])) {
    $regenerate = PMA_updateColumns($db, $table);
    if ($regenerate) {
        // This happens when updating failed
        // @todo: do something appropriate
    } else {
        // continue to show the table's structure
        unset($_REQUEST['selected']);
    }
}
Esempio n. 10
0
 /**
  * Returns the table tabs as an array
  *
  * @return array Data for generating table tabs
  */
 private function _getTableTabs()
 {
     $db_is_information_schema = PMA_is_system_schema($this->_db);
     $tbl_is_view = PMA_Table::isView($this->_db, $this->_table);
     $table_status = PMA_Table::sGetStatusInfo($this->_db, $this->_table);
     $table_info_num_rows = 0;
     if (isset($table_status['Rows'])) {
         $table_info_num_rows = $table_status['Rows'];
     }
     $tabs = array();
     $tabs['browse']['icon'] = 'b_browse.png';
     $tabs['browse']['text'] = __('Browse');
     $tabs['browse']['link'] = 'sql.php';
     $tabs['browse']['args']['pos'] = 0;
     $tabs['structure']['icon'] = 'b_props.png';
     $tabs['structure']['link'] = 'tbl_structure.php';
     $tabs['structure']['text'] = __('Structure');
     $tabs['sql']['icon'] = 'b_sql.png';
     $tabs['sql']['link'] = 'tbl_sql.php';
     $tabs['sql']['text'] = __('SQL');
     $tabs['search']['icon'] = 'b_search.png';
     $tabs['search']['text'] = __('Search');
     $tabs['search']['link'] = 'tbl_select.php';
     if (!$db_is_information_schema) {
         $tabs['insert']['icon'] = 'b_insrow.png';
         $tabs['insert']['link'] = 'tbl_change.php';
         $tabs['insert']['text'] = __('Insert');
     }
     $tabs['export']['icon'] = 'b_tblexport.png';
     $tabs['export']['link'] = 'tbl_export.php';
     $tabs['export']['args']['single_table'] = 'true';
     $tabs['export']['text'] = __('Export');
     /**
      * Don't display "Import" and "Operations"
      * for views and information_schema
      */
     if (!$tbl_is_view && !$db_is_information_schema) {
         $tabs['import']['icon'] = 'b_tblimport.png';
         $tabs['import']['link'] = 'tbl_import.php';
         $tabs['import']['text'] = __('Import');
         $tabs['operation']['icon'] = 'b_tblops.png';
         $tabs['operation']['link'] = 'tbl_operations.php';
         $tabs['operation']['text'] = __('Operations');
     }
     if (PMA_Tracker::isActive()) {
         $tabs['tracking']['icon'] = 'eye.png';
         $tabs['tracking']['text'] = __('Tracking');
         $tabs['tracking']['link'] = 'tbl_tracking.php';
     }
     if (!$db_is_information_schema && !PMA_DRIZZLE && PMA_currentUserHasPrivilege('TRIGGER', $this->_db, $this->_table) && !$tbl_is_view) {
         $tabs['triggers']['link'] = 'tbl_triggers.php';
         $tabs['triggers']['text'] = __('Triggers');
         $tabs['triggers']['icon'] = 'b_triggers.png';
     }
     /**
      * Views support a limited number of operations
      */
     if ($tbl_is_view && !$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!');
     }
     return $tabs;
 }
<div id="div_container_sub_exportoptions">
<?php 
echo PMA_pluginGetOptions('Export', $export_list);
?>
</div>
</td></tr></table>

<script type="text/javascript">
//<![CDATA[
    init_options();
//]]>
</script>

<?php 
$is_merge = !PMA_Table::isView($db, $table) && strcasecmp(PMA_Table::sGetStatusInfo($db, $table, 'Engine'), 'MRG_MYISAM') == 0;
if (strlen($table) && !isset($num_tables) && !$is_merge) {
    ?>
    <div class="formelementrow">
        <?php 
    echo '<input type="radio" name="allrows" value="0" id="radio_allrows_0" checked="checked" />';
    echo sprintf($strDumpXRows, '<input type="text" name="limit_to" size="5" value="' . (isset($unlim_num_rows) ? $unlim_num_rows : PMA_Table::countRecords($db, $table)) . '" onfocus="this.select()" />', '<input type="text" name="limit_from" value="0" size="5"' . ' onfocus="this.select()" /> ');
    echo '<input type="radio" name="allrows" value="1" id="radio_allrows_1" />';
    echo '<label for="radio_allrows_1">' . $strDumpAllRows . '</label>';
    ?>
    </div>
<?php 
}
?>
</fieldset>
Esempio n. 12
0
 /**
  * Checks if this is a merge table
  *
  * If the ENGINE of the table is MERGE or MRG_MYISAM (alias), this is a merge table.
  *
  * @param   string   the database name
  * @param   string   the table name
  * @return  boolean  true if it is a merge table
  * @access  public
  */
 public static function isMerge($db = null, $table = null)
 {
     // if called static, with parameters
     if (!empty($db) && !empty($table)) {
         $engine = PMA_Table::sGetStatusInfo($db, $table, 'ENGINE', null, true);
     } else {
         if (!empty($this)) {
             $engine = $this->get('ENGINE');
         }
     }
     return !empty($engine) && (strtoupper($engine) == 'MERGE' || strtoupper($engine) == 'MRG_MYISAM');
 }
Esempio n. 13
0
/**
 * Displays the headers of the results table
 *
 * @param array   &$is_display                 which elements to display
 * @param array   &$fields_meta                the list of fields properties
 * @param integer $fields_cnt                  the total number of fields returned by the SQL query
 * @param array   $analyzed_sql                the analyzed query
 * @param string  $sort_expression             sort expression
 * @param string  $sort_expression_nodirection sort expression without direction
 * @param string  $sort_direction              sort direction
 *
 * @return  boolean  $clause_is_unique
 *
 * @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 SQL query
 * @global  integer  $num_rows         the total number of rows returned by the
 *                                     SQL query
 * @global  array    $vertical_display informations used with vertical display
 *                                     mode
 *
 * @access  private
 *
 * @see     PMA_displayTable()
 */
function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
{
    global $db, $table, $goto;
    global $sql_query, $num_rows;
    global $vertical_display, $highlight_columns;
    // required to generate sort links that will remember whether the
    // "Show all" button has been clicked
    $sql_md5 = md5($GLOBALS['sql_query']);
    $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
    if ($analyzed_sql == '') {
        $analyzed_sql = array();
    }
    // can the result be sorted?
    if ($is_display['sort_lnk'] == '1') {
        // Just as fallback
        $unsorted_sql_query = $sql_query;
        if (isset($analyzed_sql[0]['unsorted_query'])) {
            $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
        }
        // Handles the case of multiple clicks on a column's header
        // which would add many spaces before "ORDER BY" in the
        // generated query.
        $unsorted_sql_query = trim($unsorted_sql_query);
        // sorting by indexes, only if it makes sense (only one table ref)
        if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' && isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
            // grab indexes data:
            $indexes = PMA_Index::getFromTable($table, $db);
            // do we have any index?
            if ($indexes) {
                if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
                    $span = $fields_cnt;
                    if ($is_display['edit_lnk'] != 'nn') {
                        $span++;
                    }
                    if ($is_display['del_lnk'] != 'nn') {
                        $span++;
                    }
                    if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
                        $span++;
                    }
                } else {
                    $span = $num_rows + floor($num_rows / $_SESSION['tmp_user_values']['repeat_cells']) + 1;
                }
                echo '<form action="sql.php" method="post">' . "\n";
                echo PMA_generate_common_hidden_inputs($db, $table);
                echo __('Sort by key') . ': <select name="sql_query" class="autosubmit">' . "\n";
                $used_index = false;
                $local_order = isset($sort_expression) ? $sort_expression : '';
                foreach ($indexes as $index) {
                    $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
                    $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
                    $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
                    if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $my_reg)) {
                        $unsorted_sql_query_first_part = $my_reg[1];
                        $unsorted_sql_query_second_part = $my_reg[2];
                    } else {
                        $unsorted_sql_query_first_part = $unsorted_sql_query;
                        $unsorted_sql_query_second_part = '';
                    }
                    echo '<option value="' . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $asc_sort . $unsorted_sql_query_second_part) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($index->getName()) . ' (' . __('Ascending') . ')</option>';
                    echo '<option value="' . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $desc_sort . $unsorted_sql_query_second_part) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($index->getName()) . ' (' . __('Descending') . ')</option>';
                }
                echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
                echo '</select>' . "\n";
                echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
                echo '</form>' . "\n";
            }
        }
    }
    // Output data needed for grid editing
    echo '<input id="save_cells_at_once" type="hidden" value="' . $GLOBALS['cfg']['SaveCellsAtOnce'] . '" />';
    echo '<div class="common_hidden_inputs">';
    echo PMA_generate_common_hidden_inputs($db, $table);
    echo '</div>';
    // Output data needed for column reordering and show/hide column
    if (PMA_isSelect()) {
        // generate the column order, if it is set
        $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
        $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
        if ($col_order) {
            echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
        }
        $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
        if ($col_visib) {
            echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
        }
        // generate table create time
        if (!PMA_Table::isView($GLOBALS['table'], $GLOBALS['db'])) {
            echo '<input id="table_create_time" type="hidden" value="' . PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
        }
    }
    $vertical_display['emptypre'] = 0;
    $vertical_display['emptyafter'] = 0;
    $vertical_display['textbtn'] = '';
    // Display options (if we are not in print view)
    if (!(isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
        echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
        if ($GLOBALS['cfg']['AjaxEnable']) {
            echo ' class="ajax" ';
        }
        echo '>';
        $url_params = array('db' => $db, 'table' => $table, 'sql_query' => $sql_query, 'goto' => $goto, 'display_options_form' => 1);
        echo PMA_generate_common_hidden_inputs($url_params);
        echo '<br />';
        PMA_generate_slider_effect('displayoptions', __('Options'));
        echo '<fieldset>';
        echo '<div class="formelement">';
        $choices = array('P' => __('Partial texts'), 'F' => __('Full texts'));
        PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
        echo '</div>';
        // prepare full/partial text button or link
        $url_params_full_text = array('db' => $db, 'table' => $table, 'sql_query' => $sql_query, 'goto' => $goto, 'full_text_button' => 1);
        if ($_SESSION['tmp_user_values']['display_text'] == 'F') {
            // currently in fulltext mode so show the opposite link
            $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
            $tmp_txt = __('Partial texts');
            $url_params_full_text['display_text'] = 'P';
        } else {
            $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
            $tmp_txt = __('Full texts');
            $url_params_full_text['display_text'] = 'F';
        }
        $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
        $tmp_url = 'sql.php' . PMA_generate_common_url($url_params_full_text);
        $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
        unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
        if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
            echo '<div class="formelement">';
            $choices = array('K' => __('Relational key'), 'D' => __('Relational display column'));
            PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
            echo '</div>';
        }
        echo '<div class="formelement">';
        PMA_display_html_checkbox('display_binary', __('Show binary contents'), !empty($_SESSION['tmp_user_values']['display_binary']), false);
        echo '<br />';
        PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), !empty($_SESSION['tmp_user_values']['display_blob']), false);
        echo '<br />';
        PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), !empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
        echo '</div>';
        // I would have preferred to name this "display_transformation".
        // This is the only way I found to be able to keep this setting sticky
        // per SQL query, and at the same time have a default that displays
        // the transformations.
        echo '<div class="formelement">';
        PMA_display_html_checkbox('hide_transformation', __('Hide browser transformation'), !empty($_SESSION['tmp_user_values']['hide_transformation']), false);
        echo '</div>';
        if (!PMA_DRIZZLE) {
            echo '<div class="formelement">';
            $choices = array('GEOM' => __('Geometry'), 'WKT' => __('Well Known Text'), 'WKB' => __('Well Known Binary'));
            PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
            echo '</div>';
        }
        echo '<div class="clearfloat"></div>';
        echo '</fieldset>';
        echo '<fieldset class="tblFooters">';
        echo '<input type="submit" value="' . __('Go') . '" />';
        echo '</fieldset>';
        echo '</div>';
        echo '</form>';
    }
    // Start of form for multi-rows edit/delete/export
    if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
        echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
        if ($GLOBALS['cfg']['AjaxEnable']) {
            echo ' class="ajax" ';
        }
        echo '>' . "\n";
        echo PMA_generate_common_hidden_inputs($db, $table, 1);
        echo '<input type="hidden" name="goto"             value="sql.php" />' . "\n";
    }
    echo '<table id="table_results" class="data';
    if ($GLOBALS['cfg']['AjaxEnable']) {
        echo ' ajax';
    }
    echo '">' . "\n";
    if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
        echo '<thead><tr>' . "\n";
    }
    // 1. Displays the full/partial text button (part 1)...
    if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
        $colspan = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' colspan="4"' : '';
    } else {
        $rowspan = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' rowspan="4"' : '';
    }
    //     ... before the result table
    if ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn' && $is_display['text_btn'] == '1') {
        $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 4 : 0;
        if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
            ?>
    <th colspan="<?php 
            echo $fields_cnt;
            ?>
"></th>
</tr>
<tr>
            <?php 
            // end horizontal/horizontalflipped mode
        } else {
            ?>
<tr>
    <th colspan="<?php 
            echo $num_rows + floor($num_rows / $_SESSION['tmp_user_values']['repeat_cells']) + 1;
            ?>
"></th>
</tr>
            <?php 
        }
        // end vertical mode
    } elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && $is_display['text_btn'] == '1') {
        $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 4 : 0;
        if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
            ?>
                <th <?php 
            echo $colspan;
            ?>
><?php 
            echo $full_or_partial_text_link;
            ?>
</th>
            <?php 
            // end horizontal/horizontalflipped mode
        } else {
            $vertical_display['textbtn'] = '    <th ' . $rowspan . ' valign="middle">' . "\n" . '        ' . "\n" . '    </th>' . "\n";
        }
        // end vertical mode
    } elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
        $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 4 : 0;
        if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
            ?>
    <td<?php 
            echo $colspan;
            ?>
></td>
            <?php 
            // end horizontal/horizontalfipped mode
        } else {
            $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
        }
        // end vertical mode
    } elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none' && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
        echo '<th></th>';
    }
    // 2. Displays the fields' name
    // 2.0 If sorting links should be used, checks if the query is a "JOIN"
    //     statement (see 2.1.3)
    // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
    //       Do not show comments, if using horizontalflipped mode, because of space usage
    if ($GLOBALS['cfg']['ShowBrowseComments'] && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
        $comments_map = array();
        if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
            foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
                $tb = $tbl['table_true_name'];
                $comments_map[$tb] = PMA_getComments($db, $tb);
                unset($tb);
            }
        }
    }
    if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && !$_SESSION['tmp_user_values']['hide_transformation']) {
        include_once './libraries/transformations.lib.php';
        $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
    }
    // See if we have to highlight any header fields of a WHERE query.
    // Uses SQL-Parser results.
    $highlight_columns = array();
    if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['where_clause_identifiers'])) {
        $wi = 0;
        if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
            foreach ($analyzed_sql[0]['where_clause_identifiers'] as $wci_nr => $wci) {
                $highlight_columns[$wci] = 'true';
            }
        }
    }
    if (PMA_isSelect()) {
        // prepare to get the column order, if available
        $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
        $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
        $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
    } else {
        $col_order = false;
        $col_visib = false;
    }
    for ($j = 0; $j < $fields_cnt; $j++) {
        // assign $i with appropriate column order
        $i = $col_order ? $col_order[$j] : $j;
        //  See if this column should get highlight because it's used in the
        //  where-query.
        if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
            $condition_field = true;
        } else {
            $condition_field = false;
        }
        // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
        if (isset($comments_map) && isset($comments_map[$fields_meta[$i]->table]) && isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
            $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
        } else {
            $comments = '';
        }
        // 2.1 Results can be sorted
        if ($is_display['sort_lnk'] == '1') {
            // 2.1.1 Checks if the table name is required; it's the case
            //       for a query with a "JOIN" statement and if the column
            //       isn't aliased, or in queries like
            //       SELECT `1`.`master_field` , `2`.`master_field`
            //       FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
            if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
                $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
            } else {
                $sort_tbl = '';
            }
            // 2.1.2 Checks if the current column is used to sort the
            //       results
            // the orgname member does not exist for all MySQL versions
            // but if found, it's the one on which to sort
            $name_to_use_in_sort = $fields_meta[$i]->name;
            $is_orgname = false;
            if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
                $name_to_use_in_sort = $fields_meta[$i]->orgname;
                $is_orgname = true;
            }
            // $name_to_use_in_sort might contain a space due to
            // formatting of function expressions like "COUNT(name )"
            // so we remove the space in this situation
            $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
            if (empty($sort_expression)) {
                $is_in_sort = false;
            } else {
                // Field name may be preceded by a space, or any number
                // of characters followed by a dot (tablename.fieldname)
                // so do a direct comparison for the sort expression;
                // this avoids problems with queries like
                // "SELECT id, count(id)..." and clicking to sort
                // on id or on count(id).
                // Another query to test this:
                // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
                // (and try clicking on each column's header twice)
                if (!empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
                    $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
                }
                $is_in_sort = str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false;
            }
            // 2.1.3 Check the field name for a bracket.
            //       If it contains one, it's probably a function column
            //       like 'COUNT(`field`)'
            //       It still might be a column name of a view. See bug #3383711
            //       Check is_orgname.
            if (strpos($name_to_use_in_sort, '(') !== false && !$is_orgname) {
                $sort_order = "\n" . 'ORDER BY ' . $name_to_use_in_sort . ' ';
            } else {
                $sort_order = "\n" . 'ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
            }
            unset($name_to_use_in_sort);
            unset($is_orgname);
            // 2.1.4 Do define the sorting URL
            if (!$is_in_sort) {
                // patch #455484 ("Smart" order)
                $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
                if ($GLOBALS['cfg']['Order'] === 'SMART') {
                    $sort_order .= preg_match('@time|date@i', $fields_meta[$i]->type) ? 'DESC' : 'ASC';
                } else {
                    $sort_order .= $GLOBALS['cfg']['Order'];
                }
                $order_img = '';
            } elseif ('DESC' == $sort_direction) {
                $sort_order .= ' ASC';
                $order_img = ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg{$i}", 'title' => ''));
                $order_img .= ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg{$i} hide", 'title' => ''));
            } else {
                $sort_order .= ' DESC';
                $order_img = ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg{$i}", 'title' => ''));
                $order_img .= ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg{$i} hide", 'title' => ''));
            }
            if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
                $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
            } else {
                $sorted_sql_query = $unsorted_sql_query . $sort_order;
            }
            $_url_params = array('db' => $db, 'table' => $table, 'sql_query' => $sorted_sql_query, 'session_max_rows' => $session_max_rows);
            $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
            // 2.1.5 Displays the sorting URL
            // enable sort order swapping for image
            $order_link_params = array();
            if (isset($order_img) && $order_img != '') {
                if (strstr($order_img, 'asc')) {
                    $order_link_params['onmouseover'] = "\$('.soimg{$i}').toggle()";
                    $order_link_params['onmouseout'] = "\$('.soimg{$i}').toggle()";
                } elseif (strstr($order_img, 'desc')) {
                    $order_link_params['onmouseover'] = "\$('.soimg{$i}').toggle()";
                    $order_link_params['onmouseout'] = "\$('.soimg{$i}').toggle()";
                }
            }
            if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
                if (PMA_USR_BROWSER_AGENT == 'IE') {
                    $GLOBALS['cfg']['HeaderFlipType'] = 'css';
                } else {
                    $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
                }
            }
            if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
                $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
            }
            $order_link_params['title'] = __('Sort');
            $order_link_content = $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name);
            $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
            if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
                echo '<th';
                $th_class = array();
                $th_class[] = 'draggable';
                if ($col_visib && !$col_visib[$j]) {
                    $th_class[] = 'hide';
                }
                if ($condition_field) {
                    $th_class[] = 'condition';
                }
                $th_class[] = 'column_heading';
                if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
                    $th_class[] = 'pointer';
                }
                if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
                    $th_class[] = 'marker';
                }
                echo ' class="' . implode(' ', $th_class) . '"';
                if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
                    echo ' valign="bottom"';
                }
                echo '>' . $order_link . $comments . '</th>';
            }
            $vertical_display['desc'][] = '    <th ' . 'class="draggable' . ($condition_field ? ' condition' : '') . '">' . "\n" . $order_link . $comments . '    </th>' . "\n";
        } else {
            if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
                echo '<th';
                $th_class = array();
                $th_class[] = 'draggable';
                if ($col_visib && !$col_visib[$j]) {
                    $th_class[] = 'hide';
                }
                if ($condition_field) {
                    $th_class[] = 'condition';
                }
                echo ' class="' . implode(' ', $th_class) . '"';
                if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
                    echo ' valign="bottom"';
                }
                if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
                    echo ' style="direction: ltr; writing-mode: tb-rl;"';
                }
                echo '>';
                if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
                    echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
                } else {
                    echo htmlspecialchars($fields_meta[$i]->name);
                }
                echo "\n" . $comments . '</th>';
            }
            $vertical_display['desc'][] = '    <th ' . 'class="draggable' . ($condition_field ? ' condition"' : '') . '">' . "\n" . '        ' . htmlspecialchars($fields_meta[$i]->name) . "\n" . $comments . '    </th>';
        }
        // end else (2.2)
    }
    // end for
    // 3. Displays the needed checkboxes at the right
    //    column of the result table header if possible and required...
    if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') && $is_display['text_btn'] == '1') {
        $vertical_display['emptyafter'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 4 : 1;
        if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
            echo "\n";
            ?>
        <th <?php 
            echo $colspan;
            ?>
><?php 
            echo $full_or_partial_text_link;
            ?>
</th>
            <?php 
            // end horizontal/horizontalflipped mode
        } else {
            $vertical_display['textbtn'] = '    <th ' . $rowspan . ' valign="middle">' . "\n" . '        ' . "\n" . '    </th>' . "\n";
        }
        // end vertical mode
    } elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both') && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn') && !$GLOBALS['is_header_sent']) {
        $vertical_display['emptyafter'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 4 : 1;
        if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
            echo "\n";
            ?>
<td<?php 
            echo $colspan;
            ?>
></td>
            <?php 
            // end horizontal/horizontalflipped mode
        } else {
            $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
        }
        // end vertical mode
    }
    if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
        ?>
</tr>
</thead>
        <?php 
    }
    return true;
}
Esempio n. 14
0
 public function dataDictionaryDoc($alltables)
 {
     global $db, $pdf, $orientation, $paper;
     // TOC
     $pdf->addpage($_POST['orientation']);
     $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
     $pdf->Ln(15);
     $i = 1;
     foreach ($alltables as $table) {
         $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
         $pdf->SetX(10);
         // $pdf->Ln(1);
         $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
         $pdf->SetX(10);
         $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
         // $pdf->Ln(1);
         $fields = PMA_DBI_get_columns($GLOBALS['db'], $table);
         foreach ($fields as $row) {
             $pdf->SetX(20);
             $field_name = $row['Field'];
             $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
             //$pdf->Cell(
             //    0, 6, $field_name, 0, 1,
             //    'L', 0, $pdf->PMA_links['doc'][$table][$field_name]
             //);
         }
         $i++;
     }
     $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
     $pdf->SetX(10);
     $pdf->Cell(0, 6, __('Page number:') . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['RT']['-']);
     $pdf->SetX(10);
     $pdf->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
     $z = 0;
     foreach ($alltables as $table) {
         $z++;
         $pdf->SetAutoPageBreak(true, 15);
         $pdf->addpage($_POST['orientation']);
         $pdf->Bookmark($table);
         $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo());
         $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
         $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
         $pdf->SetFont($this->_ff, 'B', 18);
         $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
         $pdf->SetFont($this->_ff, '', 8);
         $pdf->ln();
         $cfgRelation = PMA_getRelationsParam();
         $comments = PMA_getComments($db, $table);
         if ($cfgRelation['mimework']) {
             $mime_map = PMA_getMIME($db, $table, true);
         }
         /**
          * Gets table informations
          */
         $showtable = PMA_Table::sGetStatusInfo($db, $table);
         $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
         $create_time = isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '';
         $update_time = isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '';
         $check_time = isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '';
         /**
          * Gets table keys and retains them
          */
         $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
         $primary = '';
         $indexes = array();
         $lastIndex = '';
         $indexes_info = array();
         $indexes_data = array();
         $pk_array = array();
         // will be use to emphasis prim. keys in the table
         // view
         while ($row = PMA_DBI_fetch_assoc($result)) {
             // Backups the list of primary keys
             if ($row['Key_name'] == 'PRIMARY') {
                 $primary .= $row['Column_name'] . ', ';
                 $pk_array[$row['Column_name']] = 1;
             }
             // Retains keys informations
             if ($row['Key_name'] != $lastIndex) {
                 $indexes[] = $row['Key_name'];
                 $lastIndex = $row['Key_name'];
             }
             $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
             $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
             if (isset($row['Cardinality'])) {
                 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
             }
             // I don't know what does following column mean....
             // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
             $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
             if (isset($row['Sub_part'])) {
                 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
             }
         }
         // end while
         if ($result) {
             PMA_DBI_free_result($result);
         }
         /**
          * Gets fields properties
          */
         $columns = PMA_DBI_get_columns($db, $table);
         // Check if we can use Relations
         if (!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 (count($res_rel) > 0) {
                 $have_rel = true;
             } else {
                 $have_rel = false;
             }
         } else {
             $have_rel = false;
         }
         // end if
         /**
          * Displays the comments of the table if MySQL >= 3.23
          */
         $break = false;
         if (!empty($show_comment)) {
             $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
             $break = true;
         }
         if (!empty($create_time)) {
             $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
             $break = true;
         }
         if (!empty($update_time)) {
             $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
             $break = true;
         }
         if (!empty($check_time)) {
             $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
             $break = true;
         }
         if ($break == true) {
             $pdf->Cell(0, 3, '', 0, 1);
             $pdf->Ln();
         }
         $pdf->SetFont($this->_ff, 'B');
         if (isset($orientation) && $orientation == 'L') {
             $pdf->Cell(25, 8, __('Column'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Default'), 1, 0, 'C');
             $pdf->Cell(25, 8, __('Extra'), 1, 0, 'C');
             $pdf->Cell(45, 8, __('Links to'), 1, 0, 'C');
             if ($paper == 'A4') {
                 $comments_width = 67;
             } else {
                 // this is really intended for 'letter'
                 /**
                  * @todo find optimal width for all formats
                  */
                 $comments_width = 50;
             }
             $pdf->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
             $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
         } else {
             $pdf->Cell(20, 8, __('Column'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
             $pdf->Cell(15, 8, __('Default'), 1, 0, 'C');
             $pdf->Cell(15, 8, __('Extra'), 1, 0, 'C');
             $pdf->Cell(30, 8, __('Links to'), 1, 0, 'C');
             $pdf->Cell(30, 8, __('Comments'), 1, 0, 'C');
             $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
         }
         $pdf->SetFont($this->_ff, '');
         foreach ($columns as $row) {
             $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
             $type = $extracted_fieldspec['print_type'];
             $attribute = $extracted_fieldspec['attribute'];
             if (!isset($row['Default'])) {
                 if ($row['Null'] != '' && $row['Null'] != 'NO') {
                     $row['Default'] = 'NULL';
                 }
             }
             $field_name = $row['Field'];
             // $pdf->Ln();
             $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
             $pdf->Bookmark($field_name, 1, -1);
             $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
             $pdf_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], isset($res_rel[$field_name]) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : '', isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '');
             $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
             if (isset($res_rel[$field_name]['foreign_table']) and isset($res_rel[$field_name]['foreign_field']) and isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])) {
                 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
             } else {
                 unset($links[6]);
             }
             $pdf->Row($pdf_row, $links);
         }
         // end foreach
         $pdf->SetFont($this->_ff, '', 14);
     }
     //end each
 }
Esempio n. 15
0
/**
 * displays the message and the query
 * usually the message is the result of the query executed
 *
 * @param   string  $message    the message to display
 * @param   string  $sql_query  the query to display
 * @param   string  $type       the type (level) of the message
 * @global  array   the configuration array
 * @uses    $cfg
 * @access  public
 */
function PMA_showMessage($message, $sql_query = null, $type = 'notice')
{
    global $cfg;
    if (null === $sql_query) {
        if (!empty($GLOBALS['display_query'])) {
            $sql_query = $GLOBALS['display_query'];
        } elseif ($cfg['SQP']['fmtType'] == 'none' && !empty($GLOBALS['unparsed_sql'])) {
            $sql_query = $GLOBALS['unparsed_sql'];
        } elseif (!empty($GLOBALS['sql_query'])) {
            $sql_query = $GLOBALS['sql_query'];
        } else {
            $sql_query = '';
        }
    }
    // Corrects the tooltip text via JS if required
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (strlen($GLOBALS['table']) && $cfg['ShowTooltip']) {
        $tooltip = PMA_Table::sGetToolTip($GLOBALS['db'], $GLOBALS['table']);
        $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false);
        echo "\n";
        echo '<script type="text/javascript">' . "\n";
        echo '//<![CDATA[' . "\n";
        echo "if (window.parent.updateTableTitle) window.parent.updateTableTitle('" . $uni_tbl . "', '" . PMA_jsFormat($tooltip, false) . "');" . "\n";
        echo '//]]>' . "\n";
        echo '</script>' . "\n";
    }
    // end if ... elseif
    // Checks if the table needs to be repaired after a TRUNCATE query.
    // @todo what about $GLOBALS['display_query']???
    // @todo this is REALLY the wrong place to do this - very unexpected here
    if (strlen($GLOBALS['table']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) {
        if (PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Index_length') > 1024) {
            PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table']));
        }
    }
    unset($tbl_status);
    echo '<div align="' . $GLOBALS['cell_align_left'] . '">' . "\n";
    if ($message instanceof PMA_Message) {
        if (isset($GLOBALS['special_message'])) {
            $message->addMessage($GLOBALS['special_message']);
            unset($GLOBALS['special_message']);
        }
        $message->display();
        $type = $message->getLevel();
    } else {
        echo '<div class="' . $type . '">';
        echo PMA_sanitize($message);
        if (isset($GLOBALS['special_message'])) {
            echo PMA_sanitize($GLOBALS['special_message']);
            unset($GLOBALS['special_message']);
        }
        echo '</div>';
    }
    if ($cfg['ShowSQL'] == true && !empty($sql_query)) {
        // Html format the query to be displayed
        // If we want to show some sql code it is easiest to create it here
        /* SQL-Parser-Analyzer */
        if (!empty($GLOBALS['show_as_php'])) {
            $new_line = '\\n"<br />' . "\n" . '&nbsp;&nbsp;&nbsp;&nbsp;. "';
            $query_base = htmlspecialchars(addslashes($sql_query));
            $query_base = preg_replace('/((\\015\\012)|(\\015)|(\\012))/', $new_line, $query_base);
        } else {
            $query_base = $sql_query;
        }
        $query_too_big = false;
        if (strlen($query_base) > $cfg['MaxCharactersInDisplayedSQL']) {
            // when the query is large (for example an INSERT of binary
            // data), the parser chokes; so avoid parsing the query
            $query_too_big = true;
            $shortened_query_base = nl2br(htmlspecialchars(substr($sql_query, 0, $cfg['MaxCharactersInDisplayedSQL']) . '[...]'));
        } elseif (!empty($GLOBALS['parsed_sql']) && $query_base == $GLOBALS['parsed_sql']['raw']) {
            // (here, use "! empty" because when deleting a bookmark,
            // $GLOBALS['parsed_sql'] is set but empty
            $parsed_sql = $GLOBALS['parsed_sql'];
        } else {
            // Parse SQL if needed
            $parsed_sql = PMA_SQP_parse($query_base);
        }
        // Analyze it
        if (isset($parsed_sql)) {
            $analyzed_display_query = PMA_SQP_analyze($parsed_sql);
            // Here we append the LIMIT added for navigation, to
            // enable its display. Adding it higher in the code
            // to $sql_query would create a problem when
            // using the Refresh or Edit links.
            // Only append it on SELECTs.
            /**
             * @todo what would be the best to do when someone hits Refresh:
             * use the current LIMITs ?
             */
            if (isset($analyzed_display_query[0]['queryflags']['select_from']) && isset($GLOBALS['sql_limit_to_append'])) {
                $query_base = $analyzed_display_query[0]['section_before_limit'] . "\n" . $GLOBALS['sql_limit_to_append'] . $analyzed_display_query[0]['section_after_limit'];
                // Need to reparse query
                $parsed_sql = PMA_SQP_parse($query_base);
            }
        }
        if (!empty($GLOBALS['show_as_php'])) {
            $query_base = '$sql  = "' . $query_base;
        } elseif (!empty($GLOBALS['validatequery'])) {
            $query_base = PMA_validateSQL($query_base);
        } elseif (isset($parsed_sql)) {
            $query_base = PMA_formatSql($parsed_sql, $query_base);
        }
        // Prepares links that may be displayed to edit/explain the query
        // (don't go to default pages, we must go to the page
        // where the query box is available)
        // Basic url query part
        $url_params = array();
        if (strlen($GLOBALS['db'])) {
            $url_params['db'] = $GLOBALS['db'];
            if (strlen($GLOBALS['table'])) {
                $url_params['table'] = $GLOBALS['table'];
                $edit_link = 'tbl_sql.php';
            } else {
                $edit_link = 'db_sql.php';
            }
        } else {
            $edit_link = 'server_sql.php';
        }
        // Want to have the query explained (Mike Beck 2002-05-22)
        // but only explain a SELECT (that has not been explained)
        /* SQL-Parser-Analyzer */
        $explain_link = '';
        if (!empty($cfg['SQLQuery']['Explain']) && !$query_too_big) {
            $explain_params = $url_params;
            // Detect if we are validating as well
            // To preserve the validate uRL data
            if (!empty($GLOBALS['validatequery'])) {
                $explain_params['validatequery'] = 1;
            }
            if (preg_match('@^SELECT[[:space:]]+@i', $sql_query)) {
                $explain_params['sql_query'] = 'EXPLAIN ' . $sql_query;
                $_message = $GLOBALS['strExplain'];
            } elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sql_query)) {
                $explain_params['sql_query'] = substr($sql_query, 8);
                $_message = $GLOBALS['strNoExplain'];
            }
            if (isset($explain_params['sql_query'])) {
                $explain_link = 'import.php' . PMA_generate_common_url($explain_params);
                $explain_link = ' [' . PMA_linkOrButton($explain_link, $_message) . ']';
            }
        }
        //show explain
        $url_params['sql_query'] = $sql_query;
        $url_params['show_query'] = 1;
        if (!empty($cfg['SQLQuery']['Edit']) && !$query_too_big) {
            if ($cfg['EditInWindow'] == true) {
                $onclick = 'window.parent.focus_querywindow(\'' . PMA_jsFormat($sql_query, false) . '\'); return false;';
            } else {
                $onclick = '';
            }
            $edit_link .= PMA_generate_common_url($url_params) . '#querybox';
            $edit_link = ' [' . PMA_linkOrButton($edit_link, $GLOBALS['strEdit'], array('onclick' => $onclick)) . ']';
        } else {
            $edit_link = '';
        }
        $url_qpart = PMA_generate_common_url($url_params);
        // Also we would like to get the SQL formed in some nice
        // php-code (Mike Beck 2002-05-22)
        if (!empty($cfg['SQLQuery']['ShowAsPHP']) && !$query_too_big) {
            $php_params = $url_params;
            if (!empty($GLOBALS['show_as_php'])) {
                $_message = $GLOBALS['strNoPhp'];
            } else {
                $php_params['show_as_php'] = 1;
                $_message = $GLOBALS['strPhp'];
            }
            $php_link = 'import.php' . PMA_generate_common_url($php_params);
            $php_link = ' [' . PMA_linkOrButton($php_link, $_message) . ']';
            if (isset($GLOBALS['show_as_php'])) {
                $runquery_link = 'import.php' . PMA_generate_common_url($url_params);
                $php_link .= ' [' . PMA_linkOrButton($runquery_link, $GLOBALS['strRunQuery']) . ']';
            }
        } else {
            $php_link = '';
        }
        //show as php
        // Refresh query
        if (!empty($cfg['SQLQuery']['Refresh']) && preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sql_query)) {
            $refresh_link = 'import.php' . PMA_generate_common_url($url_params);
            $refresh_link = ' [' . PMA_linkOrButton($refresh_link, $GLOBALS['strRefresh']) . ']';
        } else {
            $refresh_link = '';
        }
        //show as php
        if (!empty($cfg['SQLValidator']['use']) && !empty($cfg['SQLQuery']['Validate'])) {
            $validate_params = $url_params;
            if (!empty($GLOBALS['validatequery'])) {
                $validate_message = $GLOBALS['strNoValidateSQL'];
            } else {
                $validate_params['validatequery'] = 1;
                $validate_message = $GLOBALS['strValidateSQL'];
            }
            $validate_link = 'import.php' . PMA_generate_common_url($validate_params);
            $validate_link = ' [' . PMA_linkOrButton($validate_link, $validate_message) . ']';
        } else {
            $validate_link = '';
        }
        //validator
        echo '<code class="sql">';
        if ($query_too_big) {
            echo $shortened_query_base;
        } else {
            echo $query_base;
        }
        //Clean up the end of the PHP
        if (!empty($GLOBALS['show_as_php'])) {
            echo '";';
        }
        echo '</code>';
        echo '<div class="tools">';
        // avoid displaying a Profiling checkbox that could
        // be checked, which would reexecute an INSERT, for example
        if (!empty($refresh_link)) {
            PMA_profilingCheckbox($sql_query);
        }
        echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link;
        echo '</div>';
    }
    echo '</div><br />' . "\n";
}
Esempio n. 16
0
</fieldset>
</form>
<br />
    <?php 
}
PMA_generate_slider_effect('tablestatistics', $strDetails);
/**
 * Displays Space usage and row statistics
 */
// BEGIN - Calc Table Space - staybyte - 9 June 2001
// loic1, 22 feb. 2002: updated with patch from
//                      Joshua Nye <josh at boxcarmedia.com> to get valid
//                      statistics whatever is the table type
if ($cfg['ShowStats']) {
    if (empty($showtable)) {
        $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true);
    }
    $nonisam = false;
    $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB';
    if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
        $nonisam = true;
    }
    // Gets some sizes
    $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
    // this is to display for example 261.2 MiB instead of 268k KiB
    $max_digits = 5;
    $decimals = 1;
    list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals);
    if ($mergetable == false) {
        list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals);
    }
Esempio n. 17
0
 /**
  * Checks if this is a merge table
  *
  * If the ENGINE of the table is MERGE or MRG_MYISAM (alias),
  * this is a merge table.
  *
  * @param string $db    the database name
  * @param string $table the table name
  *
  * @return boolean  true if it is a merge table
  */
 public static function isMerge($db = null, $table = null)
 {
     $engine = null;
     // if called static, with parameters
     if (!empty($db) && !empty($table)) {
         $engine = PMA_Table::sGetStatusInfo($db, $table, 'ENGINE', null, true);
     }
     // did we get engine?
     if (empty($engine)) {
         return false;
     }
     // any of known merge engines?
     return in_array(strtoupper($engine), array('MERGE', 'MRG_MYISAM'));
 }
Esempio n. 18
0
 public static function sGetToolTip($db, $table)
 {
     return PMA_Table::sGetStatusInfo($db, $table, 'Comment') . ' (' . PMA_Table::countRecords($db, $table) . ')';
 }
 /**
  * Generates data dictionary pages.
  *
  * @param array $alltables Tables to document.
  *
  * @return void
  */
 public function dataDictionaryDoc($alltables)
 {
     global $pdf;
     // TOC
     $pdf->addpage($this->orientation);
     $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
     $pdf->Ln(15);
     $i = 1;
     foreach ($alltables as $table) {
         $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
         $pdf->SetX(10);
         // $pdf->Ln(1);
         $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
         $pdf->SetX(10);
         $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
         // $pdf->Ln(1);
         $fields = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table);
         foreach ($fields as $row) {
             $pdf->SetX(20);
             $field_name = $row['Field'];
             $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
             //$pdf->Cell(
             //    0, 6, $field_name, 0, 1,
             //    'L', 0, $pdf->PMA_links['doc'][$table][$field_name]
             //);
         }
         $i++;
     }
     $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
     $pdf->SetX(10);
     $pdf->Cell(0, 6, __('Page number:') . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['RT']['-']);
     $pdf->SetX(10);
     $pdf->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
     $z = 0;
     foreach ($alltables as $table) {
         $z++;
         $pdf->SetAutoPageBreak(true, 15);
         $pdf->addpage($this->orientation);
         $pdf->Bookmark($table);
         $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo());
         $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
         $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
         $pdf->SetFont($this->_ff, 'B', 18);
         $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
         $pdf->SetFont($this->_ff, '', 8);
         $pdf->ln();
         $cfgRelation = PMA_getRelationsParam();
         $comments = PMA_getComments($GLOBALS['db'], $table);
         if ($cfgRelation['mimework']) {
             $mime_map = PMA_getMIME($GLOBALS['db'], $table, true);
         }
         /**
          * Gets table information
          */
         $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $table);
         $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
         $create_time = isset($showtable['Create_time']) ? PMA_Util::localisedDate(strtotime($showtable['Create_time'])) : '';
         $update_time = isset($showtable['Update_time']) ? PMA_Util::localisedDate(strtotime($showtable['Update_time'])) : '';
         $check_time = isset($showtable['Check_time']) ? PMA_Util::localisedDate(strtotime($showtable['Check_time'])) : '';
         /**
          * Gets fields properties
          */
         $columns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table);
         // Check if we can use Relations
         if (!empty($cfgRelation['relation'])) {
             // Find which tables are related with the current one and write it in
             // an array
             $res_rel = PMA_getForeigners($GLOBALS['db'], $table);
         }
         // end if
         /**
          * Displays the comments of the table if MySQL >= 3.23
          */
         $break = false;
         if (!empty($show_comment)) {
             $pdf->Cell(0, 3, __('Table comments:') . ' ' . $show_comment, 0, 1);
             $break = true;
         }
         if (!empty($create_time)) {
             $pdf->Cell(0, 3, __('Creation:') . ' ' . $create_time, 0, 1);
             $break = true;
         }
         if (!empty($update_time)) {
             $pdf->Cell(0, 3, __('Last update:') . ' ' . $update_time, 0, 1);
             $break = true;
         }
         if (!empty($check_time)) {
             $pdf->Cell(0, 3, __('Last check:') . ' ' . $check_time, 0, 1);
             $break = true;
         }
         if ($break == true) {
             $pdf->Cell(0, 3, '', 0, 1);
             $pdf->Ln();
         }
         $pdf->SetFont($this->_ff, 'B');
         if (isset($this->orientation) && $this->orientation == 'L') {
             $pdf->Cell(25, 8, __('Column'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Default'), 1, 0, 'C');
             $pdf->Cell(25, 8, __('Extra'), 1, 0, 'C');
             $pdf->Cell(45, 8, __('Links to'), 1, 0, 'C');
             if ($this->paper == 'A4') {
                 $comments_width = 67;
             } else {
                 // this is really intended for 'letter'
                 /**
                  * @todo find optimal width for all formats
                  */
                 $comments_width = 50;
             }
             $pdf->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
             $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
         } else {
             $pdf->Cell(20, 8, __('Column'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
             $pdf->Cell(15, 8, __('Default'), 1, 0, 'C');
             $pdf->Cell(15, 8, __('Extra'), 1, 0, 'C');
             $pdf->Cell(30, 8, __('Links to'), 1, 0, 'C');
             $pdf->Cell(30, 8, __('Comments'), 1, 0, 'C');
             $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
         }
         $pdf->SetFont($this->_ff, '');
         foreach ($columns as $row) {
             $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
             $type = $extracted_columnspec['print_type'];
             $attribute = $extracted_columnspec['attribute'];
             if (!isset($row['Default'])) {
                 if ($row['Null'] != '' && $row['Null'] != 'NO') {
                     $row['Default'] = 'NULL';
                 }
             }
             $field_name = $row['Field'];
             // $pdf->Ln();
             $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
             $pdf->Bookmark($field_name, 1, -1);
             $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
             $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name);
             $linksTo = '';
             if ($foreigner) {
                 $linksTo = '-> ';
                 if ($foreigner['foreign_db'] != $GLOBALS['db']) {
                     $linksTo .= $foreigner['foreign_db'] . '.';
                 }
                 $linksTo .= $foreigner['foreign_table'] . '.' . $foreigner['foreign_field'];
                 if (isset($foreigner['on_update'])) {
                     // not set for internal
                     $linksTo .= "\n" . 'ON UPDATE ' . $foreigner['on_update'];
                     $linksTo .= "\n" . 'ON DELETE ' . $foreigner['on_delete'];
                 }
             }
             $pdf_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], $linksTo, isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '');
             $links = array();
             $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
             if ($foreigner && isset($pdf->PMA_links['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']])) {
                 $links[6] = $pdf->PMA_links['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']];
             } else {
                 unset($links[6]);
             }
             $pdf->Row($pdf_row, $links);
         }
         // end foreach
         $pdf->SetFont($this->_ff, '', 14);
     }
     //end each
 }
Esempio n. 20
0
 /**
  * Prepare data for column restoring and show/hide
  *
  * @return  string  $data_html      html content
  *
  * @access  private
  *
  * @see     _getTableHeaders()
  */
 private function _getDataForResettingColumnOrder()
 {
     $data_html = '';
     // generate the column order, if it is set
     $pmatable = new PMA_Table($this->__get('table'), $this->__get('db'));
     $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
     if ($col_order) {
         $data_html .= '<input class="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
     }
     $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
     if ($col_visib) {
         $data_html .= '<input class="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
     }
     // generate table create time
     if (!PMA_Table::isView($this->__get('db'), $this->__get('table'))) {
         $data_html .= '<input class="table_create_time" type="hidden" value="' . PMA_Table::sGetStatusInfo($this->__get('db'), $this->__get('table'), 'Create_time') . '" />';
     }
     return $data_html;
 }
    $comments = PMA_getComments($db, $table);

    if ($count != 0) {
        echo '<div style="page-break-before: always;">' . "\n";
    } else {
        echo '<div>' . "\n";
    }

    echo '<h2>' . $table . '</h2>' . "\n";

    /**
     * Gets table informations
     */
    // The 'show table' statement works correct since 3.23.03
    $num_rows     = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_ROWS');
    $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');

    /**
     * Gets table keys and retains them
     */

    PMA_DBI_select_db($db);
    $result       = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
    $primary      = '';
    $indexes      = array();
    $lastIndex    = '';
    $indexes_info = array();
    $indexes_data = array();
    $pk_array     = array(); // will be use to emphasis prim. keys in the table
                             // view
    while ($row = PMA_DBI_fetch_assoc($result)) {
Esempio n. 22
0
/**
 * return html for tables' detail
 *
 * @param array  $the_tables      tables list
 * @param string $db              database name
 * @param array  $cfg             global config
 * @param array  $cfgRelation     config from PMA_getRelationsParam
 * @param int    $cell_align_left cell align left
 *
 * @return string
 */
function PMA_getHtmlForTablesDetail($the_tables, $db, $cfg, $cfgRelation, $cell_align_left)
{
    $html = '';
    $tables_cnt = count($the_tables);
    $multi_tables = count($the_tables) > 1;
    $counter = 0;
    foreach ($the_tables as $table) {
        if ($counter + 1 >= $tables_cnt) {
            $breakstyle = '';
        } else {
            $breakstyle = ' style="page-break-after: always;"';
        }
        $counter++;
        $html .= '<div' . $breakstyle . '>' . "\n";
        $html .= '<h1>' . htmlspecialchars($table) . '</h1>' . "\n";
        /**
         * Gets table informations
         */
        $showtable = PMA_Table::sGetStatusInfo($db, $table);
        $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
        $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
        $tbl_is_view = PMA_Table::isView($db, $table);
        /**
         * Gets fields properties
         */
        $columns = $GLOBALS['dbi']->getColumns($db, $table);
        // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
        // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
        // and SHOW CREATE TABLE says NOT NULL (tested
        // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
        $show_create_table = $GLOBALS['dbi']->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1);
        $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
        // Check if we can use Relations
        // Find which tables are related with the current one and write it in
        // an array
        $res_rel = PMA_getForeigners($db, $table);
        $have_rel = (bool) count($res_rel);
        /**
         * Displays the comments of the table if MySQL >= 3.23
         */
        if (!empty($show_comment)) {
            $html .= __('Table comments:') . ' ' . htmlspecialchars($show_comment) . '<br /><br />';
        }
        $html .= PMA_getHtmlForTableStructure($have_rel, $tbl_is_view, $columns, $analyzed_sql, $res_rel, $db, $table, $cfgRelation, $cfg, $showtable, $cell_align_left);
        if ($multi_tables) {
            unset($num_rows, $show_comment);
            $html .= '<hr />' . "\n";
        }
        // end if
        $html .= '</div>' . "\n";
    }
    // end while
    return $html;
}
Esempio n. 23
0
 }
 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
     // $showtable might already be set from ShowDbStructureCreation, see above
     if (!isset($showtable)) {
         $showtable = PMA_Table::sGetStatusInfo($db, $each_table['TABLE_NAME'], null, true);
     }
     $update_time = isset($showtable['Update_time']) ? $showtable['Update_time'] : false;
     // show newest update date in summary row
     if ($update_time && $update_time > $update_time_all) {
         $update_time_all = $update_time;
     }
 }
 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
     // $showtable might already be set from ShowDbStructureCreation, see above
     if (!isset($showtable)) {
         $showtable = PMA_Table::sGetStatusInfo($db, $each_table['TABLE_NAME'], null, true);
     }
     $check_time = isset($showtable['Check_time']) ? $showtable['Check_time'] : false;
     // show newest check date in summary row
     if ($check_time && $check_time > $check_time_all) {
         $check_time_all = $check_time;
     }
 }
 $alias = !empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]) ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']])) : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
 $truename = !empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]) ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']])) : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
 $i++;
 $row_count++;
 if ($table_is_view) {
     $hidden_fields[] = '<input type="hidden" name="views[]" value="' . htmlspecialchars($each_table['TABLE_NAME']) . '" />';
 }
 /*