/**
  * The "PMA\libraries\plugins\schema\svg\SvgRelationSchema" constructor
  *
  * Upon instantiation This starts writing the SVG XML document
  * user will be prompted for download as .svg extension
  *
  * @param string $db database name
  *
  * @see PMA_SVG
  */
 function __construct($db)
 {
     parent::__construct($db, new Svg());
     $this->setShowColor(isset($_REQUEST['svg_show_color']));
     $this->setShowKeys(isset($_REQUEST['svg_show_keys']));
     $this->setTableDimension(isset($_REQUEST['svg_show_table_dimension']));
     $this->setAllTablesSameWidth(isset($_REQUEST['svg_all_tables_same_width']));
     $this->diagram->setTitle(sprintf(__('Schema of the %s database - Page %s'), $this->db, $this->pageNumber));
     $this->diagram->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $this->diagram->setFont('Arial');
     $this->diagram->setFontSize('16px');
     $alltables = $this->getTablesFromRequest();
     foreach ($alltables as $table) {
         if (!isset($this->_tables[$table])) {
             $this->_tables[$table] = new TableStatsSvg($this->diagram, $this->db, $table, $this->diagram->getFont(), $this->diagram->getFontSize(), $this->pageNumber, $this->_tablewidth, $this->showKeys, $this->tableDimension, $this->offline);
         }
         if ($this->sameWide) {
             $this->_tables[$table]->width =& $this->_tablewidth;
         }
         $this->_setMinMax($this->_tables[$table]);
     }
     $border = 15;
     $this->diagram->startSvgDoc($this->_xMax + $border, $this->_yMax + $border, $this->_xMin - $border, $this->_yMin - $border);
     $seen_a_relation = false;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($this->db, $one_table, '', 'both');
         if (!$exist_rel) {
             continue;
         }
         $seen_a_relation = true;
         foreach ($exist_rel as $master_field => $rel) {
             /* put the foreign table on the schema only if selected
              * by the user
              * (do not use array_search() because we would have to
              * to do a === false and this is not PHP3 compatible)
              */
             if ($master_field != 'foreign_keys_data') {
                 if (in_array($rel['foreign_table'], $alltables)) {
                     $this->_addRelation($one_table, $this->diagram->getFont(), $this->diagram->getFontSize(), $master_field, $rel['foreign_table'], $rel['foreign_field'], $this->tableDimension);
                 }
                 continue;
             }
             foreach ($rel as $one_key) {
                 if (!in_array($one_key['ref_table_name'], $alltables)) {
                     continue;
                 }
                 foreach ($one_key['index_list'] as $index => $one_field) {
                     $this->_addRelation($one_table, $this->diagram->getFont(), $this->diagram->getFontSize(), $one_field, $one_key['ref_table_name'], $one_key['ref_index_list'][$index], $this->tableDimension);
                 }
             }
         }
     }
     if ($seen_a_relation) {
         $this->_drawRelations();
     }
     $this->_drawTables();
     $this->diagram->endSvgDoc();
 }
 /**
  * The "PMA\libraries\plugins\schema\dia\DiaRelationSchema" constructor
  *
  * Upon instantiation This outputs the Dia XML document
  * that user can download
  *
  * @param string $db database name
  *
  * @see Dia,TableStatsDia,RelationStatsDia
  */
 public function __construct($db)
 {
     parent::__construct($db, new Dia());
     $this->setShowColor(isset($_REQUEST['dia_show_color']));
     $this->setShowKeys(isset($_REQUEST['dia_show_keys']));
     $this->setOrientation($_REQUEST['dia_orientation']);
     $this->setPaper($_REQUEST['dia_paper']);
     $this->diagram->startDiaDoc($this->paper, $this->_topMargin, $this->_bottomMargin, $this->_leftMargin, $this->_rightMargin, $this->orientation);
     $alltables = $this->getTablesFromRequest();
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->_tables[$table] = new TableStatsDia($this->diagram, $this->db, $table, $this->pageNumber, $this->showKeys, $this->offline);
         }
     }
     $seen_a_relation = false;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($this->db, $one_table, '', 'both');
         if (!$exist_rel) {
             continue;
         }
         $seen_a_relation = true;
         foreach ($exist_rel as $master_field => $rel) {
             /* put the foreign table on the schema only if selected
              * by the user
              * (do not use array_search() because we would have to
              * to do a === false and this is not PHP3 compatible)
              */
             if ($master_field != 'foreign_keys_data') {
                 if (in_array($rel['foreign_table'], $alltables)) {
                     $this->_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field'], $this->showKeys);
                 }
                 continue;
             }
             foreach ($rel as $one_key) {
                 if (!in_array($one_key['ref_table_name'], $alltables)) {
                     continue;
                 }
                 foreach ($one_key['index_list'] as $index => $one_field) {
                     $this->_addRelation($one_table, $one_field, $one_key['ref_table_name'], $one_key['ref_index_list'][$index], $this->showKeys);
                 }
             }
         }
     }
     $this->_drawTables();
     if ($seen_a_relation) {
         $this->_drawRelations();
     }
     $this->diagram->endDiaDoc();
 }
Exemplo n.º 3
0
 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy)
 {
     global $cfgRelation;
     /**
      * Get the unique keys in the table
      */
     $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
     $keys_result = PMA_DBI_query($keys_query);
     $unique_keys = array();
     while ($key = PMA_DBI_fetch_assoc($keys_result)) {
         if ($key['Non_unique'] == 0) {
             $unique_keys[] = $key['Column_name'];
         }
     }
     PMA_DBI_free_result($keys_result);
     /**
      * Gets fields properties
      */
     PMA_DBI_select_db($db);
     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
     $result = PMA_DBI_query($local_query);
     $fields_cnt = PMA_DBI_num_rows($result);
     // Check if we can use Relations (Mike Beck)
     if ($do_relation && !empty($cfgRelation['relation'])) {
         // Find which tables are related with the current one and write it in
         // an array
         $res_rel = PMA_getForeigners($db, $table);
         if ($res_rel && count($res_rel) > 0) {
             $have_rel = TRUE;
         } else {
             $have_rel = FALSE;
         }
     } else {
         $have_rel = FALSE;
     }
     // end if
     /**
      * Displays the table structure
      */
     $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{';
     if (!PMA_exportOutputHandler($buffer)) {
         return FALSE;
     }
     $columns_cnt = 4;
     $alignment = '|l|c|c|c|';
     if ($do_relation && $have_rel) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $columns_cnt++;
         $alignment .= 'l|';
     }
     $buffer = $alignment . '} ' . $crlf;
     $header = ' \\hline ';
     $header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}';
     if ($do_relation && $have_rel) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}';
     }
     if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}';
         $comments = PMA_getComments($db, $table);
     }
     if ($do_mime && $cfgRelation['mimework']) {
         $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
         $mime_map = PMA_getMIME($db, $table, true);
     }
     $local_buffer = PMA_texEscape($table);
     // Table caption for first page and label
     if (isset($GLOBALS['latex_caption'])) {
         $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption']) . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label']) . '} \\\\' . $crlf;
     }
     $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
     // Table caption on next pages
     if (isset($GLOBALS['latex_caption'])) {
         $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption']) . '} \\\\ ' . $crlf;
     }
     $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf;
     if (!PMA_exportOutputHandler($buffer)) {
         return FALSE;
     }
     while ($row = PMA_DBI_fetch_assoc($result)) {
         $type = $row['Type'];
         // reformat mysql query output - staybyte - 9. June 2001
         // loic1: set or enum types: slashes single quotes inside options
         if (eregi('^(set|enum)\\((.+)\\)$', $type, $tmp)) {
             $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
             $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
             $type_nowrap = '';
             $binary = 0;
             $unsigned = 0;
             $zerofill = 0;
         } else {
             $type_nowrap = ' nowrap="nowrap"';
             $type = eregi_replace('BINARY', '', $type);
             $type = eregi_replace('ZEROFILL', '', $type);
             $type = eregi_replace('UNSIGNED', '', $type);
             if (empty($type)) {
                 $type = ' ';
             }
             $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);
 }
/**
 * Get HTML div for copy table
 *
 * @return string $html_output
 */
