Ejemplo n.º 1
0
/**
 * 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 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 = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true, $GLOBALS['userlink']);
    $type = "";
    $selectColHtml = "";
    foreach ($columns as $column => $def) {
        if (isset($def['Type'])) {
            $extracted_columnspec = PMA_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;
}
Ejemplo n.º 2
0
/**
 * Function to get html for each insert/edit column
 *
 * @param array  $table_columns         table columns
 * @param int    $column_number         column index in 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 bool   $odd_row               whether odd 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 $default_char_editing  default char editing mode which is stored
 *                                      in the config.inc.php script
 * @param string $text_dir              text direction
 * @param array  $repopulate            the data to be repopulated
 * @param array  $column_mime           the mime information of column
 * @param string $where_clause          the where clause
 *
 * @return string
 */
function 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)
{
    $column = $table_columns[$column_number];
    if (!isset($column['processed'])) {
        $column = PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen);
    }
    $as_is = false;
    if (!empty($repopulate) && !empty($current_row)) {
        $current_row[$column['Field']] = $repopulate[$column['Field_md5']];
        $as_is = true;
    }
    $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']);
    if (-1 === $column['len']) {
        $column['len'] = $GLOBALS['dbi']->fieldLen($current_result, $column_number);
        // length is unknown for geometry fields,
        // make enough space to edit very simple WKTs
        if (-1 === $column['len']) {
            $column['len'] = 30;
        }
    }
    //Call validation when the form submitted...
    $onChangeClause = $chg_evt_handler . "=\"return verificationsAfterFieldChange('" . PMA_escapeJsString($column['Field_md5']) . "', '" . PMA_escapeJsString($jsvkey) . "','" . $column['pma_type'] . "')\"";
    // Use an MD5 as an array index to avoid having special characters
    // in the name attribute (see bug #1746964 )
    $column_name_appendix = $vkey . '[' . $column['Field_md5'] . ']';
    if ($column['Type'] === 'datetime' && !isset($column['Default']) && !is_null($column['Default']) && $insert_mode) {
        $column['Default'] = date('Y-m-d H:i:s', time());
    }
    $html_output = PMA_getHtmlForFunctionOption($odd_row, $column, $column_name_appendix);
    if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
        $html_output .= PMA_getHtmlForInsertEditColumnType($column);
    }
    //End if
    // Get a list of GIS data types.
    $gis_data_types = PMA_Util::getGISDatatypes();
    // Prepares the field value
    $real_null_value = false;
    $special_chars_encoded = '';
    if (!empty($current_row)) {
        // (we are editing)
        list($real_null_value, $special_chars_encoded, $special_chars, $data, $backup_field) = PMA_getSpecialCharsAndBackupFieldForExistingRow($current_row, $column, $extracted_columnspec, $real_null_value, $gis_data_types, $column_name_appendix, $as_is);
    } else {
        // (we are inserting)
        // display default values
        $tmp = $column;
        if (isset($repopulate[$column['Field_md5']])) {
            $tmp['Default'] = $repopulate[$column['Field_md5']];
        }
        list($real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded) = PMA_getSpecialCharsAndBackupFieldForInsertingMode($tmp, $real_null_value);
        unset($tmp);
    }
    $idindex = $o_rows * $columns_cnt + $column_number + 1;
    $tabindex = $idindex;
    // Get a list of data types that are not yet supported.
    $no_support_types = PMA_Util::unsupportedDatatypes();
    // The function column
    // -------------------
    if ($GLOBALS['cfg']['ShowFunctionFields']) {
        $html_output .= PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, $onChangeClause, $no_support_types, $tabindex_for_function, $tabindex, $idindex, $insert_mode);
    }
    // The null column
    // ---------------
    $foreignData = PMA_getForeignData($foreigners, $column['Field'], false, '', '');
    $html_output .= PMA_getNullColumn($column, $column_name_appendix, $real_null_value, $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData);
    // The value column (depends on type)
    // ----------------
    // See bug #1667887 for the reason why we don't use the maxlength
    // HTML attribute
    //add data attributes "no of decimals" and "data type"
    $no_decimals = 0;
    $type = current(explode("(", $column['pma_type']));
    if (preg_match('/\\(([^()]+)\\)/', $column['pma_type'], $match)) {
        $match[0] = trim($match[0], '()');
        $no_decimals = $match[0];
    }
    $html_output .= '<td' . ' data-type="' . $type . '"' . ' data-decimals="' . $no_decimals . '">' . "\n";
    // Will be used by js/tbl_change.js to set the default value
    // for the "Continue insertion" feature
    $html_output .= '<span class="default_value hide">' . $special_chars . '</span>';
    // Check input transformation of column
    $transformed_html = '';
    if (!empty($column_mime['input_transformation'])) {
        $file = $column_mime['input_transformation'];
        $include_file = 'libraries/plugins/transformations/' . $file;
        if (is_file($include_file)) {
            include_once $include_file;
            $class_name = PMA_getTransformationClassName($file);
            $transformation_plugin = new $class_name();
            $transformation_options = PMA_Transformation_getOptions($column_mime['input_transformation_options']);
            $_url_params = array('db' => $db, 'table' => $table, 'transform_key' => $column['Field'], 'where_clause' => $where_clause);
            $transformation_options['wrapper_link'] = PMA_URL_getCommon($_url_params);
            $current_value = '';
            if (isset($current_row[$column['Field']])) {
                $current_value = $current_row[$column['Field']];
            }
            if (method_exists($transformation_plugin, 'getInputHtml')) {
                $transformed_html = $transformation_plugin->getInputHtml($column, $row_id, $column_name_appendix, $transformation_options, $current_value, $text_dir, $tabindex, $tabindex_for_value, $idindex);
            }
            if (method_exists($transformation_plugin, 'getScripts')) {
                $GLOBALS['plugin_scripts'] = array_merge($GLOBALS['plugin_scripts'], $transformation_plugin->getScripts());
            }
        }
    }
    if (!empty($transformed_html)) {
        $html_output .= $transformed_html;
    } else {
        $html_output .= PMA_getValueColumn($column, $backup_field, $column_name_appendix, $onChangeClause, $tabindex, $tabindex_for_value, $idindex, $data, $special_chars, $foreignData, $odd_row, array($table, $db), $row_id, $titles, $text_dir, $special_chars_encoded, $vkey, $is_upload, $biggest_max_file_size, $default_char_editing, $no_support_types, $gis_data_types, $extracted_columnspec);
    }
    $html_output .= '</td>' . '</tr>';
    return $html_output;
}
Ejemplo n.º 3
0
/**
 * Moves columns in the table's structure based on $_REQUEST
 *
 * @param string $db    database name
 * @param string $table table name
 *
 * @return void
 */
