Beispiel #1
0
 /**
  * Builds the SQL search query
  *
  * @param   string   the table name
  * @param   string   the string to search
  * @param   integer  type of search (1 -> 1 word at least, 2 -> all words,
  *                                   3 -> exact string, 4 -> regexp)
  *
  * @return  array    3 SQL querys (for count, display and delete results)
  *
  * @global  string   the url to retun to in case of errors
  */
 function PMA_getSearchSqls($table, $search_str, $search_option)
 {
     global $err_url;
     // Statement types
     $sqlstr_select = 'SELECT';
     $sqlstr_delete = 'DELETE';
     // Fields to select
     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']);
     $res = @PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, $err_url);
     $res_cnt = $res ? mysql_num_rows($res) : 0;
     for ($i = 0; $i < $res_cnt; $i++) {
         $tblfields[] = PMA_backquote(PMA_mysql_result($res, $i, 'field'));
     }
     // end if
     $sqlstr_fieldstoselect = ' ' . implode(', ', $tblfields);
     $tblfields_cnt = count($tblfields);
     if ($res) {
         mysql_free_result($res);
     }
     // Table to use
     $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table);
     // Beginning of WHERE clause
     $sqlstr_where = ' WHERE';
     $search_words = $search_option > 2 ? array($search_str) : explode(' ', $search_str);
     $search_wds_cnt = count($search_words);
     $like_or_regex = $search_option == 4 ? 'REGEXP' : 'LIKE';
     $automatic_wildcard = $search_option < 3 ? '%' : '';
     for ($i = 0; $i < $search_wds_cnt; $i++) {
         // Elimines empty values
         if (!empty($search_words[$i])) {
             for ($j = 0; $j < $tblfields_cnt; $j++) {
                 $thefieldlikevalue[] = $tblfields[$j] . ' ' . $like_or_regex . ' \'' . $automatic_wildcard . $search_words[$i] . $automatic_wildcard . '\'';
             }
             // end for
             $fieldslikevalues[] = $search_wds_cnt > 1 ? '(' . implode(' OR ', $thefieldlikevalue) . ')' : implode(' OR ', $thefieldlikevalue);
             unset($thefieldlikevalue);
         }
         // end if
     }
     // end for
     $implode_str = $search_option == 1 ? ' OR ' : ' AND ';
     $sqlstr_where .= ' ' . implode($implode_str, $fieldslikevalues);
     unset($fieldslikevalues);
     // Builds complete queries
     $sql['select_fields'] = $sqlstr_select . $sqlstr_fieldstoselect . $sqlstr_from . $sqlstr_where;
     $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS count' . $sqlstr_from . $sqlstr_where;
     $sql['delete'] = $sqlstr_delete . $sqlstr_from . $sqlstr_where;
     return $sql;
 }
/**
 * Displays the body of the results table
 *
 * @param   integer  the link id associated to the query which results have
 *                   to be displayed
 * @param   array    which elements to display
 * @param   array    the list of relations
 * @param   array    the analyzed query
 *
 * @return  boolean  always true
 *
 * @global  string   the current language
 * @global  string   the current charset for MySQL
 * @global  integer  the server to use (refers to the number in the
 *                   configuration file)
 * @global  string   the database name
 * @global  string   the table name
 * @global  string   the sql query
 * @global  string   the url to go back in case of errors
 * @global  integer  the current position in results
 * @global  integer  the maximum number of rows per page
 * @global  array    the list of fields properties
 * @global  integer  the total number of fields returned by the sql query
 * @global  array    informations used with vertical display mode
 * @global  string   the display mode (horizontal/vertical/horizontalflipped)
 * @global  integer  the number of row to display between two table headers
 * @global  boolean  whether to limit the number of displayed characters of
 *                   text type fields or not
 *
 * @access  private
 *
 * @see     PMA_displayTable()
 */
