From e60f53599d087cf27340163ad79156ee2775b93c Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sat, 14 Sep 2013 18:40:51 +0530 Subject: [PATCH 1/2] extracted methods to insert_edit.lib.php --- libraries/insert_edit.lib.php | 326 +++++++++++++++++++++++++++++++++- tbl_change.php | 178 ++----------------- 2 files changed, 344 insertions(+), 160 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 6d8de79f1f..f695f1a22c 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -2574,4 +2574,328 @@ function PMA_getUrlParameters($db, $table) return $url_params; } -?> + +/** + * Function to get html for the gis editor div + * + * @return string + */ +function PMA_getHtmlForGisEditor() +{ + return '
' + . '' + . '
'; +} + +/** + * Function to get html for the ignore option in insert mode + * + * @param int $row_id row id + * + * @return string + */ +function PMA_getHtmlForIgnoreOption($row_id) +{ + return '' + .'
' . "\n"; +} + +/** + * Function to get html for the function option + * + * @param bool $odd_row whether odd row or not + * @param array $column column + * @param string $column_name_appendix column name appendix + * + * @return String + */ +function PMA_getHtmlForFunctionOption($odd_row, $column, $column_name_appendix) +{ + $longDoubleTextArea = $GLOBALS['cfg']['LongtextDoubleTextarea']; + return '' + . '' + . $column['Field_title'] + . '' + . ''; + +} + +/** + * Function to get html for the field type + * + * @param array $column column + * + * @return string + */ +function PMA_getHtmlForFieldType($column) +{ + return '' + . '' . $column['pma_type'] . '' + . ''; + +} + +/** + * Function to get html for the insert edit form header + * + * @param bool $has_blob_field whether has blob field + * @param bool $is_upload whether is upload + * + * @return string + */ +function PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload) +{ + $html_output ='
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 submited... + $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_getHtmlForFieldType($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 .= ' ' . "\n"; + // Will be used by js/tbl_change.js to set the default value + // for the "Continue insertion" feature + $html_output .= '' + . $special_chars . ''; + + $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 .= '' + . ''; + + return $html_output; +} + +/** + * Function to get html for each inset/edit row + * + * @param array $url_params url parameters + * @param array $table_columns table columns + * @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 int &$o_rows row offset + * @param int $columns_cnt columns count + * @param bool $is_upload whether upload + * @param int $tabindex_for_function tab index offset for function + * @param array $foreigners foreigners + * @param int $tabindex_for_null tab index offset for null + * @param int $tabindex_for_value tab index offset for value + * @param string $table table + * @param string $db database + * @param int $row_id row id + * @param array $titles titles + * @param int $biggest_max_file_size biggest max file size + * @param string $text_dir text direction + * + * @return string + */ +function PMA_getHtmlForInsertEditRow($url_params, $table_columns, + $column, $comments_map, $timestamp_seen, $current_result, $chg_evt_handler, + $jsvkey, $vkey, $insert_mode, $current_row, &$o_rows, $columns_cnt, + $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null, + $tabindex_for_value, $table, $db, $row_id, $titles, + $biggest_max_file_size, $text_dir +) { + $html_output = PMA_getHeadAndFootOfInsertRowTable($url_params) + . ''; + + // Sets a multiplier used for input-field counts + // (as zero cannot be used, advance the counter plus one) + $m_rows = $o_rows + 1; + + //store the default value for CharEditing + $default_char_editing = $GLOBALS['cfg']['CharEditing']; + + $odd_row = true; + for ($i = 0; $i < $columns_cnt; $i++) { + $html_output .= 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, $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 + ); + $odd_row = !$odd_row; + } // end for + $o_rows++; + $html_output .= ' ' + . '
'; + + return $html_output; +} +?> \ No newline at end of file diff --git a/tbl_change.php b/tbl_change.php index cf11fbcfb4..721d5c2014 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -29,7 +29,9 @@ require_once 'libraries/insert_edit.lib.php'; list( $insert_mode, $where_clause, $where_clause_array, $where_clauses, $result, $rows, $found_unique_key, $after_insert -) = PMA_determineInsertOrEdit($where_clause, $db, $table); +) = PMA_determineInsertOrEdit( + isset($where_clause) ? $where_clause : null, $db, $table + ); /** * file listing @@ -123,8 +125,6 @@ $url_params = PMA_urlParamsInEditMode( $url_params, $where_clause_array, $where_clause ); -//Insert/Edit form -//If table has blob fields we have to disable ajax. $has_blob_field = false; foreach ($table_columns as $column) { if (PMA_isColumnBlob($column)) { @@ -132,15 +132,11 @@ foreach ($table_columns as $column) { break; } } -$html_output .=' $current_row) { ? $result[$row_id] : $result); if ($insert_mode && $row_id > 0) { - $html_output .= '' - .'
' . "\n"; + $html_output .= PMA_getHtmlForIgnoreOption($row_id); } - $html_output .= PMA_getHeadAndFootOfInsertRowTable($url_params) - . ''; - - // Sets a multiplier used for input-field counts - // (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_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 attribute (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 .= '' - . '' - . $column['Field_title'] - . '' - . ''; - if ($cfg['ShowFieldTypesInDataEditView']) { - $html_output .= '' - . '' . $column['pma_type'] . '' - . ''; - } //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 ($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 .= ' ' . "\n"; - // Will be used by js/tbl_change.js to set the default value - // for the "Continue insertion" feature - $html_output .= '' - . $special_chars . ''; - - $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 .= '' - . ''; - - $odd_row = !$odd_row; - } // end for - $o_rows++; - $html_output .= ' ' - . '
'; + $html_output .= PMA_getHtmlForInsertEditRow( + $url_params, $table_columns, $column, $comments_map, $timestamp_seen, + $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode, + isset($current_row) ? $current_row : null, $o_rows, $columns_cnt, + $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null, + $tabindex_for_value, $table, $db, $row_id, $titles, + $biggest_max_file_size, $text_dir + ); } // end foreach on multi-edit -$html_output .='
' - . '' - . '
'; +$html_output .= PMA_getHtmlForGisEditor(); if (! isset($after_insert)) { $after_insert = 'back'; @@ -347,6 +207,6 @@ if ($insert_mode) { $table, $db, $where_clause_array, $err_url ); } -$response->addHTML($html_output); +$response->addHTML($html_output); ?> From 17ce188db4d82b810327cc284ac321e4e6e4eba0 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Sat, 14 Sep 2013 19:35:37 +0530 Subject: [PATCH 2/2] value tab offset error corrected --- libraries/insert_edit.lib.php | 14 ++++++-------- tbl_change.php | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index f695f1a22c..d90d3b1aad 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -2683,7 +2683,8 @@ function PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload) * @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 &$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 @@ -2703,7 +2704,7 @@ function PMA_getHtmlForInsertEditFormHeader($has_blob_field, $is_upload) */ 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, $columns_cnt, $is_upload, + $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 @@ -2848,6 +2849,7 @@ function PMA_getHtmlForInsertEditFormColumn($table_columns, $i, $column, $commen * @param bool $insert_mode whether insert mode * @param array $current_row current row * @param int &$o_rows row offset + * @param int &$tabindex tab index * @param int $columns_cnt columns count * @param bool $is_upload whether upload * @param int $tabindex_for_function tab index offset for function @@ -2865,17 +2867,13 @@ function PMA_getHtmlForInsertEditFormColumn($table_columns, $i, $column, $commen */ function PMA_getHtmlForInsertEditRow($url_params, $table_columns, $column, $comments_map, $timestamp_seen, $current_result, $chg_evt_handler, - $jsvkey, $vkey, $insert_mode, $current_row, &$o_rows, $columns_cnt, + $jsvkey, $vkey, $insert_mode, $current_row, &$o_rows, &$tabindex, $columns_cnt, $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null, $tabindex_for_value, $table, $db, $row_id, $titles, $biggest_max_file_size, $text_dir ) { $html_output = PMA_getHeadAndFootOfInsertRowTable($url_params) . ''; - - // Sets a multiplier used for input-field counts - // (as zero cannot be used, advance the counter plus one) - $m_rows = $o_rows + 1; //store the default value for CharEditing $default_char_editing = $GLOBALS['cfg']['CharEditing']; @@ -2885,7 +2883,7 @@ function PMA_getHtmlForInsertEditRow($url_params, $table_columns, $html_output .= 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, $columns_cnt, $is_upload, + $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 diff --git a/tbl_change.php b/tbl_change.php index 721d5c2014..596cbd0c7d 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -173,7 +173,7 @@ foreach ($rows as $row_id => $current_row) { $html_output .= PMA_getHtmlForInsertEditRow( $url_params, $table_columns, $column, $comments_map, $timestamp_seen, $current_result, $chg_evt_handler, $jsvkey, $vkey, $insert_mode, - isset($current_row) ? $current_row : null, $o_rows, $columns_cnt, + isset($current_row) ? $current_row : null, $o_rows, $tabindex, $columns_cnt, $is_upload, $tabindex_for_function, $foreigners, $tabindex_for_null, $tabindex_for_value, $table, $db, $row_id, $titles, $biggest_max_file_size, $text_dir