function PMA_moveColumns($db, $table)
{
    $GLOBALS['dbi']->selectDb($db);
    /*
     * load the definitions for all columns
     */
    $columns = $GLOBALS['dbi']->getColumnsFull($db, $table);
    $column_names = array_keys($columns);
    $changes = array();
    $we_dont_change_keys = 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 = PMA_Util::extractColumnSpec($data['Type']);
        if (isset($data['Extra']) && $data['Extra'] == 'on update CURRENT_TIMESTAMP') {
            $extracted_columnspec['attribute'] = $data['Extra'];
            unset($data['Extra']);
        }
        $current_timestamp = false;
        if (($data['Type'] == 'timestamp' || $data['Type'] == 'datetime') && $data['Default'] == 'CURRENT_TIMESTAMP') {
            $current_timestamp = true;
        }
        $default_type = $data['Null'] === 'YES' && $data['Default'] === null ? 'NULL' : ($current_timestamp ? 'CURRENT_TIMESTAMP' : ($data['Default'] === null ? 'NONE' : 'USER_DEFINED'));
        $changes[] = 'CHANGE ' . PMA_Table::generateAlter($column, $column, 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, $we_dont_change_keys, $i, $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);
    }
    $response = PMA_Response::getInstance();
    if (empty($changes)) {
        // should never happen
        $response->isSuccess(false);
        exit;
    }
    $move_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ';
    $move_query .= implode(', ', $changes);
    // move columns
    $GLOBALS['dbi']->tryQuery($move_query);
    $tmp_error = $GLOBALS['dbi']->getError();
    if ($tmp_error) {
        $response->isSuccess(false);
        $response->addJSON('message', PMA_Message::error($tmp_error));
    } else {
        $message = PMA_Message::success(__('The columns have been moved successfully.'));
        $response->addJSON('message', $message);
        $response->addJSON('columns', $column_names);
    }
    exit;
}
 /**
  * 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
 }
 /**
  * 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);
 }
 /**
  * Test case for parsing SHOW COLUMNS output
  *
  * @dataProvider provider
  */
 public function testParsing($in, $out)
 {
     $this->assertEquals(
         $out, PMA_Util::extractColumnSpec($in)
     );
 }