function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
{
    global $lang, $convcharset, $server, $db, $table;
    global $goto;
    global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
    global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
    global $dontlimitchars;
    global $row;
    // mostly because of browser transformations, to make the row-data accessible in a plugin
    if (!is_array($map)) {
        $map = array();
    }
    ?>
<!-- Results table body -->
    <?php 
    echo "\n";
    $row_no = 0;
    $vertical_display['edit'] = array();
    $vertical_display['delete'] = array();
    $vertical_display['data'] = array();
    $vertical_display['row_delete'] = array();
    // Correction uva 19991216 in the while below
    // Previous code assumed that all tables have keys, specifically that
    // the phpMyAdmin GUI should support row delete/edit only for such
    // tables.
    // Although always using keys is arguably the prescribed way of
    // defining a relational table, it is not required. This will in
    // particular be violated by the novice.
    // We want to encourage phpMyAdmin usage by such novices. So the code
    // below has been changed to conditionally work as before when the
    // table being displayed has one or more keys; but to display
    // delete/edit options correctly for tables without keys.
    // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
    //        to get the NULL values
    while ($row = PMA_mysql_fetch_array($dt_result)) {
        // lem9: "vertical display" mode stuff
        if ($row_no != 0 && $repeat_cells != 0 && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
            echo '<tr>' . "\n";
            for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
                echo '    <td>&nbsp;</td>' . "\n";
            }
            foreach ($vertical_display['desc'] as $key => $val) {
                echo $val;
            }
            for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
                echo '    <td>&nbsp;</td>' . "\n";
            }
            echo '</tr>' . "\n";
        }
        // end if
        if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
            $bgcolor = '#ffffff';
        } else {
            $bgcolor = $row_no % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
        }
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            // loic1: pointer code part
            $on_mouse = '';
            if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
                if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
                    $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"' . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
                }
                if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
                    $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
                }
            }
            // end if
            ?>
<tr<?php 
            echo $on_mouse;
            ?>
