コード例 #1
0
function PMA_DBI_get_dblist($link = NULL)
{
    if (empty($link)) {
        if (isset($GLOBALS['userlink'])) {
            $link = $GLOBALS['userlink'];
        } else {
            return FALSE;
        }
    }
    $res = PMA_DBI_try_query('SHOW DATABASES;', $link);
    $dbs_array = array();
    while ($row = PMA_DBI_fetch_row($res)) {
        // Before MySQL 4.0.2, SHOW DATABASES could send the
        // whole list, so check if we really have access:
        //if (PMA_MYSQL_CLIENT_API < 40002) {
        // Better check the server version, in case the client API
        // is more recent than the server version
        if (PMA_MYSQL_INT_VERSION < 40002) {
            $dblink = @PMA_DBI_select_db($row[0], $link);
            if (!$dblink) {
                continue;
            }
        }
        $dbs_array[] = $row[0];
    }
    PMA_DBI_free_result($res);
    unset($res);
    return $dbs_array;
}
コード例 #2
0
ファイル: pmd_common.php プロジェクト: AmberWish/laba_web
/**
 * returns JavaScript code for intializing vars
 *
 * @return string   JavaScript code
 */
function get_script_contr()
{
    PMA_DBI_select_db($GLOBALS['db']);
    $con["C_NAME"] = array();
    $i = 0;
    $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($GLOBALS['db']), null, PMA_DBI_QUERY_STORE);
    while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
        $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal');
        //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - ";
        //print_r($row);
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
        $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign');
        //echo "<br> INNO ";
        //print_r($row);
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
    }
    $ti = 0;
    $script_contr = '<script type="text/javascript">' . "\n" . '// <![CDATA[' . "\n" . 'var contr = new Array();' . "\n";
    for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
        $js_var = ' contr[' . $ti . ']';
        $script_contr .= $js_var . " = new Array();\n";
        $js_var .= "['" . $con['C_NAME'][$i] . "']";
        $script_contr .= $js_var . " = new Array();\n";
        if (in_array($con['DTN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"]) && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) {
            $js_var .= "['" . $con['DTN'][$i] . "']";
            $script_contr .= $js_var . " = new Array();\n";
            $m_col = array();
            //}
            $js_var .= "['" . $con['DCN'][$i] . "']";
            $script_contr .= $js_var . " = new Array();\n";
            //}
            $script_contr .= $js_var . "[0] = '" . $con['STN'][$i] . "';\n";
            //
            $script_contr .= $js_var . "[1] = '" . $con['SCN'][$i] . "';\n";
            //
        }
        $ti++;
    }
    $script_contr .= '// ]]>' . "\n" . '</script>' . "\n";
    return $script_contr;
}
コード例 #3
0
 /**
  * removes all databases not accessible by current user from list
  *
  * @access  protected
  * @uses    PMA_List_Database::$items
  * @uses    PMA_List_Database::$_db_link_user
  * @uses    PMA_List_Database::$_need_to_reindex to set it if reuqired
  * @uses    PMA_DBI_select_db()
  */
 function _checkAccess()
 {
     foreach ($this->items as $key => $db) {
         if (!@PMA_DBI_select_db($db, $this->_db_link_user)) {
             unset($this->items[$key]);
         }
     }
     // re-index values
     $this->_need_to_reindex = true;
 }
コード例 #4
0
ファイル: pmd_common.php プロジェクト: yxwzaxns/sakura
/**
 * returns JavaScript code for intializing vars
 *
 * @return string   JavaScript code
 */
function get_script_contr()
{
    PMA_DBI_select_db($GLOBALS['db']);
    $con["C_NAME"] = array();
    $i = 0;
    $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_Util::backquote($GLOBALS['db']), null, PMA_DBI_QUERY_STORE);
    while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
        $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal');
        //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - ";
        //print_r($row);
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
        $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign');
        //echo "<br> INNO ";
        //print_r($row);
        if ($row !== false) {
            foreach ($row as $field => $value) {
                $con['C_NAME'][$i] = '';
                $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
                $con['DCN'][$i] = urlencode($field);
                $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
                $con['SCN'][$i] = urlencode($value['foreign_field']);
                $i++;
            }
        }
    }
    $ti = 0;
    $retval = array();
    for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
        $c_name_i = $con['C_NAME'][$i];
        $dtn_i = $con['DTN'][$i];
        $retval[$ti] = array();
        $retval[$ti][$c_name_i] = array();
        if (in_array($dtn_i, $GLOBALS['PMD_URL']["TABLE_NAME"]) && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) {
            $retval[$ti][$c_name_i][$dtn_i] = array();
            $retval[$ti][$c_name_i][$dtn_i][$con['DCN'][$i]] = array(0 => $con['STN'][$i], 1 => $con['SCN'][$i]);
        }
        $ti++;
    }
    return $retval;
}
コード例 #5
0
ファイル: relation.lib.php プロジェクト: lifecom/test
/**
 * Executes a query as controluser if possible, otherwise as normal user
 *
 * @param   string    the query to execute
 * @param   boolean   whether to display SQL error messages or not
 *
 * @return  integer   the result id
 *
 * @global  string    the URL of the page to show in case of error
 * @global  string    the name of db to come back to
 * @global  resource  the resource id of DB connect as controluser
 * @global  array     configuration infos about the relations stuff
 *
 * @access  public
 *
 * @author  Mike Beck <*****@*****.**>
 */
function PMA_query_as_cu($sql, $show_error = TRUE, $options = 0)
{
    global $err_url_0, $db, $dbh, $cfgRelation;
    PMA_DBI_select_db($cfgRelation['db'], $dbh);
    if ($show_error) {
        $result = PMA_DBI_query($sql, $dbh, $options);
    } else {
        $result = @PMA_DBI_try_query($sql, $dbh, $options);
    }
    // end if... else...
    PMA_DBI_select_db($db, $dbh);
    if ($result) {
        return $result;
    } else {
        return FALSE;
    }
}
コード例 #6
0
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH') . "\n";
?>
        </td>
    </tr>

<?php 
// Referential integrity check
// The Referential integrity check was intended for the non-InnoDB
// tables for which the relations are defined in pmadb
// so I assume that if the current table is InnoDB, I don't display
// this choice (InnoDB maintains integrity by itself)
if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
    // we need this PMA_DBI_select_db if the user has access to more than one db
    // and $db is not the last of the list, because PMA_availableDatabases()
    // has made a PMA_DBI_select_db() on the last one
    PMA_DBI_select_db($db);
    $foreign = PMA_getForeigners($db, $table);
    if ($foreign) {
        ?>
    <!-- Referential integrity check -->
    <tr>
        <td bgcolor="<?php 
        echo $cfg['BgcolorOne'];
        ?>
" colspan="2">
                <?php 
        echo $strReferentialIntegrity;
        ?>
<br />
                <?php 
        echo "\n";
コード例 #7
0
ファイル: common.lib.php プロジェクト: Apxe/Rubin_final
 /**
  * Get the list and number of available databases.
  *
  * @param   string   the url to go back to in case of error
  *
  * @return  boolean  always true
  *
  * @global  array    the list of available databases
  * @global  integer  the number of available databases
  * @global  array    current configuration
  */
 function PMA_availableDatabases($error_url = '')
 {
     global $dblist;
     global $num_dbs;
     global $cfg;
     $num_dbs = count($dblist);
     // 1. A list of allowed databases has already been defined by the
     //    authentification process -> gets the available databases list
     if ($num_dbs) {
         $true_dblist = array();
         for ($i = 0; $i < $num_dbs; $i++) {
             $dblink = @PMA_DBI_select_db($dblist[$i]);
             if ($dblink) {
                 $true_dblist[] = $dblist[$i];
             }
             // end if
         }
         // end for
         $dblist = array();
         $dblist = $true_dblist;
         unset($true_dblist);
         $num_dbs = count($dblist);
     } else {
         if (!isset($cfg['Server']['only_db']) || $cfg['Server']['only_db'] == '') {
             $dblist = PMA_DBI_get_dblist();
             // needed? or PMA_mysqlDie('', 'SHOW DATABASES;', FALSE, $error_url);
             $num_dbs = count($dblist);
         }
     }
     // end else
     return TRUE;
 }
コード例 #8
0
 * Note: this can be called also from the db panel to get the privileges of
 *       a db, in which case we want to keep displaying the tabs of
 *       the Database panel
 */
if (empty($viewing_mode)) {
    $db = $table = '';
}
/**
 * Set parameters for links
 */
$url_query = PMA_generate_common_url($db);
/**
 * Defines the urls to return to in case of error in a sql statement
 */
$err_url = 'main.php' . $url_query;
/**
 * Displays the headers
 */
require_once './libraries/header.inc.php';
/**
 * @global boolean Checks for superuser privileges
 */
$is_superuser = PMA_isSuperuser();
// now, select the mysql db
if ($is_superuser) {
    PMA_DBI_select_db('mysql', $userlink);
}
/**
 * @global array binary log files
 */
$binary_logs = PMA_DBI_fetch_result('SHOW MASTER LOGS', 'Log_name', null, null, PMA_DBI_QUERY_STORE);
コード例 #9
0
/**
 * Displays the headers of the results table
 *
 * @param   array    which elements to display
 * @param   array    the list of fields properties
 * @param   integer  the total number of fields returned by the sql query
 * @param   array    the analyzed query
 *
 * @return  boolean  always true
 *
 * @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  boolean  $dontlimitchars   whether to limit the number of displayed
 *                                     characters of text type fields or not
 * @global  string   $sql_query        the sql query
 * @global  integer  $num_rows         the total number of rows returned by the
 *                                     sql query
 * @global  integer  $pos              the current position in results
 * @global  integer  $session_max_rows the maximum number of rows per page
 * @global  array    $vertical_display informations used with vertical display
 *                                     mode
 * @global  string   $disp_direction   the display mode
 *                                     (horizontal/vertical/horizontalflipped)
 * @global  integer  $repeat_cellsthe  number of row to display between two
 *                                     table headers
 *
 * @access  private
 *
 * @see     PMA_displayTable()
 */
function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
{
    global $db, $table, $goto, $dontlimitchars;
    global $sql_query, $num_rows, $pos, $session_max_rows;
    global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
    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'];
        }
        // we need $sort_expression and $sort_expression_nodir
        // even if there are many table references
        $sort_expression = trim(str_replace('  ', ' ', $analyzed_sql[0]['order_by_clause']));
        // Get rid of ASC|DESC (TODO: analyzer)
        preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
        $sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
        // 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:
            PMA_DBI_select_db($db);
            if (!defined('PMA_IDX_INCLUDED')) {
                $ret_keys = PMA_get_indexes($table);
            }
            $prev_index = '';
            foreach ($ret_keys as $row) {
                if ($row['Key_name'] != $prev_index) {
                    $indexes[] = $row['Key_name'];
                    $prev_index = $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 the following column mean....
                //    $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
                $indexes_info[$row['Key_name']]['Comment'] = isset($row['Comment']) ? $row['Comment'] : '';
                $indexes_info[$row['Key_name']]['Index_type'] = isset($row['Index_type']) ? $row['Index_type'] : '';
                $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
            // do we have any index?
            if (isset($indexes_data)) {
                if ($disp_direction == 'horizontal' || $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 / $repeat_cells) + 1;
                }
                echo '<form action="sql.php" method="post">' . "\n";
                echo PMA_generate_common_hidden_inputs($db, $table, 5);
                echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
                echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
                echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
                echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
                echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
                echo $GLOBALS['strSortByKey'] . ': <select name="sql_query">' . "\n";
                $used_index = false;
                $local_order = isset($sort_expression) ? $sort_expression : '';
                foreach ($indexes_data as $key => $val) {
                    $asc_sort = '';
                    $desc_sort = '';
                    foreach ($val as $key2 => $val2) {
                        $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
                        $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
                    }
                    $asc_sort = substr($asc_sort, 0, -3);
                    $desc_sort = substr($desc_sort, 0, -3);
                    $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
                    echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
                    echo "\n";
                    echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
                    echo "\n";
                }
                echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
                echo "\n";
                echo '</select>' . "\n";
                echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
                echo "\n";
                echo '</form>' . "\n";
            }
        }
    }
    $vertical_display['emptypre'] = 0;
    $vertical_display['emptyafter'] = 0;
    $vertical_display['textbtn'] = '';
    // Start of form for multi-rows delete
    if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
        echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
        echo PMA_generate_common_hidden_inputs($db, $table, 1);
        echo '<input type="hidden" name="disp_direction"   value="' . $disp_direction . '" />' . "\n";
        echo '<input type="hidden" name="repeat_cells"     value="' . $repeat_cells . '" />' . "\n";
        echo '<input type="hidden" name="dontlimitchars"   value="' . $dontlimitchars . '" />' . "\n";
        echo '<input type="hidden" name="pos"              value="' . $pos . '" />' . "\n";
        echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
        echo '<input type="hidden" name="goto"             value="sql.php" />' . "\n";
    }
    echo '<table id="table_results" class="data">' . "\n";
    if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
        echo '<thead><tr>' . "\n";
    }
    // 1. Displays the full/partial text button (part 1)...
    if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
        $colspan = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' colspan="3"' : '';
    } else {
        $rowspan = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' rowspan="3"' : '';
    }
    $text_url = 'sql.php?' . PMA_generate_common_url($db, $table) . '&amp;sql_query=' . urlencode($sql_query) . '&amp;session_max_rows=' . $session_max_rows . '&amp;pos=' . $pos . '&amp;disp_direction=' . $disp_direction . '&amp;repeat_cells=' . $repeat_cells . '&amp;goto=' . $goto . '&amp;dontlimitchars=' . ($dontlimitchars ? 0 : 1);
    $text_message = '<img class="fulltext" src="' . $GLOBALS['pmaThemeImage'] . 's_' . ($dontlimitchars ? 'partialtext' : 'fulltext') . '.png" width="50" height="20" alt="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" />';
    $text_link = PMA_linkOrButton($text_url, $text_message, array(), false);
    //     ... 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' ? 3 : 0;
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            ?>
    <th colspan="<?php 
            echo $fields_cnt;
            ?>