function PMA_getHtmlForCopytable()
{
    $html_output = '<div class="operations_half_width">';
    $html_output .= '<form method="post" action="tbl_operations.php" ' . 'name="copyTable" ' . 'id="copyTable" ' . ' class="ajax" ' . 'onsubmit="return emptyCheckTheField(this, \'new_name\')">' . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']) . '<input type="hidden" name="reload" value="1" />';
    $html_output .= '<fieldset>';
    $html_output .= '<legend>' . __('Copy table to (database<b>.</b>table)') . '</legend>';
    if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
        $html_output .= '<input class="halfWidth" type="text" maxlength="100" ' . 'size="30" name="target_db" ' . 'value="' . htmlspecialchars($GLOBALS['db']) . '"/>';
    } else {
        $html_output .= '<select class="halfWidth" name="target_db">' . $GLOBALS['pma']->databases->getHtmlOptions(true, false) . '</select>';
    }
    $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
    $html_output .= '<input class="halfWidth" type="text" required="required" ' . 'size="20" name="new_name" maxlength="64" ' . 'value="' . htmlspecialchars($GLOBALS['table']) . '"/><br />';
    $choices = array('structure' => __('Structure only'), 'data' => __('Structure and data'), 'dataonly' => __('Data only'));
    $html_output .= PMA\libraries\Util::getRadioFields('what', $choices, 'data', true);
    $html_output .= '<br />';
    $html_output .= '<input type="checkbox" name="drop_if_exists" ' . 'value="true" id="checkbox_drop" />' . '<label for="checkbox_drop">' . sprintf(__('Add %s'), 'DROP TABLE') . '</label><br />' . '<input type="checkbox" name="sql_auto_increment" ' . 'value="1" id="checkbox_auto_increment_cp" />' . '<label for="checkbox_auto_increment_cp">' . __('Add AUTO_INCREMENT value') . '</label><br />';
    // display "Add constraints" choice only if there are
    // foreign keys
    if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
        $html_output .= '<input type="checkbox" name="add_constraints" ' . 'value="1" id="checkbox_constraints" checked="checked"/>';
        $html_output .= '<label for="checkbox_constraints">' . __('Add constraints') . '</label><br />';
    }
    // endif
    $html_output .= '<br />';
    if (isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv']) {
        $html_output .= '<input type="checkbox" name="adjust_privileges" ' . 'value="1" id="checkbox_adjust_privileges" checked="checked" />';
    } else {
        $html_output .= '<input type="checkbox" name="adjust_privileges" ' . 'value="1" id="checkbox_adjust_privileges" title="' . __('You don\'t have sufficient privileges to perform this ' . 'operation; Please refer to the documentation for more details') . '" disabled/>';
    }
    $html_output .= '<label for="checkbox_adjust_privileges">' . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39') . '</label><br />';
    if (isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true') {
        $pma_switch_to_new = 'true';
    }
    $html_output .= '<input type="checkbox" name="switch_to_new" value="true"' . 'id="checkbox_switch"' . (isset($pma_switch_to_new) && $pma_switch_to_new == 'true' ? ' checked="checked"' : '' . '/>');
    $html_output .= '<label for="checkbox_switch">' . __('Switch to copied table') . '</label>' . '</fieldset>';
    $html_output .= '<fieldset class="tblFooters">' . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />' . '</fieldset>' . '</form>' . '</div>';
    return $html_output;
}
Exemplo n.º 5
0
     $master_tables = 'SELECT COUNT(master_table), master_table' . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' WHERE master_db = \'' . $db . '\'' . ' GROUP BY master_table' . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
     $master_tables_rs = PMA_query_as_cu($master_tables, FALSE, $query_default_option);
     if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
         // first put all the master tables at beginning
         // of the list, so they are near the center of
         // the schema
         while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
             $all_tables[] = $master_table;
         }
         // then for each master, add its foreigns into an array
         // of foreign tables, if not already there
         // (a foreign might be foreign for more than
         // one table, and might be a master itself)
         $foreign_tables = array();
         foreach ($all_tables as $master_table) {
             $foreigners = PMA_getForeigners($db, $master_table);
             foreach ($foreigners as $foreigner) {
                 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
                     $foreign_tables[] = $foreigner['foreign_table'];
                 }
             }
         }
         // then merge the arrays
         foreach ($foreign_tables as $foreign_table) {
             if (!in_array($foreign_table, $all_tables)) {
                 $all_tables[] = $foreign_table;
             }
         }
     }
     // endif there are master tables
 }
Exemplo n.º 6
0
?>
    </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';
                $join_query .= ' AS ' . PMA_backquote($foreign_table);
Exemplo n.º 7
0
 /**
  * Loads relations for a given table into the $relations array
  *
  * @param array  &$relations array of relations
  * @param string $oneTable   the table
  *
  * @return void
  */
 private function _loadRelationsForTable(&$relations, $oneTable)
 {
     $relations[$oneTable] = array();
     $foreigners = PMA_getForeigners($GLOBALS['db'], $oneTable);
     foreach ($foreigners as $field => $foreigner) {
         // Foreign keys data
         if ($field == 'foreign_keys_data') {
             foreach ($foreigner as $oneKey) {
                 $clauses = array();
                 // There may be multiple column relations
                 foreach ($oneKey['index_list'] as $index => $oneField) {
                     $clauses[] = Util::backquote($oneTable) . "." . Util::backquote($oneField) . " = " . Util::backquote($oneKey['ref_table_name']) . "." . Util::backquote($oneKey['ref_index_list'][$index]);
                 }
                 // Combine multiple column relations with AND
                 $relations[$oneTable][$oneKey['ref_table_name']] = implode(" AND ", $clauses);
             }
         } else {
             // Internal relations
             $relations[$oneTable][$foreigner['foreign_table']] = Util::backquote($oneTable) . "." . Util::backquote($field) . " = " . Util::backquote($foreigner['foreign_table']) . "." . Util::backquote($foreigner['foreign_field']);
         }
     }
 }
Exemplo n.º 8
0
/**
 * Displays a table of results returned by a sql query.
 * This function is called by the "sql.php" script.
 *
 * @param   integer the link id associated to the query which results have
 *                  to be displayed
 * @param   array   the display mode
 * @param   array   the analyzed query
 *
 * @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 current sql query
 * @global  integer  $num_rows          the total number of rows returned by the
 *                                      sql query
 * @global  integer  $unlim_num_rows    the total number of rows returned by the
 *                                      sql query without any programmatically
 *                                      appended "LIMIT" clause
 * @global  integer  $pos               the current postion of the first record
 *                                      to be displayed
 * @global  array    $fields_meta       the list of fields properties
 * @global  integer  $fields_cnt        the total number of fields returned by
 *                                      the sql query
 * @global  array    $vertical_display  informations used with vertical display
 *                                      mode
 * @global  string   $disp_direction    the display mode
 *                                      (horizontal/vertical/horizontalflipped)
 * @global  integer  $repeat_cells      the number of row to display between two
 *                                      table headers
 * @global  array    $highlight_columns collumn names to highlight
 * @global  array    $cfgRelation       the relation settings
 *
 * @access  private
 *
 * @see     PMA_showMessage(), PMA_setDisplayMode(),
 *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
 *          PMA_displayTableBody(), PMA_displayResultsOperations()
 */
function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
{
    global $db, $table, $goto, $dontlimitchars;
    global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
    global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
    global $cfgRelation;
    // 1. ----- Prepares the work -----
    // 1.1 Gets the informations about which functionnalities should be
    //     displayed
    $total = '';
    $is_display = PMA_setDisplayMode($the_disp_mode, $total);
    if ($total == '') {
        unset($total);
    }
    // 1.2 Defines offsets for the next and previous pages
    if ($is_display['nav_bar'] == '1') {
        if (!isset($pos)) {
            $pos = 0;
        }
        if ($GLOBALS['session_max_rows'] == 'all') {
            $pos_next = 0;
            $pos_prev = 0;
        } else {
            $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
            $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
            if ($pos_prev < 0) {
                $pos_prev = 0;
            }
        }
    }
    // end if
    // 1.3 Urlencodes the query to use in input form fields
    $encoded_sql_query = urlencode($sql_query);
    // 2. ----- Displays the top of the page -----
    // 2.1 Displays a messages with position informations
    if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
        if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
            $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
        } else {
            $selectstring = '';
        }
        $last_shown_rec = $GLOBALS['session_max_rows'] == 'all' || $pos_next > $total ? $total - 1 : $pos_next - 1;
        PMA_showMessage($GLOBALS['strShowingRecords'] . " {$pos} - {$last_shown_rec} (" . PMA_formatNumber($total, 0) . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
        if (isset($table) && PMA_Table::isView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCount']) {
            echo '<div class="notice">' . "\n";
            echo PMA_sanitize(sprintf($GLOBALS['strViewMaxExactCount'], PMA_formatNumber($GLOBALS['cfg']['MaxExactCount'], 0), '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]')) . "\n";
            echo '</div>' . "\n";
        }
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        PMA_showMessage($GLOBALS['strSQLQuery']);
    }
    // 2.3 Displays the navigation bars
    if (!isset($table) || strlen(trim($table)) == 0) {
        if (isset($analyzed_sql[0]['query_type']) && $analyzed_sql[0]['query_type'] == 'SELECT') {
            // table does not always contain a real table name,
            // for example in MySQL 5.0.x, the query SHOW STATUS
            // returns STATUS as a table name
            $table = $fields_meta[0]->table;
        } else {
            $table = '';
        }
    }
    if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
    }
    if ($is_display['nav_bar'] == '1') {
        PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
        echo "\n";
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        echo "\n" . '<br /><br />' . "\n";
    }
    // 2b ----- Get field references from Database -----
    // (see the 'relation' config variable)
    // loic1, 2002-03-02: extended to php3
    // init map
    $map = array();
    // find tables
    $target = array();
    if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
        foreach ($analyzed_sql[0]['table_ref'] as $table_ref_position => $table_ref) {
            $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
        }
    }
    $tabs = '(\'' . join('\',\'', $target) . '\')';
    if ($cfgRelation['displaywork']) {
        if (!isset($table) || !strlen($table)) {
            $exist_rel = false;
        } else {
            $exist_rel = PMA_getForeigners($db, $table, '', 'both');
            if ($exist_rel) {
                foreach ($exist_rel as $master_field => $rel) {
                    $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
                    $map[$master_field] = array($rel['foreign_table'], $rel['foreign_field'], $display_field, $rel['foreign_db']);
                }
                // end while
            }
            // end if
        }
        // end if
    }
    // end if
    // end 2b
    // 3. ----- Displays the results table -----
    PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
    $url_query = '';
    echo '<tbody>' . "\n";
    PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
    echo '</tbody>' . "\n";
    // vertical output case
    if ($disp_direction == 'vertical') {
        PMA_displayVerticalTable();
    }
    // end if
    unset($vertical_display);
    ?>