>
            <?php 
            echo "\n";
        }
        // 1. Prepares the row (gets primary keys to use)
        if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
            $primary_key = '';
            $unique_key = '';
            $uva_nonprimary_condition = '';
            // 1.1 Results from a "SELECT" statement -> builds the
            //     "primary" key to use in links
            if ($is_display['edit_lnk'] == 'ur') {
                for ($i = 0; $i < $fields_cnt; ++$i) {
                    $field_flags = PMA_mysql_field_flags($dt_result, $i);
                    $meta = $fields_meta[$i];
                    // do not use an alias in a condition
                    $column_for_condition = $meta->name;
                    if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
                        foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) {
                            $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
                            if (!empty($alias)) {
                                $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
                                if ($alias == $meta->name) {
                                    $column_for_condition = $true_column;
                                }
                                // end if
                            }
                            // end if
                        }
                        // end while
                    }
                    // to fix the bug where float fields (primary or not)
                    // can't be matched because of the imprecision of
                    // floating comparison, use CONCAT
                    // (also, the syntax "CONCAT(field) IS NULL"
                    // that we need on the next "if" will work)
                    if ($meta->type == 'real') {
                        $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') ';
                    } else {
                        $condition = ' ' . PMA_backquote($column_for_condition) . ' ';
                    }
                    // end if... else...
                    // loic1: To fix bug #474943 under php4, the row
                    //        pointer will depend on whether the "is_null"
                    //        php4 function is available or not
                    $pointer = function_exists('is_null') ? $i : $meta->name;
                    if (!isset($row[$meta->name]) || function_exists('is_null') && is_null($row[$pointer])) {
                        $condition .= 'IS NULL AND';
                    } else {
                        if ($meta->type == 'blob' && stristr($field_flags, 'BINARY') && !empty($row[$pointer])) {
                            $condition .= 'LIKE 0x' . bin2hex($row[$pointer]) . ' AND';
                        } else {
                            $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer], FALSE, TRUE) . '\' AND';
                        }
                    }
                    if ($meta->primary_key > 0) {
                        $primary_key .= $condition;
                    } else {
                        if ($meta->unique_key > 0) {
                            $unique_key .= $condition;
                        }
                    }
                    $uva_nonprimary_condition .= $condition;
                }
                // end for
                // Correction uva 19991216: prefer primary or unique keys
                // for condition, but use conjunction of all values if no
                // primary key
                if ($primary_key) {
                    $uva_condition = $primary_key;
                } else {
                    if ($unique_key) {
                        $uva_condition = $unique_key;
                    } else {
                        $uva_condition = $uva_nonprimary_condition;
                    }
                }
                $uva_condition = urlencode(preg_replace('|\\s?AND$|', '', $uva_condition));
            }
            // end if (1.1)
            // 1.2 Defines the urls for the modify/delete link(s)
            $url_query = PMA_generate_common_url($db, $table) . '&amp;pos=' . $pos . '&amp;session_max_rows=' . $session_max_rows . '&amp;disp_direction=' . $disp_direction . '&amp;repeat_cells=' . $repeat_cells . '&amp;dontlimitchars=' . $dontlimitchars;
            // We need to copy the value or else the == 'both' check will always return true
            $propicon = (string) $GLOBALS['cfg']['PropertiesIconic'];
            if ($propicon == 'both') {
                $iconic_spacer = '<nobr>';
            } else {
                $iconic_spacer = '';
            }
            // 1.2.1 Modify link(s)
            if ($is_display['edit_lnk'] == 'ur') {
                // update row case
                //                    $lnk_goto = 'sql.php'
                //                             . '?' . str_replace('&amp;', '&', $url_query)
                //                              . '&sql_query=' . urlencode($sql_query)
                //                              . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
                // to reduce the length of the URL, because of some browsers limitations:
                $lnk_goto = 'sql.php';
                $edit_url = 'tbl_change.php' . '?' . $url_query . '&amp;primary_key=' . $uva_condition . '&amp;sql_query=' . urlencode($sql_query) . '&amp;goto=' . urlencode($lnk_goto);
                if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
                    $edit_str = $GLOBALS['strEdit'];
                } else {
                    $edit_str = $iconic_spacer . '<img width="12" height="13" src="images/button_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" border="0" />';
                    if ($propicon == 'both') {
                        $edit_str .= '&nbsp;' . $GLOBALS['strEdit'] . '</nobr>';
                    }
                }
            }
            // end if (1.2.1)
            if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db']) {
                $bookmark_go = '<a href="read_dump.php?' . PMA_generate_common_url($row['dbase'], '') . '&amp;id_bookmark=' . $row['id'] . '&amp;action_bookmark=0' . '&amp;action_bookmark_all=1' . '&amp;SQL=' . $GLOBALS['strExecuteBookmarked'] . ' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
                if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
                    $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
                } else {
                    $bookmark_go .= $iconic_spacer . '<img width="12" height="13" src="images/button_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" border="0" />';
                    if ($propicon == 'both') {
                        $bookmark_go .= '&nbsp;' . $GLOBALS['strExecuteBookmarked'] . '</nobr>';
                    }
                }
                $bookmark_go .= '</a>';
            } else {
                $bookmark_go = '';
            }
            // 1.2.2 Delete/Kill link(s)
            if ($is_display['del_lnk'] == 'dr') {
                // delete row case
                $lnk_goto = 'sql.php' . '?' . str_replace('&amp;', '&', $url_query) . '&sql_query=' . urlencode($sql_query) . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
                $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . '+LIMIT+1';
                $del_url = 'sql.php' . '?' . $url_query . '&amp;sql_query=' . $del_query . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&amp;goto=' . urlencode($lnk_goto);
                $js_conf = 'DELETE FROM ' . PMA_jsFormat($table) . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE)) . ' LIMIT 1';
                if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
                    $del_str = $GLOBALS['strDelete'];
                } else {
                    $del_str = $iconic_spacer . '<img width="12" height="13" src="images/button_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" border="0" />';
                    if ($propicon == 'both') {
                        $del_str .= '&nbsp;' . $GLOBALS['strDelete'] . '</nobr>';
                    }
                }
            } else {
                if ($is_display['del_lnk'] == 'kp') {
                    // kill process case
                    $lnk_goto = 'sql.php' . '?' . str_replace('&amp;', '&', $url_query) . '&sql_query=' . urlencode($sql_query) . '&goto=main.php';
                    $del_url = 'sql.php?' . PMA_generate_common_url('mysql') . '&amp;sql_query=' . urlencode('KILL ' . $row['Id']) . '&amp;goto=' . urlencode($lnk_goto);
                    $del_query = urlencode('KILL ' . $row['Id']);
                    $js_conf = 'KILL ' . $row['Id'];
                    if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
                        $del_str = $GLOBALS['strKill'];
                    } else {
                        $del_str = $iconic_spacer . '<img width="12" height="13" src="images/button_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" border="0" />';
                        if ($propicon == 'both') {
                            $del_str .= '&nbsp;' . $GLOBALS['strKill'] . '</nobr>';
                        }
                    }
                }
            }
            // end if (1.2.2)
            // 1.3 Displays the links at left if required
            if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
                require './libraries/display_tbl_links.lib.php';
            }
            // end if (1.3)
            echo $disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped' ? "\n" : '';
        }
        // end if (1)
        // 2. Displays the rows' values
        for ($i = 0; $i < $fields_cnt; ++$i) {
            $meta = $fields_meta[$i];
            // loic1: To fix bug #474943 under php4, the row pointer will
            //        depend on whether the "is_null" php4 function is
            //        available or not
            $pointer = function_exists('is_null') ? $i : $meta->name;
            // garvin: See if this column should get highlight because it's used in the
            //  where-query.
            if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
                $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
            } else {
                $column_style = '';
            }
            // garvin: Wrap MIME-transformations. [MIME]
            $default_function = 'default_function';
            // default_function
            $transform_function = $default_function;
            $transform_options = array();
            if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
                if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
                    $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
                    if (file_exists('./libraries/transformations/' . $include_file)) {
                        $transformfunction_name = preg_replace('@(\\.inc\\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
                        require_once './libraries/transformations/' . $include_file;
                        if (function_exists('PMA_transformation_' . $transformfunction_name)) {
                            $transform_function = 'PMA_transformation_' . $transformfunction_name;
                            $transform_options = PMA_transformation_getOptions(isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : '');
                            $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
                        }
                    }
                    // end if file_exists
                }
                // end if transformation is set
            }
            // end if mime/transformation works.
            $transform_options['wrapper_link'] = '?' . (isset($url_query) ? $url_query : '') . '&amp;primary_key=' . (isset($uva_condition) ? $uva_condition : '') . '&amp;sql_query=' . (isset($sql_query) ? urlencode($sql_query) : '') . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '') . '&amp;transform_key=' . urlencode($meta->name);
            // n u m e r i c
            if ($meta->numeric == 1) {
                // lem9: if two fields have the same name (this is possible
                //       with self-join queries, for example), using $meta->name
                //       will show both fields NULL even if only one is NULL,
                //       so use the $pointer
                //      (works only if function_exists('is_null')
                // PS:   why not always work with the number ($i), since
                //       the default second parameter of
                //       mysql_fetch_array() is MYSQL_BOTH, so we always get
                //       associative and numeric indices?
                //if (!isset($row[$meta->name])
                if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) {
                    $vertical_display['data'][$row_no][$i] = '    <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
                } else {
                    if ($row[$pointer] != '') {
                        $vertical_display['data'][$row_no][$i] = '    <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '" nowrap="nowrap">';
                        if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
                            foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) {
                                $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
                                if (!empty($alias)) {
                                    $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
                                    if ($alias == $meta->name) {
                                        $meta->name = $true_column;
                                    }
                                    // end if
                                }
                                // end if
                            }
                            // end while
                        }
                        if (isset($map[$meta->name])) {
                            // Field to display from the foreign table?
                            if (!empty($map[$meta->name][2])) {
                                $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer];
                                $dispresult = PMA_mysql_query($dispsql);
                                if ($dispresult && mysql_num_rows($dispresult) > 0) {
                                    $dispval = PMA_mysql_result($dispresult, 0);
                                } else {
                                    $dispval = $GLOBALS['strLinkNotFound'];
                                }
                            } else {
                                $dispval = '';
                            }
                            // end if... else...
                            if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
                                $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
                            } else {
                                $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : '';
                                $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?' . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>' . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . '</a>';
                            }
                        } else {
                            $vertical_display['data'][$row_no][$i] .= $transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta);
                        }
                        $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
                    } else {
                        $vertical_display['data'][$row_no][$i] = '    <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '" nowrap="nowrap">&nbsp;</td>' . "\n";
                    }
                }
                //  b l o b
            } else {
                if ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) {
                    // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
                    // TEXT fields type, however TEXT fields must be displayed
                    // even if $cfg['ShowBlob'] is false -> get the true type
                    // of the fields.
                    $field_flags = PMA_mysql_field_flags($dt_result, $i);
                    if (stristr($field_flags, 'BINARY')) {
                        $blobtext = '[BLOB';
                        if (isset($row[$pointer])) {
                            $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1);
                            $blobtext .= ' - ' . $blob_size[0] . ' ' . $blob_size[1];
                            unset($blob_size);
                        }
                        $blobtext .= ']';
                        $blobtext = $default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta);
                        $vertical_display['data'][$row_no][$i] = '    <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
                    } else {
                        //if (!isset($row[$meta->name])
                        if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) {
                            $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
                        } else {
                            if ($row[$pointer] != '') {
                                // garvin: if a transform function for blob is set, none of these replacements will be made
                                if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && $dontlimitchars != 1) {
                                    $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
                                }
                                // loic1: displays all space characters, 4 space
                                // characters for tabulations and <cr>/<lf>
                                $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta);
                                $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n";
                            } else {
                                $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
                            }
                        }
                    }
                } else {
                    //if (!isset($row[$meta->name])
                    if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) {
                        $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
                    } else {
                        if ($row[$pointer] != '') {
                            // loic1: support blanks in the key
                            $relation_id = $row[$pointer];
                            // nijel: Cut all fields to $cfg['LimitChars']
                            if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && $dontlimitchars != 1) {
                                $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...';
                            }
                            // loic1: displays special characters from binaries
                            $field_flags = PMA_mysql_field_flags($dt_result, $i);
                            if (stristr($field_flags, 'BINARY')) {
                                $row[$pointer] = str_replace("", '\\0', $row[$pointer]);
                                $row[$pointer] = str_replace("", '\\b', $row[$pointer]);
                                $row[$pointer] = str_replace("\n", '\\n', $row[$pointer]);
                                $row[$pointer] = str_replace("\r", '\\r', $row[$pointer]);
                                $row[$pointer] = str_replace("", '\\Z', $row[$pointer]);
                                $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta);
                            } else {
                                $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta);
                            }
                            // garvin: transform functions may enable nowrapping:
                            $function_nowrap = $transform_function . '_nowrap';
                            $bool_nowrap = $default_function != $transform_function && function_exists($function_nowrap) ? $function_nowrap($transform_options) : false;
                            // loic1: do not wrap if date field type
                            $nowrap = preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap ? ' nowrap="nowrap"' : '';
                            $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
                            if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
                                foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) {
                                    $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
                                    if (!empty($alias)) {
                                        $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
                                        if ($alias == $meta->name) {
                                            $meta->name = $true_column;
                                        }
                                        // end if
                                    }
                                    // end if
                                }
                                // end while
                            }
                            if (isset($map[$meta->name])) {
                                // Field to display from the foreign table?
                                if (!empty($map[$meta->name][2])) {
                                    $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\'';
                                    $dispresult = @PMA_mysql_query($dispsql);
                                    if ($dispresult && mysql_num_rows($dispresult) > 0) {
                                        $dispval = PMA_mysql_result($dispresult, 0);
                                    } else {
                                        $dispval = $GLOBALS['strLinkNotFound'];
                                    }
                                } else {
                                    $dispval = '';
                                }
                                $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : '';
                                $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?' . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>' . $row[$pointer] . '</a>';
                            } else {
                                $vertical_display['data'][$row_no][$i] .= $row[$pointer];
                            }
                            $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
                        } else {
                            $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">&nbsp;</td>' . "\n";
                        }
                    }
                }
            }
            // lem9: output stored cell
            if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
                echo $vertical_display['data'][$row_no][$i];
            }
            if (isset($vertical_display['rowdata'][$i][$row_no])) {
                $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
            } else {
                $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
            }
        }
        // end for (2)
        // 3. Displays the modify/delete links on the right if required
        if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
            require './libraries/display_tbl_links.lib.php';
        }
        // end if (3)
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            echo "\n";
            ?>