"><?php 
            echo $text_link;
            ?>
</th>
</tr>
<tr>
            <?php 
        } else {
            ?>
<tr>
    <th colspan="<?php 
            echo $num_rows + floor($num_rows / $repeat_cells) + 1;
            ?>
">
        <?php 
            echo $text_link;
            ?>
</th>
</tr>
            <?php 
        }
        // end vertical mode
    } elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
        $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 0;
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            ?>
    <th <?php 
            echo $colspan;
            ?>
><?php 
            echo $text_link;
            ?>
</th>
            <?php 
        } else {
            $vertical_display['textbtn'] = '    <th ' . $rowspan . ' valign="middle">' . "\n" . '        ' . $text_link . "\n" . '    </th>' . "\n";
        }
        // end vertical mode
    } elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
        $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 0;
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            ?>
    <td<?php 
            echo $colspan;
            ?>
></td>
            <?php 
        } else {
            $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
        }
        // end vertical mode
    }
    // 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'] && ($GLOBALS['cfgRelation']['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) && $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']) {
        require_once './libraries/transformations.lib.php';
        $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
    }
    if ($is_display['sort_lnk'] == '1') {
        //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt);
        $is_join = isset($analyzed_sql[0]['queryflags']['join']) ? true : false;
        $select_expr = $analyzed_sql[0]['select_expr_clause'];
    } else {
        $is_join = false;
    }
    // garvin: 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';
            }
        }
    }
    for ($i = 0; $i < $fields_cnt; $i++) {
        // garvin: 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`
            /**
             * we prefer always using table if existing
             * and second this code does not correctly check $fields_meta[$i]->table
            if (($is_join
                && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . strtr($fields_meta[$i]->name, array('[' => '\\[', '~' => '\\~', '\\' => '\\\\')) . '~i', $select_expr, $parts))
               || (isset($analyzed_sql[0]['select_expr'][$i]['expr'])
                   && isset($analyzed_sql[0]['select_expr'][$i]['column'])
                   && $analyzed_sql[0]['select_expr'][$i]['expr'] !=
                   $analyzed_sql[0]['select_expr'][$i]['column']
                  && isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table))) {
            */
            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
            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 (avoids problems with queries
                // like "SELECT id, count(id)..." and clicking to sort
                // on id or on count(id))
                $is_in_sort = $sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? true : false;
            }
            // 2.1.3 Check the field name for backquotes.
            //       If it contains some, it's probably a function column
            //       like 'COUNT(`field`)'
            if (strpos($fields_meta[$i]->name, '`') !== false) {
                $sort_order = ' ORDER BY ' . PMA_backquote($fields_meta[$i]->name) . ' ';
            } else {
                $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
            }
            // 2.1.4 Do define the sorting url
            if (!$is_in_sort) {
                // loic1: patch #455484 ("Smart" order)
                $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
                if ($GLOBALS['cfg']['Order'] == 'SMART') {
                    $GLOBALS['cfg']['Order'] = preg_match('@time|date@i', $fields_meta[$i]->type) ? 'DESC' : 'ASC';
                }
                $sort_order .= $GLOBALS['cfg']['Order'];
                $order_img = '';
            } elseif (preg_match('@[[:space:]]ASC$@i', $sort_expression)) {
                $sort_order .= ' DESC';
                $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="' . $GLOBALS['strAscending'] . '" title="' . $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
            } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
                $sort_order .= ' ASC';
                $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="' . $GLOBALS['strDescending'] . '" title="' . $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
            } else {
                $sort_order .= ' DESC';
                $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="' . $GLOBALS['strAscending'] . '" title="' . $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
            }
            if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
                $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
            } else {
                $sorted_sql_query = $unsorted_sql_query . $sort_order;
            }
            $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 . '&amp;sql_query=' . urlencode($sorted_sql_query);
            $order_url = 'sql.php?' . $url_query;
            // 2.1.5 Displays the sorting url
            // added 20004-06-09: Michael Keck <*****@*****.**>
            //                    enable sord order swapping for image
            $order_link_params = array();
            if (isset($order_img) && $order_img != '') {
                if (strstr($order_img, 'asc')) {
                    $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
                    $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
                } elseif (strstr($order_img, 'desc')) {
                    $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
                    $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
                }
            }
            if ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
                $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
            }
            $order_link_params['title'] = $GLOBALS['strSort'];
            $order_link_content = $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 ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
                echo '<th';
                if ($condition_field) {
                    echo ' class="condition"';
                }
                if ($disp_direction == 'horizontalflipped') {
                    echo ' valign="bottom"';
                }
                echo '>' . $order_link . $comments . '</th>';
            }
            $vertical_display['desc'][] = '    <th ' . ($condition_field ? ' class="condition"' : '') . '>' . "\n" . $order_link . $comments . '    </th>' . "\n";
        } else {
            if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
                echo '<th';
                if ($condition_field) {
                    echo ' class="condition"';
                }
                if ($disp_direction == 'horizontalflipped') {
                    echo ' valign="bottom"';
                }
                if ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
                    echo ' style="direction: ltr; writing-mode: tb-rl;"';
                }
                echo '>';
                if ($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 ' . ($condition_field ? ' class="condition"' : '') . '>' . "\n" . '        ' . htmlspecialchars($fields_meta[$i]->name) . "\n" . $comments . '    </th>';
        }
        // end else (2.2)
    }
    // end for
    // 3. Displays the full/partial text button (part 2) at the right
    //    column of the result table header if possible and required...
    if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($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' ? 3 : 1;
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            echo "\n";
            ?>
<th <?php 
            echo $colspan;
            ?>
>
    <?php 
            echo $text_link;
            ?>
</th>
            <?php 
        } else {
            $vertical_display['textbtn'] = '    <th ' . $rowspan . ' valign="middle">' . "\n" . '        ' . $text_link . "\n" . '    </th>' . "\n";
        }
        // end vertical mode
    } elseif ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($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' ? 3 : 1;
        if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
            echo "\n";
            ?>
<td<?php 
            echo $colspan;
            ?>
></td>
            <?php 
        } else {
            $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
        }
        // end vertical mode
    }
    if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
        ?>
</tr>
</thead>
        <?php 
    }
    return true;
}
コード例 #10
0
/**
 * This function provides synchronization of structure and data between two mysql servers. 
 * TODO: improve code sharing between the function and synchronization
 *
 * @param String $db - name of database, which should be synchronized
 * @param mixed $src_link - link of source server, note: if the server is current PMA server, use null
 * @param mixed $trg_link - link of target server, note: if the server is current PMA server, use null
 * @param boolean $data - if true, then data will be copied as well
 */