</table>

    <?php 
    // 4. ----- Displays the link for multi-fields delete
    if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
        $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
        $uncheckall_url = 'sql.php?' . PMA_generate_common_url($db, $table) . '&amp;sql_query=' . urlencode($sql_query) . '&amp;pos=' . $pos . '&amp;session_max_rows=' . $GLOBALS['session_max_rows'] . '&amp;pos=' . $pos . '&amp;disp_direction=' . $disp_direction . '&amp;repeat_cells=' . $repeat_cells . '&amp;goto=' . $goto . '&amp;dontlimitchars=' . $dontlimitchars;
        $checkall_url = $uncheckall_url . '&amp;checkall=1';
        if ($disp_direction == 'vertical') {
            $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
            $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
        } else {
            $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
            $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
        }
        $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
        $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
        if ($disp_direction != 'vertical') {
            echo '<img class="selectallarrow" width="38" height="22"' . ' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"' . ' alt="' . $GLOBALS['strWithChecked'] . '" />';
        }
        echo $checkall_link . "\n" . ' / ' . "\n" . $uncheckall_link . "\n" . '<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
        if ($GLOBALS['cfg']['PropertiesIconic']) {
            PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
            PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_delete', $delete_text, 'b_drop.png');
            if ($analyzed_sql[0]['querytype'] == 'SELECT') {
                PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', $GLOBALS['strExport'], 'b_tblexport.png');
            }
            echo "\n";
        } else {
            echo ' <input type="submit" name="submit_mult"' . ' value="' . htmlspecialchars($GLOBALS['strEdit']) . '"' . ' title="' . $GLOBALS['strEdit'] . '" />' . "\n";
            echo ' <input type="submit" name="submit_mult"' . ' value="' . htmlspecialchars($delete_text) . '"' . ' title="' . $delete_text . '" />' . "\n";
            if ($analyzed_sql[0]['querytype'] == 'SELECT') {
                echo ' <input type="submit" name="submit_mult"' . ' value="' . htmlspecialchars($GLOBALS['strExport']) . '"' . ' title="' . $GLOBALS['strExport'] . '" />' . "\n";
            }
        }
        echo '<input type="hidden" name="sql_query"' . ' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
        echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
        echo '<input type="hidden" name="url_query"' . ' value="' . $GLOBALS['url_query'] . '" />' . "\n";
        echo '</form>' . "\n";
    }
    // 5. ----- Displays the navigation bar at the bottom if required -----
    if ($is_display['nav_bar'] == '1') {
        echo '<br />' . "\n";
        PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        echo "\n" . '<br /><br />' . "\n";
    }
}
/**
 * Displays a table of results returned by a sql query.
 * This function is called by the "sql.php" script.
 *
 * @param   integer the link id associated to the query which results have
 *                  to be displayed
 * @param   array   the display mode
 * @param   array   the analyzed query
 *
 * @global  string   the current language
 * @global  integer  the server to use (refers to the number in the
 *                   configuration file)
 * @global  array    the current server config
 * @global  string   the database name
 * @global  string   the table name
 * @global  string   the url to go back in case of errors
 * @global  string   the current sql query
 * @global  integer  the total number of rows returned by the sql query
 * @global  integer  the total number of rows returned by the sql query
 *                   without any programmatically appended "LIMIT" clause
 * @global  integer  the current postion of the first record to be
 *                   displayed
 * @global  array    the list of fields properties
 * @global  integer  the total number of fields returned by the sql query
 * @global  array    informations used with vertical display mode
 * @global  string   the display mode (horizontal/vertical/horizontalflipped)
 * @global  integer  the number of row to display between two table headers
 * @global  boolean  whether to limit the number of displayed characters of
 *                   text type fields or not
 * @global  array    the relation settings
 *
 * @access  private
 *
 * @see     PMA_showMessage(), PMA_setDisplayMode(),
 *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
 *          PMA_displayTableBody()
 */
function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
{
    global $lang, $server, $cfg, $db, $table;
    global $goto, $text_url;
    global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
    global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
    global $dontlimitchars;
    global $cfgRelation;
    // 1. ----- Prepares the work -----
    // 1.1 Gets the informations about which functionnalities should be
    //     displayed
    $total = '';
    $is_display = PMA_setDisplayMode($the_disp_mode, $total);
    if ($total == '') {
        unset($total);
    }
    // 1.2 Defines offsets for the next and previous pages
    if ($is_display['nav_bar'] == '1') {
        if (!isset($pos)) {
            $pos = 0;
        }
        if ($GLOBALS['session_max_rows'] == 'all') {
            $pos_next = 0;
            $pos_prev = 0;
        } else {
            $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
            $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
            if ($pos_prev < 0) {
                $pos_prev = 0;
            }
        }
    }
    // end if
    // 1.3 Urlencodes the query to use in input form fields
    $encoded_sql_query = urlencode($sql_query);
    // 2. ----- Displays the top of the page -----
    // 2.1 Displays a messages with position informations
    if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
        if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
            $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
        } else {
            $selectstring = '';
        }
        $last_shown_rec = $GLOBALS['session_max_rows'] == 'all' || $pos_next > $total ? $total - 1 : $pos_next - 1;
        PMA_showMessage($GLOBALS['strShowingRecords'] . " {$pos} - {$last_shown_rec} ({$total} " . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
    } else {
        if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
            PMA_showMessage($GLOBALS['strSQLQuery']);
        }
    }
    // 2.3 Displays the navigation bars
    if (!isset($table) || strlen(trim($table)) == 0) {
        $table = $fields_meta[0]->table;
    }
    if ($is_display['nav_bar'] == '1') {
        PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
        echo "\n";
    } else {
        if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
            echo "\n" . '<br /><br />' . "\n";
        }
    }
    // 2b ----- Get field references from Database -----
    // (see the 'relation' config variable)
    // loic1, 2002-03-02: extended to php3
    // init map
    $map = array();
    // find tables
    $target = array();
    if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
        foreach ($analyzed_sql[0]['table_ref'] as $table_ref_position => $table_ref) {
            $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
        }
    }
    $tabs = '(\'' . join('\',\'', $target) . '\')';
    if ($cfgRelation['displaywork']) {
        if (empty($table)) {
            $exist_rel = FALSE;
        } else {
            $exist_rel = PMA_getForeigners($db, $table, '', 'both');
            if ($exist_rel) {
                foreach ($exist_rel as $master_field => $rel) {
                    $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
                    $map[$master_field] = array($rel['foreign_table'], $rel['foreign_field'], $display_field, $rel['foreign_db']);
                }
                // end while
            }
            // end if
        }
        // end if
    }
    // end if
    // end 2b
    // 3. ----- Displays the results table -----
    PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
    $url_query = '';
    PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
    // vertical output case
    if ($disp_direction == 'vertical') {
        PMA_displayVerticalTable();
    }
    // end if
    unset($vertical_display);
    ?>
</table>
    <?php 
    echo "\n";
    // 4. ----- Displays the link for multi-fields delete
    if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
        $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
        $propicon = (string) $GLOBALS['cfg']['PropertiesIconic'];
        ?>
        &nbsp;&nbsp;<img src="<?php 
        echo $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png';
        ?>
" border="0" width="38" height="22" alt="<?php 
        echo $GLOBALS['strWithChecked'];
        ?>
" />
        <a href="<?php 
        echo $text_url . '&amp;checkall=1';
        ?>