</tr>
            <?php 
        }
        // end if
        // 4. Gather links of del_urls and edit_urls in an array for later
        //    output
        if (!isset($vertical_display['edit'][$row_no])) {
            $vertical_display['edit'][$row_no] = '';
            $vertical_display['delete'][$row_no] = '';
            $vertical_display['row_delete'][$row_no] = '';
        }
        if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
            $vertical_display['row_delete'][$row_no] .= '    <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . '        <input type="checkbox" id="id_rows_to_delete' . $row_no . '" name="rows_to_delete[' . $uva_condition . ']" value="' . $del_query . '" />' . "\n" . '    </td>' . "\n";
        } else {
            unset($vertical_display['row_delete'][$row_no]);
        }
        if (isset($edit_url)) {
            $vertical_display['edit'][$row_no] .= '    <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . PMA_linkOrButton($edit_url, $edit_str, '') . $bookmark_go . '    </td>' . "\n";
        } else {
            unset($vertical_display['edit'][$row_no]);
        }
        if (isset($del_url)) {
            $vertical_display['delete'][$row_no] .= '    <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . PMA_linkOrButton($del_url, $del_str, isset($js_conf) ? $js_conf : '') . '    </td>' . "\n";
        } else {
            unset($vertical_display['delete'][$row_no]);
        }
        echo $disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped' ? "\n" : '';
        $row_no++;
    }
    // end while
    if (isset($url_query)) {
        $GLOBALS['url_query'] = $url_query;
    }
    return TRUE;
}
Beispiel #3
0
/**
 * Gets the sql command from a bookmark
 *
 * @param   string   the current database name
 * @param   array    the bookmark parameters for the current user
 * @param   mixed    the id of the bookmark to get
 * @param   string   which field to look up the $id
 * @param   boolean  TRUE: get all bookmarks regardless of the owning user
 *
 * @return  string   the sql query
 *
 * @access  public
 */
