/** * get the html of the form to add the new column to given table * * @param integer $num_fields number of columns to add * @param string $db current database * @param string $table current table * @param array $columnMeta array containing default values for the fields * * @return string HTML */ function PMA_getHtmlForCreateNewColumn($num_fields, $db, $table, $columnMeta = array()) { $cfgRelation = PMA_getRelationsParam(); $content_cells = array(); $available_mime = array(); $mime_map = array(); if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { $mime_map = PMA_getMIME($db, $table); $available_mime = PMA_getAvailableMIMEtypes(); } $comments_map = PMA_getComments($db, $table); for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { $content_cells[$columnNumber] = array('columnNumber' => $columnNumber, 'columnMeta' => $columnMeta, 'type_upper' => '', 'length_values_input_size' => 8, 'length' => '', 'extracted_columnspec' => array(), 'submit_attribute' => null, 'comments_map' => $comments_map, 'fields_meta' => null, 'is_backup' => true, 'move_columns' => array(), 'cfgRelation' => $cfgRelation, 'available_mime' => isset($available_mime) ? $available_mime : array(), 'mime_map' => $mime_map); } return PMA\libraries\Template::get('columns_definitions/table_fields_definitions')->render(array('is_backup' => true, 'fields_meta' => null, 'mimework' => $cfgRelation['mimework'], 'content_cells' => $content_cells)); }
/** * get the html of the form to add the new column to given table * * @param integer $num_fields number of columns to add * @param string $db current database * @param string $table current table * @param array $columnMeta array containing default values for the fields * * @return HTML */ function PMA_getHtmlForCreateNewColumn($num_fields, $db, $table, $columnMeta = array()) { $cfgRelation = PMA_getRelationsParam(); $content_cells = array(); $available_mime = array(); $mime_map = array(); $header_cells = PMA_getHeaderCells(true, null, $cfgRelation['mimework'], $db, $table); if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { $mime_map = PMA_getMIME($db, $table); $available_mime = PMA_getAvailableMIMEtypes(); } $comments_map = PMA_getComments($db, $table); for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) { $content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes($columnNumber, $columnMeta, '', 8, '', null, array(), null, null, null, $comments_map, null, true, array(), $cfgRelation, isset($available_mime) ? $available_mime : array(), $mime_map); } return PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells); }
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); }
/** * Sets the MIME details of the columns in the results set * * @return void */ private function _setMimeMap() { $fields_meta = $this->__get('fields_meta'); $mimeMap = array(); $added = array(); for ($currentColumn = 0; $currentColumn < $this->__get('fields_cnt'); ++$currentColumn) { $meta = $fields_meta[$currentColumn]; $orgFullTableName = $this->__get('db') . '.' . $meta->orgtable; if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && !$_SESSION['tmpval']['hide_transformation'] && empty($added[$orgFullTableName])) { $mimeMap = array_merge($mimeMap, PMA_getMIME($this->__get('db'), $meta->orgtable, false, true)); $added[$orgFullTableName] = true; } } // special browser transformation for some SHOW statements if ($this->__get('is_show') && !$_SESSION['tmpval']['hide_transformation']) { preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?' . 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS' . ')@i', $this->__get('sql_query'), $which); if (isset($which[1])) { $str = ' ' . strtoupper($which[1]); $isShowProcessList = strpos($str, 'PROCESSLIST') > 0; if ($isShowProcessList) { $mimeMap['..Info'] = array('mimetype' => 'Text_Plain', 'transformation' => 'output/Text_Plain_Sql.class.php'); } $isShowCreateTable = preg_match('@CREATE[[:space:]]+TABLE@i', $this->__get('sql_query')); if ($isShowCreateTable) { $mimeMap['..Create Table'] = array('mimetype' => 'Text_Plain', 'transformation' => 'output/Text_Plain_Sql.class.php'); } } } $this->__set('mime_map', $mimeMap); }
/** * Displays the headers of the results table * * @param array which elements to display * @param array the list of fields properties * @param integer the total number of fields returned by the sql query * @param array the analyzed query * * @return boolean always true * * @global string $db the database name * @global string $table the table name * @global string $goto the url to go back in case of errors * @global boolean $dontlimitchars whether to limit the number of displayed * characters of text type fields or not * @global string $sql_query the sql query * @global integer $num_rows the total number of rows returned by the * sql query * @global integer $pos the current position in results * @global integer $session_max_rows the maximum number of rows per page * @global array $vertical_display informations used with vertical display * mode * @global string $disp_direction the display mode * (horizontal/vertical/horizontalflipped) * @global integer $repeat_cellsthe number of row to display between two * table headers * * @access private * * @see PMA_displayTable() */ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '') { global $db, $table, $goto, $dontlimitchars; global $sql_query, $num_rows, $pos, $session_max_rows; global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns; if ($analyzed_sql == '') { $analyzed_sql = array(); } // can the result be sorted? if ($is_display['sort_lnk'] == '1') { // Just as fallback $unsorted_sql_query = $sql_query; if (isset($analyzed_sql[0]['unsorted_query'])) { $unsorted_sql_query = $analyzed_sql[0]['unsorted_query']; } // we need $sort_expression and $sort_expression_nodir // even if there are many table references $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause'])); // Get rid of ASC|DESC (TODO: analyzer) preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches); $sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression; // sorting by indexes, only if it makes sense (only one table ref) if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' && isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) { // grab indexes data: PMA_DBI_select_db($db); if (!defined('PMA_IDX_INCLUDED')) { $ret_keys = PMA_get_indexes($table); } $prev_index = ''; foreach ($ret_keys as $row) { if ($row['Key_name'] != $prev_index) { $indexes[] = $row['Key_name']; $prev_index = $row['Key_name']; } $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index']; $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique']; if (isset($row['Cardinality'])) { $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality']; } // I don't know what does the following column mean.... // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed']; $indexes_info[$row['Key_name']]['Comment'] = isset($row['Comment']) ? $row['Comment'] : ''; $indexes_info[$row['Key_name']]['Index_type'] = isset($row['Index_type']) ? $row['Index_type'] : ''; $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name']; if (isset($row['Sub_part'])) { $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part']; } } // end while // do we have any index? if (isset($indexes_data)) { if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { $span = $fields_cnt; if ($is_display['edit_lnk'] != 'nn') { $span++; } if ($is_display['del_lnk'] != 'nn') { $span++; } if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') { $span++; } } else { $span = $num_rows + floor($num_rows / $repeat_cells) + 1; } echo '<form action="sql.php" method="post">' . "\n"; echo PMA_generate_common_hidden_inputs($db, $table, 5); echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n"; echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n"; echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n"; echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n"; echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n"; echo $GLOBALS['strSortByKey'] . ': <select name="sql_query">' . "\n"; $used_index = false; $local_order = isset($sort_expression) ? $sort_expression : ''; foreach ($indexes_data as $key => $val) { $asc_sort = ''; $desc_sort = ''; foreach ($val as $key2 => $val2) { $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , '; $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , '; } $asc_sort = substr($asc_sort, 0, -3); $desc_sort = substr($desc_sort, 0, -3); $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort; echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>'; echo "\n"; echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>'; echo "\n"; } echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>'; echo "\n"; echo '</select>' . "\n"; echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />'; echo "\n"; echo '</form>' . "\n"; } } } $vertical_display['emptypre'] = 0; $vertical_display['emptyafter'] = 0; $vertical_display['textbtn'] = ''; // Start of form for multi-rows delete if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') { echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n"; echo PMA_generate_common_hidden_inputs($db, $table, 1); echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n"; echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n"; echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n"; echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n"; echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n"; echo '<input type="hidden" name="goto" value="sql.php" />' . "\n"; } echo '<table id="table_results" class="data">' . "\n"; if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo '<thead><tr>' . "\n"; } // 1. Displays the full/partial text button (part 1)... if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { $colspan = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' colspan="3"' : ''; } else { $rowspan = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' rowspan="3"' : ''; } $text_url = 'sql.php?' . PMA_generate_common_url($db, $table) . '&sql_query=' . urlencode($sql_query) . '&session_max_rows=' . $session_max_rows . '&pos=' . $pos . '&disp_direction=' . $disp_direction . '&repeat_cells=' . $repeat_cells . '&goto=' . $goto . '&dontlimitchars=' . ($dontlimitchars ? 0 : 1); $text_message = '<img class="fulltext" src="' . $GLOBALS['pmaThemeImage'] . 's_' . ($dontlimitchars ? 'partialtext' : 'fulltext') . '.png" width="50" height="20" alt="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" />'; $text_link = PMA_linkOrButton($text_url, $text_message, array(), false); // ... before the result table if ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn' && $is_display['text_btn'] == '1') { $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 0; if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { ?> <th colspan="<?php echo $fields_cnt; ?> "><?php echo $text_link; ?> </th> </tr> <tr> <?php } else { ?> <tr> <th colspan="<?php echo $num_rows + floor($num_rows / $repeat_cells) + 1; ?> "> <?php echo $text_link; ?> </th> </tr> <?php } // end vertical mode } elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') { $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 0; if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { ?> <th <?php echo $colspan; ?> ><?php echo $text_link; ?> </th> <?php } else { $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n" . ' ' . $text_link . "\n" . ' </th>' . "\n"; } // end vertical mode } elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) { $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 0; if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { ?> <td<?php echo $colspan; ?> ></td> <?php } else { $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n"; } // end vertical mode } // 2. Displays the fields' name // 2.0 If sorting links should be used, checks if the query is a "JOIN" // statement (see 2.1.3) // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']). // Do not show comments, if using horizontalflipped mode, because of space usage if ($GLOBALS['cfg']['ShowBrowseComments'] && ($GLOBALS['cfgRelation']['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) && $disp_direction != 'horizontalflipped') { $comments_map = array(); if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) { foreach ($analyzed_sql[0]['table_ref'] as $tbl) { $tb = $tbl['table_true_name']; $comments_map[$tb] = PMA_getComments($db, $tb); unset($tb); } } } if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { require_once './libraries/transformations.lib.php'; $GLOBALS['mime_map'] = PMA_getMIME($db, $table); } if ($is_display['sort_lnk'] == '1') { //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt); $is_join = isset($analyzed_sql[0]['queryflags']['join']) ? true : false; $select_expr = $analyzed_sql[0]['select_expr_clause']; } else { $is_join = false; } // garvin: See if we have to highlight any header fields of a WHERE query. // Uses SQL-Parser results. $highlight_columns = array(); if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['where_clause_identifiers'])) { $wi = 0; if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) { foreach ($analyzed_sql[0]['where_clause_identifiers'] as $wci_nr => $wci) { $highlight_columns[$wci] = 'true'; } } } for ($i = 0; $i < $fields_cnt; $i++) { // garvin: See if this column should get highlight because it's used in the // where-query. if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) { $condition_field = true; } else { $condition_field = false; } // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled. if (isset($comments_map) && isset($comments_map[$fields_meta[$i]->table]) && isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) { $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>'; } else { $comments = ''; } // 2.1 Results can be sorted if ($is_display['sort_lnk'] == '1') { // 2.1.1 Checks if the table name is required; it's the case // for a query with a "JOIN" statement and if the column // isn't aliased, or in queries like // SELECT `1`.`master_field` , `2`.`master_field` // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2` /** * we prefer always using table if existing * and second this code does not correctly check $fields_meta[$i]->table if (($is_join && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . strtr($fields_meta[$i]->name, array('[' => '\\[', '~' => '\\~', '\\' => '\\\\')) . '~i', $select_expr, $parts)) || (isset($analyzed_sql[0]['select_expr'][$i]['expr']) && isset($analyzed_sql[0]['select_expr'][$i]['column']) && $analyzed_sql[0]['select_expr'][$i]['expr'] != $analyzed_sql[0]['select_expr'][$i]['column'] && isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table))) { */ if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) { $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.'; } else { $sort_tbl = ''; } // 2.1.2 Checks if the current column is used to sort the // results if (empty($sort_expression)) { $is_in_sort = false; } else { // field name may be preceded by a space, or any number // of characters followed by a dot (tablename.fieldname) // so do a direct comparison // for the sort expression (avoids problems with queries // like "SELECT id, count(id)..." and clicking to sort // on id or on count(id)) $is_in_sort = $sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? true : false; } // 2.1.3 Check the field name for backquotes. // If it contains some, it's probably a function column // like 'COUNT(`field`)' if (strpos($fields_meta[$i]->name, '`') !== false) { $sort_order = ' ORDER BY ' . PMA_backquote($fields_meta[$i]->name) . ' '; } else { $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' '; } // 2.1.4 Do define the sorting url if (!$is_in_sort) { // loic1: patch #455484 ("Smart" order) $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']); if ($GLOBALS['cfg']['Order'] == 'SMART') { $GLOBALS['cfg']['Order'] = preg_match('@time|date@i', $fields_meta[$i]->type) ? 'DESC' : 'ASC'; } $sort_order .= $GLOBALS['cfg']['Order']; $order_img = ''; } elseif (preg_match('@[[:space:]]ASC$@i', $sort_expression)) { $sort_order .= ' DESC'; $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="' . $GLOBALS['strAscending'] . '" title="' . $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />'; } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) { $sort_order .= ' ASC'; $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="' . $GLOBALS['strDescending'] . '" title="' . $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />'; } else { $sort_order .= ' DESC'; $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="' . $GLOBALS['strAscending'] . '" title="' . $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />'; } if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) { $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2]; } else { $sorted_sql_query = $unsorted_sql_query . $sort_order; } $url_query = PMA_generate_common_url($db, $table) . '&pos=' . $pos . '&session_max_rows=' . $session_max_rows . '&disp_direction=' . $disp_direction . '&repeat_cells=' . $repeat_cells . '&dontlimitchars=' . $dontlimitchars . '&sql_query=' . urlencode($sorted_sql_query); $order_url = 'sql.php?' . $url_query; // 2.1.5 Displays the sorting url // added 20004-06-09: Michael Keck <*****@*****.**> // enable sord order swapping for image $order_link_params = array(); if (isset($order_img) && $order_img != '') { if (strstr($order_img, 'asc')) { $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }'; $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }'; } elseif (strstr($order_img, 'desc')) { $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }'; $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }'; } } if ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') { $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;'; } $order_link_params['title'] = $GLOBALS['strSort']; $order_link_content = $disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name); $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true); if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo '<th'; if ($condition_field) { echo ' class="condition"'; } if ($disp_direction == 'horizontalflipped') { echo ' valign="bottom"'; } echo '>' . $order_link . $comments . '</th>'; } $vertical_display['desc'][] = ' <th ' . ($condition_field ? ' class="condition"' : '') . '>' . "\n" . $order_link . $comments . ' </th>' . "\n"; } else { if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo '<th'; if ($condition_field) { echo ' class="condition"'; } if ($disp_direction == 'horizontalflipped') { echo ' valign="bottom"'; } if ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') { echo ' style="direction: ltr; writing-mode: tb-rl;"'; } echo '>'; if ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') { echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />'); } else { echo htmlspecialchars($fields_meta[$i]->name); } echo "\n" . $comments . '</th>'; } $vertical_display['desc'][] = ' <th ' . ($condition_field ? ' class="condition"' : '') . '>' . "\n" . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n" . $comments . ' </th>'; } // end else (2.2) } // end for // 3. Displays the full/partial text button (part 2) at the right // column of the result table header if possible and required... if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') && $is_display['text_btn'] == '1') { $vertical_display['emptyafter'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 1; if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo "\n"; ?> <th <?php echo $colspan; ?> > <?php echo $text_link; ?> </th> <?php } else { $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n" . ' ' . $text_link . "\n" . ' </th>' . "\n"; } // end vertical mode } elseif ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn') && !$GLOBALS['is_header_sent']) { $vertical_display['emptyafter'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 1; if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo "\n"; ?> <td<?php echo $colspan; ?> ></td> <?php } else { $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n"; } // end vertical mode } if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { ?> </tr> </thead> <?php } return true; }
/** * Returns $table's CREATE definition * * @param string $db the database name * @param string $table the table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * $this->exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $show_dates whether to include creation/update/check dates * @param bool $add_semicolon whether to add semicolon and end-of-line * at the end * @param bool $view whether we're handling a view * @param array $aliases Aliases of db/table/columns * * @return string resulting schema */ public function getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false, $aliases = array()) { global $cfgRelation; $text_output = ''; /** * Get the unique keys in the table */ $unique_keys = array(); $keys = $GLOBALS['dbi']->getTableIndexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations list($res_rel, $have_rel) = PMA_getRelationsAndStatus($do_relation && !empty($cfgRelation['relation']), $db, $table); /** * Displays the table structure */ $text_output .= "|------\n"; $text_output .= '|' . __('Column'); $text_output .= '|' . __('Type'); $text_output .= '|' . __('Null'); $text_output .= '|' . __('Default'); if ($do_relation && $have_rel) { $text_output .= '|' . __('Links to'); } if ($do_comments) { $text_output .= '|' . __('Comments'); $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $text_output .= '|' . htmlspecialchars('MIME'); $mime_map = PMA_getMIME($db, $table, true); } $text_output .= "\n|------\n"; $columns = $GLOBALS['dbi']->getColumns($db, $table); foreach ($columns as $column) { $col_as = $column['Field']; if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) { $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as]; } $text_output .= $this->formatOneColumnDefinition($column, $unique_keys, $col_as); $field_name = $column['Field']; if ($do_relation && $have_rel) { $text_output .= '|' . htmlspecialchars($this->getRelationString($res_rel, $field_name, $db, $aliases)); } if ($do_comments && $cfgRelation['commwork']) { $text_output .= '|' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : ''); } if ($do_mime && $cfgRelation['mimework']) { $text_output .= '|' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : ''); } $text_output .= "\n"; } // end foreach return $text_output; }
function PMA_RT_DOC($alltables) { global $db, $pdf, $orientation; //TOC $pdf->addpage("P"); $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 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, $GLOBALS['strPageNumber'] . ' {' . 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); $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table); $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); while ($row = PMA_mysql_fetch_array($result)) { $pdf->SetX(20); $field_name = $row['Field']; $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink(); //$pdf->Cell(0,6,$field_name,0,1,'L',0,$pdf->PMA_links['doc'][$table][$field_name]); } $lasttable = $table; $i++; } $pdf->PMA_links['RT']['-'] = $pdf->AddLink(); $pdf->SetX(10); $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']); $pdf->SetX(10); $pdf->Cell(0, 6, $i . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']); $z = 0; foreach ($alltables as $table) { $z++; $pdf->addpage($GLOBALS['orientation']); $pdf->Bookmark($table); $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()); $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink(); $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1); $pdf->SetFont('', 'B', 18); $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']); $pdf->SetFont('', '', 8); $pdf->ln(); $cfgRelation = PMA_getRelationsParam(); if ($cfgRelation['commwork']) { $comments = PMA_getComments($db, $table); } if ($cfgRelation['mimework']) { $mime_map = PMA_getMIME($db, $table, true); } /** * Gets table informations */ $local_query = "SHOW TABLE STATUS LIKE '" . PMA_sqlAddslashes($table, TRUE) . "'"; $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); $showtable = PMA_mysql_fetch_array($result); $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0; $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : ''; $create_time = isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : ''; $update_time = isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''; $check_time = isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''; if ($result) { mysql_free_result($result); } /** * Gets table keys and retains them */ $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table); $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); $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_mysql_fetch_array($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) { mysql_free_result($result); } /** * Gets fields properties */ $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table); $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); $fields_cnt = mysql_num_rows($result); // Check if we can use Relations (Mike Beck) if (!empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if (count($res_rel) > 0) { $have_rel = TRUE; } else { $have_rel = FALSE; } } else { $have_rel = FALSE; } // end if /** * Displays the comments of the table if MySQL >= 3.23 */ $break = false; if (!empty($show_comment)) { $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1); $break = true; } if (!empty($create_time)) { $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1); $break = true; } if (!empty($update_time)) { $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1); $break = true; } if (!empty($check_time)) { $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1); $break = true; } if ($break == true) { $pdf->Cell(0, 3, '', 0, 1); $pdf->Ln(); } $i = 0; $pdf->SetFont('', 'B'); if (isset($orientation) && $orientation == 'L') { $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C'); $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C'); $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C'); $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C'); $pdf->Cell(67, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C'); $pdf->Cell(45, 8, 'MIME', 1, 1, 'C'); $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, 67, 45)); } else { $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C'); $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C'); $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C'); $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C'); $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C'); $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 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('', ''); while ($row = PMA_mysql_fetch_array($result)) { $bgcolor = $i % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; $i++; $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 = ' '; } $binary = stristr($row['Type'], 'BINARY'); $unsigned = stristr($row['Type'], 'UNSIGNED'); $zerofill = stristr($row['Type'], 'ZEROFILL'); } $strAttribute = ' '; if ($binary) { $strAttribute = 'BINARY'; } if ($unsigned) { $strAttribute = 'UNSIGNED'; } if ($zerofill) { $strAttribute = 'UNSIGNED ZEROFILL'; } if (!isset($row['Default'])) { if ($row['Null'] != '') { $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, $strAttribute, $row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes'], 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); /*$pdf->Cell(20,8,$field_name,1,0,'L',0,$pdf->PMA_links['RT'][$table][$field_name]); //echo ' ' . $field_name . ' ' . "\n"; } $pdf->Cell(20,8,$type,1,0,'L'); $pdf->Cell(20,8,$strAttribute,1,0,'L'); $pdf->Cell(15,8,,1,0,'L'); $pdf->Cell(15,8,((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L'); $pdf->Cell(15,8,$row['Extra'],1,0,'L'); if ($have_rel) { if (isset($res_rel[$field_name])) { $pdf->Cell(30,8,$res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L'); } } if ($cfgRelation['commwork']) { if (isset($comments[$field_name])) { $pdf->Cell(0,8,$comments[$field_name],1,0,'L'); } } */ } // end while $pdf->SetFont('', '', 14); mysql_free_result($result); } //end each }
/** * Function to get html for each insert/edit row * * @param array $url_params url parameters * @param array $table_columns table columns * @param array $comments_map comments map * @param bool $timestamp_seen whether timestamp seen * @param array $current_result current result * @param string $chg_evt_handler javascript change event handler * @param string $jsvkey javascript validation key * @param string $vkey validation key * @param bool $insert_mode whether insert mode * @param array $current_row current row * @param int &$o_rows row offset * @param int &$tabindex tab index * @param int $columns_cnt columns count * @param bool $is_upload whether upload * @param int $tabindex_for_function tab index offset for function * @param array $foreigners foreigners * @param int $tabindex_for_null tab index offset for null * @param int $tabindex_for_value tab index offset for value * @param string $table table * @param string $db database * @param int $row_id row id * @param array $titles titles * @param int $biggest_max_file_size biggest max file size * @param string $text_dir text direction * @param array $repopulate the data to be repopulated * @param array $where_clause_array the array of where clauses * * @return string */ function PMA_getHtmlForInsertEditRow($url_params, $table_columns, $comments_map, $timestamp_seen, $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode, $current_row, &$o_rows, &$tabindex, $columns_cnt, $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null, $tabindex_for_value, $table, $db, $row_id, $titles, $biggest_max_file_size, $text_dir, $repopulate, $where_clause_array) { $html_output = PMA_getHeadAndFootOfInsertRowTable($url_params) . '<tbody>'; //store the default value for CharEditing $default_char_editing = $GLOBALS['cfg']['CharEditing']; $mime_map = PMA_getMIME($db, $table); $odd_row = true; $where_clause = ''; if (isset($where_clause_array[$row_id])) { $where_clause = $where_clause_array[$row_id]; } for ($column_number = 0; $column_number < $columns_cnt; $column_number++) { $table_column = $table_columns[$column_number]; // skip this column if user does not have necessary column privilges if (!PMA_userHasColumnPrivileges($table_column, $insert_mode)) { continue; } $column_mime = array(); if (isset($mime_map[$table_column['Field']])) { $column_mime = $mime_map[$table_column['Field']]; } $html_output .= PMA_getHtmlForInsertEditFormColumn($table_columns, $column_number, $comments_map, $timestamp_seen, $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode, $current_row, $odd_row, $o_rows, $tabindex, $columns_cnt, $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null, $tabindex_for_value, $table, $db, $row_id, $titles, $biggest_max_file_size, $default_char_editing, $text_dir, $repopulate, $column_mime, $where_clause); $odd_row = !$odd_row; } // end for $o_rows++; $html_output .= ' </tbody>' . '</table><br />' . '<div class="clearfloat"></div>'; return $html_output; }
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy) { global $cfgRelation; /* Heading */ $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">' . htmlspecialchars(__('Table structure for table') . ' ' . $table) . '</text:h>'; /** * 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 */ $GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_data">'; $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="' . $columns_cnt . '"/>'; /* Header */ $GLOBALS['odt_buffer'] .= '<table:table-row>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(__('Column')) . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(__('Type')) . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(__('Null')) . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(__('Default')) . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(__('Links to')) . '</text:p>' . '</table:table-cell>'; } if ($do_comments) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(__('Comments')) . '</text:p>' . '</table:table-cell>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(__('MIME type')) . '</text:p>' . '</table:table-cell>'; $mime_map = PMA_getMIME($db, $table, true); } $GLOBALS['odt_buffer'] .= '</table:table-row>'; while ($row = PMA_DBI_fetch_assoc($result)) { $GLOBALS['odt_buffer'] .= '<table:table-row>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($row['Field']) . '</text:p>' . '</table:table-cell>'; // reformat mysql query output // set or enum types: slashes single quotes inside options $field_name = $row['Field']; $type = $row['Type']; 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 = ' '; } $binary = preg_match('/BINARY/i', $row['Type']); $unsigned = preg_match('/UNSIGNED/i', $row['Type']); $zerofill = preg_match('/ZEROFILL/i', $row['Type']); } $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($type) . '</text:p>' . '</table:table-cell>'; if (!isset($row['Default'])) { if ($row['Null'] != 'NO') { $row['Default'] = 'NULL'; } else { $row['Default'] = ''; } } else { $row['Default'] = $row['Default']; } $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes')) . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($row['Default']) . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { if (isset($res_rel[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') . '</text:p>' . '</table:table-cell>'; } } if ($do_comments) { if (isset($comments[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($comments[$field_name]) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } if ($do_mime && $cfgRelation['mimework']) { if (isset($mime_map[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } $GLOBALS['odt_buffer'] .= '</table:table-row>'; } // end while PMA_DBI_free_result($result); $GLOBALS['odt_buffer'] .= '</table:table>'; return TRUE; }
/** * Returns $table's CREATE definition * * @param string $db the database name * @param string $table the table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * @param bool $do_mime whether to include mime comments * @param bool $show_dates whether to include creation/update/check dates * @param bool $add_semicolon whether to add semicolon and end-of-line at * the end * @param bool $view whether we're handling a view * * @return bool true */ public function getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false) { global $cfgRelation; /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_structure">'; $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $GLOBALS['odt_buffer'] .= '<table:table-column' . ' table:number-columns-repeated="' . $columns_cnt . '"/>'; /* Header */ $GLOBALS['odt_buffer'] .= '<table:table-row>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Column') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Type') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Null') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Default') . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Links to') . '</text:p>' . '</table:table-cell>'; } if ($do_comments) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Comments') . '</text:p>' . '</table:table-cell>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('MIME type') . '</text:p>' . '</table:table-cell>'; $mime_map = PMA_getMIME($db, $table, true); } $GLOBALS['odt_buffer'] .= '</table:table-row>'; $columns = PMA_DBI_get_columns($db, $table); foreach ($columns as $column) { $field_name = $column['Field']; $GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column); if ($do_relation && $have_rel) { if (isset($res_rel[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') . '</text:p>' . '</table:table-cell>'; } } if ($do_comments) { if (isset($comments[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($comments[$field_name]) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } if ($do_mime && $cfgRelation['mimework']) { if (isset($mime_map[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } $GLOBALS['odt_buffer'] .= '</table:table-row>'; } // end foreach $GLOBALS['odt_buffer'] .= '</table:table>'; return true; }
/** * Displays the table structure ('show table' works correct since 3.23.03) * * @param array $cfgRelation current relation parameters * @param array $columns_with_unique_index Columns with unique index * @param mixed $url_params Contains an associative * array with url params * @param PMA_Index|false $primary_index primary index or false if * no one exists * @param array $fields Fields * @param array $columns_with_index Columns with index * @param array $create_table_fields Fields of the table. * * @return string */ protected function displayStructure($cfgRelation, $columns_with_unique_index, $url_params, $primary_index, $fields, $columns_with_index, $create_table_fields) { /* TABLE INFORMATION */ $HideStructureActions = ''; if ($GLOBALS['cfg']['HideStructureActions'] === true) { $HideStructureActions .= ' HideStructureActions'; } // prepare comments $comments_map = array(); $mime_map = array(); if ($GLOBALS['cfg']['ShowPropertyComments']) { include_once 'libraries/transformations.lib.php'; $comments_map = PMA_getComments($this->db, $this->table); if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { $mime_map = PMA_getMIME($this->db, $this->table, true); } } include_once 'libraries/central_columns.lib.php'; $central_list = PMA_getCentralColumnsFromTable($this->db, $this->table); $columns_list = array(); $titles = array('Change' => PMA_Util::getIcon('b_edit.png', __('Change')), 'Drop' => PMA_Util::getIcon('b_drop.png', __('Drop')), 'NoDrop' => PMA_Util::getIcon('b_drop.png', __('Drop')), 'Primary' => PMA_Util::getIcon('b_primary.png', __('Primary')), 'Index' => PMA_Util::getIcon('b_index.png', __('Index')), 'Unique' => PMA_Util::getIcon('b_unique.png', __('Unique')), 'Spatial' => PMA_Util::getIcon('b_spatial.png', __('Spatial')), 'IdxFulltext' => PMA_Util::getIcon('b_ftext.png', __('Fulltext')), 'NoPrimary' => PMA_Util::getIcon('bd_primary.png', __('Primary')), 'NoIndex' => PMA_Util::getIcon('bd_index.png', __('Index')), 'NoUnique' => PMA_Util::getIcon('bd_unique.png', __('Unique')), 'NoSpatial' => PMA_Util::getIcon('bd_spatial.png', __('Spatial')), 'NoIdxFulltext' => PMA_Util::getIcon('bd_ftext.png', __('Fulltext')), 'DistinctValues' => PMA_Util::getIcon('b_browse.png', __('Distinct values'))); /** * Work on the table */ if ($this->_tbl_is_view) { $item = $this->dbi->fetchSingleRow(sprintf("SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`,\n `SECURITY_TYPE`\n FROM `INFORMATION_SCHEMA`.`VIEWS`\n WHERE TABLE_SCHEMA='%s'\n AND TABLE_NAME='%s';", PMA_Util::sqlAddSlashes($this->db), PMA_Util::sqlAddSlashes($this->table))); $createView = $this->dbi->getTable($this->db, $this->table)->showCreate(); // get algorithm from $createView of the form // CREATE ALGORITHM=<ALGORITHM> DE... $parts = explode(" ", substr($createView, 17)); $item['ALGORITHM'] = $parts[0]; $view = array('operation' => 'alter', 'definer' => $item['DEFINER'], 'sql_security' => $item['SECURITY_TYPE'], 'name' => $this->table, 'as' => $item['VIEW_DEFINITION'], 'with' => $item['CHECK_OPTION'], 'algorithm' => $item['ALGORITHM']); $edit_view_url = 'view_create.php' . PMA_URL_getCommon($url_params) . '&' . implode('&', array_map(function ($key, $val) { return 'view[' . urlencode($key) . ']=' . urlencode($val); }, array_keys($view), $view)); } /** * Displays Space usage and row statistics */ // BEGIN - Calc Table Space // Get valid statistics whatever is the table type if ($GLOBALS['cfg']['ShowStats']) { //get table stats in HTML format $tablestats = $this->getTableStats(); //returning the response in JSON format to be used by Ajax $this->response->addJSON('tableStat', $tablestats); } // END - Calc Table Space return Template::get('table/structure/display_structure')->render(array('HideStructureActions' => $HideStructureActions, 'db' => $this->db, 'table' => $this->table, 'db_is_system_schema' => $this->_db_is_system_schema, 'tbl_is_view' => $this->_tbl_is_view, 'mime_map' => $mime_map, 'url_query' => $this->_url_query, 'titles' => $titles, 'tbl_storage_engine' => $this->_tbl_storage_engine, 'primary' => $primary_index, 'columns_with_unique_index' => $columns_with_unique_index, 'edit_view_url' => isset($edit_view_url) ? $edit_view_url : null, 'columns_list' => $columns_list, 'tablestats' => isset($tablestats) ? $tablestats : null, 'fields' => $fields, 'columns_with_index' => $columns_with_index, 'central_list' => $central_list, 'create_table_fields' => $create_table_fields)); }
/** * Returns $table's CREATE definition * * @param string $db the database name * @param string $table the table name * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * at the end * @param bool $view whether we're handling a view * @param array $aliases Aliases of db/table/columns * * @return string resulting schema */ public function getTableDef($db, $table, $do_relation, $do_comments, $do_mime, $view = false, $aliases = array()) { // set $cfgRelation here, because there is a chance that it's modified // since the class initialization global $cfgRelation; $schema_insert = ''; /** * Gets fields properties */ $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations list($res_rel, $have_rel) = PMA_getRelationsAndStatus($do_relation && !empty($cfgRelation['relation']), $db, $table); /** * Displays the table structure */ $schema_insert .= '<table class="width100" cellspacing="1">'; $schema_insert .= '<tr class="print-category">'; $schema_insert .= '<th class="print">' . __('Column') . '</th>'; $schema_insert .= '<td class="print"><strong>' . __('Type') . '</strong></td>'; $schema_insert .= '<td class="print"><strong>' . __('Null') . '</strong></td>'; $schema_insert .= '<td class="print"><strong>' . __('Default') . '</strong></td>'; if ($do_relation && $have_rel) { $schema_insert .= '<td class="print"><strong>' . __('Links to') . '</strong></td>'; } if ($do_comments) { $schema_insert .= '<td class="print"><strong>' . __('Comments') . '</strong></td>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print"><strong>' . htmlspecialchars('MIME') . '</strong></td>'; $mime_map = PMA_getMIME($db, $table, true); } $schema_insert .= '</tr>'; $columns = $GLOBALS['dbi']->getColumns($db, $table); /** * Get the unique keys in the table */ $unique_keys = array(); $keys = $GLOBALS['dbi']->getTableIndexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } foreach ($columns as $column) { $col_as = $column['Field']; if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) { $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as]; } $schema_insert .= $this->formatOneColumnDefinition($column, $unique_keys, $col_as); $field_name = $column['Field']; if ($do_relation && $have_rel) { $schema_insert .= '<td class="print">' . htmlspecialchars($this->getRelationString($res_rel, $field_name, $db, $aliases)) . '</td>'; } if ($do_comments && $cfgRelation['commwork']) { $schema_insert .= '<td class="print">' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>'; } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print">' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>'; } $schema_insert .= '</tr>'; } // end foreach $schema_insert .= '</table>'; return $schema_insert; }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column comments * as comments in the structure; this is deprecated * but the parameter is left here because export.php * calls PMA_exportStructure() also for other export * types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in' * @param string $export_type 'server', 'database', 'table' * * @return bool Whether it succeeded * * @access public */ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type) { global $cfgRelation; /* We do not export triggers */ if ($export_mode == 'triggers') { return true; } /* Heading */ $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</text:h>'; /** * Get the unique keys in the table */ $unique_keys = array(); $keys = PMA_DBI_get_table_indexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_data">'; $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="' . $columns_cnt . '"/>'; /* Header */ $GLOBALS['odt_buffer'] .= '<table:table-row>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Column') . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Type') . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Null') . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Default') . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Links to') . '</text:p>' . '</table:table-cell>'; } if ($do_comments) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Comments') . '</text:p>' . '</table:table-cell>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('MIME type') . '</text:p>' . '</table:table-cell>'; $mime_map = PMA_getMIME($db, $table, true); } $GLOBALS['odt_buffer'] .= '</table:table-row>'; $columns = PMA_DBI_get_columns($db, $table); foreach ($columns as $column) { $field_name = $column['Field']; $GLOBALS['odt_buffer'] .= '<table:table-row>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($field_name) . '</text:p>' . '</table:table-cell>'; $extracted_fieldspec = PMA_extractFieldSpec($column['Type']); $type = htmlspecialchars($extracted_fieldspec['print_type']); if (empty($type)) { $type = ' '; } $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($type) . '</text:p>' . '</table:table-cell>'; if (!isset($column['Default'])) { if ($column['Null'] != 'NO') { $column['Default'] = 'NULL'; } else { $column['Default'] = ''; } } else { $column['Default'] = $column['Default']; } $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')) . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($column['Default']) . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { if (isset($res_rel[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') . '</text:p>' . '</table:table-cell>'; } } if ($do_comments) { if (isset($comments[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($comments[$field_name]) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } if ($do_mime && $cfgRelation['mimework']) { if (isset($mime_map[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } $GLOBALS['odt_buffer'] .= '</table:table-row>'; } // end while $GLOBALS['odt_buffer'] .= '</table:table>'; return true; }
public function dataDictionaryDoc($alltables) { global $db, $pdf, $orientation, $paper; // TOC $pdf->addpage($GLOBALS['orientation']); $pdf->Cell(0, 9, __('Table of contents'), 1, 0, 'C'); $pdf->Ln(15); $i = 1; foreach ($alltables as $table) { $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink(); $pdf->SetX(10); // $pdf->Ln(1); $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']); $pdf->SetX(10); $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']); // $pdf->Ln(1); $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); while ($row = PMA_DBI_fetch_assoc($result)) { $pdf->SetX(20); $field_name = $row['Field']; $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink(); // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]); } $lasttable = $table; $i++; } $pdf->PMA_links['RT']['-'] = $pdf->AddLink(); $pdf->SetX(10); $pdf->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i + 1) . '}', 0, 0, 'R', 0, $pdf->PMA_links['RT']['-']); $pdf->SetX(10); $pdf->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']); $z = 0; foreach ($alltables as $table) { $z++; $pdf->SetAutoPageBreak(true, 15); $pdf->addpage($GLOBALS['orientation']); $pdf->Bookmark($table); $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()); $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink(); $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1); $pdf->SetFont($this->_ff, 'B', 18); $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']); $pdf->SetFont($this->_ff, '', 8); $pdf->ln(); $cfgRelation = PMA_getRelationsParam(); $comments = PMA_getComments($db, $table); if ($cfgRelation['mimework']) { $mime_map = PMA_getMIME($db, $table, true); } /** * Gets table informations */ $showtable = PMA_Table::sGetStatusInfo($db, $table); $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0; $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : ''; $create_time = isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : ''; $update_time = isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''; $check_time = isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''; /** * Gets table keys and retains them */ $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); $primary = ''; $indexes = array(); $lastIndex = ''; $indexes_info = array(); $indexes_data = array(); $pk_array = array(); // will be use to emphasis prim. keys in the table // view while ($row = PMA_DBI_fetch_assoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; $pk_array[$row['Column_name']] = 1; } // Retains keys informations if ($row['Key_name'] != $lastIndex) { $indexes[] = $row['Key_name']; $lastIndex = $row['Key_name']; } $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index']; $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique']; if (isset($row['Cardinality'])) { $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality']; } // I don't know what does following column mean.... // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed']; $indexes_info[$row['Key_name']]['Comment'] = $row['Comment']; $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name']; if (isset($row['Sub_part'])) { $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part']; } } // end while if ($result) { PMA_DBI_free_result($result); } /** * Gets fields properties */ $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations (Mike Beck) if (!empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if (count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the comments of the table if MySQL >= 3.23 */ $break = false; if (!empty($show_comment)) { $pdf->Cell(0, 3, __('Table comments') . ' : ' . $show_comment, 0, 1); $break = true; } if (!empty($create_time)) { $pdf->Cell(0, 3, __('Creation') . ': ' . $create_time, 0, 1); $break = true; } if (!empty($update_time)) { $pdf->Cell(0, 3, __('Last update') . ': ' . $update_time, 0, 1); $break = true; } if (!empty($check_time)) { $pdf->Cell(0, 3, __('Last check') . ': ' . $check_time, 0, 1); $break = true; } if ($break == true) { $pdf->Cell(0, 3, '', 0, 1); $pdf->Ln(); } $pdf->SetFont($this->_ff, 'B'); if (isset($orientation) && $orientation == 'L') { $pdf->Cell(25, 8, ucfirst(__('Column')), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C'); $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst(__('Default')), 1, 0, 'C'); $pdf->Cell(25, 8, ucfirst(__('Extra')), 1, 0, 'C'); $pdf->Cell(45, 8, ucfirst(__('Links to')), 1, 0, 'C'); if ($paper == 'A4') { $comments_width = 67; } else { // this is really intended for 'letter' /** * @todo find optimal width for all formats */ $comments_width = 50; } $pdf->Cell($comments_width, 8, ucfirst(__('Comments')), 1, 0, 'C'); $pdf->Cell(45, 8, 'MIME', 1, 1, 'C'); $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45)); } else { $pdf->Cell(20, 8, ucfirst(__('Column')), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst(__('Type')), 1, 0, 'C'); $pdf->Cell(20, 8, ucfirst(__('Attributes')), 1, 0, 'C'); $pdf->Cell(10, 8, ucfirst(__('Null')), 1, 0, 'C'); $pdf->Cell(15, 8, ucfirst(__('Default')), 1, 0, 'C'); $pdf->Cell(15, 8, ucfirst(__('Extra')), 1, 0, 'C'); $pdf->Cell(30, 8, ucfirst(__('Links to')), 1, 0, 'C'); $pdf->Cell(30, 8, ucfirst(__('Comments')), 1, 0, 'C'); $pdf->Cell(30, 8, 'MIME', 1, 1, 'C'); $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30)); } $pdf->SetFont($this->_ff, ''); while ($row = PMA_DBI_fetch_assoc($result)) { $type = $row['Type']; // reformat mysql query output // set or enum types: slashes single quotes inside options if (preg_match('@^(set|enum)\\((.+)\\)$@i', $type, $tmp)) { $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1); $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; $type_nowrap = ''; $binary = 0; $unsigned = 0; $zerofill = 0; } else { $type_nowrap = ' nowrap="nowrap"'; $type = preg_replace('@BINARY@i', '', $type); $type = preg_replace('@ZEROFILL@i', '', $type); $type = preg_replace('@UNSIGNED@i', '', $type); if (empty($type)) { $type = ' '; } $binary = stristr($row['Type'], 'BINARY'); $unsigned = stristr($row['Type'], 'UNSIGNED'); $zerofill = stristr($row['Type'], 'ZEROFILL'); } $attribute = ' '; if ($binary) { $attribute = 'BINARY'; } if ($unsigned) { $attribute = 'UNSIGNED'; } if ($zerofill) { $attribute = 'UNSIGNED ZEROFILL'; } if (!isset($row['Default'])) { if ($row['Null'] != '' && $row['Null'] != 'NO') { $row['Default'] = 'NULL'; } } $field_name = $row['Field']; // $pdf->Ln(); $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink(); $pdf->Bookmark($field_name, 1, -1); $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1); $pdf_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], isset($res_rel[$field_name]) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : '', isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : ''); $links[0] = $pdf->PMA_links['RT'][$table][$field_name]; if (isset($res_rel[$field_name]['foreign_table']) and isset($res_rel[$field_name]['foreign_field']) and isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']])) { $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']]; } else { unset($links[6]); } $pdf->Row($pdf_row, $links); } // end while $pdf->SetFont($this->_ff, '', 14); PMA_DBI_free_result($result); } //end each }
/** * Returns $table's CREATE definition * * @param string $db the database name * @param string $table the table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * @param bool $do_mime whether to include mime comments * @param bool $show_dates whether to include creation/update/check dates * @param bool $add_semicolon whether to add semicolon and end-of-line at * the end * @param bool $view whether we're handling a view * @param array $aliases Aliases of db/table/columns * * @return bool true */ public function getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false, $aliases = array()) { global $cfgRelation; $db_alias = $db; $table_alias = $table; $this->initAlias($aliases, $db_alias, $table_alias); /** * Gets fields properties */ $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations list($res_rel, $have_rel) = PMA_getRelationsAndStatus($do_relation && !empty($cfgRelation['relation']), $db, $table); /** * Displays the table structure */ $GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table_alias) . '_structure">'; $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $GLOBALS['odt_buffer'] .= '<table:table-column' . ' table:number-columns-repeated="' . $columns_cnt . '"/>'; /* Header */ $GLOBALS['odt_buffer'] .= '<table:table-row>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Column') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Type') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Null') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Default') . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Links to') . '</text:p>' . '</table:table-cell>'; } if ($do_comments) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Comments') . '</text:p>' . '</table:table-cell>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('MIME type') . '</text:p>' . '</table:table-cell>'; $mime_map = PMA_getMIME($db, $table, true); } $GLOBALS['odt_buffer'] .= '</table:table-row>'; $columns = $GLOBALS['dbi']->getColumns($db, $table); foreach ($columns as $column) { $col_as = $field_name = $column['Field']; if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) { $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as]; } $GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column, $col_as); if ($do_relation && $have_rel) { $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name); if ($foreigner) { $rtable = $foreigner['foreign_table']; $rfield = $foreigner['foreign_field']; if (!empty($aliases[$db]['tables'][$rtable]['columns'][$rfield])) { $rfield = $aliases[$db]['tables'][$rtable]['columns'][$rfield]; } if (!empty($aliases[$db]['tables'][$rtable]['alias'])) { $rtable = $aliases[$db]['tables'][$rtable]['alias']; } $relation = htmlspecialchars($rtable . ' (' . $rfield . ')'); $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($relation) . '</text:p>' . '</table:table-cell>'; } } if ($do_comments) { if (isset($comments[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($comments[$field_name]) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } if ($do_mime && $cfgRelation['mimework']) { if (isset($mime_map[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } $GLOBALS['odt_buffer'] .= '</table:table-row>'; } // end foreach $GLOBALS['odt_buffer'] .= '</table:table>'; return true; }
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 = ' '; } $binary = preg_match('/BINARY/i', $row['Type']); $unsigned = preg_match('/UNSIGNED/i', $row['Type']); $zerofill = preg_match('/ZEROFILL/i', $row['Type']); } $strAttribute = ' '; 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>'); }
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 }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column comments * as comments in the structure; this is deprecated * but the parameter is left here because export.php * calls PMA_exportStructure() also for other export * types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in' * @param string $export_type 'server', 'database', 'table' * * @return bool Whether it succeeded * * @access public */ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type) { global $cfgRelation; /* We do not export triggers */ if ($export_mode == 'triggers') { return true; } /** * Get the unique keys in the table */ $unique_keys = array(); $keys = PMA_DBI_get_table_indexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $buffer = $crlf . '%' . $crlf . '% ' . __('Structure') . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{'; if (!PMA_exportOutputHandler($buffer)) { return false; } $columns_cnt = 4; $alignment = '|l|c|c|c|'; if ($do_relation && $have_rel) { $columns_cnt++; $alignment .= 'l|'; } if ($do_comments) { $columns_cnt++; $alignment .= 'l|'; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; $alignment .= 'l|'; } $buffer = $alignment . '} ' . $crlf; $header = ' \\hline '; $header .= '\\multicolumn{1}{|c|}{\\textbf{' . __('Column') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Type') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Null') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Default') . '}}'; if ($do_relation && $have_rel) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Links to') . '}}'; } if ($do_comments) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; $mime_map = PMA_getMIME($db, $table, true); } // Table caption for first page and label if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_expandUserString($GLOBALS['latex_structure_caption'], 'PMA_texEscape', array('table' => $table, 'database' => $db)) . '} \\label{' . PMA_expandUserString($GLOBALS['latex_structure_label'], null, array('table' => $table, 'database' => $db)) . '} \\\\' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf; // Table caption on next pages if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_expandUserString($GLOBALS['latex_structure_continued_caption'], 'PMA_texEscape', array('table' => $table, 'database' => $db)) . '} \\\\ ' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } $fields = PMA_DBI_get_columns($db, $table); foreach ($fields as $row) { $extracted_fieldspec = PMA_extractFieldSpec($row['Type']); $type = $extracted_fieldspec['print_type']; if (empty($type)) { $type = ' '; } if (!isset($row['Default'])) { if ($row['Null'] != 'NO') { $row['Default'] = 'NULL'; } } $field_name = $row['Field']; $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes')) . "" . (isset($row['Default']) ? $row['Default'] : ''); if ($do_relation && $have_rel) { $local_buffer .= ""; if (isset($res_rel[$field_name])) { $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')'; } } if ($do_comments && $cfgRelation['commwork']) { $local_buffer .= ""; if (isset($comments[$field_name])) { $local_buffer .= $comments[$field_name]; } } if ($do_mime && $cfgRelation['mimework']) { $local_buffer .= ""; if (isset($mime_map[$field_name])) { $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']); } } $local_buffer = PMA_texEscape($local_buffer); if ($row['Key'] == 'PRI') { $pos = strpos($local_buffer, ""); $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { $pos = strpos($local_buffer, ""); $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } $buffer = str_replace("", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } } // end while $buffer = ' \\end{longtable}' . $crlf; return PMA_exportOutputHandler($buffer); }
/** * Get the headers of the results table * * @param array &$is_display which elements to display * @param array|string $analyzed_sql the analyzed query * @param string $sort_expression sort expression * @param string $sort_expression_nodirection sort expression * without direction * @param string $sort_direction sort direction * @param boolean $is_limited_display with limited operations * or not * * @return string html content * * @access private * * @see getTable() */ private function _getTableHeaders(&$is_display, $analyzed_sql = '', $sort_expression = '', $sort_expression_nodirection = '', $sort_direction = '', $is_limited_display = false) { $table_headers_html = ''; // Following variable are needed for use in isset/empty or // use with array indexes/safe use in foreach $fields_meta = $this->__get('fields_meta'); $highlight_columns = $this->__get('highlight_columns'); $printview = $this->__get('printview'); $vertical_display = $this->__get('vertical_display'); // required to generate sort links that will remember whether the // "Show all" button has been clicked $sql_md5 = md5($this->__get('sql_query')); $session_max_rows = $is_limited_display ? 0 : $_SESSION['tmpval']['query'][$sql_md5]['max_rows']; $direction = isset($_SESSION['tmpval']['disp_direction']) ? $_SESSION['tmpval']['disp_direction'] : ''; if ($analyzed_sql == '') { $analyzed_sql = array(); } $directionCondition = $direction == self::DISP_DIR_HORIZONTAL || $direction == self::DISP_DIR_HORIZONTAL_FLIPPED; // can the result be sorted? if ($is_display['sort_lnk'] == '1') { list($unsorted_sql_query, $drop_down_html) = $this->_getUnsortedSqlAndSortByKeyDropDown($analyzed_sql, $sort_expression); $table_headers_html .= $drop_down_html; } // Output data needed for grid editing $table_headers_html .= '<input id="save_cells_at_once" type="hidden" value="' . $GLOBALS['cfg']['SaveCellsAtOnce'] . '" />' . '<div class="common_hidden_inputs">' . PMA_URL_getHiddenInputs($this->__get('db'), $this->__get('table')) . '</div>'; // Output data needed for column reordering and show/hide column if ($this->_isSelect($analyzed_sql)) { $table_headers_html .= $this->_getDataForResettingColumnOrder(); } $vertical_display['emptypre'] = 0; $vertical_display['emptyafter'] = 0; $vertical_display['textbtn'] = ''; $full_or_partial_text_link = null; $this->__set('vertical_display', $vertical_display); // Display options (if we are not in print view) if (!(isset($printview) && $printview == '1') && !$is_limited_display) { $table_headers_html .= $this->_getOptionsBlock(); // prepare full/partial text button or link $full_or_partial_text_link = $this->_getFullOrPartialTextButtonOrLink(); } // Start of form for multi-rows edit/delete/export $table_headers_html .= $this->_getFormForMultiRowOperations($is_display['del_lnk']); // 1. Set $colspan or $rowspan and generate html with full/partial // text button or link list($colspan, $rowspan, $button_html) = $this->_getFieldVisibilityParams($directionCondition, $is_display, $full_or_partial_text_link); $table_headers_html .= $button_html; // 2. Displays the fields' name // 2.0 If sorting links should be used, checks if the query is a "JOIN" // statement (see 2.1.3) // 2.0.1 Prepare Display column comments if enabled // ($GLOBALS['cfg']['ShowBrowseComments']). // Do not show comments, if using horizontalflipped mode, // because of space usage $comments_map = $this->_getTableCommentsArray($direction, $analyzed_sql); if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && !$_SESSION['tmpval']['hide_transformation']) { include_once './libraries/transformations.lib.php'; $this->__set('mime_map', PMA_getMIME($this->__get('db'), $this->__get('table'))); } // See if we have to highlight any header fields of a WHERE query. // Uses SQL-Parser results. $this->_setHighlightedColumnGlobalField($analyzed_sql); list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); for ($j = 0; $j < $this->__get('fields_cnt'); $j++) { // assign $i with appropriate column order $i = $col_order ? $col_order[$j] : $j; // See if this column should get highlight because it's used in the // where-query. $condition_field = isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_Util::backquote($fields_meta[$i]->name)]) ? true : false; // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled. $comments = $this->_getCommentForRow($comments_map, $fields_meta[$i]); $vertical_display = $this->__get('vertical_display'); if ($is_display['sort_lnk'] == '1' && !$is_limited_display) { list($order_link, $sorted_header_html) = $this->_getOrderLinkAndSortedHeaderHtml($fields_meta[$i], $sort_expression, $sort_expression_nodirection, $i, $unsorted_sql_query, $session_max_rows, $direction, $comments, $sort_direction, $directionCondition, $col_visib, $col_visib[$j]); $table_headers_html .= $sorted_header_html; $vertical_display['desc'][] = ' <th ' . 'class="draggable' . ($condition_field ? ' condition' : '') . '" data-column="' . htmlspecialchars($fields_meta[$i]->name) . '">' . "\n" . $order_link . $comments . ' </th>' . "\n"; } else { // 2.2 Results can't be sorted if ($directionCondition) { $table_headers_html .= $this->_getDraggableClassForNonSortableColumns($col_visib, $col_visib[$j], $condition_field, $direction, $fields_meta[$i], $comments); } $vertical_display['desc'][] = ' <th ' . 'class="draggable' . ($condition_field ? ' condition"' : '') . '" data-column="' . htmlspecialchars($fields_meta[$i]->name) . '">' . "\n" . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n" . $comments . ' </th>'; } // end else (2.2) $this->__set('vertical_display', $vertical_display); } // end for // Display column at rightside - checkboxes or empty column if (!$printview) { $table_headers_html .= $this->_getColumnAtRightSide($is_display, $directionCondition, $full_or_partial_text_link, $colspan, $rowspan); } if ($directionCondition) { $table_headers_html .= '</tr>' . '</thead>'; } return $table_headers_html; }
/** * Print $table's CREATE definition * * @param string $db the database name * @param string $table the table name * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $view whether we're handling a view * @param array $aliases aliases of db/table/columns * * @return void */ public function getTableDef($db, $table, $do_relation, $do_comments, $do_mime, $view = false, $aliases = array()) { // set $cfgRelation here, because there is a chance that it's modified // since the class initialization global $cfgRelation; unset($this->tablewidths); unset($this->colTitles); unset($this->titleWidth); unset($this->colFits); unset($this->display_column); unset($this->colAlign); /** * Gets fields properties */ $GLOBALS['dbi']->selectDb($db); /** * All these three checks do_relation, do_comment and do_mime is * not required. As presently all are set true by default. * But when, methods to take user input will be developed, * it will be of use */ // Check if we can use Relations if ($do_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 //column count and table heading $this->colTitles[0] = __('Column'); $this->tablewidths[0] = 90; $this->colTitles[1] = __('Type'); $this->tablewidths[1] = 80; $this->colTitles[2] = __('Null'); $this->tablewidths[2] = 40; $this->colTitles[3] = __('Default'); $this->tablewidths[3] = 120; for ($columns_cnt = 0; $columns_cnt < 4; $columns_cnt++) { $this->colAlign[$columns_cnt] = 'L'; $this->display_column[$columns_cnt] = true; } if ($do_relation && $have_rel) { $this->colTitles[$columns_cnt] = __('Links to'); $this->display_column[$columns_cnt] = true; $this->colAlign[$columns_cnt] = 'L'; $this->tablewidths[$columns_cnt] = 120; $columns_cnt++; } if ($do_comments) { $this->colTitles[$columns_cnt] = __('Comments'); $this->display_column[$columns_cnt] = true; $this->colAlign[$columns_cnt] = 'L'; $this->tablewidths[$columns_cnt] = 120; $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $this->colTitles[$columns_cnt] = __('MIME'); $this->display_column[$columns_cnt] = true; $this->colAlign[$columns_cnt] = 'L'; $this->tablewidths[$columns_cnt] = 120; $columns_cnt++; } // Starting to fill table with required info $this->setY($this->tMargin); $this->AddPage(); $this->SetFont(PMA_PDF_FONT, '', 9); // Now let's start to write the table structure if ($do_comments) { $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $mime_map = PMA_getMIME($db, $table, true); } $columns = $GLOBALS['dbi']->getColumns($db, $table); /** * Get the unique keys in the table. * Presently, this information is not used. We will have to find out * way of displaying it. */ $unique_keys = array(); $keys = $GLOBALS['dbi']->getTableIndexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } // some things to set and 'remember' $l = $this->lMargin; $startheight = $h = $this->dataY; $startpage = $currpage = $this->page; // calculate the whole width $fullwidth = 0; foreach ($this->tablewidths as $width) { $fullwidth += $width; } $row = 0; $tmpheight = array(); $maxpage = $this->page; // fun begin foreach ($columns as $column) { $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']); $type = $extracted_columnspec['print_type']; if (empty($type)) { $type = ' '; } if (!isset($column['Default'])) { if ($column['Null'] != 'NO') { $column['Default'] = 'NULL'; } } $data[] = $column['Field']; $data[] = $type; $data[] = $column['Null'] == '' || $column['Null'] == 'NO' ? 'No' : 'Yes'; $data[] = isset($column['Default']) ? $column['Default'] : ''; $field_name = $column['Field']; if ($do_relation && $have_rel) { $data[] = isset($res_rel[$field_name]) ? $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')' : ''; } if ($do_comments) { $data[] = isset($comments[$field_name]) ? $comments[$field_name] : ''; } if ($do_mime) { $data[] = isset($mime_map[$field_name]) ? $mime_map[$field_name]['mimetype'] : ''; } $this->page = $currpage; // write the horizontal borders $this->Line($l, $h, $fullwidth + $l, $h); // write the content and remember the height of the highest col foreach ($data as $col => $txt) { $this->page = $currpage; $this->SetXY($l, $h); if ($this->tablewidths[$col] > 0) { $this->MultiCell($this->tablewidths[$col], $this->FontSizePt, $txt, 0, $this->colAlign[$col]); $l += $this->tablewidths[$col]; } if (!isset($tmpheight[$row . '-' . $this->page])) { $tmpheight[$row . '-' . $this->page] = 0; } if ($tmpheight[$row . '-' . $this->page] < $this->GetY()) { $tmpheight[$row . '-' . $this->page] = $this->GetY(); } if ($this->page > $maxpage) { $maxpage = $this->page; } } // get the height we were in the last used page $h = $tmpheight[$row . '-' . $maxpage]; // set the "pointer" to the left margin $l = $this->lMargin; // set the $currpage to the last page $currpage = $maxpage; unset($data); $row++; } // draw the borders // we start adding a horizontal line on the last page $this->page = $maxpage; $this->Line($l, $h, $fullwidth + $l, $h); // now we start at the top of the document and walk down for ($i = $startpage; $i <= $maxpage; $i++) { $this->page = $i; $l = $this->lMargin; $t = $i == $startpage ? $startheight : $this->tMargin; $lh = $i == $maxpage ? $h : $this->h - $this->bMargin; $this->Line($l, $t, $l, $lh); foreach ($this->tablewidths as $width) { $l += $width; $this->Line($l, $t, $l, $lh); } } // set it to the last page, if not it'll cause some problems $this->page = $maxpage; }
/** * 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; }
/** * 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 * @param array $aliases Aliases of db/table/columns * * @return string resulting comments */ private function _getTableComments($db, $table, $crlf, $do_relation = false, $do_mime = false, $aliases = array()) { global $cfgRelation, $sql_backquotes; $db_alias = $db; $table_alias = $table; $this->initAlias($aliases, $db_alias, $table_alias); $schema_create = ''; // Check if we can use Relations list($res_rel, $have_rel) = PMA_getRelationsAndStatus($do_relation && !empty($cfgRelation['relation']), $db, $table); 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_alias, $sql_backquotes) . ':'); foreach ($res_rel as $rel_field => $rel) { if ($rel_field != 'foreign_keys_data') { $rel_field_alias = !empty($aliases[$db]['tables'][$table]['columns'][$rel_field]) ? $aliases[$db]['tables'][$table]['columns'][$rel_field] : $rel_field; $schema_create .= $this->_exportComment(' ' . PMA_Util::backquote($rel_field_alias, $sql_backquotes)) . $this->_exportComment(' ' . PMA_Util::backquote($rel['foreign_table'], $sql_backquotes) . ' -> ' . PMA_Util::backquote($rel['foreign_field'], $sql_backquotes)); } else { foreach ($rel as $one_key) { foreach ($one_key['index_list'] as $index => $field) { $rel_field_alias = !empty($aliases[$db]['tables'][$table]['columns'][$field]) ? $aliases[$db]['tables'][$table]['columns'][$field] : $field; $schema_create .= $this->_exportComment(' ' . PMA_Util::backquote($rel_field_alias, $sql_backquotes)) . $this->_exportComment(' ' . PMA_Util::backquote($one_key['ref_table_name'], $sql_backquotes) . ' -> ' . PMA_Util::backquote($one_key['ref_index_list'][$index], $sql_backquotes)); } } } } $schema_create .= $this->_exportComment(); } return $schema_create; }
/** * Displays the headers of the results table * * @uses $_SESSION['tmp_user_values']['disp_direction'] * @uses $_SESSION['tmp_user_values']['repeat_cells'] * @uses $_SESSION['tmp_user_values']['max_rows'] * @uses $_SESSION['tmp_user_values']['display_text'] * @uses $_SESSION['tmp_user_values']['display_binary'] * @uses $_SESSION['tmp_user_values']['display_binary_as_hex'] * @param array which elements to display * @param array the list of fields properties * @param integer the total number of fields returned by the SQL query * @param array the analyzed query * * @return boolean $clause_is_unique * * @global string $db the database name * @global string $table the table name * @global string $goto the URL to go back in case of errors * @global string $sql_query the SQL query * @global integer $num_rows the total number of rows returned by the * SQL query * @global array $vertical_display informations used with vertical display * mode * * @access private * * @see PMA_displayTable() */ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction) { global $db, $table, $goto; global $sql_query, $num_rows; global $vertical_display, $highlight_columns; if ($analyzed_sql == '') { $analyzed_sql = array(); } // can the result be sorted? if ($is_display['sort_lnk'] == '1') { // Just as fallback $unsorted_sql_query = $sql_query; if (isset($analyzed_sql[0]['unsorted_query'])) { $unsorted_sql_query = $analyzed_sql[0]['unsorted_query']; } // Handles the case of multiple clicks on a column's header // which would add many spaces before "ORDER BY" in the // generated query. $unsorted_sql_query = trim($unsorted_sql_query); // sorting by indexes, only if it makes sense (only one table ref) if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' && isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) { // grab indexes data: $indexes = PMA_Index::getFromTable($table, $db); // do we have any index? if ($indexes) { if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { $span = $fields_cnt; if ($is_display['edit_lnk'] != 'nn') { $span++; } if ($is_display['del_lnk'] != 'nn') { $span++; } if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') { $span++; } } else { $span = $num_rows + floor($num_rows / $_SESSION['tmp_user_values']['repeat_cells']) + 1; } echo '<form action="sql.php" method="post">' . "\n"; echo PMA_generate_common_hidden_inputs($db, $table); echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n"; $used_index = false; $local_order = isset($sort_expression) ? $sort_expression : ''; foreach ($indexes as $index) { $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC'; $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC'; $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort; echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($index->getName()) . ' (' . $GLOBALS['strAscending'] . ')</option>'; echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($index->getName()) . ' (' . $GLOBALS['strDescending'] . ')</option>'; } echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>'; echo '</select>' . "\n"; echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>'; echo '</form>' . "\n"; } } } $vertical_display['emptypre'] = 0; $vertical_display['emptyafter'] = 0; $vertical_display['textbtn'] = ''; // Display options (if we are not in print view) if (!(isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) { echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">'; $url_params = array('db' => $db, 'table' => $table, 'sql_query' => $sql_query, 'goto' => $goto, 'display_options_form' => 1); echo PMA_generate_common_hidden_inputs($url_params); echo '<br />'; PMA_generate_slider_effect('displayoptions', $GLOBALS['strOptions']); echo '<fieldset>'; echo '<div class="formelement">'; $choices = array('P' => $GLOBALS['strPartialText'], 'F' => $GLOBALS['strFullText']); PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']); echo '</div>'; // prepare full/partial text button or link if ($_SESSION['tmp_user_values']['display_text'] == 'F') { // currently in fulltext mode so show the opposite link $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png'; $tmp_txt = $GLOBALS['strPartialText']; $url_params['display_text'] = 'P'; } else { $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png'; $tmp_txt = $GLOBALS['strFullText']; $url_params['display_text'] = 'F'; } $tmp_image = '<img class="fulltext" width="50" height="20" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />'; $tmp_url = 'sql.php' . PMA_generate_common_url($url_params); $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false); unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image); if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) { echo '<div class="formelement">'; $choices = array('K' => $GLOBALS['strRelationalKey'], 'D' => $GLOBALS['strRelationalDisplayField']); PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']); echo '</div>'; } echo '<div class="formelement">'; PMA_display_html_checkbox('display_binary', $GLOBALS['strShowBinaryContents'], !empty($_SESSION['tmp_user_values']['display_binary']), false); echo '<br />'; PMA_display_html_checkbox('display_blob', $GLOBALS['strShowBLOBContents'], !empty($_SESSION['tmp_user_values']['display_blob']), false); echo '<br />'; PMA_display_html_checkbox('display_binary_as_hex', $GLOBALS['strShowBinaryContentsAsHex'], !empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false); echo '</div>'; // I would have preferred to name this "display_transformation". // This is the only way I found to be able to keep this setting sticky // per SQL query, and at the same time have a default that displays // the transformations. echo '<div class="formelement">'; PMA_display_html_checkbox('hide_transformation', $GLOBALS['strHide'] . ' ' . $GLOBALS['strMIME_transformation'], !empty($_SESSION['tmp_user_values']['hide_transformation']), false); echo '</div>'; echo '<div class="clearfloat"></div>'; echo '</fieldset>'; echo '<fieldset class="tblFooters">'; echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />'; echo '</fieldset>'; echo '</div>'; echo '</form>'; } // Start of form for multi-rows edit/delete/export if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') { echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n"; echo PMA_generate_common_hidden_inputs($db, $table, 1); echo '<input type="hidden" name="goto" value="sql.php" />' . "\n"; } echo '<table id="table_results" class="data">' . "\n"; if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { echo '<thead><tr>' . "\n"; } // 1. Displays the full/partial text button (part 1)... if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { $colspan = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' colspan="3"' : ''; } else { $rowspan = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? ' rowspan="3"' : ''; } // ... before the result table if ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn' && $is_display['text_btn'] == '1') { $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 0; if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { ?> <th colspan="<?php echo $fields_cnt; ?> "></th> </tr> <tr> <?php } else { ?> <tr> <th colspan="<?php echo $num_rows + floor($num_rows / $_SESSION['tmp_user_values']['repeat_cells']) + 1; ?> "></th> </tr> <?php } // end vertical mode } elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') { $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 0; if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { ?> <th <?php echo $colspan; ?> ><?php echo $full_or_partial_text_link; ?> </th> <?php } else { $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n" . ' ' . "\n" . ' </th>' . "\n"; } // end vertical mode } elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) { $vertical_display['emptypre'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 0; if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { ?> <td<?php echo $colspan; ?> ></td> <?php } else { $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n"; } // end vertical mode } // 2. Displays the fields' name // 2.0 If sorting links should be used, checks if the query is a "JOIN" // statement (see 2.1.3) // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']). // Do not show comments, if using horizontalflipped mode, because of space usage if ($GLOBALS['cfg']['ShowBrowseComments'] && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') { $comments_map = array(); if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) { foreach ($analyzed_sql[0]['table_ref'] as $tbl) { $tb = $tbl['table_true_name']; $comments_map[$tb] = PMA_getComments($db, $tb); unset($tb); } } } if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && !$_SESSION['tmp_user_values']['hide_transformation']) { require_once './libraries/transformations.lib.php'; $GLOBALS['mime_map'] = PMA_getMIME($db, $table); } if ($is_display['sort_lnk'] == '1') { $select_expr = $analyzed_sql[0]['select_expr_clause']; } // garvin: See if we have to highlight any header fields of a WHERE query. // Uses SQL-Parser results. $highlight_columns = array(); if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['where_clause_identifiers'])) { $wi = 0; if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) { foreach ($analyzed_sql[0]['where_clause_identifiers'] as $wci_nr => $wci) { $highlight_columns[$wci] = 'true'; } } } for ($i = 0; $i < $fields_cnt; $i++) { // garvin: See if this column should get highlight because it's used in the // where-query. if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) { $condition_field = true; } else { $condition_field = false; } // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled. if (isset($comments_map) && isset($comments_map[$fields_meta[$i]->table]) && isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) { $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>'; } else { $comments = ''; } // 2.1 Results can be sorted if ($is_display['sort_lnk'] == '1') { // 2.1.1 Checks if the table name is required; it's the case // for a query with a "JOIN" statement and if the column // isn't aliased, or in queries like // SELECT `1`.`master_field` , `2`.`master_field` // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2` if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) { $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.'; } else { $sort_tbl = ''; } // 2.1.2 Checks if the current column is used to sort the // results // the orgname member does not exist for all MySQL versions // but if found, it's the one on which to sort $name_to_use_in_sort = $fields_meta[$i]->name; if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) { $name_to_use_in_sort = $fields_meta[$i]->orgname; } // $name_to_use_in_sort might contain a space due to // formatting of function expressions like "COUNT(name )" // so we remove the space in this situation $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort); if (empty($sort_expression)) { $is_in_sort = false; } else { // Field name may be preceded by a space, or any number // of characters followed by a dot (tablename.fieldname) // so do a direct comparison for the sort expression; // this avoids problems with queries like // "SELECT id, count(id)..." and clicking to sort // on id or on count(id). // Another query to test this: // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p // (and try clicking on each column's header twice) if (!empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) { $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection; } $is_in_sort = str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false; } // 2.1.3 Check the field name for a bracket. // If it contains one, it's probably a function column // like 'COUNT(`field`)' if (strpos($name_to_use_in_sort, '(') !== false) { $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' '; } else { $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' '; } unset($name_to_use_in_sort); // 2.1.4 Do define the sorting URL if (!$is_in_sort) { // loic1: patch #455484 ("Smart" order) $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']); if ($GLOBALS['cfg']['Order'] === 'SMART') { $sort_order .= preg_match('@time|date@i', $fields_meta[$i]->type) ? 'DESC' : 'ASC'; } else { $sort_order .= $GLOBALS['cfg']['Order']; } $order_img = ''; } elseif ('DESC' == $sort_direction) { $sort_order .= ' ASC'; $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="' . $GLOBALS['strDescending'] . '" title="' . $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />'; } else { $sort_order .= ' DESC'; $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="' . $GLOBALS['strAscending'] . '" title="' . $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />'; } if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) { $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2]; } else { $sorted_sql_query = $unsorted_sql_query . $sort_order; } $_url_params = array('db' => $db, 'table' => $table, 'sql_query' => $sorted_sql_query); $order_url = 'sql.php' . PMA_generate_common_url($_url_params); // 2.1.5 Displays the sorting URL // added 20004-06-09: Michael Keck <*****@*****.**> // enable sort order swapping for image $order_link_params = array(); if (isset($order_img) && $order_img != '') { if (strstr($order_img, 'asc')) { $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }'; $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }'; } elseif (strstr($order_img, 'desc')) { $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }'; $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }'; } } if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') { $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;'; } $order_link_params['title'] = $GLOBALS['strSort']; $order_link_content = $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name); $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true); if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { echo '<th'; if ($condition_field) { echo ' class="condition"'; } if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { echo ' valign="bottom"'; } echo '>' . $order_link . $comments . '</th>'; } $vertical_display['desc'][] = ' <th ' . ($condition_field ? ' class="condition"' : '') . '>' . "\n" . $order_link . $comments . ' </th>' . "\n"; } else { if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { echo '<th'; if ($condition_field) { echo ' class="condition"'; } if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { echo ' valign="bottom"'; } if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') { echo ' style="direction: ltr; writing-mode: tb-rl;"'; } echo '>'; if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') { echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />'); } else { echo htmlspecialchars($fields_meta[$i]->name); } echo "\n" . $comments . '</th>'; } $vertical_display['desc'][] = ' <th ' . ($condition_field ? ' class="condition"' : '') . '>' . "\n" . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n" . $comments . ' </th>'; } // end else (2.2) } // end for // 3. Displays the needed checkboxes at the right // column of the result table header if possible and required... if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') && $is_display['text_btn'] == '1') { $vertical_display['emptyafter'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 1; if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { echo "\n"; ?> <th <?php echo $colspan; ?> ><?php echo $full_or_partial_text_link; ?> </th> <?php } else { $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n" . ' ' . "\n" . ' </th>' . "\n"; } // end vertical mode } elseif ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn') && !$GLOBALS['is_header_sent']) { $vertical_display['emptyafter'] = $is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn' ? 3 : 1; if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { echo "\n"; ?> <td<?php echo $colspan; ?> ></td> <?php } else { $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n"; } // end vertical mode } if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') { ?> </tr> </thead> <?php } return true; }
/** * Returns $table's CREATE definition * * @param string $db the database name * @param string $table the table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $show_dates whether to include creation/update/check dates * @param bool $add_semicolon whether to add semicolon and end-of-line * at the end * @param bool $view whether we're handling a view * * @return string resulting schema */ public function getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false) { // set $cfgRelation here, because there is a chance that it's modified // since the class initialization global $cfgRelation; $schema_insert = ''; /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $schema_insert .= '<table class="width100" cellspacing="1">'; $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments && $cfgRelation['commwork']) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $schema_insert .= '<tr class="print-category">'; $schema_insert .= '<th class="print">' . __('Column') . '</th>'; $schema_insert .= '<td class="print"><strong>' . __('Type') . '</strong></td>'; $schema_insert .= '<td class="print"><strong>' . __('Null') . '</strong></td>'; $schema_insert .= '<td class="print"><strong>' . __('Default') . '</strong></td>'; if ($do_relation && $have_rel) { $schema_insert .= '<td class="print"><strong>' . __('Links to') . '</strong></td>'; } if ($do_comments) { $schema_insert .= '<td class="print"><strong>' . __('Comments') . '</strong></td>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print"><strong>' . htmlspecialchars('MIME') . '</strong></td>'; $mime_map = PMA_getMIME($db, $table, true); } $schema_insert .= '</tr>'; $columns = PMA_DBI_get_columns($db, $table); /** * Get the unique keys in the table */ $unique_keys = array(); $keys = PMA_DBI_get_table_indexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } foreach ($columns as $column) { $schema_insert .= $this->formatOneColumnDefinition($column, $unique_keys); $field_name = $column['Field']; if ($do_relation && $have_rel) { $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>'; } if ($do_comments && $cfgRelation['commwork']) { $schema_insert .= '<td class="print">' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>'; } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print">' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>'; } $schema_insert .= '</tr>'; } // end foreach $schema_insert .= '</table>'; return $schema_insert; }
/** * Tests getting mime types for table * * @return void */ public function testGetMime() { $_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'] = PMA_VERSION; $_SESSION['relation'][$GLOBALS['server']]['commwork'] = true; $_SESSION['relation'][$GLOBALS['server']]['db'] = "pmadb"; $_SESSION['relation'][$GLOBALS['server']]['column_info'] = "column_info"; $_SESSION['relation'][$GLOBALS['server']]['trackingwork'] = false; $this->assertEquals(array('o' => array('column_name' => 'o', 'mimetype' => 'Text/plain', 'transformation' => 'Sql', 'transformation_options' => '', 'input_transformation' => 'regex', 'input_transformation_options' => '/pma/i'), 'col' => array('column_name' => 'col', 'mimetype' => 'T', 'transformation' => 'o/P', 'transformation_options' => '', 'input_transformation' => 'i/p', 'input_transformation_options' => '')), PMA_getMIME('pma_test', 'table1')); }
/** * Outputs table's structure * * @param string $db database name * @param string $table table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param string $export_mode 'create_table', 'triggers', 'create_view', * 'stand_in' * @param string $export_type 'server', 'database', 'table' * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $dates whether to include creation/update/check dates * @param array $aliases Aliases of db/table/columns * * @return bool Whether it succeeded */ public function exportStructure($db, $table, $crlf, $error_url, $export_mode, $export_type, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $aliases = array()) { $db_alias = $db; $table_alias = $table; $this->initAlias($aliases, $db_alias, $table_alias); global $cfgRelation; /* We do not export triggers */ if ($export_mode == 'triggers') { return true; } /** * Get the unique keys in the table */ $unique_keys = array(); $keys = $GLOBALS['dbi']->getTableIndexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Gets fields properties */ $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations list($res_rel, $have_rel) = PMA_getRelationsAndStatus($do_relation && !empty($cfgRelation['relation']), $db, $table); /** * Displays the table structure */ $buffer = $crlf . '%' . $crlf . '% ' . __('Structure:') . ' ' . $table_alias . $crlf . '%' . $crlf . ' \\begin{longtable}{'; if (!PMA_exportOutputHandler($buffer)) { return false; } $alignment = '|l|c|c|c|'; if ($do_relation && $have_rel) { $alignment .= 'l|'; } if ($do_comments) { $alignment .= 'l|'; } if ($do_mime && $cfgRelation['mimework']) { $alignment .= 'l|'; } $buffer = $alignment . '} ' . $crlf; $header = ' \\hline '; $header .= '\\multicolumn{1}{|c|}{\\textbf{' . __('Column') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Type') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Null') . '}} & \\multicolumn{1}{|c|}{\\textbf{' . __('Default') . '}}'; if ($do_relation && $have_rel) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Links to') . '}}'; } if ($do_comments) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . __('Comments') . '}}'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; $mime_map = PMA_getMIME($db, $table, true); } // Table caption for first page and label if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_Util::expandUserString($GLOBALS['latex_structure_caption'], array('texEscape', get_class($this), 'libraries/plugins/export/' . get_class($this) . ".class.php"), array('table' => $table_alias, 'database' => $db_alias)) . '} \\label{' . PMA_Util::expandUserString($GLOBALS['latex_structure_label'], null, array('table' => $table_alias, 'database' => $db_alias)) . '} \\\\' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf; // Table caption on next pages if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . PMA_Util::expandUserString($GLOBALS['latex_structure_continued_caption'], array('texEscape', get_class($this), 'libraries/plugins/export/' . get_class($this) . ".class.php"), array('table' => $table_alias, 'database' => $db_alias)) . '} \\\\ ' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } $fields = $GLOBALS['dbi']->getColumns($db, $table); foreach ($fields as $row) { $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']); $type = $extracted_columnspec['print_type']; if (empty($type)) { $type = ' '; } if (!isset($row['Default'])) { if ($row['Null'] != 'NO') { $row['Default'] = 'NULL'; } } $field_name = $col_as = $row['Field']; if (!empty($aliases[$db]['tables'][$table]['columns'][$col_as])) { $col_as = $aliases[$db]['tables'][$table]['columns'][$col_as]; } $local_buffer = $col_as . "" . $type . "" . ($row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes')) . "" . (isset($row['Default']) ? $row['Default'] : ''); if ($do_relation && $have_rel) { $local_buffer .= ""; $local_buffer .= $this->getRelationString($res_rel, $field_name, $db, $aliases); } 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 = self::texEscape($local_buffer); if ($row['Key'] == 'PRI') { $pos = mb_strpos($local_buffer, ""); $local_buffer = '\\textit{' . mb_substr($local_buffer, 0, $pos) . '}' . mb_substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { $pos = mb_strpos($local_buffer, ""); $local_buffer = '\\textbf{' . mb_substr($local_buffer, 0, $pos) . '}' . mb_substr($local_buffer, $pos); } $buffer = str_replace("", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return false; } } // end while $buffer = ' \\end{longtable}' . $crlf; return PMA_exportOutputHandler($buffer); }
/** * return html for Print View Columns * * @param bool $tbl_is_view whether table is a view * @param array $columns columns list * @param array $analyzed_sql analyzed sql * @param bool $have_rel have relation? * @param array $res_rel relations array * @param string $db database name * @param string $table table name * @param array $cfgRelation config from PMA_getRelationsParam * * @return string */ function PMA_getHtmlForPrintViewColumns($tbl_is_view, $columns, $analyzed_sql, $have_rel, $res_rel, $db, $table, $cfgRelation) { $html = ''; $primary = PMA_Index::getPrimary($table, $db); foreach ($columns as $row) { $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']); $type = $extracted_columnspec['print_type']; if (!isset($row['Default'])) { if ($row['Null'] != '' && $row['Null'] != 'NO') { $row['Default'] = '<i>NULL</i>'; } } else { $row['Default'] = htmlspecialchars($row['Default']); } $field_name = htmlspecialchars($row['Field']); if (!$tbl_is_view) { // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having // the NULL attribute, but SHOW CREATE TABLE says the contrary. // Believe the latter. /** * @todo merge this logic with the one in tbl_structure.php * or move it in a function similar to $GLOBALS['dbi']->getColumnsFull() * but based on SHOW CREATE TABLE because information_schema * cannot be trusted in this case (MySQL bug) */ $analyzed_for_field = $analyzed_sql[0]['create_table_fields'][$field_name]; if (!empty($analyzed_for_field['type']) && $analyzed_for_field['type'] == 'TIMESTAMP' && $analyzed_for_field['timestamp_not_null']) { $row['Null'] = ''; } } $html .= "\n"; $html .= '<tr><td>'; $html .= ' ' . $field_name . "\n"; if ($primary && $primary->hasColumn($field_name)) { $html .= ' <em>(' . __('Primary') . ')</em>'; } $html .= "\n"; $html .= '</td>'; $html .= '<td>' . htmlspecialchars($type) . '<bdo dir="ltr"></bdo></td>'; $html .= '<td>'; $html .= $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'); $html .= ' </td>'; $html .= '<td>'; if (isset($row['Default'])) { $html .= $row['Default']; } $html .= ' </td>'; if ($have_rel) { $html .= ' <td>'; $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name); if ($foreigner) { $html .= htmlspecialchars($foreigner['foreign_table'] . ' -> ' . $foreigner['foreign_field']); } $html .= ' </td>' . "\n"; } $html .= ' <td>'; $comments = PMA_getComments($db, $table); if (isset($comments[$field_name])) { $html .= htmlspecialchars($comments[$field_name]); } $html .= ' </td>' . "\n"; if ($cfgRelation['mimework']) { $mime_map = PMA_getMIME($db, $table, true); $html .= ' <td>'; if (isset($mime_map[$field_name])) { $html .= htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])); } $html .= ' </td>' . "\n"; } $html .= '</tr>'; } // end foreach return $html; }
/** * Generates data dictionary pages. * * @param array $alltables Tables to document. * * @return void */ public function dataDictionaryDoc($alltables) { // TOC $this->diagram->addpage($this->orientation); $this->diagram->Cell(0, 9, __('Table of contents'), 1, 0, 'C'); $this->diagram->Ln(15); $i = 1; foreach ($alltables as $table) { $this->diagram->PMA_links['doc'][$table]['-'] = $this->diagram->AddLink(); $this->diagram->SetX(10); // $this->diagram->Ln(1); $this->diagram->Cell(0, 6, __('Page number:') . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $this->diagram->PMA_links['doc'][$table]['-']); $this->diagram->SetX(10); $this->diagram->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $this->diagram->PMA_links['doc'][$table]['-']); // $this->diagram->Ln(1); $fields = $GLOBALS['dbi']->getColumns($this->db, $table); foreach ($fields as $row) { $this->diagram->SetX(20); $field_name = $row['Field']; $this->diagram->PMA_links['doc'][$table][$field_name] = $this->diagram->AddLink(); //$this->diagram->Cell( // 0, 6, $field_name, 0, 1, // 'L', 0, $this->diagram->PMA_links['doc'][$table][$field_name] //); } $i++; } $this->diagram->PMA_links['RT']['-'] = $this->diagram->AddLink(); $this->diagram->SetX(10); $this->diagram->Cell(0, 6, __('Page number:') . ' {00}', 0, 0, 'R', 0, $this->diagram->PMA_links['RT']['-']); $this->diagram->SetX(10); $this->diagram->Cell(0, 6, $i . ' ' . __('Relational schema'), 0, 1, 'L', 0, $this->diagram->PMA_links['RT']['-']); $z = 0; foreach ($alltables as $table) { $z++; $this->diagram->SetAutoPageBreak(true, 15); $this->diagram->addpage($this->orientation); $this->diagram->Bookmark($table); $this->diagram->SetAlias('{' . sprintf("%02d", $z) . '}', $this->diagram->PageNo()); $this->diagram->PMA_links['RT'][$table]['-'] = $this->diagram->AddLink(); $this->diagram->SetLink($this->diagram->PMA_links['doc'][$table]['-'], -1); $this->diagram->SetFont($this->_ff, 'B', 18); $this->diagram->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $this->diagram->PMA_links['RT'][$table]['-']); $this->diagram->SetFont($this->_ff, '', 8); $this->diagram->ln(); $cfgRelation = PMA_getRelationsParam(); $comments = PMA_getComments($this->db, $table); if ($cfgRelation['mimework']) { $mime_map = PMA_getMIME($this->db, $table, true); } /** * Gets table information */ $showtable = $GLOBALS['dbi']->getTable($this->db, $table)->getStatusInfo(); $show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : ''; $create_time = isset($showtable['Create_time']) ? PMA_Util::localisedDate(strtotime($showtable['Create_time'])) : ''; $update_time = isset($showtable['Update_time']) ? PMA_Util::localisedDate(strtotime($showtable['Update_time'])) : ''; $check_time = isset($showtable['Check_time']) ? PMA_Util::localisedDate(strtotime($showtable['Check_time'])) : ''; /** * Gets fields properties */ $columns = $GLOBALS['dbi']->getColumns($this->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($this->db, $table); } // end if /** * Displays the comments of the table if MySQL >= 3.23 */ $break = false; if (!empty($show_comment)) { $this->diagram->Cell(0, 3, __('Table comments:') . ' ' . $show_comment, 0, 1); $break = true; } if (!empty($create_time)) { $this->diagram->Cell(0, 3, __('Creation:') . ' ' . $create_time, 0, 1); $break = true; } if (!empty($update_time)) { $this->diagram->Cell(0, 3, __('Last update:') . ' ' . $update_time, 0, 1); $break = true; } if (!empty($check_time)) { $this->diagram->Cell(0, 3, __('Last check:') . ' ' . $check_time, 0, 1); $break = true; } if ($break == true) { $this->diagram->Cell(0, 3, '', 0, 1); $this->diagram->Ln(); } $this->diagram->SetFont($this->_ff, 'B'); if (isset($this->orientation) && $this->orientation == 'L') { $this->diagram->Cell(25, 8, __('Column'), 1, 0, 'C'); $this->diagram->Cell(20, 8, __('Type'), 1, 0, 'C'); $this->diagram->Cell(20, 8, __('Attributes'), 1, 0, 'C'); $this->diagram->Cell(10, 8, __('Null'), 1, 0, 'C'); $this->diagram->Cell(20, 8, __('Default'), 1, 0, 'C'); $this->diagram->Cell(25, 8, __('Extra'), 1, 0, 'C'); $this->diagram->Cell(45, 8, __('Links to'), 1, 0, 'C'); if ($this->paper == 'A4') { $comments_width = 67; } else { // this is really intended for 'letter' /** * @todo find optimal width for all formats */ $comments_width = 50; } $this->diagram->Cell($comments_width, 8, __('Comments'), 1, 0, 'C'); $this->diagram->Cell(45, 8, 'MIME', 1, 1, 'C'); $this->diagram->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45)); } else { $this->diagram->Cell(20, 8, __('Column'), 1, 0, 'C'); $this->diagram->Cell(20, 8, __('Type'), 1, 0, 'C'); $this->diagram->Cell(20, 8, __('Attributes'), 1, 0, 'C'); $this->diagram->Cell(10, 8, __('Null'), 1, 0, 'C'); $this->diagram->Cell(15, 8, __('Default'), 1, 0, 'C'); $this->diagram->Cell(15, 8, __('Extra'), 1, 0, 'C'); $this->diagram->Cell(30, 8, __('Links to'), 1, 0, 'C'); $this->diagram->Cell(30, 8, __('Comments'), 1, 0, 'C'); $this->diagram->Cell(30, 8, 'MIME', 1, 1, 'C'); $this->diagram->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30)); } $this->diagram->SetFont($this->_ff, ''); foreach ($columns as $row) { $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']); $type = $extracted_columnspec['print_type']; $attribute = $extracted_columnspec['attribute']; if (!isset($row['Default'])) { if ($row['Null'] != '' && $row['Null'] != 'NO') { $row['Default'] = 'NULL'; } } $field_name = $row['Field']; // $this->diagram->Ln(); $this->diagram->PMA_links['RT'][$table][$field_name] = $this->diagram->AddLink(); $this->diagram->Bookmark($field_name, 1, -1); $this->diagram->SetLink($this->diagram->PMA_links['doc'][$table][$field_name], -1); $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name); $linksTo = ''; if ($foreigner) { $linksTo = '-> '; if ($foreigner['foreign_db'] != $this->db) { $linksTo .= $foreigner['foreign_db'] . '.'; } $linksTo .= $foreigner['foreign_table'] . '.' . $foreigner['foreign_field']; if (isset($foreigner['on_update'])) { // not set for internal $linksTo .= "\n" . 'ON UPDATE ' . $foreigner['on_update']; $linksTo .= "\n" . 'ON DELETE ' . $foreigner['on_delete']; } } $this->diagram_row = array($field_name, $type, $attribute, $row['Null'] == '' || $row['Null'] == 'NO' ? __('No') : __('Yes'), isset($row['Default']) ? $row['Default'] : '', $row['Extra'], $linksTo, isset($comments[$field_name]) ? $comments[$field_name] : '', isset($mime_map) && isset($mime_map[$field_name]) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : ''); $links = array(); $links[0] = $this->diagram->PMA_links['RT'][$table][$field_name]; if ($foreigner && isset($this->diagram->PMA_links['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']])) { $links[6] = $this->diagram->PMA_links['doc'][$foreigner['foreign_table']][$foreigner['foreign_field']]; } else { unset($links[6]); } $this->diagram->Row($this->diagram_row, $links); } // end foreach $this->diagram->SetFont($this->_ff, '', 14); } //end each }
*/ require_once './libraries/Partition.class.php'; require_once './libraries/tbl_columns_definition_form.lib.php'; /** @var PMA_String $pmaString */ $pmaString = $GLOBALS['PMA_String']; $length_values_input_size = 8; $_form_params = PMA_getFormsParameters($server, $db, $table, $action, isset($num_fields) ? $num_fields : null, isset($selected) ? $selected : null); $is_backup = $action != 'tbl_create.php' && $action != 'tbl_addfield.php'; require_once './libraries/transformations.lib.php'; $cfgRelation = PMA_getRelationsParam(); $comments_map = PMA_getComments($db, $table); if (isset($fields_meta)) { $move_columns = PMA_getMoveColumns($db, $table); } if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { $mime_map = PMA_getMIME($db, $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; }
// Defines the url to return in case of failure of the query $err_url = PMA_getErrorUrl($url_params); /** * Prepares the update/insert of a row */ list($loop_array, $using_key, $is_insert, $is_insertignore) = PMA_getParamsForUpdateOrInsert(); $query = array(); $value_sets = array(); $func_no_param = array('CONNECTION_ID', 'CURRENT_USER', 'CURDATE', 'CURTIME', 'CURRENT_DATE', 'CURRENT_TIME', 'DATABASE', 'LAST_INSERT_ID', 'NOW', 'PI', 'RAND', 'SYSDATE', 'UNIX_TIMESTAMP', 'USER', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'UUID', 'UUID_SHORT', 'VERSION'); $func_optional_param = array('RAND', 'UNIX_TIMESTAMP'); $gis_from_text_functions = array('GeomFromText', 'GeomCollFromText', 'LineFromText', 'MLineFromText', 'PointFromText', 'MPointFromText', 'PolyFromText', 'MPolyFromText'); $gis_from_wkb_functions = array('GeomFromWKB', 'GeomCollFromWKB', 'LineFromWKB', 'MLineFromWKB', 'PointFromWKB', 'MPointFromWKB', 'PolyFromWKB', 'MPolyFromWKB'); // to create an object of PMA_File class require_once './libraries/File.class.php'; //if some posted fields need to be transformed. $mime_map = PMA_getMIME($GLOBALS['db'], $GLOBALS['table']); if ($mime_map === false) { $mime_map = array(); } $query_fields = array(); $insert_errors = array(); $row_skipped = false; $unsaved_values = array(); foreach ($loop_array as $rownumber => $where_clause) { // skip fields to be ignored if (!$using_key && isset($_REQUEST['insert_ignore_' . $where_clause])) { continue; } // Defines the SET part of the sql query $query_values = array(); // Map multi-edit keys to single-level arrays, dependent on how we got the fields