" onclick="setCheckboxesRange('rowsDeleteForm', true, 'id_rows_to_delete', 0, '<?php 
        echo $num_rows;
        ?>
'); return false;">
            <?php 
        echo $GLOBALS['strCheckAll'];
        ?>
</a>
        &nbsp;/&nbsp;
        <a href="<?php 
        echo $text_url;
        ?>
" onclick="setCheckboxesRange('rowsDeleteForm', false, 'id_rows_to_delete', 0, '<?php 
        echo $num_rows;
        ?>
'); return false;">
            <?php 
        echo $GLOBALS['strUncheckAll'];
        ?>
</a>
<?php 
        echo '&nbsp;&nbsp;<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
        if ($cfg['PropertiesIconic']) {
            PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
            PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_delete', $delete_text, 'b_drop.png');
            if ($analyzed_sql[0]['querytype'] == 'SELECT') {
                PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', $GLOBALS['strExport'], 'b_tblexport.png');
            }
            echo "\n";
        } else {
            echo '                    <input type="submit" name="submit_mult" value="' . htmlspecialchars($GLOBALS['strEdit']) . '" title="' . $GLOBALS['strEdit'] . '" />' . "\n";
            echo '&nbsp;<input type="submit" name="submit_mult" value="' . htmlspecialchars($delete_text) . '" title="' . $delete_text . '" />' . "\n";
            if ($analyzed_sql[0]['querytype'] == 'SELECT') {
                echo '&nbsp;<input type="submit" name="submit_mult" value="' . htmlspecialchars($GLOBALS['strExport']) . '" title="' . $GLOBALS['strExport'] . '" />' . "\n";
            }
        }
        echo '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />' . "\n";
        echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
        echo '<input type="hidden" name="url_query" value="' . $GLOBALS['url_query'] . '" />' . "\n";
        echo '<br />' . "\n";
        echo '</form>' . "\n";
    }
    // 5. ----- Displays the navigation bar at the bottom if required -----
    if ($is_display['nav_bar'] == '1') {
        echo '<br />' . "\n";
        PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
    } else {
        if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
            echo "\n" . '<br /><br />' . "\n";
        }
    }
}
Exemplo n.º 10
0
 public function dataDictionaryDoc($alltables)
 {
     global $db, $pdf, $orientation, $paper;
     // TOC
     $pdf->addpage($_POST['orientation']);
     $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C');
     $pdf->Ln(15);
     $i = 1;
     foreach ($alltables as $table) {
         $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink();
         $pdf->SetX(10);
         // $pdf->Ln(1);
         $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']);
         $pdf->SetX(10);
         $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
         // $pdf->Ln(1);
         $fields = PMA_DBI_get_columns($GLOBALS['db'], $table);
         foreach ($fields as $row) {
             $pdf->SetX(20);
             $field_name = $row['Field'];
             $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink();
             //$pdf->Cell(
             //    0, 6, $field_name, 0, 1,
             //    'L', 0, $pdf->PMA_links['doc'][$table][$field_name]
             //);
         }
         $i++;
     }
     $pdf->PMA_links['RT']['-'] = $pdf->AddLink();
     $pdf->SetX(10);
     $pdf->Cell(0, 6, __('Page number:') . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['RT']['-']);
     $pdf->SetX(10);
     $pdf->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']);
     $z = 0;
     foreach ($alltables as $table) {
         $z++;
         $pdf->SetAutoPageBreak(true, 15);
         $pdf->addpage($_POST['orientation']);
         $pdf->Bookmark($table);
         $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo());
         $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink();
         $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1);
         $pdf->SetFont($this->_ff, 'B', 18);
         $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']);
         $pdf->SetFont($this->_ff, '', 8);
         $pdf->ln();
         $cfgRelation = PMA_getRelationsParam();
         $comments = PMA_getComments($db, $table);
         if ($cfgRelation['mimework']) {
             $mime_map = PMA_getMIME($db, $table, true);
         }
         /**
          * Gets table informations
          */
         $showtable = PMA_Table::sGetStatusInfo($db, $table);
         $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
         $create_time = isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : '';
         $update_time = isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : '';
         $check_time = isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : '';
         /**
          * Gets table keys and retains them
          */
         $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
         $primary = '';
         $indexes = array();
         $lastIndex = '';
         $indexes_info = array();
         $indexes_data = array();
         $pk_array = array();
         // will be use to emphasis prim. keys in the table
         // view
         while ($row = PMA_DBI_fetch_assoc($result)) {
             // Backups the list of primary keys
             if ($row['Key_name'] == 'PRIMARY') {
                 $primary .= $row['Column_name'] . ', ';
                 $pk_array[$row['Column_name']] = 1;
             }
             // Retains keys informations
             if ($row['Key_name'] != $lastIndex) {
                 $indexes[] = $row['Key_name'];
                 $lastIndex = $row['Key_name'];
             }
             $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
             $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
             if (isset($row['Cardinality'])) {
                 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
             }
             // I don't know what does following column mean....
             // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
             $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
             if (isset($row['Sub_part'])) {
                 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
             }
         }
         // end while
         if ($result) {
             PMA_DBI_free_result($result);
         }
         /**
          * Gets fields properties
          */
         $columns = PMA_DBI_get_columns($db, $table);
         // Check if we can use Relations
         if (!empty($cfgRelation['relation'])) {
             // Find which tables are related with the current one and write it in
             // an array
             $res_rel = PMA_getForeigners($db, $table);
             if (count($res_rel) > 0) {
                 $have_rel = true;
             } else {
                 $have_rel = false;
             }
         } else {
             $have_rel = false;
         }
         // end if
         /**
          * Displays the comments of the table if MySQL >= 3.23
          */
         $break = false;
         if (!empty($show_comment)) {
             $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1);
             $break = true;
         }
         if (!empty($create_time)) {
             $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1);
             $break = true;
         }
         if (!empty($update_time)) {
             $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1);
             $break = true;
         }
         if (!empty($check_time)) {
             $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1);
             $break = true;
         }
         if ($break == true) {
             $pdf->Cell(0, 3, '', 0, 1);
             $pdf->Ln();
         }
         $pdf->SetFont($this->_ff, 'B');
         if (isset($orientation) && $orientation == 'L') {
             $pdf->Cell(25, 8, __('Column'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Default'), 1, 0, 'C');
             $pdf->Cell(25, 8, __('Extra'), 1, 0, 'C');
             $pdf->Cell(45, 8, __('Links to'), 1, 0, 'C');
             if ($paper == 'A4') {
                 $comments_width = 67;
             } else {
                 // this is really intended for 'letter'
                 /**
                  * @todo find optimal width for all formats
                  */
                 $comments_width = 50;
             }
             $pdf->Cell($comments_width, 8, __('Comments'), 1, 0, 'C');
             $pdf->Cell(45, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45));
         } else {
             $pdf->Cell(20, 8, __('Column'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Type'), 1, 0, 'C');
             $pdf->Cell(20, 8, __('Attributes'), 1, 0, 'C');
             $pdf->Cell(10, 8, __('Null'), 1, 0, 'C');
             $pdf->Cell(15, 8, __('Default'), 1, 0, 'C');
             $pdf->Cell(15, 8, __('Extra'), 1, 0, 'C');
             $pdf->Cell(30, 8, __('Links to'), 1, 0, 'C');
             $pdf->Cell(30, 8, __('Comments'), 1, 0, 'C');
             $pdf->Cell(30, 8, 'MIME', 1, 1, 'C');
             $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30));
         }
         $pdf->SetFont($this->_ff, '');
         foreach ($columns as $row) {
             $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
             $type = $extracted_fieldspec['print_type'];
             $attribute = $extracted_fieldspec['attribute'];
             if (!isset($row['Default'])) {
                 if ($row['Null'] != '' && $row['Null'] != 'NO') {
                     $row['Default'] = 'NULL';
                 }
             }
             $field_name = $row['Field'];
             // $pdf->Ln();
             $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink();
             $pdf->Bookmark($field_name, 1, -1);
             $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1);
             $pdf_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], isset($res_rel[$field_name]) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : '', isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '');
             $links[0] = $pdf->PMA_links['RT'][$table][$field_name];
             if (isset($res_rel[$field_name]['foreign_table']) and isset($res_rel[$field_name]['foreign_field']) and isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])) {
                 $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']];
             } else {
                 unset($links[6]);
             }
             $pdf->Row($pdf_row, $links);
         }
         // end foreach
         $pdf->SetFont($this->_ff, '', 14);
     }
     //end each
 }
 /**
  * The "PMA_Svg_Relation_Schema" constructor
  *
  * Upon instantiation This starts writing the SVG XML document
  * user will be prompted for download as .svg extension
  *
  * @return void
  * @see PMA_SVG
  */
 function __construct()
 {
     global $svg, $db;
     $this->setPageNumber($_POST['pdf_page_number']);
     $this->setShowColor(isset($_POST['show_color']));
     $this->setShowKeys(isset($_POST['show_keys']));
     $this->setTableDimension(isset($_POST['show_table_dimension']));
     $this->setAllTableSameWidth(isset($_POST['all_table_same_wide']));
     $this->setExportType($_POST['export_type']);
     $svg = new PMA_SVG();
     $svg->setTitle(sprintf(__('Schema of the %s database - Page %s'), $db, $this->pageNumber));
     $svg->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $svg->setFont('Arial');
     $svg->setFontSize('16px');
     $svg->startSvgDoc('1000px', '1000px');
     $alltables = $this->getAllTables($db, $this->pageNumber);
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->tables[$table] = new Table_Stats($table, $svg->getFont(), $svg->getFontSize(), $this->pageNumber, $this->_tablewidth, $this->showKeys, $this->tableDimension);
         }
         if ($this->sameWide) {
             $this->tables[$table]->width = $this->_tablewidth;
         }
         $this->_setMinMax($this->tables[$table]);
     }
     $seen_a_relation = false;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
         if ($exist_rel) {
             $seen_a_relation = true;
             foreach ($exist_rel as $master_field => $rel) {
                 /* put the foreign table on the schema only if selected
                  * by the user
                  * (do not use array_search() because we would have to
                  * to do a === FALSE and this is not PHP3 compatible)
                  */
                 if (in_array($rel['foreign_table'], $alltables)) {
                     $this->_addRelation($one_table, $svg->getFont(), $svg->getFontSize(), $master_field, $rel['foreign_table'], $rel['foreign_field'], $this->tableDimension);
                 }
             }
         }
     }
     if ($seen_a_relation) {
         $this->_drawRelations($this->showColor);
     }
     $this->_drawTables($this->showColor);
     $svg->endSvgDoc();
     $svg->showOutput($db . '-' . $this->pageNumber);
     exit;
 }
Exemplo n.º 12
0
// vim: expandtab sw=4 ts=4 sts=4:
include_once 'pmd_common.php';
$die_save_pos = 0;
include_once 'pmd_save_pos.php';
require_once './libraries/relation.lib.php';
extract($_POST);
$tables = PMA_DBI_get_tables_full($db, $T1);
$type_T1 = strtoupper($tables[$T1]['ENGINE']);
$tables = PMA_DBI_get_tables_full($db, $T2);
//print_r($tables);
//die();
$type_T2 = strtoupper($tables[$T2]['ENGINE']);
//  I n n o D B
if ($type_T1 == 'INNODB' and $type_T2 == 'INNODB') {
    // relation exists?
    $existrel_innodb = PMA_getForeigners($db, $T2, '', 'innodb');
    if (isset($existrel_innodb[$F2]) && isset($existrel_innodb[$F2]['constraint'])) {
        PMD_return(0, 'strErrorRelationExists');
    }
    // note: in InnoDB, the index does not requires to be on a PRIMARY
    // or UNIQUE key
    // improve: check all other requirements for InnoDB relations
    $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($T1) . ';');
    $index_array1 = array();
    // will be use to emphasis prim. keys in the table view
    while ($row = PMA_DBI_fetch_assoc($result)) {
        $index_array1[$row['Column_name']] = 1;
    }
    PMA_DBI_free_result($result);
    $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($T2) . ';');
    $index_array2 = array();
