Extracts the various parts from a column spec
public static extractColumnSpec ( string $columnspec ) : array | ||
$columnspec | string | Column specification |
return | array | associative array containing type, spec_in_brackets and possibly enum_set_values (another array) |
/** * build the html for columns of $colTypeCategory category * in form of given $listType in a table * * @param string $db current database * @param string $table current table * @param string $colTypeCategory supported all|Numeric|String|Spatial * |Date and time using the _pgettext() format * @param string $listType type of list to build, supported dropdown|checkbox * * @return string HTML for list of columns in form of given list types */ function PMA_getHtmlForColumnsList($db, $table, $colTypeCategory = 'all', $listType = 'dropdown') { $columnTypeList = array(); if ($colTypeCategory != 'all') { $types = $GLOBALS['PMA_Types']->getColumns(); $columnTypeList = $types[$colTypeCategory]; } $GLOBALS['dbi']->selectDb($db, $GLOBALS['userlink']); $columns = $GLOBALS['dbi']->getColumns($db, $table, null, true, $GLOBALS['userlink']); $type = ""; $selectColHtml = ""; foreach ($columns as $column => $def) { if (isset($def['Type'])) { $extracted_columnspec = Util::extractColumnSpec($def['Type']); $type = $extracted_columnspec['type']; } if (empty($columnTypeList) || in_array(mb_strtoupper($type), $columnTypeList)) { if ($listType == 'checkbox') { $selectColHtml .= '<input type="checkbox" value="' . htmlspecialchars($column) . '"/>' . htmlspecialchars($column) . ' [ ' . htmlspecialchars($def['Type']) . ' ]</br>'; } else { $selectColHtml .= '<option value="' . htmlspecialchars($column) . '' . '">' . htmlspecialchars($column) . ' [ ' . htmlspecialchars($def['Type']) . ' ]' . '</option>'; } } } return $selectColHtml; }
/** * build the insert query for central columns list given PMA storage * db, central_columns table, column name and corresponding definition to be added * * @param string $column column to add into central list * @param array $def list of attributes of the column being added * @param string $db PMA configuration storage database name * @param string $central_list_table central columns configuration storage table name * * @return string query string to insert the given column * with definition into central list */ function PMA_getInsertQuery($column, $def, $db, $central_list_table) { $type = ""; $length = 0; $attribute = ""; if (isset($def['Type'])) { $extracted_columnspec = Util::extractColumnSpec($def['Type']); $attribute = trim($extracted_columnspec['attribute']); $type = $extracted_columnspec['type']; $length = $extracted_columnspec['spec_in_brackets']; } if (isset($def['Attribute'])) { $attribute = $def['Attribute']; } $collation = isset($def['Collation']) ? $def['Collation'] : ""; $isNull = $def['Null'] == "NO" ? 0 : 1; $extra = isset($def['Extra']) ? $def['Extra'] : ""; $default = isset($def['Default']) ? $def['Default'] : ""; $insQuery = 'INSERT INTO ' . Util::backquote($central_list_table) . ' ' . 'VALUES ( \'' . Util::sqlAddSlashes($db) . '\' ,' . '\'' . Util::sqlAddSlashes($column) . '\',\'' . Util::sqlAddSlashes($type) . '\',' . '\'' . Util::sqlAddSlashes($length) . '\',\'' . Util::sqlAddSlashes($collation) . '\',' . '\'' . Util::sqlAddSlashes($isNull) . '\',' . '\'' . implode(',', array($extra, $attribute)) . '\',\'' . Util::sqlAddSlashes($default) . '\');'; return $insQuery; }
/** * Moves columns in the table's structure based on $_REQUEST * * @return void */ protected function moveColumns() { $this->dbi->selectDb($this->db); /* * load the definitions for all columns */ $columns = $this->dbi->getColumnsFull($this->db, $this->table); $column_names = array_keys($columns); $changes = array(); // move columns from first to last for ($i = 0, $l = count($_REQUEST['move_columns']); $i < $l; $i++) { $column = $_REQUEST['move_columns'][$i]; // is this column already correctly placed? if ($column_names[$i] == $column) { continue; } // it is not, let's move it to index $i $data = $columns[$column]; $extracted_columnspec = Util::extractColumnSpec($data['Type']); if (isset($data['Extra']) && $data['Extra'] == 'on update CURRENT_TIMESTAMP') { $extracted_columnspec['attribute'] = $data['Extra']; unset($data['Extra']); } $current_timestamp = ($data['Type'] == 'timestamp' || $data['Type'] == 'datetime') && $data['Default'] == 'CURRENT_TIMESTAMP'; if ($data['Null'] === 'YES' && $data['Default'] === null) { $default_type = 'NULL'; } elseif ($current_timestamp) { $default_type = 'CURRENT_TIMESTAMP'; } elseif ($data['Default'] === null) { $default_type = 'NONE'; } else { $default_type = 'USER_DEFINED'; } $virtual = array('VIRTUAL', 'PERSISTENT', 'VIRTUAL GENERATED', 'STORED GENERATED'); $data['Virtuality'] = ''; $data['Expression'] = ''; if (isset($data['Extra']) && in_array($data['Extra'], $virtual)) { $data['Virtuality'] = str_replace(' GENERATED', '', $data['Extra']); $expressions = $this->table->getColumnGenerationExpression($column); $data['Expression'] = $expressions[$column]; } $changes[] = 'CHANGE ' . Table::generateAlter($column, $column, mb_strtoupper($extracted_columnspec['type']), $extracted_columnspec['spec_in_brackets'], $extracted_columnspec['attribute'], isset($data['Collation']) ? $data['Collation'] : '', $data['Null'] === 'YES' ? 'NULL' : 'NOT NULL', $default_type, $current_timestamp ? '' : $data['Default'], isset($data['Extra']) && $data['Extra'] !== '' ? $data['Extra'] : false, isset($data['COLUMN_COMMENT']) && $data['COLUMN_COMMENT'] !== '' ? $data['COLUMN_COMMENT'] : false, $data['Virtuality'], $data['Expression'], $i === 0 ? '-first' : $column_names[$i - 1]); // update current column_names array, first delete old position for ($j = 0, $ll = count($column_names); $j < $ll; $j++) { if ($column_names[$j] == $column) { unset($column_names[$j]); } } // insert moved column array_splice($column_names, $i, 0, $column); } if (empty($changes)) { // should never happen $this->response->setRequestStatus(false); return; } // move columns $this->dbi->tryQuery(sprintf('ALTER TABLE %s %s', Util::backquote($this->table), implode(', ', $changes))); $tmp_error = $this->dbi->getError(); if ($tmp_error) { $this->response->setRequestStatus(false); $this->response->addJSON('message', Message::error($tmp_error)); } else { $message = Message::success(__('The columns have been moved successfully.')); $this->response->addJSON('message', $message); $this->response->addJSON('columns', $column_names); } }
/** * Returns CREATE definition that matches $view's structure * * @param string $db the database name * @param string $view the view name * @param string $crlf the end of line sequence * @param bool $add_semicolon whether to add semicolon and end-of-line at * the end * @param array $aliases Aliases of db/table/columns * * @return string resulting schema */ private function _getTableDefForView($db, $view, $crlf, $add_semicolon = true, $aliases = array()) { $db_alias = $db; $view_alias = $view; $this->initAlias($aliases, $db_alias, $view_alias); $create_query = "CREATE TABLE"; if (isset($GLOBALS['sql_if_not_exists'])) { $create_query .= " IF NOT EXISTS "; } $create_query .= Util::backquote($view_alias) . "(" . $crlf; $columns = $GLOBALS['dbi']->getColumns($db, $view, null, true); $firstCol = true; foreach ($columns as $column) { $col_alias = $column['Field']; if (!empty($aliases[$db]['tables'][$view]['columns'][$col_alias])) { $col_alias = $aliases[$db]['tables'][$view]['columns'][$col_alias]; } $extracted_columnspec = Util::extractColumnSpec($column['Type']); if (!$firstCol) { $create_query .= "," . $crlf; } $create_query .= " " . Util::backquote($col_alias); $create_query .= " " . $column['Type']; if ($extracted_columnspec['can_contain_collation'] && !empty($column['Collation'])) { $create_query .= " COLLATE " . $column['Collation']; } if ($column['Null'] == 'NO') { $create_query .= " NOT NULL"; } if (isset($column['Default'])) { $create_query .= " DEFAULT '" . Util::sqlAddSlashes($column['Default']) . "'"; } else { if ($column['Null'] == 'YES') { $create_query .= " DEFAULT NULL"; } } if (!empty($column['Comment'])) { $create_query .= " COMMENT '" . Util::sqlAddSlashes($column['Comment']) . "'"; } $firstCol = false; } $create_query .= $crlf . ")" . ($add_semicolon ? ';' : '') . $crlf; if (isset($GLOBALS['sql_compatibility'])) { $compat = $GLOBALS['sql_compatibility']; } else { $compat = 'NONE'; } if ($compat == 'MSSQL') { $create_query = $this->_makeCreateTableMSSQLCompatible($create_query); } return $create_query; }
/** * 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{' . Util::expandUserString($GLOBALS['latex_structure_caption'], array('texEscape', get_class($this)), array('table' => $table_alias, 'database' => $db_alias)) . '} \\label{' . 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{' . Util::expandUserString($GLOBALS['latex_structure_continued_caption'], array('texEscape', get_class($this)), 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 = 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); }
/** * Formats the definition for one column * * @param array $column info about this column * @param array $unique_keys unique keys of the table * @param string $col_alias Column Alias * * @return string Formatted column definition */ protected function formatOneColumnDefinition($column, $unique_keys, $col_alias = '') { if (empty($col_alias)) { $col_alias = $column['Field']; } $definition = '<tr class="print-category">'; $extracted_columnspec = Util::extractColumnSpec($column['Type']); $type = htmlspecialchars($extracted_columnspec['print_type']); if (empty($type)) { $type = ' '; } if (!isset($column['Default'])) { if ($column['Null'] != 'NO') { $column['Default'] = 'NULL'; } } $fmt_pre = ''; $fmt_post = ''; if (in_array($column['Field'], $unique_keys)) { $fmt_pre = '<strong>' . $fmt_pre; $fmt_post = $fmt_post . '</strong>'; } if ($column['Key'] == 'PRI') { $fmt_pre = '<em>' . $fmt_pre; $fmt_post = $fmt_post . '</em>'; } $definition .= '<td class="print">' . $fmt_pre . htmlspecialchars($col_alias) . $fmt_post . '</td>'; $definition .= '<td class="print">' . htmlspecialchars($type) . '</td>'; $definition .= '<td class="print">' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')) . '</td>'; $definition .= '<td class="print">' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : '') . '</td>'; return $definition; }
/** * Formats the definition for one column * * @param array $column info about this column * @param array $unique_keys unique keys for this table * @param string $col_alias Column Alias * * @return string Formatted column definition */ public function formatOneColumnDefinition($column, $unique_keys, $col_alias = '') { if (empty($col_alias)) { $col_alias = $column['Field']; } $extracted_columnspec = Util::extractColumnSpec($column['Type']); $type = $extracted_columnspec['print_type']; if (empty($type)) { $type = ' '; } if (!isset($column['Default'])) { if ($column['Null'] != 'NO') { $column['Default'] = 'NULL'; } } $fmt_pre = ''; $fmt_post = ''; if (in_array($column['Field'], $unique_keys)) { $fmt_pre = '**' . $fmt_pre; $fmt_post = $fmt_post . '**'; } if ($column['Key'] == 'PRI') { $fmt_pre = '//' . $fmt_pre; $fmt_post = $fmt_post . '//'; } $definition = '|' . $fmt_pre . htmlspecialchars($col_alias) . $fmt_post; $definition .= '|' . htmlspecialchars($type); $definition .= '|' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')); $definition .= '|' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : ''); return $definition; }
/** * 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); $have_rel = !empty($res_rel); } 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(PDF::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; $data = array(); // fun begin foreach ($columns as $column) { $extracted_columnspec = 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; }
/** * 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']) ? Util::localisedDate(strtotime($showtable['Create_time'])) : ''; $update_time = isset($showtable['Update_time']) ? Util::localisedDate(strtotime($showtable['Update_time'])) : ''; $check_time = isset($showtable['Check_time']) ? Util::localisedDate(strtotime($showtable['Check_time'])) : ''; /** * Gets fields properties */ $columns = $GLOBALS['dbi']->getColumns($this->db, $table); // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($this->db, $table); /** * 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 = 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 }
/** * Formats the definition for one column * * @param array $column info about this column * @param string $col_as column alias * * @return string Formatted column definition */ protected function formatOneColumnDefinition($column, $col_as = '') { if (empty($col_as)) { $col_as = $column['Field']; } $definition = '<table:table-row>'; $definition .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($col_as) . '</text:p>' . '</table:table-cell>'; $extracted_columnspec = Util::extractColumnSpec($column['Type']); $type = htmlspecialchars($extracted_columnspec['print_type']); if (empty($type)) { $type = ' '; } $definition .= '<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'] = ''; } } $definition .= '<table:table-cell office:value-type="string">' . '<text:p>' . ($column['Null'] == '' || $column['Null'] == 'NO' ? __('No') : __('Yes')) . '</text:p>' . '</table:table-cell>'; $definition .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($column['Default']) . '</text:p>' . '</table:table-cell>'; return $definition; }