function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true)
{
    $src_db = $trg_db = $db;
    $src_connection = PMA_DBI_select_db($src_db, $src_link);
    $trg_connection = PMA_DBI_select_db($trg_db, $trg_link);
    $src_tables = PMA_DBI_get_tables($src_db, $src_link);
    $source_tables_num = sizeof($src_tables);
    $trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
    $target_tables_num = sizeof($trg_tables);
    /**
     * initializing arrays to save table names 
     */
    $unmatched_num_src = 0;
    $source_tables_uncommon = array();
    $unmatched_num_trg = 0;
    $target_tables_uncommon = array();
    $matching_tables = array();
    $matching_tables_num = 0;
    /**
     * Criterion for matching tables is just their names.
     * Finding the uncommon tables for the source database
     * BY comparing the matching tables with all the tables in the source database
     */
    PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);
    /**
     * Finding the uncommon tables for the target database
     * BY comparing the matching tables with all the tables in the target database
     */
    PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);
    /**
     * 
     * Comparing Data In the Matching Tables 
     * It is assumed that the matching tables are structurally 
     * and typely exactly the same  
     */
    $fields_num = array();
    $matching_tables_fields = array();
    $matching_tables_keys = array();
    $insert_array = array(array(array()));
    $update_array = array(array(array()));
    $delete_array = array();
    $row_count = array();
    $uncommon_tables_fields = array();
    $matching_tables_num = sizeof($matching_tables);
    for ($i = 0; $i < sizeof($matching_tables); $i++) {
        PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array, $delete_array, $fields_num, $i, $matching_tables_keys);
    }
    for ($j = 0; $j < sizeof($source_tables_uncommon); $j++) {
        PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count);
    }
    /**
     * INTEGRATION OF STRUCTURE DIFFERENCE CODE
     *
     */
    $source_columns = array();
    $target_columns = array();
    $alter_str_array = array(array());
    $add_column_array = array(array());
    $uncommon_columns = array();
    $target_tables_keys = array();
    $source_indexes = array();
    $target_indexes = array();
    $add_indexes_array = array();
    $remove_indexes_array = array();
    $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');
    for ($counter = 0; $counter < $matching_tables_num; $counter++) {
        PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $counter);
        PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, $alter_indexes_array, $remove_indexes_array, $counter);
    }
    $matching_table_data_diff = array();
    $matching_table_structure_diff = array();
    $uncommon_table_structure_diff = array();
    $uncommon_table_data_diff = array();
    $uncommon_tables = $source_tables_uncommon;
    /**
     * Generating Create Table query for all the non-matching tables present in Source but not in Target and populating tables.  
     */
    for ($q = 0; $q < sizeof($source_tables_uncommon); $q++) {
        if (isset($uncommon_tables[$q])) {
            PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, false);
        }
        if (isset($row_count[$q]) && $data) {
            PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, false);
        }
    }
}
コード例 #11
0
 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy)
 {
     global $cfgRelation;
     if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strTableStructure'] . ' ' . $table . '</h2>')) {
         return FALSE;
     }
     /**
      * Get the unique keys in the table
      */
     $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
     $keys_result = PMA_DBI_query($keys_query);
     $unique_keys = array();
     while ($key = PMA_DBI_fetch_assoc($keys_result)) {
         if ($key['Non_unique'] == 0) {
             $unique_keys[] = $key['Column_name'];
         }
     }
     PMA_DBI_free_result($keys_result);
     /**
      * Gets fields properties
      */
     PMA_DBI_select_db($db);
     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
     $result = PMA_DBI_query($local_query);
     $fields_cnt = PMA_DBI_num_rows($result);
     // Check if we can use Relations (Mike Beck)
     if ($do_relation && !empty($cfgRelation['relation'])) {
         // Find which tables are related with the current one and write it in
         // an array
         $res_rel = PMA_getForeigners($db, $table);
         if ($res_rel && count($res_rel) > 0) {
             $have_rel = TRUE;
         } else {
             $have_rel = FALSE;
         }
     } else {
         $have_rel = FALSE;
     }
     // end if
     /**
      * Displays the table structure
      */
     if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) {
         return FALSE;
     }
     $columns_cnt = 4;
     if ($do_relation && $have_rel) {
         $columns_cnt++;
     }
     if ($do_comments && $cfgRelation['commwork']) {
         $columns_cnt++;
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $columns_cnt++;
     }
     $schema_insert = '<tr class="print-category">';
     $schema_insert .= '<th class="print">' . htmlspecialchars($GLOBALS['strField']) . '</th>';
     $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strType']) . '</b></td>';
     $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strNull']) . '</b></td>';
     $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strDefault']) . '</b></td>';
     if ($do_relation && $have_rel) {
         $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strLinksTo']) . '</b></td>';
     }
     if ($do_comments) {
         $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strComments']) . '</b></td>';
         $comments = PMA_getComments($db, $table);
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $schema_insert .= '<td class="print"><b>' . htmlspecialchars('MIME') . '</b></td>';
         $mime_map = PMA_getMIME($db, $table, true);
     }
     $schema_insert .= '</tr>';
     if (!PMA_exportOutputHandler($schema_insert)) {
         return FALSE;
     }
     while ($row = PMA_DBI_fetch_assoc($result)) {
         $schema_insert = '<tr class="print-category">';
         $type = $row['Type'];
         // reformat mysql query output - staybyte - 9. June 2001
         // loic1: 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 = preg_match('/BINARY/i', $row['Type']);
             $unsigned = preg_match('/UNSIGNED/i', $row['Type']);
             $zerofill = preg_match('/ZEROFILL/i', $row['Type']);
         }
         $strAttribute = '&nbsp;';
         if ($binary) {
             $strAttribute = 'BINARY';
         }
         if ($unsigned) {
             $strAttribute = 'UNSIGNED';
         }
         if ($zerofill) {
             $strAttribute = 'UNSIGNED ZEROFILL';
         }
         if (!isset($row['Default'])) {
             if ($row['Null'] != 'NO') {
                 $row['Default'] = 'NULL';
             }
         } else {
             $row['Default'] = $row['Default'];
         }
         $fmt_pre = '';
         $fmt_post = '';
         if (in_array($row['Field'], $unique_keys)) {
             $fmt_pre = '<b>' . $fmt_pre;
             $fmt_post = $fmt_post . '</b>';
         }
         if ($row['Key'] == 'PRI') {
             $fmt_pre = '<i>' . $fmt_pre;
             $fmt_post = $fmt_post . '</i>';
         }
         $schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($row['Field']) . $fmt_post . '</td>';
         $schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>';
         $schema_insert .= '<td class="print">' . htmlspecialchars($row['Null'] == '' || $row['Null'] == 'NO' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . '</td>';
         $schema_insert .= '<td class="print">' . htmlspecialchars(isset($row['Default']) ? $row['Default'] : '') . '</td>';
         $field_name = $row['Field'];
         if ($do_relation && $have_rel) {
             $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>';
         }
         if ($do_comments && $cfgRelation['commwork']) {
             $schema_insert .= '<td class="print">' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>';
         }
         if ($do_mime && $cfgRelation['mimework']) {
             $schema_insert .= '<td class="print">' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>';
         }
         $schema_insert .= '</tr>';
         if (!PMA_exportOutputHandler($schema_insert)) {
             return FALSE;
         }
     }
     // end while
     PMA_DBI_free_result($result);
     return PMA_exportOutputHandler('</table>');
 }
コード例 #12
0
/**
 * creates a HTTP link to a given blob reference for a given database
 *
 * @access  public
 * @param   string - BLOB reference
 * @param   string - database name
 * @uses    PMA_Config::get()
 * @uses    PMA_DBI_select_db()
 * @uses    PMA_backquote()
 * @uses    PMA_sqlAddslashes()
 * @uses    PMA_DBI_query()
 * @uses    PMA_DBI_fetch_assoc()
 * @return  string - HTTP link or Error
*/
function PMA_BS_CreateReferenceLink($bs_reference, $db_name)
{
    // load PMA configuration
    $PMA_Config = $_SESSION['PMA_Config'];
    // return if unable to load PMA configuration
    if (empty($PMA_Config)) {
        return '';
    }
    // generate bs reference link
    $bs_ref_link = 'http://' . $PMA_Config->get('BLOBSTREAMING_SERVER') . '/' . $bs_reference;
    // select specified database
    PMA_DBI_select_db($db_name);
    $pbms_repo_bq = PMA_backquote($PMA_Config->get('PBMS_NAME') . "_repository");
    $pbms_ref_bq = PMA_backquote($PMA_Config->get('PBMS_NAME') . "_reference");
    $pbms_cust_content_bq = PMA_backquote($PMA_Config->get('PBMS_NAME') . "_custom_content_type");
    // run query on determining specified BS reference
    $query = "SELECT {$pbms_repo_bq}.Content_type, {$pbms_cust_content_bq}.Content_type AS Custom_type";
    $query .= " FROM {$pbms_repo_bq} LEFT JOIN {$pbms_ref_bq} ON";
    $query .= "{$pbms_repo_bq}.Repository_id={$pbms_ref_bq}.Repository_id";
    $query .= " AND {$pbms_repo_bq}.Blob_size={$pbms_ref_bq}.Blob_size";
    $query .= " AND {$pbms_repo_bq}.Repo_blob_offset={$pbms_ref_bq}.Repo_blob_offset";
    $query .= " LEFT JOIN {$pbms_cust_content_bq} ON {$pbms_cust_content_bq}.Blob_url={$pbms_ref_bq}.Blob_url";
    $query .= " WHERE {$pbms_ref_bq}.Blob_url='" . PMA_sqlAddslashes($bs_reference) . "'";
    $result = PMA_DBI_query($query);
    // if record exists
    if ($data = @PMA_DBI_fetch_assoc($result)) {
        // determine content-type for BS repository file (original or custom)
        $is_custom_type = false;
        if (isset($data['Custom_type'])) {
            $content_type = $data['Custom_type'];
            $is_custom_type = true;
        } else {
            $content_type = $data['Content_type'];
        }
        if (!$content_type) {
            $content_type = NULL;
        }
        $output = "<a href=\"#\" onclick=\"requestMIMETypeChange('" . urlencode($db_name) . "', '" . urlencode($GLOBALS['table']) . "', '" . urlencode($bs_reference) . "', '" . urlencode($content_type) . "')\">{$content_type}</a>";
        // specify custom HTML for various content types
        switch ($content_type) {
            // no content specified
            case NULL:
                $output = "NULL";
                break;
                // image content
            // image content
            case 'image/jpeg':
            case 'image/png':
                $output .= ' (<a href="' . $bs_ref_link . '" target="new">' . $GLOBALS['strViewImage'] . '</a>)';
                break;
                // audio content
            // audio content
            case 'audio/mpeg':
                $output .= ' (<a href="#" onclick="popupBSMedia(\'' . PMA_generate_common_url() . '\',\'' . urlencode($bs_reference) . '\', \'' . urlencode($content_type) . '\',' . ($is_custom_type ? 1 : 0) . ', 640, 120)">' . $GLOBALS['strPlayAudio'] . '</a>)';
                break;
                // video content
            // video content
            case 'application/x-flash-video':
            case 'video/mpeg':
                $output .= ' (<a href="#" onclick="popupBSMedia(\'' . PMA_generate_common_url() . '\',\'' . urlencode($bs_reference) . '\', \'' . urlencode($content_type) . '\',' . ($is_custom_type ? 1 : 0) . ', 640, 480)">' . $GLOBALS['strViewVideo'] . '</a>)';
                break;
                // unsupported content. specify download
            // unsupported content. specify download
            default:
                $output .= ' (<a href="' . $bs_ref_link . '" target="new">' . $GLOBALS['strDownloadFile'] . '</a>)';
        }
        // return HTML
        return $output;
    }
    // end if ($data = @PMA_DBI_fetch_assoc($result))
    // return on error
    return 'Error';
}
コード例 #13
0
ファイル: User_Schema.class.php プロジェクト: htom78/project
 /**
  * get all the export options and verify
  * call and include the appropriate Schema Class depending on $export_type
  *
  * @return void
  * @access private
  */
 private function _processExportSchema()
 {
     /**
      * Settings for relation stuff
      */
     include_once './libraries/transformations.lib.php';
     include_once './libraries/Index.class.php';
     /**
      * default is PDF, otherwise validate it's only letters a-z
      */
     global $db, $export_type;
     if (!isset($export_type) || !preg_match('/^[a-zA-Z]+$/', $export_type)) {
         $export_type = 'pdf';
     }
     PMA_DBI_select_db($db);
     include "./libraries/schema/" . ucfirst($export_type) . "_Relation_Schema.class.php";
     $obj_schema = eval("new PMA_" . ucfirst($export_type) . "_Relation_Schema();");
 }