Exemplo n.º 13
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>');
 }
Exemplo n.º 14
0
/**
 * The following section only applies to grid editing.
 * However, verifying isAjax() is not enough to ensure we are coming from
 * grid editing. If we are coming from the Edit or Copy link in Browse mode,
 * ajax_page_request is present in the POST parameters.
 */
if ($response->isAjax() && !isset($_POST['ajax_page_request'])) {
    /**
     * If we are in grid editing, we need to process the relational and
     * transformed fields, if they were edited. After that, output the correct
     * link/transformed value and exit
     *
     * Logic taken from libraries/DisplayResults.class.php
     */
    if (isset($_REQUEST['rel_fields_list']) && $_REQUEST['rel_fields_list'] != '') {
        $map = PMA_getForeigners($db, $table, '', 'both');
        $relation_fields = array();
        parse_str($_REQUEST['rel_fields_list'], $relation_fields);
        // loop for each relation cell
        /** @var array $relation_fields */
        foreach ($relation_fields as $cell_index => $curr_rel_field) {
            foreach ($curr_rel_field as $relation_field => $relation_field_value) {
                $where_comparison = "='" . $relation_field_value . "'";
                $dispval = PMA_getDisplayValueForForeignTableColumn($where_comparison, $map, $relation_field);
                $extra_data['relations'][$cell_index] = PMA_getLinkForRelationalDisplayField($map, $relation_field, $where_comparison, $dispval, $relation_field_value);
            }
        }
        // end of loop for each relation cell
    }
    if (isset($_REQUEST['do_transformations']) && $_REQUEST['do_transformations'] == true) {
        $edited_values = array();
Exemplo n.º 15
0
    $db = $fields['dbase'];
}

/**
 * During grid edit, if we have a relational field, show the dropdown for it
 *
 * Logic taken from libraries/display_tbl_lib.php
 *
 * This doesn't seem to be the right place to do this, but I can't think of any
 * better place either.
 */
if (isset($_REQUEST['get_relational_values']) && $_REQUEST['get_relational_values'] == true) {
    include_once 'libraries/relation.lib.php';

    $column = $_REQUEST['column'];
    $foreigners = PMA_getForeigners($db, $table, $column);

    $display_field = PMA_getDisplayField($foreigners[$column]['foreign_db'], $foreigners[$column]['foreign_table']);

    $foreignData = PMA_getForeignData($foreigners, $column, false, '', '');

    if ($_SESSION['tmp_user_values']['relational_display'] == 'D'
        && isset($display_field)
        && strlen($display_field)
        && isset($_REQUEST['relation_key_or_display_column'])
        && $_REQUEST['relation_key_or_display_column']
    ) {
            $curr_value = $_REQUEST['relation_key_or_display_column'];
    } else {
        $curr_value = $_REQUEST['curr_value'];
    }
Exemplo n.º 16
0
 /**
  * Returns $table's comments, relations etc.
  *
  * @param string $db          database name
  * @param string $table       table name
  * @param string $crlf        end of line sequence
  * @param bool   $do_relation whether to include relation comments
  * @param bool   $do_mime     whether to include mime comments
  *
  * @return string resulting comments
  */
 private function _getTableComments($db, $table, $crlf, $do_relation = false, $do_mime = false)
 {
     global $cfgRelation, $sql_backquotes;
     $schema_create = '';
     // 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
     if ($do_mime && $cfgRelation['mimework']) {
         if (!($mime_map = PMA_getMIME($db, $table, true))) {
             unset($mime_map);
         }
     }
     if (isset($mime_map) && count($mime_map) > 0) {
         $schema_create .= $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment(__('MIME TYPES FOR TABLE') . ' ' . PMA_Util::backquote($table, $sql_backquotes) . ':');
         @reset($mime_map);
         foreach ($mime_map as $mime_field => $mime) {
             $schema_create .= $this->_exportComment('  ' . PMA_Util::backquote($mime_field, $sql_backquotes)) . $this->_exportComment('      ' . PMA_Util::backquote($mime['mimetype'], $sql_backquotes));
         }
         $schema_create .= $this->_exportComment();
     }
     if ($have_rel) {
         $schema_create .= $this->_possibleCRLF() . $this->_exportComment() . $this->_exportComment(__('RELATIONS FOR TABLE') . ' ' . PMA_Util::backquote($table, $sql_backquotes) . ':');
         foreach ($res_rel as $rel_field => $rel) {
             $schema_create .= $this->_exportComment('  ' . PMA_Util::backquote($rel_field, $sql_backquotes)) . $this->_exportComment('      ' . PMA_Util::backquote($rel['foreign_table'], $sql_backquotes) . ' -> ' . PMA_Util::backquote($rel['foreign_field'], $sql_backquotes));
         }
         $schema_create .= $this->_exportComment();
     }
     return $schema_create;
 }
Exemplo n.º 17
0
/**
 * Displays a table of results returned by a SQL query.
 * This function is called by the "sql.php" script.
 *
 * @param   integer the link id associated to the query which results have
 *                  to be displayed
 * @param   array   the display mode
 * @param   array   the analyzed query
 *
 * @uses    $_SESSION['tmp_user_values']['pos']
 * @global  string   $db                the database name
 * @global  string   $table             the table name
 * @global  string   $goto              the URL to go back in case of errors
 * @global  string   $sql_query         the current SQL query
 * @global  integer  $num_rows          the total number of rows returned by the
 *                                      SQL query
 * @global  integer  $unlim_num_rows    the total number of rows returned by the
 *                                      SQL query without any programmatically
 *                                      appended "LIMIT" clause
 * @global  array    $fields_meta       the list of fields properties
 * @global  integer  $fields_cnt        the total number of fields returned by
 *                                      the SQL query
 * @global  array    $vertical_display  informations used with vertical display
 *                                      mode
 * @global  array    $highlight_columns column names to highlight
 * @global  array    $cfgRelation       the relation settings
 *
 * @access  private
 *
 * @see     PMA_showMessage(), PMA_setDisplayMode(),
 *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
 *          PMA_displayTableBody(), PMA_displayResultsOperations()
 */
function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
{
    global $db, $table, $goto;
    global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
    global $vertical_display, $highlight_columns;
    global $cfgRelation;
    global $showtable;
    // why was this called here? (already called from sql.php)
    //PMA_displayTable_checkConfigParams();
    /**
     * @todo move this to a central place
     * @todo for other future table types
     */
    $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB';
    if ($is_innodb && !isset($analyzed_sql[0]['queryflags']['union']) && !isset($analyzed_sql[0]['table_ref'][1]['table_name']) && (empty($analyzed_sql[0]['where_clause']) || $analyzed_sql[0]['where_clause'] == '1 ')) {
        // "j u s t   b r o w s i n g"
        $pre_count = '~';
        $after_count = PMA_showHint(PMA_sanitize($GLOBALS['strApproximateCount']), true);
    } else {
        $pre_count = '';
        $after_count = '';
    }
    // 1. ----- Prepares the work -----
    // 1.1 Gets the informations about which functionalities should be
    //     displayed
    $total = '';
    $is_display = PMA_setDisplayMode($the_disp_mode, $total);
    // 1.2 Defines offsets for the next and previous pages
    if ($is_display['nav_bar'] == '1') {
        if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
            $pos_next = 0;
            $pos_prev = 0;
        } else {
            $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
            $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
            if ($pos_prev < 0) {
                $pos_prev = 0;
            }
        }
    }
    // end if
    // 1.3 Find the sort expression
    // we need $sort_expression and $sort_expression_nodirection
    // even if there are many table references
    if (!empty($analyzed_sql[0]['order_by_clause'])) {
        $sort_expression = trim(str_replace('  ', ' ', $analyzed_sql[0]['order_by_clause']));
        /**
         * Get rid of ASC|DESC
         */
        preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
        $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
        $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
        unset($matches);
    } else {
        $sort_expression = $sort_expression_nodirection = $sort_direction = '';
    }
    // 1.4 Prepares display of first and last value of the sorted column
    if (!empty($sort_expression_nodirection)) {
        list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
        $sort_table = PMA_unQuote($sort_table);
        $sort_column = PMA_unQuote($sort_column);
        // find the sorted column index in row result
        // (this might be a multi-table query)
        $sorted_column_index = false;
        foreach ($fields_meta as $key => $meta) {
            if ($meta->table == $sort_table && $meta->name == $sort_column) {
                $sorted_column_index = $key;
                break;
            }
        }
        if ($sorted_column_index !== false) {
            // fetch first row of the result set
            $row = PMA_DBI_fetch_row($dt_result);
            $column_for_first_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
            // fetch last row of the result set
            PMA_DBI_data_seek($dt_result, $num_rows - 1);
            $row = PMA_DBI_fetch_row($dt_result);
            $column_for_last_row = substr($row[$sorted_column_index], 0, $GLOBALS['cfg']['LimitChars']);
            // reset to first row for the loop in PMA_displayTableBody()
            PMA_DBI_data_seek($dt_result, 0);
            // we could also use here $sort_expression_nodirection
            $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
            unset($row, $column_for_first_row, $column_for_last_row);
        }
        unset($sorted_column_index, $sort_table, $sort_column);
    }
    // 2. ----- Displays the top of the page -----
    // 2.1 Displays a messages with position informations
    if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
        if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
            $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
        } else {
            $selectstring = '';
        }
        $last_shown_rec = $_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total ? $total - 1 : $pos_next - 1;
        if (PMA_Table::isView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
            $message = PMA_Message::notice('strViewHasAtLeast');
            $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
            $message->addParam('[/a]');
            $message_view_warning = PMA_showHint($message);
        } else {
            $message_view_warning = false;
        }
        $message = PMA_Message::success('strShowingRecords');
        $message->addMessage($_SESSION['tmp_user_values']['pos']);
        if ($message_view_warning) {
            $message->addMessage('...', ' - ');
            $message->addMessage($message_view_warning);
            $message->addMessage('(');
        } else {
            $message->addMessage($last_shown_rec, ' - ');
            $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' (');
            $message->addString('strTotal');
            $message->addMessage($selectstring, '');
            $message->addMessage(', ', '');
        }
        $messagge_qt = PMA_Message::notice('strQueryTime');
        $messagge_qt->addParam($GLOBALS['querytime']);
        $message->addMessage($messagge_qt, '');
        $message->addMessage(')', '');
        $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
        PMA_showMessage($message, $sql_query, 'success');
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success');
    }
    // 2.3 Displays the navigation bars
    if (!strlen($table)) {
        if (isset($analyzed_sql[0]['query_type']) && $analyzed_sql[0]['query_type'] == 'SELECT') {
            // table does not always contain a real table name,
            // for example in MySQL 5.0.x, the query SHOW STATUS
            // returns STATUS as a table name
            $table = $fields_meta[0]->table;
        } else {
            $table = '';
        }
    }
    if ($is_display['nav_bar'] == '1') {
        PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
        echo "\n";
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        echo "\n" . '<br /><br />' . "\n";
    }
    // 2b ----- Get field references from Database -----
    // (see the 'relation' configuration variable)
    // loic1, 2002-03-02: extended to php3
    // initialize map
    $map = array();
    // find tables
    $target = array();
    if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
        foreach ($analyzed_sql[0]['table_ref'] as $table_ref_position => $table_ref) {
            $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
        }
    }
    $tabs = '(\'' . join('\',\'', $target) . '\')';
    if ($cfgRelation['displaywork']) {
        if (!strlen($table)) {
            $exist_rel = false;
        } else {
            $exist_rel = PMA_getForeigners($db, $table, '', 'both');
            if ($exist_rel) {
                foreach ($exist_rel as $master_field => $rel) {
                    $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
                    $map[$master_field] = array($rel['foreign_table'], $rel['foreign_field'], $display_field, $rel['foreign_db']);
                }
                // end while
            }
            // end if
        }
        // end if
    }
    // end if
    // end 2b
    // 3. ----- Displays the results table -----
    PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
    $url_query = '';
    echo '<tbody>' . "\n";
    $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
    // vertical output case
    if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
        PMA_displayVerticalTable();
    }
    // end if
    unset($vertical_display);
    echo '</tbody>' . "\n";
    ?>
