From ca2689461ddd2248bcfef1f10d14e8e49746514d Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Wed, 31 Jul 2013 22:02:09 +0530 Subject: [PATCH] added libraries/tbl_columns_definition_form.lib.php . Added methods PMA_getFormsParameters, PMA_getHtmlForTableConfigurations, PMA_getHtmlForFooter, PMA_getHtmlForTableNameAndNoOfColumns, PMA_getHtmlForTableFieldDefinitions, PMA_getHtmlForTableCreateOrAddField --- libraries/tbl_columns_definition_form.inc.php | 195 +----------- libraries/tbl_columns_definition_form.lib.php | 279 ++++++++++++++++++ 2 files changed, 290 insertions(+), 184 deletions(-) create mode 100644 libraries/tbl_columns_definition_form.lib.php diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 24ef8da59d..dcd355a41b 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -27,6 +27,8 @@ require_once './libraries/StorageEngine.class.php'; */ require_once './libraries/Partition.class.php'; +require_once './libraries/tbl_columns_definition_form.lib.php'; + /** * We are in transition between old-style echo and new-style PMA_Response * so this script generates $html and at the bottom, either echos it @@ -39,54 +41,13 @@ $html = ''; $length_values_input_size = 8; -$_form_params = array( - 'db' => $db +$_form_params = PMA_getFormsParameters( + $db, $table, $action, isset($num_fields) ? $num_fields : null, + isset($selected) ? $selected : null, + isset($true_selected) ? $true_selected : null, + isset($orig_field) ? $orig_field : null ); -if ($action == 'tbl_create.php') { - $_form_params['reload'] = 1; -} elseif ($action == 'tbl_addfield.php') { - $_form_params['field_where'] = $_REQUEST['field_where']; - $_form_params['after_field'] = $_REQUEST['after_field']; - $_form_params['table'] = $table; -} else { - $_form_params['table'] = $table; -} - -if (isset($num_fields)) { - $_form_params['orig_num_fields'] = $num_fields; -} - -if (isset($_REQUEST['field_where'])) { - $_form_params['orig_field_where'] = $_REQUEST['field_where']; -} - -if (isset($_REQUEST['after_field'])) { - $_form_params['orig_after_field'] = $_REQUEST['after_field']; -} - -if (isset($selected) && is_array($selected)) { - foreach ($selected as $o_fld_nr => $o_fld_val) { - $_form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val; - if (! isset($true_selected)) { - $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val; - } - } - - if (isset($true_selected) && is_array($true_selected)) { - foreach ($true_selected as $o_fld_nr => $o_fld_val) { - $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val; - } - } -} elseif (isset($_REQUEST['field'])) { - $_form_params['orig_field'] = $_REQUEST['field']; - if (isset($orig_field)) { - $_form_params['true_selected[]'] = $orig_field; - } else { - $_form_params['true_selected[]'] = $_REQUEST['field']; - } -} - $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php'); $header_cells = array(); @@ -725,74 +686,6 @@ for ($i = 0; $i < $num_fields; $i++) { } } // end for -$html .= '
'; - -$html .= PMA_generate_common_hidden_inputs($_form_params); -unset($_form_params); -if ($action == 'tbl_create.php') { - $html .= '' - . '' - . '' - . '' - . '' - . '
' . __('Table name') - . ': ' - . ''; - if ($action == 'tbl_create.php' - || $action == 'tbl_addfield.php' - ) { - $html .= sprintf( - __('Add %s column(s)'), '' - ); - - $html .= ''; - } - $html .= '
'; -} - -if (is_array($content_cells) && is_array($header_cells)) { - // last row is for javascript insert - //$empty_row = array_pop($content_cells); - - $html .= ''; - $html .= ''; - - $html .= ''; - foreach ($header_cells as $header_val) { - $html .= ''; - } - $html .= ''; - - $odd_row = true; - foreach ($content_cells as $content_row) { - $html .= ''; - $odd_row = ! $odd_row; - - if (is_array($content_row)) { - foreach ($content_row as $content_row_val) { - $html .= ''; - } - } - $html .= ''; - } - $html .= '
' . __('Structure') - . PMA_Util::showMySQLDocu('SQL-Syntax', 'CREATE_TABLE') . '
' . $header_val . '
' . $content_row_val . '
' - . '
'; -} - /** * needs to be finished * @@ -830,77 +723,11 @@ function addField() } */ -if ($action == 'tbl_create.php') { - $html .= '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . ''; +$html .= PMA_getHtmlForTableCreateOrAddField( + $action, $_form_params, $content_cells, $header_cells +); - if (PMA_Partition::havePartitioning()) { - $html .= '' - . '' - . '' - . '' - . '' - . ''; - } - $html .= '
' . __('Table comments:') . ' ' . __('Storage Engine:') - . PMA_Util::showMySQLDocu('Storage_engines', 'Storage_engines') - . ' ' . __('Collation:') . '
' - . ' ' - . PMA_StorageEngine::getHtmlSelect( - 'tbl_storage_engine', null, - (isset($_REQUEST['tbl_storage_engine']) - ? $_REQUEST['tbl_storage_engine'] - : null - ) - ) - . ' ' - . PMA_generateCharsetDropdownBox( - PMA_CSDROPDOWN_COLLATION, 'tbl_collation', null, - (isset($_REQUEST['tbl_collation']) - ? $_REQUEST['tbl_collation'] - : null - ), - false, 3 - ) - . '
' . __('PARTITION definition:') . ' ' - . PMA_Util::showMySQLDocu('Partitioning', 'Partitioning') - . '
' - . '' - . '
' - . '
'; -} // end if ($action == 'tbl_create.php') - -$html .= '
' - . '' - . '
' - . '
' - . '
'; - -$html .= ''; +unset($_form_params); PMA_Response::getInstance()->addHTML($html); ?> diff --git a/libraries/tbl_columns_definition_form.lib.php b/libraries/tbl_columns_definition_form.lib.php new file mode 100644 index 0000000000..9b5f45ada4 --- /dev/null +++ b/libraries/tbl_columns_definition_form.lib.php @@ -0,0 +1,279 @@ + $db + ); + + if ($action == 'tbl_create.php') { + $form_params['reload'] = 1; + } elseif ($action == 'tbl_addfield.php') { + $form_params['field_where'] = $_REQUEST['field_where']; + $form_params['after_field'] = $_REQUEST['after_field']; + $form_params['table'] = $table; + } else { + $form_params['table'] = $table; + } + + if (isset($num_fields)) { + $form_params['orig_num_fields'] = $num_fields; + } + + if (isset($_REQUEST['field_where'])) { + $form_params['orig_field_where'] = $_REQUEST['field_where']; + } + + if (isset($_REQUEST['after_field'])) { + $form_params['orig_after_field'] = $_REQUEST['after_field']; + } + + if (isset($selected) && is_array($selected)) { + foreach ($selected as $o_fld_nr => $o_fld_val) { + $form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val; + if (! isset($true_selected)) { + $form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val; + } + } + + if (isset($true_selected) && is_array($true_selected)) { + foreach ($true_selected as $o_fld_nr => $o_fld_val) { + $form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val; + } + } + } elseif (isset($_REQUEST['field'])) { + $form_params['orig_field'] = $_REQUEST['field']; + if (isset($orig_field)) { + $form_params['true_selected[]'] = $orig_field; + } else { + $form_params['true_selected[]'] = $_REQUEST['field']; + } + } + + return $form_params; +} + +/** + * Function to get html for table comments, storage engine, collation and + * partition definition + * + * @return string + */ +function PMA_getHtmlForTableConfigurations() +{ + $html = '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . '' + . ''; + + if (PMA_Partition::havePartitioning()) { + $html .= '' + . '' + . '' + . '' + . '' + . ''; + } + $html .= '
' . __('Table comments:') . ' ' . __('Storage Engine:') + . PMA_Util::showMySQLDocu('Storage_engines', 'Storage_engines') + . ' ' . __('Collation:') . '
' + . ' ' + . PMA_StorageEngine::getHtmlSelect( + 'tbl_storage_engine', null, + (isset($_REQUEST['tbl_storage_engine']) + ? $_REQUEST['tbl_storage_engine'] + : null + ) + ) + . ' ' + . PMA_generateCharsetDropdownBox( + PMA_CSDROPDOWN_COLLATION, 'tbl_collation', null, + (isset($_REQUEST['tbl_collation']) + ? $_REQUEST['tbl_collation'] + : null + ), + false, 3 + ) + . '
' . __('PARTITION definition:') . ' ' + . PMA_Util::showMySQLDocu('Partitioning', 'Partitioning') + . '
' + . '' + . '
' + . '
'; + + return $html; +} + +/** + * Function to get html for the footer + * + * @return string + */ +function PMA_getHtmlForFooter() +{ + $html = '
' + . '' + . '
' + . '
' + . ''; + + $html .= ''; + + return $html; +} + +/** + * Function to get html for table create table name and number of fields + * + * @return string + */ +function PMA_getHtmlForTableNameAndNoOfColumns() +{ + $html = '' + . '' + . '' + . '' + . '' + . '
' . __('Table name') + . ': ' + . ''; + $html .= sprintf( + __('Add %s column(s)'), '' + ); + + $html .= ''; + + $html .= '
'; + + return $html; +} + +/** + * Function to get html for table field definitions + * + * @param array $header_cells + * @param array $content_cells + * + * @return string + */ +function PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells) +{ + $html = ''; + $html .= ''; + + $html .= ''; + foreach ($header_cells as $header_val) { + $html .= ''; + } + $html .= ''; + + $odd_row = true; + foreach ($content_cells as $content_row) { + $html .= ''; + $odd_row = ! $odd_row; + + if (is_array($content_row)) { + foreach ($content_row as $content_row_val) { + $html .= ''; + } + } + $html .= ''; + } + $html .= '
' . __('Structure') + . PMA_Util::showMySQLDocu('SQL-Syntax', 'CREATE_TABLE') . '
' . $header_val . '
' . $content_row_val . '
' + . '
'; + + return $html; +} + +/** + * Function to get html for the create table or field add view + * + * @param string $action action + * @param array $form_params forms parameters + * @param array $content_cells content cells + * @param array $header_cells header cells + * + * @return string + */ +function PMA_getHtmlForTableCreateOrAddField($action, $form_params, $content_cells, + $header_cells +) { + $html = '
'; + $html .= PMA_generate_common_hidden_inputs($form_params); + + if ($action == 'tbl_create.php') { + $html .= PMA_getHtmlForTableNameAndNoOfColumns(); + } + + if (is_array($content_cells) && is_array($header_cells)) { + $html .= PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells); + } + + if ($action == 'tbl_create.php') { + $html .= PMA_getHtmlForTableConfigurations(); + } + + $html .= PMA_getHtmlForFooter(); + + return $html; +} +?>