コード例 #14
0
ファイル: latex.php プロジェクト: ljhchshm/weixin
 /**
  * Outputs table's structure
  *
  * @param string $db          database name
  * @param string $table       table name
  * @param string $crlf        the end of line sequence
  * @param string $error_url   the url to go back in case of error
  * @param bool   $do_relation whether to include relation comments
  * @param bool   $do_comments whether to include the pmadb-style column comments
  *                            as comments in the structure; this is deprecated
  *                            but the parameter is left here because export.php
  *                            calls PMA_exportStructure() also for other export
  *                            types which use this parameter
  * @param bool   $do_mime     whether to include mime comments
  * @param bool   $dates       whether to include creation/update/check dates
  * @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
  * @param string $export_type 'server', 'database', 'table'
  *
  * @return bool Whether it succeeded
  *
  * @access public
  */
 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
 {
     global $cfgRelation;
     /* We do not export triggers */
     if ($export_mode == 'triggers') {
         return true;
     }
     /**
      * Get the unique keys in the table
      */
     $unique_keys = array();
     $keys = PMA_DBI_get_table_indexes($db, $table);
     foreach ($keys as $key) {
         if ($key['Non_unique'] == 0) {
             $unique_keys[] = $key['Column_name'];
         }
     }
     /**
      * Gets fields properties
      */
     PMA_DBI_select_db($db);
     // Check if we can use Relations
     if ($do_relation && !empty($cfgRelation['relation'])) {
         // Find which tables are related with the current one and write it in
         // an array
         $res_rel = PMA_getForeigners($db, $table);
         if ($res_rel && count($res_rel) > 0) {
             $have_rel = true;
         } else {
             $have_rel = false;
         }
     } else {
         $have_rel = false;
     }
     // end if
     /**
      * Displays the table structure
      */
     $buffer = $crlf . '%' . $crlf . '% ' . __('Structure') . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{';
     if (!PMA_exportOutputHandler($buffer)) {
         return false;
     }
     $columns_cnt = 4;
     $alignment = '|l|c|c|c|';
     if ($do_relation && $have_rel) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     if ($do_comments) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     $buffer = $alignment . '} ' . $crlf;
     $header = ' \\hline ';
     $header .= '\\multicolumn{1}{|c|}{\\textbf{' . __('Column') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Type') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Null') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Default') . '}}';
     if ($do_relation && $have_rel) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Links to') . '}}';
     }
     if ($do_comments) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}';
         $comments = PMA_getComments($db, $table);
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
         $mime_map = PMA_getMIME($db, $table, true);
     }
     // Table caption for first page and label
     if (isset($GLOBALS['latex_caption'])) {
         $buffer .= ' \\caption{' . PMA_expandUserString($GLOBALS['latex_structure_caption'], 'PMA_texEscape', array('table' => $table, 'database' => $db)) . '} \\label{' . PMA_expandUserString($GLOBALS['latex_structure_label'], null, array('table' => $table, 'database' => $db)) . '} \\\\' . $crlf;
     }
     $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
     // Table caption on next pages
     if (isset($GLOBALS['latex_caption'])) {
         $buffer .= ' \\caption{' . PMA_expandUserString($GLOBALS['latex_structure_continued_caption'], 'PMA_texEscape', array('table' => $table, 'database' => $db)) . '} \\\\ ' . $crlf;
     }
     $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf;
     if (!PMA_exportOutputHandler($buffer)) {
         return false;
     }
     $fields = PMA_DBI_get_columns($db, $table);
     foreach ($fields as $row) {
         $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
         $type = $extracted_fieldspec['print_type'];
         if (empty($type)) {
             $type = ' ';
         }
         if (!isset($row['Default'])) {
             if ($row['Null'] != 'NO') {
                 $row['Default'] = 'NULL';
             }
         }
         $field_name = $row['Field'];
         $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes')) . "" . (isset($row['Default']) ? $row['Default'] : '');
         if ($do_relation && $have_rel) {
             $local_buffer .= "";
             if (isset($res_rel[$field_name])) {
                 $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')';
             }
         }
         if ($do_comments && $cfgRelation['commwork']) {
             $local_buffer .= "";
             if (isset($comments[$field_name])) {
                 $local_buffer .= $comments[$field_name];
             }
         }
         if ($do_mime && $cfgRelation['mimework']) {
             $local_buffer .= "";
             if (isset($mime_map[$field_name])) {
                 $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
             }
         }
         $local_buffer = PMA_texEscape($local_buffer);
         if ($row['Key'] == 'PRI') {
             $pos = strpos($local_buffer, "");
             $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
         }
         if (in_array($field_name, $unique_keys)) {
             $pos = strpos($local_buffer, "");
             $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
         }
         $buffer = str_replace("", ' & ', $local_buffer);
         $buffer .= ' \\\\ \\hline ' . $crlf;
         if (!PMA_exportOutputHandler($buffer)) {
             return false;
         }
     }
     // end while
     $buffer = ' \\end{longtable}' . $crlf;
     return PMA_exportOutputHandler($buffer);
 }
コード例 #15
0
ファイル: relation.lib.php プロジェクト: hoogle/ttt
/**
 * Defines the relation parameters for the current user
 * just a copy of the functions used for relations ;-)
 * but added some stuff to check what will work
 *
 * @param   boolean  whether to check validity of settings or not
 *
 * @return  array    the relation parameters for the current user
 *
 * @global  array    the list of settings for servers
 * @global  integer  the id of the current server
 * @global  string   the URL of the page to show in case of error
 * @global  string   the name of the current db
 * @global  string   the name of the current table
 * @global  array    configuration infos about the relations stuff
 *
 * @access  public
 *
 * @author  Mike Beck <*****@*****.**>
 */
function PMA_getRelationsParam($verbose = FALSE)
{
    global $cfg, $server, $err_url_0, $db, $table, $controllink;
    global $cfgRelation;
    $cfgRelation = array();
    $cfgRelation['relwork'] = FALSE;
    $cfgRelation['displaywork'] = FALSE;
    $cfgRelation['bookmarkwork'] = FALSE;
    $cfgRelation['pdfwork'] = FALSE;
    $cfgRelation['commwork'] = FALSE;
    $cfgRelation['mimework'] = FALSE;
    $cfgRelation['historywork'] = FALSE;
    $cfgRelation['allworks'] = FALSE;
    // No server selected -> no bookmark table
    // we return the array with the FALSEs in it,
    // to avoid some 'Unitialized string offset' errors later
    if ($server == 0 || empty($cfg['Server']) || empty($cfg['Server']['pmadb'])) {
        if ($verbose == TRUE) {
            echo 'PMA Database ... ' . '<font color="red"><b>' . $GLOBALS['strNotOK'] . '</b></font>' . '[ <a href="Documentation.html#pmadb">' . $GLOBALS['strDocu'] . '</a> ]<br />' . "\n" . $GLOBALS['strGeneralRelationFeat'] . ' <font color="green">' . $GLOBALS['strDisabled'] . '</font>' . "\n";
        }
        return $cfgRelation;
    }
    $cfgRelation['user'] = $cfg['Server']['user'];
    $cfgRelation['db'] = $cfg['Server']['pmadb'];
    //  Now I just check if all tables that i need are present so I can for
    //  example enable relations but not pdf...
    //  I was thinking of checking if they have all required columns but I
    //  fear it might be too slow
    PMA_DBI_select_db($cfgRelation['db'], $controllink);
    $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($cfgRelation['db']);
    $tab_rs = PMA_query_as_cu($tab_query, FALSE, PMA_DBI_QUERY_STORE);
    if ($tab_rs) {
        while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) {
            if ($curr_table[0] == $cfg['Server']['bookmarktable']) {
                $cfgRelation['bookmark'] = $curr_table[0];
            } elseif ($curr_table[0] == $cfg['Server']['relation']) {
                $cfgRelation['relation'] = $curr_table[0];
            } elseif ($curr_table[0] == $cfg['Server']['table_info']) {
                $cfgRelation['table_info'] = $curr_table[0];
            } elseif ($curr_table[0] == $cfg['Server']['table_coords']) {
                $cfgRelation['table_coords'] = $curr_table[0];
            } elseif ($curr_table[0] == $cfg['Server']['column_info']) {
                $cfgRelation['column_info'] = $curr_table[0];
            } elseif ($curr_table[0] == $cfg['Server']['pdf_pages']) {
                $cfgRelation['pdf_pages'] = $curr_table[0];
            } elseif ($curr_table[0] == $cfg['Server']['history']) {
                $cfgRelation['history'] = $curr_table[0];
            }
        }
        // end while
    }
    if (isset($cfgRelation['relation'])) {
        $cfgRelation['relwork'] = TRUE;
        if (isset($cfgRelation['table_info'])) {
            $cfgRelation['displaywork'] = TRUE;
        }
    }
    if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) {
        $cfgRelation['pdfwork'] = TRUE;
    }
    if (isset($cfgRelation['column_info'])) {
        $cfgRelation['commwork'] = TRUE;
        if ($cfg['Server']['verbose_check']) {
            $mime_query = 'SHOW FIELDS FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']);
            $mime_rs = PMA_query_as_cu($mime_query, FALSE);
            $mime_field_mimetype = FALSE;
            $mime_field_transformation = FALSE;
            $mime_field_transformation_options = FALSE;
            while ($curr_mime_field = @PMA_DBI_fetch_row($mime_rs)) {
                if ($curr_mime_field[0] == 'mimetype') {
                    $mime_field_mimetype = TRUE;
                } elseif ($curr_mime_field[0] == 'transformation') {
                    $mime_field_transformation = TRUE;
                } elseif ($curr_mime_field[0] == 'transformation_options') {
                    $mime_field_transformation_options = TRUE;
                }
            }
            PMA_DBI_free_result($mime_rs);
            if ($mime_field_mimetype == TRUE && $mime_field_transformation == TRUE && $mime_field_transformation_options == TRUE) {
                $cfgRelation['mimework'] = TRUE;
            }
        } else {
            $cfgRelation['mimework'] = TRUE;
        }
    }
    if (isset($cfgRelation['history'])) {
        $cfgRelation['historywork'] = TRUE;
    }
    if (isset($cfgRelation['bookmark'])) {
        $cfgRelation['bookmarkwork'] = TRUE;
    }
    if ($cfgRelation['relwork'] == TRUE && $cfgRelation['displaywork'] == TRUE && $cfgRelation['pdfwork'] == TRUE && $cfgRelation['commwork'] == TRUE && $cfgRelation['mimework'] == TRUE && $cfgRelation['historywork'] == TRUE && $cfgRelation['bookmarkwork'] == TRUE) {
        $cfgRelation['allworks'] = TRUE;
    }
    if ($tab_rs) {
        PMA_DBI_free_result($tab_rs);
    } else {
        $cfg['Server']['pmadb'] = FALSE;
    }
    if ($verbose == TRUE) {
        $shit = '<font color="red"><b>' . $GLOBALS['strNotOK'] . '</b></font> [ <a href="Documentation.html#%s">' . $GLOBALS['strDocu'] . '</a> ]';
        $hit = '<font color="green"><b>' . $GLOBALS['strOK'] . '</b></font>';
        $enabled = '<font color="green">' . $GLOBALS['strEnabled'] . '</font>';
        $disabled = '<font color="red">' . $GLOBALS['strDisabled'] . '</font>';
        echo '<table>' . "\n";
        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'pmadb\'] ... </th><td align="right">' . ($cfg['Server']['pmadb'] == FALSE ? sprintf($shit, 'pmadb') : $hit) . '</td></tr>' . "\n";
        echo '    <tr><td>&nbsp;</td></tr>' . "\n";
        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'relation\'] ... </th><td align="right">' . (isset($cfgRelation['relation']) ? $hit : sprintf($shit, 'relation')) . '</td></tr>' . "\n";
        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strGeneralRelationFeat'] . ': ' . ($cfgRelation['relwork'] == TRUE ? $enabled : $disabled) . '</td></tr>' . "\n";
        echo '    <tr><td>&nbsp;</td></tr>' . "\n";
        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'table_info\']   ... </th><td align="right">' . ($cfgRelation['displaywork'] == FALSE ? sprintf($shit, 'table_info') : $hit) . '</td></tr>' . "\n";
        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strDisplayFeat'] . ': ' . ($cfgRelation['displaywork'] == TRUE ? $enabled : $disabled) . '</td></tr>' . "\n";
        echo '    <tr><td>&nbsp;</td></tr>' . "\n";
        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'table_coords\'] ... </th><td align="right">' . (isset($cfgRelation['table_coords']) ? $hit : sprintf($shit, 'table_coords')) . '</td></tr>' . "\n";
        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'pdf_pages\'] ... </th><td align="right">' . (isset($cfgRelation['pdf_pages']) ? $hit : sprintf($shit, 'table_coords')) . '</td></tr>' . "\n";
        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strCreatePdfFeat'] . ': ' . ($cfgRelation['pdfwork'] == TRUE ? $enabled : $disabled) . '</td></tr>' . "\n";
        echo '    <tr><td>&nbsp;</td></tr>' . "\n";
        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'column_info\'] ... </th><td align="right">' . (isset($cfgRelation['column_info']) ? $hit : sprintf($shit, 'col_com')) . '</td></tr>' . "\n";
        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strColComFeat'] . ': ' . ($cfgRelation['commwork'] == TRUE ? $enabled : $disabled) . '</td></tr>' . "\n";
        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strBookmarkQuery'] . ': ' . ($cfgRelation['bookmarkwork'] == TRUE ? $enabled : $disabled) . '</td></tr>' . "\n";
        echo '    <tr><th align="left">MIME ...</th><td align="right">' . ($cfgRelation['mimework'] == TRUE ? $hit : sprintf($shit, 'col_com')) . '</td></tr>' . "\n";
        if ($cfgRelation['commwork'] == TRUE && $cfgRelation['mimework'] != TRUE) {
            echo '<tr><td colspan=2 align="left">' . $GLOBALS['strUpdComTab'] . '</td></tr>' . "\n";
        }
        echo '    <tr><th align="left">$cfg[\'Servers\'][$i][\'history\'] ... </th><td align="right">' . (isset($cfgRelation['history']) ? $hit : sprintf($shit, 'history')) . '</td></tr>' . "\n";
        echo '    <tr><td colspan=2 align="center">' . $GLOBALS['strQuerySQLHistory'] . ': ' . ($cfgRelation['historywork'] == TRUE ? $enabled : $disabled) . '</td></tr>' . "\n";
        echo '</table>' . "\n";
    }
    // end if ($verbose == TRUE) {
    return $cfgRelation;
}
コード例 #16
0
/**
 * returns collation of given db
 *
 * @uses    PMA_DBI_fetch_value()
 * @uses    PMA_DBI_select_db()
 * @uses    PMA_sqlAddSlashes()
 * @uses    $GLOBALS['db']
 * @param   string  $db     name of db
 * @return  string  collation of $db
 */