function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id', $action_bookmark_all = FALSE)
{
    if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) {
        return '';
    }
    $query = 'SELECT query FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' . ($action_bookmark_all ? '' : ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . '      OR user = \'\')') . ' AND ' . PMA_backquote($id_field) . ' = ' . $id;
    if (isset($GLOBALS['dbh'])) {
        $result = PMA_mysql_query($query, $GLOBALS['dbh']);
    } else {
        $result = PMA_mysql_query($query);
    }
    $bookmark_query = @PMA_mysql_result($result, 0, 'query') or FALSE;
    return $bookmark_query;
}
Beispiel #4
0
 /**
  * Counts and displays the number of records in a table
  *
  * Last revision 13 July 2001: Patch for limiting dump size from
  * vinay@sanisoft.com & girish@sanisoft.com
  *
  * @param   string   the current database name
  * @param   string   the current table name
  * @param   boolean  whether to retain or to displays the result
  *
  * @return  mixed    the number of records if retain is required, true else
  *
  * @access  public
  */
 function PMA_countRecords($db, $table, $ret = FALSE)
 {
     global $err_url, $cfg;
     $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
     $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
     $showtable = PMA_mysql_fetch_array($result);
     $num = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
     if ($num < $cfg['MaxExactCount']) {
         unset($num);
     }
     mysql_free_result($result);
     if (!isset($num)) {
         $result = PMA_mysql_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)) or PMA_mysqlDie('', $local_query, '', $err_url);
         $num = $result ? PMA_mysql_result($result, 0, 'num') : 0;
         mysql_free_result($result);
     }
     if ($ret) {
         return $num;
     } else {
         echo number_format($num, 0, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']);
         return TRUE;
     }
 }