</table>

    <?php 
    // 4. ----- Displays the link for multi-fields edit and delete
    if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
        $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
        $_url_params = array('db' => $db, 'table' => $table, 'sql_query' => $sql_query, 'goto' => $goto);
        $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
        $_url_params['checkall'] = '1';
        $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
        if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
            $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
            $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
        } else {
            $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
            $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
        }
        $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
        $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
        if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
            echo '<img class="selectallarrow" width="38" height="22"' . ' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"' . ' alt="' . $GLOBALS['strWithChecked'] . '" />';
        }
        echo $checkall_link . "\n" . ' / ' . "\n" . $uncheckall_link . "\n" . '<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
        PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
        PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_delete', $delete_text, 'b_drop.png');
        if ($analyzed_sql[0]['querytype'] == 'SELECT') {
            PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', $GLOBALS['strExport'], 'b_tblexport.png');
        }
        echo "\n";
        echo '<input type="hidden" name="sql_query"' . ' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
        echo '<input type="hidden" name="url_query"' . ' value="' . $GLOBALS['url_query'] . '" />' . "\n";
        echo '<input type="hidden" name="clause_is_unique"' . ' value="' . $clause_is_unique . '" />' . "\n";
        echo '</form>' . "\n";
    }
    // 5. ----- Displays the navigation bar at the bottom if required -----
    if ($is_display['nav_bar'] == '1') {
        echo '<br />' . "\n";
        PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
    } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        echo "\n" . '<br /><br />' . "\n";
    }
    // 6. ----- Displays "Query results operations"
    if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
        PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
    }
}
Exemplo n.º 18
0
 /**
  * Gets fields properties
  */
 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
 $fields_cnt = PMA_DBI_num_rows($result);
 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
 // and SHOW CREATE TABLE says NOT NULL (tested
 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
 $show_create_table = PMA_DBI_fetch_value('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0, 1);
 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
 // Check if we can use Relations (Mike Beck)
 if (!empty($cfgRelation['relation'])) {
     // Find which tables are related with the current one and write it in
     // an array
     $res_rel = PMA_getForeigners($db, $table);
     if (count($res_rel) > 0) {
         $have_rel = TRUE;
     } else {
         $have_rel = FALSE;
     }
 } else {
     $have_rel = FALSE;
 }
 // end if
 /**
  * Displays the comments of the table if MySQL >= 3.23
  */
 if (!empty($show_comment)) {
     echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
 }
Exemplo n.º 19
0
/**
 * Get the HTML for relational column dropdown
 * During grid edit, if we have a relational field, returns the html for the
 * dropdown
 *
 * @param string $db         current database
 * @param string $table      current table
 * @param string $column     current column
 * @param string $curr_value current selected value
 *
 * @return string $dropdown html for the dropdown
 */
function PMA_getHtmlForRelationalColumnDropdown($db, $table, $column, $curr_value)
{
    $foreigners = PMA_getForeigners($db, $table, $column);
    $foreignData = PMA_getForeignData($foreigners, $column, false, '', '');
    if ($foreignData['disp_row'] == null) {
        //Handle the case when number of values
        //is more than $cfg['ForeignKeyMaxLimit']
        $_url_params = array('db' => $db, 'table' => $table, 'field' => $column);
        $dropdown = '<span class="curr_value">' . htmlspecialchars($_REQUEST['curr_value']) . '</span>' . '<a href="browse_foreigners.php' . PMA_URL_getCommon($_url_params) . '"' . 'class="ajax browse_foreign" ' . '>' . __('Browse foreign values') . '</a>';
    } else {
        $dropdown = PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $curr_value, $GLOBALS['cfg']['ForeignKeyMaxLimit']);
        $dropdown = '<select>' . $dropdown . '</select>';
    }
    return $dropdown;
}
Exemplo n.º 20
0
 */
/**
 * Gets a core script and starts output buffering work
 */
require_once './libraries/common.inc.php';
PMA_checkParameters(array('db', 'table', 'field'));
require_once './libraries/ob.lib.php';
PMA_outBufferPre();
require_once './libraries/header_http.inc.php';
/**
 * Displays the frame
 */