function PMA_getDbCollation($db)
{
    if ($db == 'information_schema') {
        // We don't have to check the collation of the virtual
        // information_schema database: We know it!
        return 'utf8_general_ci';
    }
    if (!$GLOBALS['cfg']['Server']['DisableIS']) {
        // this is slow with thousands of databases
        return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
    } else {
        PMA_DBI_select_db($db);
        $return = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'collation_database\'', 0, 1);
        if ($db !== $GLOBALS['db']) {
            PMA_DBI_select_db($GLOBALS['db']);
        }
        return $return;
    }
}
コード例 #17
0
ファイル: tbl_addfield.php プロジェクト: robmat/samplebator
             if ($field_where == 'first') {
                 $query .= ' FIRST';
             } else {
                 $query .= ' AFTER ' . PMA_backquote(urldecode($after_field));
             }
         } else {
             $query .= ' AFTER ' . PMA_backquote($field_name[$i - 1]);
         }
     }
     $query .= ', ADD ';
 }
 // end for
 $query = preg_replace('@, ADD $@', '', $query);
 // To allow replication, we first select the db to use and then run queries
 // on this db.
 PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_getError(), 'USE ' . PMA_backquotes($db), '', $err_url);
 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD ' . $query;
 $error_create = FALSE;
 PMA_DBI_try_query($sql_query) or $error_create = TRUE;
 if ($error_create == false) {
     $sql_query_cpy = $sql_query . ';';
     // Builds the primary keys statements and updates the table
     $primary = '';
     if (isset($field_primary)) {
         $primary_cnt = count($field_primary);
         for ($i = 0; $i < $primary_cnt; $i++) {
             $j = $field_primary[$i];
             if (isset($field_name[$j]) && strlen($field_name[$j])) {
                 $primary .= PMA_backquote($field_name[$j]) . ', ';
             }
         }
コード例 #18
0
 /**
  * Returns $table's CREATE definition
  *
  * @param string $db            the database name
  * @param string $table         the table name
  * @param string $crlf          the end of line sequence
  * @param string $error_url     the url to go back in case of error
  * @param bool   $do_relation   whether to include relation comments
  * @param bool   $do_comments   whether to include the pmadb-style column
  *                                comments as comments in the structure;
  *                                this is deprecated but the parameter is
  *                                left here because export.php calls
  *                                PMA_exportStructure() also for other
  *                                export types which use this parameter
  * @param bool   $do_mime       whether to include mime comments
  * @param bool   $show_dates    whether to include creation/update/check dates
  * @param bool   $add_semicolon whether to add semicolon and end-of-line
  *                                at the end
  * @param bool   $view          whether we're handling a view
  *
  * @return string resulting schema
  */
 public function getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false)
 {
     // set $cfgRelation here, because there is a chance that it's modified
     // since the class initialization
     global $cfgRelation;
     $schema_insert = '';
     /**
      * Gets fields properties
      */
     PMA_DBI_select_db($db);
     // Check if we can use Relations
     if ($do_relation && !empty($cfgRelation['relation'])) {
         // Find which tables are related with the current one and write it in
         // an array
         $res_rel = PMA_getForeigners($db, $table);
         if ($res_rel && count($res_rel) > 0) {
             $have_rel = true;
         } else {
             $have_rel = false;
         }
     } else {
         $have_rel = false;
     }
     // end if
     /**
      * Displays the table structure
      */
     $schema_insert .= '<table class="width100" cellspacing="1">';
     $columns_cnt = 4;
     if ($do_relation && $have_rel) {
         $columns_cnt++;
     }
     if ($do_comments && $cfgRelation['commwork']) {
         $columns_cnt++;
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $columns_cnt++;
     }
     $schema_insert .= '<tr class="print-category">';
     $schema_insert .= '<th class="print">' . __('Column') . '</th>';
     $schema_insert .= '<td class="print"><strong>' . __('Type') . '</strong></td>';
     $schema_insert .= '<td class="print"><strong>' . __('Null') . '</strong></td>';
     $schema_insert .= '<td class="print"><strong>' . __('Default') . '</strong></td>';
     if ($do_relation && $have_rel) {
         $schema_insert .= '<td class="print"><strong>' . __('Links to') . '</strong></td>';
     }
     if ($do_comments) {
         $schema_insert .= '<td class="print"><strong>' . __('Comments') . '</strong></td>';
         $comments = PMA_getComments($db, $table);
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $schema_insert .= '<td class="print"><strong>' . htmlspecialchars('MIME') . '</strong></td>';
         $mime_map = PMA_getMIME($db, $table, true);
     }
     $schema_insert .= '</tr>';
     $columns = PMA_DBI_get_columns($db, $table);
     /**
      * Get the unique keys in the table
      */
     $unique_keys = array();
     $keys = PMA_DBI_get_table_indexes($db, $table);
     foreach ($keys as $key) {
         if ($key['Non_unique'] == 0) {
             $unique_keys[] = $key['Column_name'];
         }
     }
     foreach ($columns as $column) {
         $schema_insert .= $this->formatOneColumnDefinition($column, $unique_keys);
         $field_name = $column['Field'];
         if ($do_relation && $have_rel) {
             $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>';
         }
         if ($do_comments && $cfgRelation['commwork']) {
             $schema_insert .= '<td class="print">' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>';
         }
         if ($do_mime && $cfgRelation['mimework']) {
             $schema_insert .= '<td class="print">' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>';
         }
         $schema_insert .= '</tr>';
     }
     // end foreach
     $schema_insert .= '</table>';
     return $schema_insert;
 }
コード例 #19
0
 /**
  * Finds all related tables
  *
  * @param   string   wether to go from master to foreign or vice versa
  *
  * @return  boolean  always TRUE
  *
  * @global  array    the list of tables that we still couldn't connect
  * @global  array    the list of allready connected tables
  * @global  string   the current databse name
  * @global  string   the super user connection id
  * @global  array    the list of relation settings
  *
  * @access  private
  */
 function PMA_getRelatives($from)
 {
     global $tab_left, $tab_know, $fromclause;
     global $controllink, $db, $cfgRelation;
     if ($from == 'master') {
         $to = 'foreign';
     } else {
         $to = 'master';
     }
     $in_know = '(\'' . implode('\', \'', $tab_know) . '\')';
     $in_left = '(\'' . implode('\', \'', $tab_left) . '\')';
     $rel_query = 'SELECT *' . ' FROM ' . PMA_backquote($cfgRelation['relation']) . ' WHERE ' . $from . '_db   = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $to . '_db   = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $from . '_table IN ' . $in_know . ' AND ' . $to . '_table IN ' . $in_left;
     PMA_DBI_select_db($cfgRelation['db'], $controllink);
     $relations = @PMA_DBI_query($rel_query, $controllink);
     PMA_DBI_select_db($db, $controllink);
     while ($row = PMA_DBI_fetch_assoc($relations)) {
         $found_table = $row[$to . '_table'];
         if (isset($tab_left[$found_table])) {
             $fromclause .= "\n" . ' LEFT JOIN ' . PMA_backquote($row[$to . '_table']) . ' ON ' . PMA_backquote($row[$from . '_table']) . '.' . PMA_backquote($row[$from . '_field']) . ' = ' . PMA_backquote($row[$to . '_table']) . '.' . PMA_backquote($row[$to . '_field']) . ' ';
             $tab_know[$found_table] = $found_table;
             $tab_left = PMA_arrayShort($tab_left, $found_table);
         }
     }
     // end while
     return TRUE;
 }
コード例 #20
0
     }
     $definitions[] = ' ADD UNIQUE (' . implode(', ', $fields) . ') ';
     unset($fields);
 }
 // Builds the fulltext statements and updates the table
 if (count($field_fulltext)) {
     $fields = array();
     foreach ($field_fulltext as $field_nr) {
         $fields[] = PMA_Util::backquote($_REQUEST['field_name'][$field_nr]);
     }
     $definitions[] = ' ADD FULLTEXT (' . implode(', ', $fields) . ') ';
     unset($fields);
 }
 // To allow replication, we first select the db to use and then run queries
 // on this db.
 PMA_DBI_select_db($db) or PMA_Util::mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_Util::backquote($db), '', $err_url);
 $sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ' . implode(', ', $definitions) . ';';
 $result = PMA_DBI_try_query($sql_query);
 if ($result === true) {
     // If comments were sent, enable relation stuff
     include_once 'libraries/transformations.lib.php';
     // Update comment table for mime types [MIME]
     if (isset($_REQUEST['field_mimetype']) && is_array($_REQUEST['field_mimetype']) && $cfg['BrowseMIME']) {
         foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
             if (isset($_REQUEST['field_name'][$fieldindex]) && strlen($_REQUEST['field_name'][$fieldindex])) {
                 PMA_setMIME($db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype, $_REQUEST['field_transformation'][$fieldindex], $_REQUEST['field_transformation_options'][$fieldindex]);
             }
         }
     }
     // Go back to the structure sub-page
     $message = PMA_Message::success(__('Table %1$s has been altered successfully'));