Beispiel #5
0
                         $unlim_num_rows = 0;
                     }
                 }
             } else {
                 PMA_mysql_query($count_query);
                 // if (mysql_error()) {
                 // void. I tried the case
                 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
                 // UNION (SELECT `User`, `Host`, "%" AS "Db",
                 // `Select_priv`
                 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
                 // and although the generated count_query is wrong
                 // the SELECT FOUND_ROWS() work!
                 // }
                 $cnt_all_result = PMA_mysql_query('SELECT FOUND_ROWS() as count');
                 $unlim_num_rows = PMA_mysql_result($cnt_all_result, 0, 'count');
             }
         }
         // end else "just browsing"
     } else {
         // not $is_select
         $unlim_num_rows = 0;
     }
 }
 // end rows total count
 // garvin: if a table or database gets dropped, check column comments.
 if (isset($purge) && $purge == '1') {
     require_once './libraries/relation_cleanup.lib.php';
     if (isset($table) && isset($db) && !empty($table) && !empty($db)) {
         PMA_relationsCleanupTable($db, $table);
     } elseif (isset($db) && !empty($db)) {
     }
     $sum_entries += $sts_data['Rows'];
     $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
 } else {
     if (isset($sts_data['Type']) && $sts_data['Type'] == 'InnoDB') {
         if ($cfg['ShowStats']) {
             $tblsize = $sts_data['Data_length'] + $sts_data['Index_length'];
             $sum_size += $tblsize;
             list($formated_size, $unit) = PMA_formatByteDown($tblsize, 3, $tblsize > 0 ? 1 : 0);
         }
         //$display_rows                   =  '&nbsp;-&nbsp;';
         // get row count with another method
         if ($sts_data['Rows'] < $cfg['MaxExactCount']) {
             $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
             $table_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0);
             $row_count = PMA_mysql_result($table_info_result, 0, 'count');
             $sum_entries += $row_count;
         } else {
             $row_count = $sts_data['Rows'];
             $sum_entries += $sts_data['Rows'];
         }
         $display_rows = number_format($row_count, 0, $number_decimal_separator, $number_thousands_separator);
     } else {
         if (isset($sts_data['Type']) && preg_match('@^(MRG_MyISAM|BerkeleyDB)$@', $sts_data['Type'])) {
             if ($cfg['ShowStats']) {
                 $formated_size = '&nbsp;-&nbsp;';
                 $unit = '';
             }
             $sum_entries += $sts_data['Rows'];
             $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
         } else {
Beispiel #7
0
    if (!empty($cfg['Server']['verbose'])) {
        $server_info = $cfg['Server']['verbose'];
    } else {
        $server_info = $cfg['Server']['host'];
    }
    $server_info .= empty($cfg['Server']['port']) ? '' : ':' . $cfg['Server']['port'];
    // loic1: skip this because it's not a so good idea to display sockets
    //        used to everybody
    // if (!empty($cfg['Server']['socket']) && PMA_PHP_INT_VERSION >= 30010) {
    //     $server_info .= ':' . $cfg['Server']['socket'];
    // }
    $local_query = 'SELECT VERSION() as version, USER() as user';
    $res = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, '');
    $mysql_cur_user_and_host = PMA_mysql_result($res, 0, 'user');
    $mysql_cur_user = substr($mysql_cur_user_and_host, 0, strrpos($mysql_cur_user_and_host, '@'));
    $full_string = str_replace('%pma_s1%', PMA_mysql_result($res, 0, 'version'), $strMySQLServerProcess);
    $full_string = str_replace('%pma_s2%', $server_info, $full_string);
    $full_string = str_replace('%pma_s3%', $mysql_cur_user_and_host, $full_string);
    echo '<p><b>' . $full_string . '</b></p><br />' . "\n";
}
// end if
/**
 * Reload mysql (flush privileges)
 */
if ($server > 0 && isset($mode) && $mode == 'reload') {
    $result = PMA_mysql_query('FLUSH PRIVILEGES');
    // Debug: or PMA_mysqlDie('', 'FLUSH PRIVILEGES', FALSE, 'main.php?' . PMA_generate_common_url());
    echo '<p><b>';
    if ($result != 0) {
        echo $strMySQLReloaded;
    } else {