From 38fb1f1a4afaf3cb5453811f2cecf4621ff08aa9 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Tue, 12 Jun 2012 16:34:32 +0530 Subject: [PATCH] Break PMA_getForeignFields_Values into smaller functions --- libraries/tbl_select.lib.php | 260 +++++++++++++++++++++-------------- 1 file changed, 157 insertions(+), 103 deletions(-) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index 8f234590d3..b18ceb5844 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -121,6 +121,144 @@ function PMA_tbl_getSubTabs() return $subtabs; } +/** + * Provides html elements for search criteria inputbox + * in case the column's type is geometrical + * + * @param int $column_index Column's index + * @param bool $in_fbs Whether we are in 'function based search' + * + * @return HTML elements. + */ +function PMA_tblSearchGetGeometricalInputBox($column_index, $in_fbs) +{ + $html_output = ''; + + if ($in_fbs) { + $edit_url = 'gis_data_editor.php?' . PMA_generate_common_url(); + $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert')); + $html_output .= ''; + $html_output .= PMA_linkOrButton( + $edit_url, $edit_str, array(), false, false, '_blank' + ); + $html_output .= ''; + } + return $html_output; +} + +/** + * Provides html elements for search criteria inputbox + * in case the column is a Foreign Key + * + * @param array $foreignData Foreign keys data + * @param string $field Column name + * @param int $column_index Column index + * @param string $db Selected database + * @param string $table Selected table + * @param array $titles Selected title + * @param int $foreignMaxLimit Max limit of displaying foreign elements + * @param array $criteriaValues Array of search criteria inputs + * @param string $field_id Column's inputbox's id + * @param bool $in_zoom_search_edit Whether we are in zoom search edit + * + * @return HTML elements. + */ +function PMA_tblSearchGetForeignKeyInputBox($foreignData, $field, $column_index, + $db, $table, $titles, $foreignMaxLimit, $criteriaValues, + $field_id, $in_zoom_search_edit = false +) { + $html_output = ''; + if (is_array($foreignData['disp_row'])) { + $html_output .= ''; + + } elseif ($foreignData['foreign_link'] == true) { + $html_output .= ''; + + $html_output .= <<'; + } + return $html_output; +} + +/** + * Provides html elements for search criteria inputbox + * in case the column is of ENUM or SET type + * + * @param int $column_index Column index + * @param array $criteriaValues Array of search criteria inputs + * @param string $field_type Column type + * @param string $field_id Column's inputbox's id + * @param bool $in_zoom_search_edit Whether we are in zoom search edit + * + * @return HTML elements. + */ +function PMA_tblSearchGetEnumSetInputBox($column_index, $criteriaValues, $field_type, + $field_id, $in_zoom_search_edit = false +) { + $html_output = ''; + $value = explode( + ', ', + str_replace("'", '', substr($field_type, 5, -1)) + ); + $cnt_value = count($value); + + /* + * Enum in edit mode --> dropdown + * Enum in search mode --> multiselect + * Set in edit mode --> multiselect + * Set in search mode --> input (skipped here, so the 'else' + * section would handle it) + */ + if ((strncasecmp($field_type, 'enum', 4) && ! $in_zoom_search_edit) + || (strncasecmp($field_type, 'set', 3) && $in_zoom_search_edit) + ) { + $html_output .= ''; + } + + //Add select options + for ($j = 0; $j < $cnt_value; $j++) { + if (isset($criteriaValues[$column_index]) + && is_array($criteriaValues[$column_index]) + && in_array($value[$j], $criteriaValues[$column_index]) + ) { + $html_output .= ''; + } else { + $html_output .= ''; + } + } // end for + $html_output .= ''; + return $html_output; +} + /** * Creates the HTML content for: * 1) Browsing foreign data for a field. @@ -149,107 +287,27 @@ function PMA_getForeignFields_Values($foreigners, $foreignData, $field, $str = ''; $field_type = (string)$field_type; $field_id = ($in_zoom_search_edit) ? 'edit_fieldID_' : 'fieldID_'; - if ($foreigners - && isset($foreigners[$field]) - && is_array($foreignData['disp_row']) - ) { - // f o r e i g n k e y s - $str .= ''; - } elseif ($foreignData['foreign_link'] == true) { - if (isset($criteriaValues[$column_index]) - && is_string($criteriaValues[$column_index]) - ) { - $str .= ''; - } else { - $str .= ''; - } - $str .= <<'; + //Get inputbox based on different column types (Foreign key, geometrical, enum) + if ($foreigners && isset($foreigners[$field])) { + $str .= PMA_tblSearchGetForeignKeyInputBox( + $foreignData, $field, $column_index, $db, $table, $titles, + $foreignMaxLimit, $criteriaValues, $field_id + ); } elseif (in_array($field_type, PMA_getGISDatatypes())) { - // g e o m e t r y - $str .= ''; - - if ($in_fbs) { - $edit_url = 'gis_data_editor.php?' . PMA_generate_common_url(); - $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert')); - $str .= ''; - $str .= PMA_linkOrButton( - $edit_url, $edit_str, array(), false, false, '_blank' - ); - $str .= ''; - } + $str .= PMA_tblSearchGetGeometricalInputBox($column_index, $in_fbs); } elseif (strncasecmp($field_type, 'enum', 4) == 0 || (strncasecmp($field_type, 'set', 3) == 0 && $in_zoom_search_edit) ) { - // e n u m s a n d s e t s - - // Enum in edit mode --> dropdown - // Enum in search mode --> multiselect - // Set in edit mode --> multiselect - // Set in search mode --> input (skipped here, so the 'else' - // section would handle it) - - $value = explode( - ', ', - str_replace("'", '', substr($field_type, 5, -1)) + $str .= PMA_tblSearchGetEnumSetInputBox( + $column_index, $criteriaValues, $field_type, $field_id, + $in_zoom_search_edit = false ); - $cnt_value = count($value); - - if ((strncasecmp($field_type, 'enum', 4) && ! $in_zoom_search_edit) - || (strncasecmp($field_type, 'set', 3) && $in_zoom_search_edit) - ) { - $str .= ''; - } - - for ($j = 0; $j < $cnt_value; $j++) { - if (isset($criteriaValues[$column_index]) - && is_array($criteriaValues[$column_index]) - && in_array($value[$j], $criteriaValues[$column_index]) - ) { - $str .= ''; - } else { - $str .= ''; - } - } // end for - $str .= ''; } else { - // o t h e r c a s e s + // other cases $the_class = 'textfield'; if ($field_type == 'date') { @@ -260,18 +318,14 @@ EOT; $the_class .= ' bit'; } - if (isset($criteriaValues[$column_index]) - && is_string($criteriaValues[$column_index]) - ) { - $str .= ''; - } else { - $str .= ''; - } + $str .= ''; } return $str; }