Ejemplo n.º 7
0
/**
 * 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 .= '&nbsp;</td>';
        $html .= '<td>';
        if (isset($row['Default'])) {
            $html .= $row['Default'];
        }
        $html .= '&nbsp;</td>';
        if ($have_rel) {
            $html .= '    <td>';
            $foreigner = PMA_searchColumnInForeigners($res_rel, $field_name);
            if ($foreigner) {
                $html .= htmlspecialchars($foreigner['foreign_table'] . ' -> ' . $foreigner['foreign_field']);
            }
            $html .= '&nbsp;</td>' . "\n";
        }
        $html .= '    <td>';
        $comments = PMA_getComments($db, $table);
        if (isset($comments[$field_name])) {
            $html .= htmlspecialchars($comments[$field_name]);
        }
        $html .= '&nbsp;</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 .= '&nbsp;</td>' . "\n";
        }
        $html .= '</tr>';
    }
    // end foreach
    return $html;
}
Ejemplo n.º 8
0
 /**
  * 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 = PMA_Util::extractColumnSpec($column['Type']);
     $type = $extracted_columnspec['print_type'];
     if (empty($type)) {
         $type = '&nbsp;';
     }
     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;
 }
Ejemplo n.º 9
0
 /**
  * Formats the definition for one column
  *
  * @param array $column info about this column
  *
  * @return string Formatted column definition
  */
 protected function formatOneColumnDefinition($column)
 {
     $field_name = $column['Field'];
     $definition = '<table:table-row>';
     $definition .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($field_name) . '</text:p>' . '</table:table-cell>';
     $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']);
     $type = htmlspecialchars($extracted_columnspec['print_type']);
     if (empty($type)) {
         $type = '&nbsp;';
     }
     $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'] = '';
         }
     } else {
         $column['Default'] = $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;
 }