require_once './libraries/transformations.lib.php';
// Transformations
$cfgRelation = PMA_getRelationsParam();
$foreigners = $cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : false;
$override_total = true;
if (!isset($pos)) {
    $pos = 0;
}
$foreign_limit = 'LIMIT ' . $pos . ', ' . $GLOBALS['cfg']['MaxRows'] . ' ';
if (isset($foreign_navig) && $foreign_navig == __('Show all')) {
    unset($foreign_limit);
}
$foreignData = PMA_getForeignData($foreigners, $field, $override_total, isset($foreign_filter) ? $foreign_filter : '', $foreign_limit);
if (isset($rownumber)) {
    $rownumber_param = '&amp;rownumber=' . urlencode($rownumber);
} else {
    $rownumber_param = '';
}
$gotopage = '';
Exemplo n.º 21
0
 /**
  * Set the value of $map array for linking foreign key related tables
  *
  * @param array &$map the list of relations
  *
  * @return  void
  *
  * @access  private
  *
  * @see      getTable()
  */
 private function _setParamForLinkForeignKeyRelatedTables(&$map)
 {
     // To be able to later display a link to the related table,
     // we verify both types of relations: either those that are
     // native foreign keys or those defined in the phpMyAdmin
     // configuration storage. If no PMA storage, we won't be able
     // to use the "column to display" notion (for example show
     // the name related to a numeric id).
     $exist_rel = PMA_getForeigners($this->__get('db'), $this->__get('table'), '', self::POSITION_BOTH);
     if ($exist_rel) {
         foreach ($exist_rel as $master_field => $rel) {
             if ($master_field != 'foreign_keys_data') {
                 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
                 $map[$master_field] = array($rel['foreign_table'], $rel['foreign_field'], $display_field, $rel['foreign_db']);
             } else {
                 foreach ($rel as $key => $one_key) {
                     foreach ($one_key['index_list'] as $index => $one_field) {
                         $display_field = PMA_getDisplayField(isset($one_key['ref_db_name']) ? $one_key['ref_db_name'] : $GLOBALS['db'], $one_key['ref_table_name']);
                         $map[$one_field] = array($one_key['ref_table_name'], $one_key['ref_index_list'][$index], $display_field, isset($one_key['ref_db_name']) ? $one_key['ref_db_name'] : $GLOBALS['db']);
                     }
                 }
             }
         }
         // end while
     }
     // end if
 }
 /**
  * The "PMA_EPS_Relation_Schema" constructor
  *
  * Upon instantiation This starts writing the EPS document
  * user will be prompted for download as .eps extension
  *
  * @see PMA_EPS
  */
 function __construct()
 {
     parent::__construct();
     global $eps;
     $this->setShowColor(isset($_REQUEST['eps_show_color']));
     $this->setShowKeys(isset($_REQUEST['eps_show_keys']));
     $this->setTableDimension(isset($_REQUEST['eps_show_table_dimension']));
     $this->setAllTablesSameWidth(isset($_REQUEST['eps_all_tables_same_width']));
     $this->setOrientation($_REQUEST['eps_orientation']);
     $eps = new PMA_EPS();
     $eps->setTitle(sprintf(__('Schema of the %s database - Page %s'), $GLOBALS['db'], $this->pageNumber));
     $eps->setAuthor('phpMyAdmin ' . PMA_VERSION);
     $eps->setDate(date("j F Y, g:i a"));
     $eps->setOrientation($this->orientation);
     $eps->setFont('Verdana', '10');
     $alltables = $this->getTablesFromRequest();
     foreach ($alltables as $table) {
         if (!isset($this->_tables[$table])) {
             $this->_tables[$table] = new Table_Stats_Eps($table, $eps->getFont(), $eps->getFontSize(), $this->pageNumber, $this->_tablewidth, $this->showKeys, $this->tableDimension, $this->offline);
         }
         if ($this->sameWide) {
             $this->_tables[$table]->width = $this->_tablewidth;
         }
     }
     $seen_a_relation = false;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($GLOBALS['db'], $one_table, '', 'both');
         if (!$exist_rel) {
             continue;
         }
         $seen_a_relation = true;
         foreach ($exist_rel as $master_field => $rel) {
             /* put the foreign table on the schema only if selected
              * by the user
              * (do not use array_search() because we would have to
              * to do a === false and this is not PHP3 compatible)
              */
             if ($master_field != 'foreign_keys_data') {
                 if (in_array($rel['foreign_table'], $alltables)) {
                     $this->_addRelation($one_table, $eps->getFont(), $eps->getFontSize(), $master_field, $rel['foreign_table'], $rel['foreign_field'], $this->tableDimension);
                 }
                 continue;
             }
             foreach ($rel as $one_key) {
                 if (!in_array($one_key['ref_table_name'], $alltables)) {
                     continue;
                 }
                 foreach ($one_key['index_list'] as $index => $one_field) {
                     $this->_addRelation($one_table, $eps->getFont(), $eps->getFontSize(), $one_field, $one_key['ref_table_name'], $one_key['ref_index_list'][$index], $this->tableDimension);
                 }
             }
         }
     }
     if ($seen_a_relation) {
         $this->_drawRelations();
     }
     $this->_drawTables();
     $eps->endEpsDoc();
 }
Exemplo n.º 23
0
/**
 * Gets the relations info and status, depending on the condition
 *
 * @param boolean $condition whether to look for foreigners or not
 * @param string  $db        database name
 * @param string  $table     table name
 *
 * @return array ($res_rel, $have_rel)
 */
function PMA_getRelationsAndStatus($condition, $db, $table)
{
    if ($condition) {
        // Find which tables are related with the current one and write it in
        // an array
        $res_rel = PMA_getForeigners($db, $table);
        if (count($res_rel) > 0) {
            $have_rel = true;
        } else {
            $have_rel = false;
        }
    } else {
        $have_rel = false;
        $res_rel = array();
    }
    // end if
    return array($res_rel, $have_rel);
}
Exemplo n.º 24
0
/**
 * Removes a foreign relation
 *
 * @param string $T1 foreign db.table
 * @param string $F1 foreign field
 * @param string $T2 master db.table
 * @param string $F2 master field
 *
 * @return array array of success/failure and message
 */
function PMA_removeRelation($T1, $F1, $T2, $F2)
{
    list($DB1, $T1) = explode(".", $T1);
    list($DB2, $T2) = explode(".", $T2);
    $tables = $GLOBALS['dbi']->getTablesFull($DB1, $T1);
    $type_T1 = mb_strtoupper($tables[$T1]['ENGINE']);
    $tables = $GLOBALS['dbi']->getTablesFull($DB2, $T2);
    $type_T2 = mb_strtoupper($tables[$T2]['ENGINE']);
    if (PMA_Util::isForeignKeySupported($type_T1) && PMA_Util::isForeignKeySupported($type_T2) && $type_T1 == $type_T2) {
        // InnoDB
        $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');
        $foreigner = PMA_searchColumnInForeigners($existrel_foreign, $F2);
        if (isset($foreigner['constraint'])) {
            $upd_query = 'ALTER TABLE ' . PMA_Util::backquote($DB2) . '.' . PMA_Util::backquote($T2) . ' DROP FOREIGN KEY ' . PMA_Util::backquote($foreigner['constraint']) . ';';
            if ($GLOBALS['dbi']->query($upd_query)) {
                return array(true, __('FOREIGN KEY relation has been removed.'));
            }
            $error = $GLOBALS['dbi']->getError();
            return array(false, __('Error: FOREIGN KEY relation could not be removed!') . "<br/>" . $error);
        }
    }
    // internal relations
    $delete_query = "DELETE FROM " . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . "." . $GLOBALS['cfgRelation']['relation'] . " WHERE " . "master_db = '" . PMA_Util::sqlAddSlashes($DB2) . "'" . " AND master_table = '" . PMA_Util::sqlAddSlashes($T2) . "'" . " AND master_field = '" . PMA_Util::sqlAddSlashes($F2) . "'" . " AND foreign_db = '" . PMA_Util::sqlAddSlashes($DB1) . "'" . " AND foreign_table = '" . PMA_Util::sqlAddSlashes($T1) . "'" . " AND foreign_field = '" . PMA_Util::sqlAddSlashes($F1) . "'";
    $result = PMA_queryAsControlUser($delete_query, false, PMA_DatabaseInterface::QUERY_STORE);
    if (!$result) {
        $error = $GLOBALS['dbi']->getError($GLOBALS['controllink']);
        return array(false, __('Error: Internal relation could not be removed!') . "<br/>" . $error);
    }
    return array(true, __('Internal relation has been removed.'));
}
?>
        </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";
        foreach ($foreign as $master => $arr) {
Exemplo n.º 26
0
    if (!(isset($db_is_system_schema) && $db_is_system_schema)) {
        $this_sql_query = 'DROP TABLE ' . PMA\libraries\Util::backquote($GLOBALS['table']);
        $drop_table_url_params = array_merge($url_params, array('sql_query' => $this_sql_query, 'goto' => 'db_operations.php', 'reload' => '1', 'purge' => '1', 'message_to_show' => sprintf($tbl_is_view ? __('View %s has been dropped.') : __('Table %s has been dropped.'), htmlspecialchars($table)), 'table' => $GLOBALS['table']));
    }
    $response->addHTML(PMA_getHtmlForDeleteDataOrTable($truncate_table_url_params, $drop_table_url_params));
}
if (Partition::havePartitioning()) {
    $partition_names = Partition::getPartitionNames($db, $table);
    // show the Partition maintenance section only if we detect a partition
    if (!is_null($partition_names[0])) {
        $response->addHTML(PMA_getHtmlForPartitionMaintenance($partition_names, $url_params));
    }
    // end if
}
// end if
unset($partition_names);
// 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'] && !$is_innodb) {
    $GLOBALS['dbi']->selectDb($GLOBALS['db']);
    $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'internal');
    if (!empty($foreign)) {
        $response->addHTML(PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params));
    }
    // end if ($foreign)
}
// end  if (!empty($cfg['Server']['relation']))
$response->addHTML('</div>');
Exemplo n.º 27
0
/**
 * return html for tables' detail
 *
 * @param array  $the_tables      tables list
 * @param string $db              database name
 * @param array  $cfg             global config
 * @param array  $cfgRelation     config from PMA_getRelationsParam
 * @param int    $cell_align_left cell align left
 *
 * @return string
 */
