/** * Returns $table's CREATE definition * * @param string $db the database name * @param string $table the table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * export types which use this parameter * @param bool $do_mime whether to include mime comments * @param bool $show_dates whether to include creation/update/check dates * @param bool $add_semicolon whether to add semicolon and end-of-line * at the end * @param bool $view whether we're handling a view * * @return string resulting schema * * @access public */ function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false) { global $cfgRelation; $schema_insert = ''; /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $schema_insert .= '<table class="width100" cellspacing="1">'; $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments && $cfgRelation['commwork']) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $schema_insert .= '<tr class="print-category">'; $schema_insert .= '<th class="print">' . __('Column') . '</th>'; $schema_insert .= '<td class="print"><strong>' . __('Type') . '</strong></td>'; $schema_insert .= '<td class="print"><strong>' . __('Null') . '</strong></td>'; $schema_insert .= '<td class="print"><strong>' . __('Default') . '</strong></td>'; if ($do_relation && $have_rel) { $schema_insert .= '<td class="print"><strong>' . __('Links to') . '</strong></td>'; } if ($do_comments) { $schema_insert .= '<td class="print"><strong>' . __('Comments') . '</strong></td>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print"><strong>' . htmlspecialchars('MIME') . '</strong></td>'; $mime_map = PMA_getMIME($db, $table, true); } $schema_insert .= '</tr>'; $columns = PMA_DBI_get_columns($db, $table); /** * Get the unique keys in the table */ $unique_keys = array(); $keys = PMA_DBI_get_table_indexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } foreach ($columns as $column) { $schema_insert .= PMA_formatOneColumnDefinition($column, $unique_keys); $field_name = $column['Field']; if ($do_relation && $have_rel) { $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>'; } if ($do_comments && $cfgRelation['commwork']) { $schema_insert .= '<td class="print">' . (isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>'; } if ($do_mime && $cfgRelation['mimework']) { $schema_insert .= '<td class="print">' . (isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>'; } $schema_insert .= '</tr>'; } // end foreach $schema_insert .= '</table>'; return $schema_insert; }
/** * Returns $table's CREATE definition * * @param string $db the database name * @param string $table the table name * @param string $crlf the end of line sequence * @param string $error_url the url to go back in case of error * @param bool $do_relation whether to include relation comments * @param bool $do_comments whether to include the pmadb-style column * comments as comments in the structure; * this is deprecated but the parameter is * left here because export.php calls * PMA_exportStructure() also for other * @param bool $do_mime whether to include mime comments * @param bool $show_dates whether to include creation/update/check dates * @param bool $add_semicolon whether to add semicolon and end-of-line at * the end * @param bool $view whether we're handling a view * * @return bool true * * @access public */ function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false) { global $cfgRelation; /** * Gets fields properties */ PMA_DBI_select_db($db); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = true; } else { $have_rel = false; } } else { $have_rel = false; } // end if /** * Displays the table structure */ $GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_structure">'; $columns_cnt = 4; if ($do_relation && $have_rel) { $columns_cnt++; } if ($do_comments) { $columns_cnt++; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; } $GLOBALS['odt_buffer'] .= '<table:table-column' . ' table:number-columns-repeated="' . $columns_cnt . '"/>'; /* Header */ $GLOBALS['odt_buffer'] .= '<table:table-row>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Column') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Type') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Null') . '</text:p>' . '</table:table-cell>' . '<table:table-cell office:value-type="string">' . '<text:p>' . __('Default') . '</text:p>' . '</table:table-cell>'; if ($do_relation && $have_rel) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Links to') . '</text:p>' . '</table:table-cell>'; } if ($do_comments) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('Comments') . '</text:p>' . '</table:table-cell>'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . __('MIME type') . '</text:p>' . '</table:table-cell>'; $mime_map = PMA_getMIME($db, $table, true); } $GLOBALS['odt_buffer'] .= '</table:table-row>'; $columns = PMA_DBI_get_columns($db, $table); foreach ($columns as $column) { $field_name = $column['Field']; $GLOBALS['odt_buffer'] .= PMA_formatOneColumnDefinition($column); if ($do_relation && $have_rel) { if (isset($res_rel[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') . '</text:p>' . '</table:table-cell>'; } } if ($do_comments) { if (isset($comments[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars($comments[$field_name]) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } if ($do_mime && $cfgRelation['mimework']) { if (isset($mime_map[$field_name])) { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) . '</text:p>' . '</table:table-cell>'; } else { $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' . '<text:p></text:p>' . '</table:table-cell>'; } } $GLOBALS['odt_buffer'] .= '</table:table-row>'; } // end foreach $GLOBALS['odt_buffer'] .= '</table:table>'; return true; }