Ejemplo n.º 10
0
 /**
  * Generates data dictionary pages.
  *
  * @param array $alltables Tables to document.
  *
  * @return void
  */
 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 = $GLOBALS['dbi']->getColumns($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_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 table keys and retains them
          */
         $result = $GLOBALS['dbi']->query('SHOW KEYS FROM ' . PMA_Util::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 = $GLOBALS['dbi']->fetchAssoc($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) {
             $GLOBALS['dbi']->freeResult($result);
         }
         /**
          * Gets fields properties
          */
         $columns = $GLOBALS['dbi']->getColumns($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_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'];
             // $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']) && isset($res_rel[$field_name]['foreign_field']) && 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
 }
Ejemplo n.º 11
0
/**
 * 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 = PMA_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 ' . PMA_Util::backquote($central_list_table) . ' ' . 'VALUES ( \'' . PMA_Util::sqlAddSlashes($db) . '\' ,' . '\'' . PMA_Util::sqlAddSlashes($column) . '\',\'' . PMA_Util::sqlAddSlashes($type) . '\',' . '\'' . PMA_Util::sqlAddSlashes($length) . '\',\'' . PMA_Util::sqlAddSlashes($collation) . '\',' . '\'' . PMA_Util::sqlAddSlashes($isNull) . '\',' . '\'' . implode(',', array($extra, $attribute)) . '\',\'' . PMA_Util::sqlAddSlashes($default) . '\');';
    return $insQuery;
}
Ejemplo n.º 12
0
/**
 * Function to get html for each insert/edit column
 *
 * @param array  $table_columns         table columns
 * @param int    $i                     row counter
 * @param array  $column                column
 * @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 bool   $odd_row               whether odd 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 $default_char_editing  default char editing mode which is stroe
 *                                      in the config.inc.php script
 * @param string $text_dir              text direction
 *
 * @return string
 */
function PMA_getHtmlForInsertEditFormColumn($table_columns, $i, $column, $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)
{
    if (!isset($table_columns[$i]['processed'])) {
        $column = $table_columns[$i];
        $column = PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen);
    }
    $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']);
    if (-1 === $column['len']) {
        $column['len'] = $GLOBALS['dbi']->fieldLen($current_result, $i);
        // length is unknown for geometry fields,
        // make enough space to edit very simple WKTs
        if (-1 === $column['len']) {
            $column['len'] = 30;
        }
    }
    //Call validation when the form submitted...
    $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('" . PMA_escapeJsString($column['Field_md5']) . "', '" . PMA_escapeJsString($jsvkey) . "','" . $column['pma_type'] . "')\"";
    // Use an MD5 as an array index to avoid having special characters
    // in the name atttibute (see bug #1746964 )
    $column_name_appendix = $vkey . '[' . $column['Field_md5'] . ']';
    if ($column['Type'] == 'datetime' && !isset($column['Default']) && !is_null($column['Default']) && ($insert_mode || !isset($current_row[$column['Field']]))) {
        // INSERT case or
        // UPDATE case with an NULL value
        $current_row[$column['Field']] = date('Y-m-d H:i:s', time());
    }
    $html_output = PMA_getHtmlForFunctionOption($odd_row, $column, $column_name_appendix);
    if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
        $html_output .= PMA_getHtmlForInsertEditColumnType($column);
    }
    //End if
    // Get a list of GIS data types.
    $gis_data_types = PMA_Util::getGISDatatypes();
    // Prepares the field value
    $real_null_value = false;
    $special_chars_encoded = '';
    if (isset($current_row)) {
        // (we are editing)
        list($real_null_value, $special_chars_encoded, $special_chars, $data, $backup_field) = PMA_getSpecialCharsAndBackupFieldForExistingRow($current_row, $column, $extracted_columnspec, $real_null_value, $gis_data_types, $column_name_appendix);
    } else {
        // (we are inserting)
        // display default values
        list($real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded) = PMA_getSpecialCharsAndBackupFieldForInsertingMode($column, $real_null_value);
    }
    $idindex = $o_rows * $columns_cnt + $i + 1;
    $tabindex = $idindex;
    // Get a list of data types that are not yet supported.
    $no_support_types = PMA_Util::unsupportedDatatypes();
    // The function column
    // -------------------
    if ($GLOBALS['cfg']['ShowFunctionFields']) {
        $html_output .= PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, $unnullify_trigger, $no_support_types, $tabindex_for_function, $tabindex, $idindex, $insert_mode);
    }
    // The null column
    // ---------------
    $foreignData = PMA_getForeignData($foreigners, $column['Field'], false, '', '');
    $html_output .= PMA_getNullColumn($column, $column_name_appendix, $real_null_value, $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData);
    // The value column (depends on type)
    // ----------------
    // See bug #1667887 for the reason why we don't use the maxlength
    // HTML attribute
    $html_output .= '        <td>' . "\n";
    // Will be used by js/tbl_change.js to set the default value
    // for the "Continue insertion" feature
    $html_output .= '<span class="default_value hide">' . $special_chars . '</span>';
    $html_output .= PMA_getValueColumn($column, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $special_chars, $foreignData, $odd_row, array($table, $db), $row_id, $titles, $text_dir, $special_chars_encoded, $vkey, $is_upload, $biggest_max_file_size, $default_char_editing, $no_support_types, $gis_data_types, $extracted_columnspec);
    $html_output .= '</td>' . '</tr>';
    return $html_output;
}
Ejemplo n.º 13
0
    // (as zero cannot be used, advance the counter plus one)
    $m_rows = $o_rows + 1;
    //store the default value for CharEditing
    $default_char_editing  = $cfg['CharEditing'];

    $odd_row = true;
    for ($i = 0; $i < $columns_cnt; $i++) {
        if (! isset($table_fields[$i]['processed'])) {
            $column = $table_fields[$i];
            $column = PMA_analyzeTableColumnsArray(
                $column, $comments_map, $timestamp_seen
            );
        }

        $extracted_columnspec
            = PMA_Util::extractColumnSpec($column['Type']);

        if (-1 === $column['len']) {
            $column['len'] = PMA_DBI_field_len($current_result, $i);
            // length is unknown for geometry fields,
            // make enough space to edit very simple WKTs
            if (-1 === $column['len']) {
                $column['len'] = 30;
            }
        }
        //Call validation when the form submited...
        $unnullify_trigger = $chg_evt_handler
            . "=\"return verificationsAfterFieldChange('"
            . PMA_escapeJsString($column['Field_md5']) . "', '"
            . PMA_escapeJsString($jsvkey) . "','".$column['pma_type'] . "')\"";
 /**
  * Tests for PMA_getHtmlForPrintViewColumns() method.
  *
  * @return void
  * @test
  */
 public function testPMAGetHtmlForPrintViewColumns()
 {
     $columns = array(array("Type" => "Type1", "Default" => "Default1", "Null" => "Null1", "Field" => "Field1"));
     $analyzed_sql = array(array('create_table_fields' => array("Field1" => array("type" => "TIMESTAMP", "timestamp_not_null" => true))));
     $pk_array = array("Field1" => "pk_array");
     $have_rel = false;
     $res_rel = array();
     $db = "pma_db";
     $table = "pma_table";
     $cfgRelation = array('mimework' => true);
     $html = PMA_getHtmlForPrintViewColumns($columns, $analyzed_sql, $pk_array, $have_rel, $res_rel, $db, $table, $cfgRelation);
     //validation 1 : $row
     $row = $columns[0];
     $this->assertContains(htmlspecialchars($row['Default']), $html);
     $this->assertContains(htmlspecialchars($row['Field']), $html);
     //validation 2 : $pk_array
     $field_name = htmlspecialchars($row['Field']);
     $comments = PMA_getComments($db, $table);
     $this->assertContains($field_name, $html);
     //validation 3 : $extracted_columnspec
     $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
     $type = $extracted_columnspec['print_type'];
     $attribute = $extracted_columnspec['attribute'];
     $this->assertContains($type, $html);
 }
Ejemplo n.º 15
0
 /**
  * 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;
 }
Ejemplo n.º 16
0
/**
 * Function to get html for field
 *
 * @param int    $index index
 * @param array  $field field
 * @param string $style style
 *
 * @return string
 */
function PMA_getHtmlForField($index, $field, $style)
{
    $html = '<tr class="noclick ' . $style . '">';
    $html .= '<td>' . $index . '</td>';
    $html .= '<td><b>' . htmlspecialchars($field['Field']);
    if ($field['Key'] == 'PRI') {
        $html .= ' ' . PMA_Util::getImage('b_primary.png', __('Primary'));
    } elseif (!empty($field['Key'])) {
        $html .= ' ' . PMA_Util::getImage('bd_primary.png', __('Index'));
    }
    $html .= '</b></td>';
    $html .= "\n";
    $html .= '<td>' . htmlspecialchars($field['Type']) . '</td>';
    $html .= '<td>' . htmlspecialchars($field['Collation']) . '</td>';
    $html .= '<td>' . ($field['Null'] == 'YES' ? __('Yes') : __('No')) . '</td>';
    $html .= '<td>';
    if (isset($field['Default'])) {
        $extracted_columnspec = PMA_Util::extractColumnSpec($field['Type']);
        if ($extracted_columnspec['type'] == 'bit') {
            // here, $field['Default'] contains something like b'010'
            $html .= PMA_Util::convertBitDefaultValue($field['Default']);
        } else {
            $html .= htmlspecialchars($field['Default']);
        }
    } else {
        if ($field['Null'] == 'YES') {
            $html .= '<i>NULL</i>';
        } else {
            $html .= '<i>' . _pgettext('None for default', 'None') . '</i>';
        }
    }
    $html .= '</td>';
    $html .= '<td>' . htmlspecialchars($field['Extra']) . '</td>';
    $html .= '<td>' . htmlspecialchars($field['Comment']) . '</td>';
    $html .= '</tr>';
    return $html;
}
Ejemplo n.º 17
0
 /**
  * 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
  *
  * @return string resulting schema
  */
 private function _getTableDefForView($db, $view, $crlf, $add_semicolon = true)
 {
     $create_query = "CREATE TABLE";
     if (isset($GLOBALS['sql_if_not_exists'])) {
         $create_query .= " IF NOT EXISTS ";
     }
     $create_query .= PMA_Util::backquote($view) . "(" . $crlf;
     $columns = $GLOBALS['dbi']->getColumns($db, $view, null, true);
     $firstCol = true;
     foreach ($columns as $column) {
         $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']);
         if (!$firstCol) {
             $create_query .= "," . $crlf;
         }
         $create_query .= "    " . PMA_Util::backquote($column['Field']);
         $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 '" . PMA_Util::sqlAddSlashes($column['Default']) . "'";
         } else {
             if ($column['Null'] == 'YES') {
                 $create_query .= " DEFAULT NULL";
             }
         }
         if (!empty($column['Comment'])) {
             $create_query .= " COMMENT '" . PMA_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;
 }
    if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
        $mime_map = PMA_getMIME($db, $table, true);
    }
}
require_once 'libraries/central_columns.lib.php';
$central_list = PMA_getCentralColumnsFromTable($db, $table);
$rownum = 0;
$columns_list = array();
$save_row = array();
$odd_row = true;
foreach ($fields as $row) {
    $save_row[] = $row;
    $rownum++;
    $columns_list[] = $row['Field'];
    $type = $row['Type'];
    $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
    if ('set' == $extracted_columnspec['type'] || 'enum' == $extracted_columnspec['type']) {
        $type_nowrap = '';
    } else {
        $type_nowrap = ' class="nowrap"';
    }
    $type = $extracted_columnspec['print_type'];
    if (empty($type)) {
        $type = ' ';
    }
    $field_charset = '';
    if ($extracted_columnspec['can_contain_collation'] && !empty($row['Collation'])) {
        $field_charset = $row['Collation'];
    }
    // Display basic mimetype [MIME]
    if ($cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME'] && isset($mime_map[$row['Field']]['mimetype'])) {
Ejemplo n.º 19
0
 /**
  * Formats the definition for one column
  *
  * @param array $column      info about this column
  * @param array $unique_keys unique keys of the table
  *
  * @return string Formatted column definition
  */
 protected function formatOneColumnDefinition($column, $unique_keys)
 {
     $definition = '<tr class="print-category">';
     $extracted_columnspec = PMA_Util::extractColumnSpec($column['Type']);
     $type = htmlspecialchars($extracted_columnspec['print_type']);
     if (empty($type)) {
         $type = '&nbsp;';
     }
     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($column['Field']) . $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;
 }
    }
}
if (isset($_REQUEST['submit_num_fields'])) {
    //if adding new fields, set regenerate to keep the original values
    $regenerate = 1;
}
$foreigners = PMA_getForeigners($db, $table, '', 'foreign');
$child_references = PMA_getChildReferences($db, $table);
for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
    if (!empty($regenerate)) {
        list($columnMeta, $submit_length, $submit_attribute, $submit_default_current_timestamp, $comments_map, $mime_map) = PMA_handleRegeneration($columnNumber, isset($available_mime) ? $mime_map : null, $comments_map, $mime_map);
    } elseif (isset($fields_meta[$columnNumber])) {
        $columnMeta = PMA_getColumnMetaForDefault($fields_meta[$columnNumber], isset($analyzed_sql[0]['create_table_fields'][$fields_meta[$columnNumber]['Field']]['default_value']));
    }
    if (isset($columnMeta['Type'])) {
        $extracted_columnspec = PMA_Util::extractColumnSpec($columnMeta['Type']);
        if ($extracted_columnspec['type'] == 'bit') {
            $columnMeta['Default'] = PMA_Util::convertBitDefaultValue($columnMeta['Default']);
        }
        $type = $extracted_columnspec['type'];
        $length = $extracted_columnspec['spec_in_brackets'];
    } else {
        // creating a column
        $columnMeta['Type'] = '';
        $type = '';
        $length = '';
        $extracted_columnspec = array();
    }
    // some types, for example longtext, are reported as
    // "longtext character set latin7" when their charset and / or collation
    // differs from the ones of the corresponding database.
Ejemplo n.º 21
0
 /**
  * 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
  *
  * @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)
 {
     global $cfgRelation;
     /**
      * 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_Util::expandUserString($GLOBALS['latex_structure_caption'], array('texEscape', get_class($this), 'libraries/plugins/export/' . get_class($this) . ".class.php"), array('table' => $table, 'database' => $db)) . '} \\label{' . PMA_Util::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_Util::expandUserString($GLOBALS['latex_structure_continued_caption'], array('texEscape', get_class($this), 'libraries/plugins/export/' . get_class($this) . ".class.php"), 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_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 = $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 = $this::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);
 }