function PMA_getHtmlForTablesDetail($the_tables, $db, $cfg, $cfgRelation, $cell_align_left)
{
    $html = '';
    $tables_cnt = count($the_tables);
    $multi_tables = count($the_tables) > 1;
    $counter = 0;
    foreach ($the_tables as $table) {
        if ($counter + 1 >= $tables_cnt) {
            $breakstyle = '';
        } else {
            $breakstyle = ' style="page-break-after: always;"';
        }
        $counter++;
        $html .= '<div' . $breakstyle . '>' . "\n";
        $html .= '<h1>' . htmlspecialchars($table) . '</h1>' . "\n";
        /**
         * Gets table informations
         */
        $showtable = PMA_Table::sGetStatusInfo($db, $table);
        $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
        $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
        $tbl_is_view = PMA_Table::isView($db, $table);
        /**
         * Gets fields properties
         */
        $columns = $GLOBALS['dbi']->getColumns($db, $table);
        // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
        // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
        // and SHOW CREATE TABLE says NOT NULL (tested
        // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
        $show_create_table = $GLOBALS['dbi']->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1);
        $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
        // Check if we can use Relations
        // Find which tables are related with the current one and write it in
        // an array
        $res_rel = PMA_getForeigners($db, $table);
        $have_rel = (bool) count($res_rel);
        /**
         * Displays the comments of the table if MySQL >= 3.23
         */
        if (!empty($show_comment)) {
            $html .= __('Table comments:') . ' ' . htmlspecialchars($show_comment) . '<br /><br />';
        }
        $html .= PMA_getHtmlForTableStructure($have_rel, $tbl_is_view, $columns, $analyzed_sql, $res_rel, $db, $table, $cfgRelation, $cfg, $showtable, $cell_align_left);
        if ($multi_tables) {
            unset($num_rows, $show_comment);
            $html .= '<hr />' . "\n";
        }
        // end if
        $html .= '</div>' . "\n";
    }
    // end while
    return $html;
}
Exemplo n.º 28
0
 /**
  * Gets all the columns of a table along with their types, collations
  * and whether null or not.
  *
  * @return void
  */
 private function _loadTableInfo()
 {
     // Gets the list and number of columns
     $columns = $GLOBALS['dbi']->getColumns($this->_db, $this->_table, null, true);
     // Get details about the geometry fucntions
     $geom_types = PMA_Util::getGISDatatypes();
     foreach ($columns as $row) {
         // set column name
         $this->_columnNames[] = $row['Field'];
         $type = $row['Type'];
         // check whether table contains geometric columns
         if (in_array($type, $geom_types)) {
             $this->_geomColumnFlag = true;
         }
         // reformat mysql query output
         if (strncasecmp($type, 'set', 3) == 0 || strncasecmp($type, 'enum', 4) == 0) {
             $type = str_replace(',', ', ', $type);
         } else {
             // strip the "BINARY" attribute, except if we find "BINARY(" because
             // this would be a BINARY or VARBINARY column type
             if (!preg_match('@BINARY[\\(]@i', $type)) {
                 $type = preg_replace('@BINARY@i', '', $type);
             }
             $type = preg_replace('@ZEROFILL@i', '', $type);
             $type = preg_replace('@UNSIGNED@i', '', $type);
             $type = strtolower($type);
         }
         if (empty($type)) {
             $type = '&nbsp;';
         }
         $this->_columnTypes[] = $type;
         $this->_columnNullFlags[] = $row['Null'];
         $this->_columnCollations[] = !empty($row['Collation']) && $row['Collation'] != 'NULL' ? $row['Collation'] : '';
     }
     // end for
     // Retrieve foreign keys
     $this->_foreigners = PMA_getForeigners($this->_db, $this->_table);
 }
    $available_mime = PMA_getAvailableMIMEtypes();
}
$header_cells = PMA_getHeaderCells($is_backup, isset($fields_meta) ? $fields_meta : null, $cfgRelation['mimework'], $db, $table);
//  workaround for field_fulltext, because its submitted indices contain
//  the index as a value, not a key. Inserted here for easier maintenance
//  and less code to change in existing files.
if (isset($field_fulltext) && is_array($field_fulltext)) {
    foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
        $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
    }
}
if (isset($_REQUEST['submit_num_fields'])) {
    //if adding new fields, set regenerate to keep the original values
    $regenerate = 1;
}
$foreigners = PMA_getForeigners($db, $table, '', 'foreign');
$child_references = PMA_getChildReferences($db, $table);
for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
    if (!empty($regenerate)) {
        list($columnMeta, $submit_length, $submit_attribute, $submit_default_current_timestamp, $comments_map, $mime_map) = PMA_handleRegeneration($columnNumber, isset($available_mime) ? $mime_map : null, $comments_map, $mime_map);
    } elseif (isset($fields_meta[$columnNumber])) {
        $columnMeta = PMA_getColumnMetaForDefault($fields_meta[$columnNumber], isset($analyzed_sql[0]['create_table_fields'][$fields_meta[$columnNumber]['Field']]['default_value']));
    }
    if (isset($columnMeta['Type'])) {
        $extracted_columnspec = PMA_Util::extractColumnSpec($columnMeta['Type']);
        if ($extracted_columnspec['type'] == 'bit') {
            $columnMeta['Default'] = PMA_Util::convertBitDefaultValue($columnMeta['Default']);
        }
        $type = $extracted_columnspec['type'];
        $length = $extracted_columnspec['spec_in_brackets'];
    } else {
Exemplo n.º 30
0
 /**
  * The "PMA_RT" constructor
  *
  * @param   mixed    The scaling factor
  * @param   integer  The page number to draw (from the
  *                   $cfg['Servers'][$i]['table_coords'] table)
  * @param   boolean  Whether to display table position or not
  * @param   boolean  Was originally whether to use one color per
  *                   relation or not, now enables/disables color
  *                   everywhere, due to some problems printing with color
  * @param   boolean  Whether to draw grids or not
  * @param   boolean  Whether all tables should have the same width or not
  *
  * @global  object   The current PDF document
  * @global  string   The current db name
  * @global  array    The relations settings
  *
  * @access  private
  *
  * @see     PMA_PDF
  */
 function PMA_RT($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4')
 {
     global $pdf, $db, $cfgRelation, $with_doc;
     // Font face depends on the current language
     $this->ff = str_replace('"', '', substr($GLOBALS['right_font_family'], 0, strpos($GLOBALS['right_font_family'], ',')));
     $this->same_wide = $all_tab_same_wide;
     // Initializes a new document
     $pdf = new PMA_PDF('L', 'mm', $paper);
     $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel);
     $pdf->cMargin = 0;
     $pdf->Open();
     $pdf->SetTitle($pdf->title);
     $pdf->SetAuthor('phpMyAdmin ' . PMA_VERSION);
     $pdf->AliasNbPages();
     // fonts added to phpMyAdmin and considered non-standard by fpdf
     // (Note: those tahoma fonts are iso-8859-2 based)
     if ($this->ff == 'tahoma') {
         $pdf->AddFont('tahoma', '', 'tahoma.php');
         $pdf->AddFont('tahoma', 'B', 'tahomab.php');
     }
     $pdf->SetFont($this->ff, '', 14);
     $pdf->SetAutoPageBreak('auto');
     // Gets tables on this page
     $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND pdf_page_number = ' . $which_rel;
     $tab_rs = PMA_query_as_cu($tab_sql);
     if (!$tab_rs || !mysql_num_rows($tab_rs) > 0) {
         $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']);
         //            die('No tables');
     }
     while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) {
         $alltables[] = PMA_sqlAddslashes($curr_table['table_name']);
         //$intable     = '\'' . implode('\', \'', $alltables) . '\'';
     }
     //              make doc                    //
     if ($with_doc) {
         $pdf->SetAutoPageBreak('auto', 15);
         $pdf->cMargin = 1;
         PMA_RT_DOC($alltables);
         $pdf->SetAutoPageBreak('auto');
         $pdf->cMargin = 0;
     }
     $pdf->Addpage();
     if ($with_doc) {
         $pdf->SetLink($pdf->PMA_links['RT']['-'], -1);
         $pdf->Bookmark($GLOBALS['strRelationalSchema']);
         $pdf->SetAlias('{00}', $pdf->PageNo());
         $this->t_marg = 18;
         $this->b_marg = 18;
     }
     /* snip */
     foreach ($alltables as $table) {
         if (!isset($this->tables[$table])) {
             $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth);
         }
         if ($this->same_wide) {
             $this->tables[$table]->width = $this->tablewidth;
         }
         $this->PMA_RT_setMinMax($this->tables[$table]);
     }
     // Defines the scale factor
     $this->scale = ceil(max(($this->x_max - $this->x_min) / ($pdf->fh - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->fw - $this->t_marg - $this->b_marg)) * 100) / 100;
     $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg);
     // Builds and save the PDF document
     $pdf->PMA_PDF_setLineWidthScale(0.1);
     if ($show_grid) {
         $pdf->SetFontSize(10);
         $this->PMA_RT_strokeGrid();
     }
     $pdf->PMA_PDF_setFontSizeScale(14);
     //        $sql    = 'SELECT * FROM ' . PMA_backquote($cfgRelation['relation'])
     //                .   ' WHERE master_db   = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND foreign_db    = \'' . PMA_sqlAddslashes($db) . '\' '
     //                .   ' AND master_table  IN (' . $intable . ')'
     //                .   ' AND foreign_table IN (' . $intable . ')';
     //        $result =  PMA_query_as_cu($sql);
     //
     // lem9:
     // previous logic was checking master tables and foreign tables
     // but I think that looping on every table of the pdf page as a master
     // and finding its foreigns is OK (then we can support innodb)
     $seen_a_relation = FALSE;
     foreach ($alltables as $one_table) {
         $exist_rel = PMA_getForeigners($db, $one_table, '', 'both');
         if ($exist_rel) {
             $seen_a_relation = TRUE;
             foreach ($exist_rel as $master_field => $rel) {
                 // put the foreign table on the schema only if selected
                 // by the user
                 // (do not use array_search() because we would have to
                 // to do a === FALSE and this is not PHP3 compatible)
                 if (PMA_isInto($rel['foreign_table'], $alltables) > -1) {
                     $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']);
                 }
             }
             // end while
         }
         // end if
     }
     // end while
     // loic1: also show tables without relations
     //        $norelations     = TRUE;
     //        if ($result && mysql_num_rows($result) > 0) {
     //            $norelations = FALSE;
     //            while ($row = PMA_mysql_fetch_array($result)) {
     //                $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']);
     //            }
     //        }
     //        if ($norelations == FALSE) {
     if ($seen_a_relation) {
         $this->PMA_RT_drawRelations($change_color);
     }
     $this->PMA_RT_drawTables($show_info, $change_color);
     $this->PMA_RT_showRt();
 }