コード例 #21
0
 /**
  * renames table
  *
  * @param string $new_name new table name
  * @param string $new_db   new database name
  * @param bool   $is_view  is this for a VIEW rename?
  * @todo    remove the $is_view parameter (also in callers)
  *
  * @return bool success
  */
 function rename($new_name, $new_db = null, $is_view = false)
 {
     if (null !== $new_db && $new_db !== $this->getDbName()) {
         // Ensure the target is valid
         if (!$GLOBALS['pma']->databases->exists($new_db)) {
             $this->errors[] = __('Invalid database') . ': ' . $new_db;
             return false;
         }
     } else {
         $new_db = $this->getDbName();
     }
     $new_table = new PMA_Table($new_name, $new_db);
     if ($this->getFullName() === $new_table->getFullName()) {
         return true;
     }
     if (!PMA_Table::isValidName($new_name)) {
         $this->errors[] = __('Invalid table name') . ': ' . $new_table->getFullName();
         return false;
     }
     // If the table is moved to a different database drop its triggers first
     $triggers = PMA_DBI_get_triggers($this->getDbName(), $this->getName(), '');
     $handle_triggers = $this->getDbName() != $new_db && $triggers;
     if ($handle_triggers) {
         foreach ($triggers as $trigger) {
             $sql = 'DROP TRIGGER IF EXISTS ' . PMA_backquote($this->getDbName()) . '.' . PMA_backquote($trigger['name']) . ';';
             PMA_DBI_query($sql);
         }
     }
     /*
      * tested also for a view, in MySQL 5.0.92, 5.1.55 and 5.5.13
      */
     $GLOBALS['sql_query'] = '
         RENAME TABLE ' . $this->getFullName(true) . '
               TO ' . $new_table->getFullName(true) . ';';
     // I don't think a specific error message for views is necessary
     if (!PMA_DBI_query($GLOBALS['sql_query'])) {
         // Restore triggers in the old database
         if ($handle_triggers) {
             PMA_DBI_select_db($this->getDbName());
             foreach ($triggers as $trigger) {
                 PMA_DBI_query($trigger['create']);
             }
         }
         $this->errors[] = sprintf(__('Error renaming table %1$s to %2$s'), $this->getFullName(), $new_table->getFullName());
         return false;
     }
     $old_name = $this->getName();
     $old_db = $this->getDbName();
     $this->setName($new_name);
     $this->setDbName($new_db);
     /**
      * @todo move into extra function PMA_Relation::renameTable($new_name, $old_name, $new_db, $old_db)
      */
     // Move old entries from comments to new table
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     if ($GLOBALS['cfgRelation']['commwork']) {
         $remove_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($remove_query);
         unset($remove_query);
     }
     if ($GLOBALS['cfgRelation']['displaywork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . '
                SET `db_name`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['relwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `foreign_db`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `foreign_table` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `foreign_db`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `foreign_table` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . '
                SET `master_db`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `master_table` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `master_db`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `master_table` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['pdfwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     if ($GLOBALS['cfgRelation']['designerwork']) {
         $table_query = '
             UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . '
                SET `db_name`    = \'' . PMA_sqlAddSlashes($new_db) . '\',
                    `table_name` = \'' . PMA_sqlAddSlashes($new_name) . '\'
              WHERE `db_name`    = \'' . PMA_sqlAddSlashes($old_db) . '\'
                AND `table_name` = \'' . PMA_sqlAddSlashes($old_name) . '\'';
         PMA_query_as_controluser($table_query);
         unset($table_query);
     }
     $this->messages[] = sprintf(__('Table %1$s has been renamed to %2$s.'), htmlspecialchars($old_name), htmlspecialchars($new_name));
     return true;
 }
コード例 #22
0
/**
 * Gets some core libraries
 */
require_once './libraries/common.inc.php';

$response = PMA_Response::getInstance();
$header   = $response->getHeader();
$scripts  = $header->getScripts();
$scripts->addFile('server_privileges.js');

/**
 * Displays an error message and exits if the user isn't allowed to use this
 * script
 */
if (! $cfg['ShowChgPassword']) {
    $cfg['ShowChgPassword'] = PMA_DBI_select_db('mysql');
}
if ($cfg['Server']['auth_type'] == 'config' || ! $cfg['ShowChgPassword']) {
    PMA_Message::error(
        __('You don\'t have sufficient privileges to be here right now!')
    )->display();
    exit;
} // end if

/**
 * If the "change password" form has been submitted, checks for valid values
 * and submit the query or logout
 */
if (isset($_REQUEST['nopass'])) {
    if ($_REQUEST['nopass'] == '1') {
        $password = '';
コード例 #23
0
ファイル: Table.class.php プロジェクト: jmathai/photos
 /**
  * Copies or renames table
  * @todo use RENAME for move operations
  *        - would work only if the databases are on the same filesystem,
  *          how can we check that? try the operation and
  *          catch an error?
  *        - for views, only if MYSQL > 50013
  *        - still have to handle pmadb synch.
  *
  * @author          Michal Cihar <*****@*****.**>
  */
 function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
 {
     global $err_url;
     // set export settings we need
     $GLOBALS['sql_backquotes'] = 1;
     $GLOBALS['asfile'] = 1;
     // Ensure the target is valid
     if (!$GLOBALS['PMA_List_Database']->exists($source_db, $target_db)) {
         /**
          * @todo exit really needed here? or just a return?
          */
         exit;
     }
     $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
     if (!isset($target_db) || !strlen($target_db)) {
         $target_db = $source_db;
     }
     // Doing a select_db could avoid some problems with replicated databases,
     // when moving table from replicated one to not replicated one
     PMA_DBI_select_db($target_db);
     $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
     // do not create the table if dataonly
     if ($what != 'dataonly') {
         require_once './libraries/export/sql.php';
         $no_constraints_comments = true;
         $GLOBALS['sql_constraints_query'] = '';
         $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
         unset($no_constraints_comments);
         $parsed_sql = PMA_SQP_parse($sql_structure);
         $analyzed_sql = PMA_SQP_analyze($parsed_sql);
         $i = 0;
         if (empty($analyzed_sql[0]['create_table_fields'])) {
             // this is not a CREATE TABLE, so find the first VIEW
             $target_for_view = PMA_backquote($target_db);
             while (true) {
                 if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') {
                     break;
                 }
                 $i++;
             }
         }
         unset($analyzed_sql);
         $server_sql_mode = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'sql_mode'", 0, 1);
         if ('ANSI_QUOTES' == $server_sql_mode) {
             $table_delimiter = 'quote_double';
         } else {
             $table_delimiter = 'quote_backtick';
         }
         unset($server_sql_mode);
         /* nijel: Find table name in query and replace it */
         while ($parsed_sql[$i]['type'] != $table_delimiter) {
             $i++;
         }
         /* no need to PMA_backquote() */
         if (isset($target_for_view)) {
             // this a view definition; we just found the first db name
             // that follows DEFINER VIEW
             // so change it for the new db name
             $parsed_sql[$i]['data'] = $target_for_view;
             // then we have to find all references to the source db
             // and change them to the target db, ensuring we stay into
             // the $parsed_sql limits
             $last = $parsed_sql['len'] - 1;
             $backquoted_source_db = PMA_backquote($source_db);
             for (++$i; $i <= $last; $i++) {
                 if ($parsed_sql[$i]['type'] == $table_delimiter && $parsed_sql[$i]['data'] == $backquoted_source_db) {
                     $parsed_sql[$i]['data'] = $target_for_view;
                 }
             }
             unset($last, $backquoted_source_db);
         } else {
             $parsed_sql[$i]['data'] = $target;
         }
         /* Generate query back */
         $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
         // If table exists, and 'add drop table' is selected: Drop it!
         $drop_query = '';
         if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') {
             if (PMA_Table::_isView($target_db, $target_table)) {
                 $drop_query = 'DROP VIEW';
             } else {
                 $drop_query = 'DROP TABLE';
             }
             $drop_query .= ' IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
             PMA_DBI_query($drop_query);
             $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
             // garvin: If an existing table gets deleted, maintain any
             // entries for the PMA_* tables
             $maintain_relations = true;
         }
         @PMA_DBI_query($sql_structure);
         $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';';
         if (($move || isset($GLOBALS['add_constraints'])) && !empty($GLOBALS['sql_constraints_query'])) {
             $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints_query']);
             $i = 0;
             // find the first $table_delimiter, it must be the source table name
             while ($parsed_sql[$i]['type'] != $table_delimiter) {
                 $i++;
                 // maybe someday we should guard against going over limit
                 //if ($i == $parsed_sql['len']) {
                 //    break;
                 //}
             }
             // replace it by the target table name, no need to PMA_backquote()
             $parsed_sql[$i]['data'] = $target;
             // now we must remove all $table_delimiter that follow a CONSTRAINT
             // keyword, because a constraint name must be unique in a db
             $cnt = $parsed_sql['len'] - 1;
             for ($j = $i; $j < $cnt; $j++) {
                 if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') {
                     if ($parsed_sql[$j + 1]['type'] == $table_delimiter) {
                         $parsed_sql[$j + 1]['data'] = '';
                     }
                 }
             }
             // Generate query back
             $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
             if ($mode == 'one_table') {
                 PMA_DBI_query($GLOBALS['sql_constraints_query']);
             }
             $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
             if ($mode == 'one_table') {
                 unset($GLOBALS['sql_constraints_query']);
             }
         }
     } else {
         $GLOBALS['sql_query'] = '';
     }
     // Copy the data unless this is a VIEW
     if (($what == 'data' || $what == 'dataonly') && !PMA_Table::_isView($target_db, $target_table)) {
         $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
         PMA_DBI_query($sql_insert_data);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';';
     }
     require_once './libraries/relation.lib.php';
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     // Drops old table if the user has requested to move it
     if ($move) {
         // This could avoid some problems with replicated databases, when
         // moving table from replicated one to not replicated one
         PMA_DBI_select_db($source_db);
         if (PMA_Table::_isView($source_db, $source_table)) {
             $sql_drop_query = 'DROP VIEW';
         } else {
             $sql_drop_query = 'DROP TABLE';
         }
         $sql_drop_query .= ' ' . $source;
         PMA_DBI_query($sql_drop_query);
         // garvin: Move old entries from PMA-DBs to new table
         if ($GLOBALS['cfgRelation']['commwork']) {
             $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . '        db_name    = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($remove_query);
             unset($remove_query);
         }
         // garvin: updating bookmarks is not possible since only a single table is moved,
         // and not the whole DB.
         if ($GLOBALS['cfgRelation']['displaywork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . '         table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         if ($GLOBALS['cfgRelation']['relwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET     foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET     master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         /**
          * @todo garvin: Can't get moving PDFs the right way. The page numbers
          * always get screwed up independently from duplication because the
          * numbers do not seem to be stored on a per-database basis. Would
          * the author of pdf support please have a look at it?
          */
         if ($GLOBALS['cfgRelation']['pdfwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
             /*
             $pdf_query = 'SELECT pdf_page_number '
                        . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords'])
                        . ' WHERE db_name  = \'' . PMA_sqlAddslashes($target_db) . '\''
                        . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
             $pdf_rs = PMA_query_as_cu($pdf_query);
             
             while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
                 $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['pdf_pages'])
                                 . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
                                 . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\''
                                 . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
                 $tb_rs    = PMA_query_as_cu($table_query);
                 unset($table_query);
                 unset($tb_rs);
             }
             */
         }
         if ($GLOBALS['cfgRelation']['designerwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_query . ';';
         // end if ($move)
     } else {
         // we are copying
         // garvin: Create new entries as duplicates from old PMA DBs
         if ($what != 'dataonly' && !isset($maintain_relations)) {
             if ($GLOBALS['cfgRelation']['commwork']) {
                 // Get all comments and MIME-Types for current table
                 $comments_copy_query = 'SELECT
                                             column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                         FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                                         WHERE
                                             db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
                                             table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
                 $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
                 // Write every comment as new copied entry. [MIME]
                 while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                     $new_comment_query = 'REPLACE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                     PMA_query_as_cu($new_comment_query);
                 }
                 // end while
                 PMA_DBI_free_result($comments_copy_rs);
                 unset($comments_copy_rs);
             }
             // duplicating the bookmarks must not be done here, but
             // just once per db
             $get_fields = array('display_field');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
             /**
              * @todo revise this code when we support cross-db relations
              */
             $get_fields = array('master_field', 'foreign_table', 'foreign_field');
             $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'master_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('foreign_field', 'master_table', 'master_field');
             $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'foreign_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('x', 'y', 'v', 'h');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('designerwork', 'designer_coords', $get_fields, $where_fields, $new_fields);
             /**
             * @todo garvin: Can't get duplicating PDFs the right way. The
             * page numbers always get screwed up independently from
             * duplication because the numbers do not seem to be stored on a
             * per-database basis. Would the author of pdf support please
             * have a look at it?
             *
                             $get_fields = array('page_descr');
                             $where_fields = array('db_name' => $source_db);
                             $new_fields = array('db_name' => $target_db);
                             $last_id = PMA_Table::duplicateInfo('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields);
             
                             if (isset($last_id) && $last_id >= 0) {
                $get_fields = array('x', 'y');
                $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
                $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id);
                PMA_Table::duplicateInfo('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields);
                             }
             */
         }
     }
 }
コード例 #24
0
ファイル: relation.lib.php プロジェクト: AmberWish/laba_web
/**
 * Defines the relation parameters for the current user
 * just a copy of the functions used for relations ;-)
 * but added some stuff to check what will work
 *
 * @access  protected
 * @return  array    the relation parameters for the current user
 */
function PMA__getRelationsParam()
{
    $cfgRelation = array();
    $cfgRelation['relwork'] = false;
    $cfgRelation['displaywork'] = false;
    $cfgRelation['bookmarkwork'] = false;
    $cfgRelation['pdfwork'] = false;
    $cfgRelation['commwork'] = false;
    $cfgRelation['mimework'] = false;
    $cfgRelation['historywork'] = false;
    $cfgRelation['recentwork'] = false;
    $cfgRelation['uiprefswork'] = false;
    $cfgRelation['trackingwork'] = false;
    $cfgRelation['designerwork'] = false;
    $cfgRelation['userconfigwork'] = false;
    $cfgRelation['allworks'] = false;
    $cfgRelation['user'] = null;
    $cfgRelation['db'] = null;
    if ($GLOBALS['server'] == 0 || empty($GLOBALS['cfg']['Server']['pmadb']) || !PMA_DBI_select_db($GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink'])) {
        // No server selected -> no bookmark table
        // we return the array with the falses in it,
        // to avoid some 'Unitialized string offset' errors later
        $GLOBALS['cfg']['Server']['pmadb'] = false;
        return $cfgRelation;
    }
    $cfgRelation['user'] = $GLOBALS['cfg']['Server']['user'];
    $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb'];
    //  Now I just check if all tables that i need are present so I can for
    //  example enable relations but not pdf...
    //  I was thinking of checking if they have all required columns but I
    //  fear it might be too slow
    $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($GLOBALS['cfg']['Server']['pmadb']);
    $tab_rs = PMA_query_as_controluser($tab_query, false, PMA_DBI_QUERY_STORE);
    if (!$tab_rs) {
        // query failed ... ?
        //$GLOBALS['cfg']['Server']['pmadb'] = false;
        return $cfgRelation;
    }
    while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) {
        if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) {
            $cfgRelation['bookmark'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) {
            $cfgRelation['relation'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_info']) {
            $cfgRelation['table_info'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) {
            $cfgRelation['table_coords'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['designer_coords']) {
            $cfgRelation['designer_coords'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['column_info']) {
            $cfgRelation['column_info'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) {
            $cfgRelation['pdf_pages'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) {
            $cfgRelation['history'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) {
            $cfgRelation['recent'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) {
            $cfgRelation['table_uiprefs'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) {
            $cfgRelation['tracking'] = $curr_table[0];
        } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) {
            $cfgRelation['userconfig'] = $curr_table[0];
        }
    }
    // end while
    PMA_DBI_free_result($tab_rs);
    if (isset($cfgRelation['relation'])) {
        $cfgRelation['relwork'] = true;
        if (isset($cfgRelation['table_info'])) {
            $cfgRelation['displaywork'] = true;
        }
    }
    if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) {
        $cfgRelation['pdfwork'] = true;
    }
    if (isset($cfgRelation['column_info'])) {
        $cfgRelation['commwork'] = true;
        if ($GLOBALS['cfg']['Server']['verbose_check']) {
            $mime_query = PMA_DBI_get_columns_sql($cfgRelation['db'], $cfgRelation['column_info']);
            $mime_rs = PMA_query_as_controluser($mime_query, false);
            $mime_field_mimetype = false;
            $mime_field_transformation = false;
            $mime_field_transformation_options = false;
            while ($curr_mime_field = @PMA_DBI_fetch_row($mime_rs)) {
                if ($curr_mime_field[0] == 'mimetype') {
                    $mime_field_mimetype = true;
                } elseif ($curr_mime_field[0] == 'transformation') {
                    $mime_field_transformation = true;
                } elseif ($curr_mime_field[0] == 'transformation_options') {
                    $mime_field_transformation_options = true;
                }
            }
            PMA_DBI_free_result($mime_rs);
            if ($mime_field_mimetype && $mime_field_transformation && $mime_field_transformation_options) {
                $cfgRelation['mimework'] = true;
            }
        } else {
            $cfgRelation['mimework'] = true;
        }
    }
    if (isset($cfgRelation['history'])) {
        $cfgRelation['historywork'] = true;
    }
    if (isset($cfgRelation['recent'])) {
        $cfgRelation['recentwork'] = true;
    }
    if (isset($cfgRelation['table_uiprefs'])) {
        $cfgRelation['uiprefswork'] = true;
    }
    if (isset($cfgRelation['tracking'])) {
        $cfgRelation['trackingwork'] = true;
    }
    if (isset($cfgRelation['userconfig'])) {
        $cfgRelation['userconfigwork'] = true;
    }
    // we do not absolutely need that the internal relations or the PDF
    // schema feature be activated
    if (isset($cfgRelation['designer_coords'])) {
        $cfgRelation['designerwork'] = true;
    }
    if (isset($cfgRelation['bookmark'])) {
        $cfgRelation['bookmarkwork'] = true;
    }
    if ($cfgRelation['relwork'] && $cfgRelation['displaywork'] && $cfgRelation['pdfwork'] && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfgRelation['historywork'] && $cfgRelation['recentwork'] && $cfgRelation['uiprefswork'] && $cfgRelation['trackingwork'] && $cfgRelation['userconfigwork'] && $cfgRelation['bookmarkwork'] && $cfgRelation['designerwork']) {
        $cfgRelation['allworks'] = true;
    }
    return $cfgRelation;
}
コード例 #25
0
/**
 * Defines the urls to return to in case of error in a sql statement
 */
$err_url_0 = 'main.php?' . PMA_generate_common_url();
$err_url   = $cfg['DefaultTabDatabase'] . '?' . PMA_generate_common_url($db);


/**
 * Ensures the database exists (else move to the "parent" script) and displays
 * headers
 */
if (!isset($is_db) || !$is_db) {
    // Not a valid db name -> back to the welcome page
    if (strlen($db)) {
        $is_db = PMA_DBI_select_db($db);
    }
    if (! strlen($db) || !$is_db) {
        PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php?' . PMA_generate_common_url('', '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1');
        exit;
    }
} // end if (ensures db exists)

/**
 * Changes database charset if requested by the user
 */
if (isset($submitcollation) && !empty($db_collation)) {
    list($db_charset) = explode('_', $db_collation);
    $sql_query        = 'ALTER DATABASE ' . PMA_backquote($db) . ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
    $result           = PMA_DBI_query($sql_query);
    $message          = PMA_Message::success();
コード例 #26
0
 /**
  * returns collation of given db
  *
  * @uses    PMA_MYSQL_INT_VERSION
  * @uses    PMA_DBI_fetch_value()
  * @uses    PMA_DBI_select_db()
  * @uses    PMA_sqlAddSlashes()
  * @uses    $GLOBALS['db']
  * @param   string  $db     name of db
  * @return  string  collation of $db
  */
 function PMA_getDbCollation($db)
 {
     if (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema') {
         // We don't have to check the collation of the virtual
         // information_schema database: We know it!
         return 'utf8_general_ci';
     }
     if (PMA_MYSQL_INT_VERSION >= 50006) {
         // Since MySQL 5.0.6, we don't have to parse SHOW CREATE DATABASE anymore.
         return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
     } elseif (PMA_MYSQL_INT_VERSION >= 40101) {
         // MySQL 4.1.0 does not support seperate charset settings
         // for databases.
         PMA_DBI_select_db($db);
         // the query does not work if this string is in double quotes
         // and MySQL is running in ANSI mode
         $return = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'collation_database\'', 0, 1);
         if ($db !== $GLOBALS['db']) {
             PMA_DBI_select_db($GLOBALS['db']);
         }
         return $return;
     }
     return '';
 }
コード例 #27
0
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH');
?>
    </li>
</ul>
<?php 
// Referential integrity check
// The Referential integrity check was intended for the non-InnoDB
// tables for which the relations are defined in pmadb
// so I assume that if the current table is InnoDB, I don't display
// this choice (InnoDB maintains integrity by itself)
if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
    // we need this PMA_DBI_select_db if the user has access to more than one db
    // and $GLOBALS['db'] is not the last of the list, because
    // PMA_List_Database::_checkAccess()
    // has made a PMA_DBI_select_db() on the last one
    PMA_DBI_select_db($GLOBALS['db']);
    $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
    if ($foreign) {
        ?>
    <!-- Referential integrity check -->
    <ul>
        <?php 
        echo $strReferentialIntegrity;
        ?>
<br />
        <?php 
        echo "\n";
        foreach ($foreign as $master => $arr) {
            $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM ' . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN ' . PMA_backquote($arr['foreign_table']);
            if ($arr['foreign_table'] == $GLOBALS['table']) {
                $foreign_table = $GLOBALS['table'] . '1';
コード例 #28
0
ファイル: tbl_alter.php プロジェクト: rajatsinghal/phpmyadmin
     *  - the column has an index, if not create one
     *
    if (count($key_fields)) {
        $fields = array();
        foreach ($key_fields as $each_field) {
            if (isset($_REQUEST['field_name'][$each_field]) && strlen($_REQUEST['field_name'][$each_field])) {
                $fields[] = PMA_CommonFunctions::getInstance()->backquote($_REQUEST['field_name'][$each_field]);
            }
        } // end for
        $key_query = ', ADD KEY (' . implode(', ', $fields) . ') ';
    }
     */

    // To allow replication, we first select the db to use and then run queries
    // on this db.
    if (! PMA_DBI_select_db($db)) {
        $common_functions->mysqlDie(
            PMA_DBI_getError(),
            'USE ' . $common_functions->backquote($db) . ';',
            '',
            $err_url
        );
    }
    $sql_query = 'ALTER TABLE ' . $common_functions->backquote($table) . ' ';
    $sql_query .= implode(', ', $changes) . $key_query;
    $sql_query .= ';';
    $result    = PMA_DBI_try_query($sql_query);

    if ($result !== false) {
        $message = PMA_Message::success(
            __('Table %1$s has been altered successfully')
コード例 #29
0
ファイル: latex.php プロジェクト: findlakes/XSS-Platform
 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy)
 {
     global $cfgRelation;
     /**
      * Get the unique keys in the table
      */
     $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
     $keys_result = PMA_DBI_query($keys_query);
     $unique_keys = array();
     while ($key = PMA_DBI_fetch_assoc($keys_result)) {
         if ($key['Non_unique'] == 0) {
             $unique_keys[] = $key['Column_name'];
         }
     }
     PMA_DBI_free_result($keys_result);
     /**
      * Gets fields properties
      */
     PMA_DBI_select_db($db);
     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
     $result = PMA_DBI_query($local_query);
     $fields_cnt = PMA_DBI_num_rows($result);
     // Check if we can use Relations (Mike Beck)
     if ($do_relation && !empty($cfgRelation['relation'])) {
         // Find which tables are related with the current one and write it in
         // an array
         $res_rel = PMA_getForeigners($db, $table);
         if ($res_rel && count($res_rel) > 0) {
             $have_rel = TRUE;
         } else {
             $have_rel = FALSE;
         }
     } else {
         $have_rel = FALSE;
     }
     // end if
     /**
      * Displays the table structure
      */
     $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{';
     if (!PMA_exportOutputHandler($buffer)) {
         return FALSE;
     }
     $columns_cnt = 4;
     $alignment = '|l|c|c|c|';
     if ($do_relation && $have_rel) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     $buffer = $alignment . '} ' . $crlf;
     $header = ' \\hline ';
     $header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}';
     if ($do_relation && $have_rel) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}';
     }
     if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}';
         $comments = PMA_getComments($db, $table);
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
         $mime_map = PMA_getMIME($db, $table, true);
     }
     $local_buffer = PMA_texEscape($table);
     // Table caption for first page and label
     if (isset($GLOBALS['latex_caption'])) {
         $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption']) . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label']) . '} \\\\' . $crlf;
     }
     $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
     // Table caption on next pages
     if (isset($GLOBALS['latex_caption'])) {
         $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption']) . '} \\\\ ' . $crlf;
     }
     $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf;
     if (!PMA_exportOutputHandler($buffer)) {
         return FALSE;
     }
     while ($row = PMA_DBI_fetch_assoc($result)) {
         $type = $row['Type'];
         // reformat mysql query output - staybyte - 9. June 2001
         // loic1: set or enum types: slashes single quotes inside options
         if (eregi('^(set|enum)\\((.+)\\)$', $type, $tmp)) {
             $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
             $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
             $type_nowrap = '';
             $binary = 0;
             $unsigned = 0;
             $zerofill = 0;
         } else {
             $type_nowrap = ' nowrap="nowrap"';
             $type = eregi_replace('BINARY', '', $type);
             $type = eregi_replace('ZEROFILL', '', $type);
             $type = eregi_replace('UNSIGNED', '', $type);
             if (empty($type)) {
                 $type = '&nbsp;';
             }
             $binary = eregi('BINARY', $row['Type']);
             $unsigned = eregi('UNSIGNED', $row['Type']);
             $zerofill = eregi('ZEROFILL', $row['Type']);
         }
         if (!isset($row['Default'])) {
             if ($row['Null'] != '') {
                 $row['Default'] = 'NULL';
             }
         } else {
             $row['Default'] = $row['Default'];
         }
         $field_name = $row['Field'];
         $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "" . (isset($row['Default']) ? $row['Default'] : '');
         if ($do_relation && $have_rel) {
             $local_buffer .= "";
             if (isset($res_rel[$field_name])) {
                 $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')';
             }
         }
         if ($do_comments && $cfgRelation['commwork']) {
             $local_buffer .= "";
             if (isset($comments[$field_name])) {
                 $local_buffer .= $comments[$field_name];
             }
         }
         if ($do_mime && $cfgRelation['mimework']) {
             $local_buffer .= "";
             if (isset($mime_map[$field_name])) {
                 $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']);
             }
         }
         $local_buffer = PMA_texEscape($local_buffer);
         if ($row['Key'] == 'PRI') {
             $pos = strpos($local_buffer, "");
             $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
         }
         if (in_array($field_name, $unique_keys)) {
             $pos = strpos($local_buffer, "");
             $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos);
         }
         $buffer = str_replace("", ' & ', $local_buffer);
         $buffer .= ' \\\\ \\hline ' . $crlf;
         if (!PMA_exportOutputHandler($buffer)) {
             return FALSE;
         }
     }
     // end while
     PMA_DBI_free_result($result);
     $buffer = ' \\end{longtable}' . $crlf;
     return PMA_exportOutputHandler($buffer);
 }
コード例 #30
0
ファイル: Table.class.php プロジェクト: mindfeederllc/openemr
 /**
  * renames table
  *
  * @param string $new_name new table name
  * @param string $new_db   new database name
  *
  * @return bool success
  */
 function rename($new_name, $new_db = null)
 {
     if (null !== $new_db && $new_db !== $this->getDbName()) {
         // Ensure the target is valid
         if (!$GLOBALS['pma']->databases->exists($new_db)) {
             $this->errors[] = __('Invalid database') . ': ' . $new_db;
             return false;
         }
     } else {
         $new_db = $this->getDbName();
     }
     $new_table = new PMA_Table($new_name, $new_db);
     if ($this->getFullName() === $new_table->getFullName()) {
         return true;
     }
     if (!PMA_Table::isValidName($new_name)) {
         $this->errors[] = __('Invalid table name') . ': ' . $new_table->getFullName();
         return false;
     }
     // If the table is moved to a different database drop its triggers first
     $triggers = PMA_DBI_get_triggers($this->getDbName(), $this->getName(), '');
     $handle_triggers = $this->getDbName() != $new_db && $triggers;
     if ($handle_triggers) {
         foreach ($triggers as $trigger) {
             $sql = 'DROP TRIGGER IF EXISTS ' . PMA_Util::backquote($this->getDbName()) . '.' . PMA_Util::backquote($trigger['name']) . ';';
             PMA_DBI_query($sql);
         }
     }
     /*
      * tested also for a view, in MySQL 5.0.92, 5.1.55 and 5.5.13
      */
     $GLOBALS['sql_query'] = '
         RENAME TABLE ' . $this->getFullName(true) . '
               TO ' . $new_table->getFullName(true) . ';';
     // I don't think a specific error message for views is necessary
     if (!PMA_DBI_query($GLOBALS['sql_query'])) {
         // Restore triggers in the old database
         if ($handle_triggers) {
             PMA_DBI_select_db($this->getDbName());
             foreach ($triggers as $trigger) {
                 PMA_DBI_query($trigger['create']);
             }
         }
         $this->errors[] = sprintf(__('Error renaming table %1$s to %2$s'), $this->getFullName(), $new_table->getFullName());
         return false;
     }
     $old_name = $this->getName();
     $old_db = $this->getDbName();
     $this->setName($new_name);
     $this->setDbName($new_db);
     // Renable table in configuration storage
     PMA_REL_renameTable($old_db, $new_db, $old_name, $new_name);
     $this->messages[] = sprintf(__('Table %1$s has been renamed to %2$s.'), htmlspecialchars($old_name), htmlspecialchars($new_name));
     return true;
 }