$db, 'table' => $table, 'goto' => $GLOBALS['goto'], 'err_url' => $err_url, 'sql_query' => $_REQUEST['sql_query'], ); if (isset($where_clauses)) { foreach ($where_clause_array as $key_id => $where_clause) { $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause); } } if (isset($_REQUEST['clause_is_unique'])) { $_form_params['clause_is_unique'] = $_REQUEST['clause_is_unique']; } return $_form_params; } /** * Retrieve the values for pma edit mode * * @param type $where_clause where clauses * @param type $table name of the table * @param type $db name of the database * * @return type containing insert_mode,whereClauses, result array * where_clauses_array and found_unique_key boolean value */ function PMA_getValuesForEditMode($where_clause, $table, $db) { $found_unique_key = false; if (isset($where_clause)) { $where_clause_array = PMA_getWhereClauseArray($where_clause); list($whereClauses, $resultArray, $rowsArray, $found_unique_key) = PMA_analyzeWhereClauses($where_clause_array, $table, $db, $found_unique_key); return array(false, $whereClauses, $resultArray, $rowsArray, $where_clause_array, $found_unique_key); } else { list($results, $row) = PMA_loadFirstRowInEditMode($table, $db); return array(true, null, $results, $row, null, $found_unique_key); } } /** * * @return whereClauseArray array of where clauses */ function PMA_getWhereClauseArray($where_clause) { if (isset ($where_clause)) { if (is_array($where_clause)) { return $where_clause; } else { return array(0 => $where_clause); } } } /** * Analysing where cluases array * * @param array $where_clause_array array of where clauses * @param string $table name of the table * @param string $db name of the database * @param boolean $found_unique_key boolean variable for unique key * * @return array $where_clauses, $result, $rows */ function PMA_analyzeWhereClauses($where_clause_array, $table, $db, $found_unique_key) { $rows = array(); $result = array(); $where_clauses = array(); foreach ($where_clause_array as $key_id => $where_clause) { $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';'; $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); $found_unique_key = PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); } return array($where_clauses, $result, $rows, $found_unique_key); } /** * Show message for empty reult or set the unique_condition * * @param array $rows * @param string $key_id * @param array $where_clause_array * @param string $local_query * @param array $result * @param boolean $found_unique_key * * @return boolean $found_unique_key */ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key ) { // No row returned if (! $rows[$key_id]) { unset($rows[$key_id], $where_clause_array[$key_id]); PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); echo "\n"; include 'libraries/footer.inc.php'; } else {// end if (no row returned) $meta = PMA_DBI_get_fields_meta($result[$key_id]); list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); if (! empty($unique_condition)) { $found_unique_key = true; } unset($unique_condition, $tmp_clause_is_unique); } return $found_unique_key; } /** * No primary key given, just load first row * * @param string $table name of the table * @param string $db name of the database * * @return array containing $result and $rows arrays */ function PMA_loadFirstRowInEditMode($table, $db) { $result = PMA_DBI_query( 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE ); $rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false); return array($result, $rows); } /** * Add some url parameters * * @param array $url_params containing $db and $table as url parameters * * @return array Add some url parameters to $url_params array * and return it */ function PMA_urlParamsInEditMode($url_params) { if (isset($_REQUEST['where_clause'])) { $url_params['where_clause'] = trim($_REQUEST['where_clause']); } if (! empty($_REQUEST['sql_query'])) { $url_params['sql_query'] = $_REQUEST['sql_query']; } return $url_params; } /** * Show function fields in data edit view in pma * * @param array $url_params containing url parameters * * @return string an html snippet */ function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields) { $params = array(); if (! $showFuncFields) { $params['ShowFunctionFields'] = 1; } else { $params['ShowFunctionFields'] = 0; } $params['ShowFieldTypesInDataEditView'] = $GLOBALS['cfg']['ShowFieldTypesInDataEditView']; $params['goto'] = 'sql.php'; $this_url_params = array_merge($url_params, $params); if (! $showFuncFields) { return ' : ' . __('Function') . '' . "\n"; } return ' ' . __('Function') . '' . "\n"; } /** * Show field types in data edit view in pma * * @param array $url_params containing url parameters * * @return stirng an html snippet */ function PMA_showColumnTypesInDataEditView($url_params, $showColumnType ) { $params = array(); if (! $showColumnType) { $params['ShowFieldTypesInDataEditView'] = 1; } else { $params['ShowFieldTypesInDataEditView'] = 0; } $params['ShowFunctionFields'] = $GLOBALS['cfg']['ShowFunctionFields']; $params['goto'] = 'sql.php'; $this_other_url_params = array_merge($url_params, $params); if (! $showColumnType) { return ' : ' . __('Type') . '' . "\n"; } return ' ' . __('Type') . '' . "\n"; } /** * Retrieve the default for datetime data type * * @param array $column containing column type, Default and null */ function PMA_getDefaultForDatetime($column) { // d a t e t i m e // // Current date should not be set as default if the field is NULL // for the current row, but do not put here the current datetime // if there is a default value (the real default value will be set // in the Default value logic below) // Note: (tested in MySQL 4.0.16): when lang is some UTF-8, // $column['Default'] is not set if it contains NULL: // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime) // but, look what we get if we switch to iso: (Default is NULL) // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime) // so I force a NULL into it (I don't think it's possible // to have an empty default value for DATETIME) // then, the "if" after this one will work if ($column['Type'] == 'datetime' && ! isset($column['Default']) && isset($column['Null']) && $column['Null'] == 'YES' ) { $column['Default'] = null; } } /** * Analyze the table column array * * @param array $column description of column in given table * @param array $comments_map comments for every column that has a comment * @param integer $timestamp_seen 0 interger * * @return array description of column in given table */ function PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen) { $column['Field_html'] = htmlspecialchars($column['Field']); $column['Field_md5'] = md5($column['Field']); // True_Type contains only the type (stops at first bracket) $column['True_Type'] = preg_replace('@\(.*@s', '', $column['Type']); PMA_getDefaultForDatetime($column); $column['len'] = preg_match('@float|double@', $column['Type']) ? 100 : -1; $column['Field_title'] = PMA_getColumnTitle($column, $comments_map); $column['is_binary'] = PMA_isColumnBinary($column); $column['is_blob'] = PMA_isColumnBlob($column); $column['is_char'] = PMA_isColumnChar($column); list($column['pma_type'], $column['wrap'], $column['first_timestamp']) = PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen); return $column; } /** * Retrieve the column title * * @param array $column description of column in given table * @param array $comments_map comments for every column that has a comment * * @return string column title */ function PMA_getColumnTitle($column, $comments_map) { if (isset($comments_map[$column['Field']])) { return '' . $column['Field_html'] . ''; } else { return $column['Field_html']; } } /** * check whether the column is a bainary * * @param array $column description of column in given table * * @return boolean If check to ensure types such as "enum('one','two','binary',..)" or * "enum('one','two','varbinary',..)" are not categorized as binary. */ function PMA_isColumnBinary($column) { // The type column. // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option' if (stripos($column['Type'], 'binary') === 0 || stripos($column['Type'], 'varbinary') === 0 ) { return stristr($column['Type'], 'binary'); } else { return false; } } /** * check whether the column is a blob * * @param array $column description of column in given table * * @return boolean If check to ensure types such as "enum('one','two','blob',..)" or * "enum('one','two','tinyblob',..)" etc. are not categorized as blob. */ function PMA_isColumnBlob($column) { if (stripos($column['Type'], 'blob') === 0 || stripos($column['Type'], 'tinyblob') === 0 || stripos($column['Type'], 'mediumblob') === 0 || stripos($column['Type'], 'longblob') === 0 ) { return stristr($column['Type'], 'blob'); } else { return false; } } /** * check is table column char * * @param array $column description of column in given table * * @return boolean If check to ensure types such as "enum('one','two','char',..)" or * "enum('one','two','varchar',..)" are not categorized as char. */ function PMA_isColumnChar($column) { if (stripos($column['Type'], 'char') === 0 || stripos($column['Type'], 'varchar') === 0 ) { return stristr($column['Type'], 'char'); } else { return false; } } /** * Retieve set, enum, timestamp table columns * * @param array $column description of column in given table * @param int $timestamp_seen 0 interger * * return array $column['pma_type'], $column['wrap'], $column['first_timestamp'] */ function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen) { $column['first_timestamp'] = false; switch ($column['True_Type']) { case 'set': $column['pma_type'] = 'set'; $column['wrap'] = ''; break; case 'enum': $column['pma_type'] = 'enum'; $column['wrap'] = ''; break; case 'timestamp': if (!$timestamp_seen) { // can only occur once per table $timestamp_seen = 1; $column['first_timestamp'] = true; } $column['pma_type'] = $column['Type']; $column['wrap'] = ' nowrap'; break; default: $column['pma_type'] = $column['Type']; $column['wrap'] = ' nowrap'; break; } return array($column['pma_type'], $column['wrap'], $column['first_timestamp']); } /** * The function column * We don't want binary data to be destroyed * Note: from the MySQL manual: "BINARY doesn't affect how the column is * stored or retrieved" so it does not mean that the contents is binary * * @param array $column description of column in given table * @param boolean $is_upload upload or no * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param array $no_support_types list of datatypes that are not (yet) handled by PMA * @param integer $tabindex_for_function +3000 * @param integer $tabindex tab index * @param integer $idindex id index * @param boolean $insert_mode insert mode or edit mode * * @return string an html sippet */ function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, $unnullify_trigger, $no_support_types, $tabindex_for_function, $tabindex, $idindex, $insert_mode ) { $html_output = ''; if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'] && !$is_upload) || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $column['is_binary']) || ($GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$column['is_blob']) ) { $html_output .= ' ' . __('Binary') . '' . "\n"; } elseif (strstr($column['True_Type'], 'enum') || strstr($column['True_Type'], 'set') || in_array($column['pma_type'], $no_support_types) ) { $html_output .= ' --' . "\n"; } else { $html_output .= '' . "\n"; $html_output .= '' . "\n"; $html_output .= '' . "\n"; } return $html_output; } /** * The null column * * @param array $column description of column in given table * @param string $column_name_appendix the name atttibute * @param array $real_null_value is column value null or not null * @param integer $tabindex tab index * @param integer $tabindex_for_null +6000 * @param integer $idindex id index * @param array $vkey [multi_edit]['row_id'] * @param array $foreigners keys into foreign fields * @param array $foreignData data about the foreign keys * * @return string an html snippet */ function PMA_getNullColumn($column, $column_name_appendix, $real_null_value, $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData ) { $html_output = ''; $html_output .= ' ' . "\n"; if ($column['Null'] == 'YES') { $html_output .= ' '; // nullify_code is needed by the js nullify() function $nullify_code = PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData); // to be able to generate calls to nullify() in jQuery $html_output .= ''; $html_output .= ''; $html_output .= ''; } $html_output .= ' ' . "\n"; return $html_output; } /** * Retrieve the nullify code for the null column * * @param array $column description of column in given table * @param array $foreigners keys into foreign fields * @param array $foreignData data about the foreign keys * * @return integer $nullify_code */ function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData) { if (strstr($column['True_Type'], 'enum')) { if (strlen($column['Type']) > 20) { $nullify_code = '1'; } else { $nullify_code = '2'; } } elseif (strstr($column['True_Type'], 'set')) { $nullify_code = '3'; } elseif ($foreigners && isset($foreigners[$column['Field']]) && $foreignData['foreign_link'] == false) { // foreign key in a drop-down $nullify_code = '4'; } elseif ($foreigners && isset($foreigners[$column['Field']]) && $foreignData['foreign_link'] == true) { // foreign key with a browsing icon $nullify_code = '6'; } else { $nullify_code = '5'; } return $nullify_code; } /** * Get the HTML elements for value column in inert form * * @param array $column description of column in given table * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * @param array $data description of the column field * @param array $special_chars special characters * @param array $foreignData data about the foreign keys * @param array $paramTableDbArray array containing $db and $table * @param array $rownumber_param &rownumber=row_id * @param array $titles An HTML IMG tag for a particular icon from a theme, * which may be an actual file or an icon from a sprite * @param array $text_dir * @param string $special_chars_encoded replaced char if the string starts * with a \r\n pair (0x0d0a) add an extra \n * @param integer $biggest_max_file_size 0 intger * @param string $default_char_editing default char editing mode which is stroe * in the config.inc.php script * @param array $no_support_types list of datatypes that are not (yet) handled by PMA * @param array $gis_data_types list of GIS data types * * @return string an html snippet */ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $unnullify_trigger,$tabindex, $tabindex_for_value, $idindex, $data, $special_chars, $foreignData, $odd_row, $paramTableDbArray,$rownumber_param, $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 = ''; if ($foreignData['foreign_link'] == true) { $html_output .= PMA_getForeignLink($column, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $paramTableDbArray, $rownumber_param, $titles ); } elseif (is_array($foreignData['disp_row'])) { $html_output .= PMA_dispRowForeignData($backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $foreignData ); } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea'] && strstr($column['pma_type'], 'longtext')) { $html_output = ' '; $html_output .= ''; $html_output .= '' . ''; $html_output .= PMA_getTextarea($column,$backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded ); } elseif (strstr($column['pma_type'], 'text')) { $html_output .= PMA_getTextarea($column,$backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded ); $html_output .= "\n"; if (strlen($special_chars) > 32000) { $html_output .= " \n"; $html_output .= ' ' . __('Because of its length,
this column might not be editable'); } } elseif ($column['pma_type'] == 'enum') { $html_output .= PMA_getPmaTypeEnum($paramsArrayForColumns, $column,$extracted_columnspec); } elseif ($column['pma_type'] == 'set') { $html_output .= PMA_getPmaTypeSet($column,$extracted_columnspec, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex); } elseif ($column['is_binary'] || $column['is_blob']) { $html_output .= PMA_getBinaryAndBlobColumn($column, $data, $special_chars,$biggest_max_file_size, $backup_field,$column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $vkey, $is_upload); } elseif (! in_array($column['pma_type'], $no_support_types)) { $html_output .= PMA_getNoSupportTypes($column, $default_char_editing,$backup_field, $column_name_appendix, $unnullify_trigger,$tabindex,$special_chars, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $data, $extracted_columnspec); } if (in_array($column['pma_type'], $gis_data_types)) { $html_output .= PMA_getHTMLforGisDataTypes($current_row, $column); } return $html_output; } /** * Get HTML for foreign link in insert form * * @param array $column description of column in given table * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * @param array $data * @param array $paramTableDbArray array containing $db and $table * @param array $rownumber_param &rownumber=row_id * @param array $titles An HTML IMG tag for a particular icon from a theme, * which may be an actual file or an icon from a sprite * * @return string an html snippet */ function PMA_getForeignLink($column, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $paramTableDbArray, $rownumber_param, $titles ) { list($db, $table) = $paramTableDbArray; $html_output = ''; $html_output .= $backup_field . "\n"; $html_output .= ''; $html_output .= '' . '' . str_replace("'", "\'", $titles['Browse']) . ''; return $html_output; } /** * Get HTML to display foreign data * * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * @param array $data * @param array $foreignData data about the foreign keys * * @return string an html snippet */ function PMA_dispRowForeignData($backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $foreignData ) { $html_output = ''; $html_output .= $backup_field . "\n"; $html_output .= '' . ''; return $html_output; } /** * Get HTML for enum type * * @param array $column description of column in given table * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param array $extracted_columnspec associative array containing type, spec_in_brackets * and possibly enum_set_values (another array) * * @return string an html snippet */ function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix, $extracted_columnspec) { $html_output = ''; if (! isset($column['values'])) { $column['values'] = PMA_getColumnEnumValues($column, $extracted_columnspec); } $column_enum_values = $column['values']; $html_output .= ''; $html_output .= ''; $html_output .= "\n" . ' ' . $backup_field . "\n"; if (strlen($column['Type']) > 20) { $html_output .= PMA_getDropDownDependingOnLength($column, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values ); } else { $html_output .= PMA_getRadioButtonDependingOnLength($column_name_appendix, $unnullify_trigger, $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values ); } return $html_output; } /** * Get column values * * @param array $column description of column in given table * @param array $extracted_columnspec associative array containing type, spec_in_brackets * and possibly enum_set_values (another array) * * @return array column values as an associative array */ function PMA_getColumnEnumValues($column, $extracted_columnspec) { $column['values'] = array(); foreach ($extracted_columnspec['enum_set_values'] as $val) { // Removes automatic MySQL escape format $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val)); $column['values'][] = array( 'plain' => $val, 'html' => htmlspecialchars($val), ); } return $column['values']; } /** * Get HTML drop down for more than 20 string length * * @param array $column description of column in given table * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * @param array $data * @param array $column_enum_values $column['values'] * * @return string an html snippet */ function PMA_getDropDownDependingOnLength($column, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values ) { $html_output = ''; return $html_output; } /** * Get HTML radio button for less than 20 string length * * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param array $column description of column in given table * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * @param array $data * @param array $column_enum_values $column['values'] * * @return string an html snippet */ function PMA_getRadioButtonDependingOnLength($column_name_appendix, $unnullify_trigger, $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values ) { $j = 0; $html_output = ''; foreach ($column_enum_values as $enum_value) { $html_output .= ' ' . ''; $html_output .= '' . "\n"; $j++; } return $html_output; } /** * Get the HTML for 'set' pma type * * @param array $column description of column in given table * @param array $extracted_columnspec associative array containing type, spec_in_brackets * and possibly enum_set_values (another array) * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * * @return string an html snippet */ function PMA_getPmaTypeSet($column,$extracted_columnspec, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex ) { list($column_set_values, $select_size) = PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec); $vset = array_flip(explode(',', $data)); $html_output = $backup_field . "\n"; $html_output .= ''; $html_output .= ''; return $html_output; } /** * Retrieve column 'set' value and select size * * @param array $column description of column in given table * @param array $extracted_columnspec associative array containing type, spec_in_brackets * and possibly enum_set_values (another array) * * @return array $column['values'], $column['select_size'] */ function PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec) { if (! isset($column['values'])) { $column['values'] = array(); foreach ($extracted_columnspec['enum_set_values'] as $val) { $column['values'][] = array( 'plain' => $val, 'html' => htmlspecialchars($val), ); } $column['select_size'] = min(4, count($column['values'])); } return array($column['values'], $column['select_size']); } /** * Get HTML for binary and blob column * * @param array $column description of column in given table * @param array $data * @param array $special_chars special characters * @param integer $biggest_max_file_size biggest max file size for uploading * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * @param string $text_dir * @param string $special_chars_encoded replaced char if the string starts * with a \r\n pair (0x0d0a) add an extra \n * @param string $vkey [multi_edit]['row_id'] * @param boolean $is_upload is upload or not * * @return string an html snippet */ function PMA_getBinaryAndBlobColumn($column, $data, $special_chars,$biggest_max_file_size, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,$vkey, $is_upload ) { $html_output = ''; if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob']) || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $column['is_binary']) || ($GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$column['is_blob']) ) { $html_output .= __('Binary - do not edit'); if (isset($data)) { $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1); $html_output .= ' ('. $data_size [0] . ' ' . $data_size[1] . ')'; unset($data_size); } $html_output .= '' . ''; } elseif ($column['is_blob']) { $html_output .= "\n" . PMA_getTextarea($column,$backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded); } else { // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars'] $fieldsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']); $html_output .= "\n" . $backup_field . "\n" . PMA_getHTMLinput($column, $column_name_appendix, $special_chars, $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex); } if ($is_upload && $column['is_blob']) { $html_output .= '
' . ' '; list($html_out, $biggest_max_file_size) = PMA_getMaxUploadSize($column,$biggest_max_file_size); $html_output .= $html_out; } if (!empty($GLOBALS['cfg']['UploadDir'])) { $html_output .= PMA_getSelectOptionForUpload($vkey, $column); } return $html_output; } /** * Get HTML input type * * @param array $column description of column in given table * @param string $column_name_appendix the name atttibute * @param array $special_chars special characters * @param integer $fieldsize html field size * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * * @return string an html snippet */ function PMA_getHTMLinput($column, $column_name_appendix, $special_chars, $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex ) { $the_class = 'textfield'; if ($column['pma_type'] == 'date') { $the_class .= ' datefield'; } elseif ($column['pma_type'] == 'datetime' || substr($column['pma_type'], 0, 9) == 'timestamp' ) { $the_class .= ' datetimefield'; } return ''; } /** * Get HTML select option for upload * * @param string $vkey [multi_edit]['row_id'] * @param array $column description of column in given table * * @return string an html snippet */ function PMA_getSelectOptionForUpload($vkey, $column) { $files = PMA_getFileSelectOptions(PMA_userDir($GLOBALS['cfg']['UploadDir'])); if ($files === false) { return ' ' . __('Error') . '
' . "\n" . ' ' . __('The directory you set for upload work cannot be reached') . "\n"; } elseif (!empty($files)) { return "
\n" . ' ' . __('Or') . '' . ' ' . __('web server upload directory') . ':
' . "\n" . ' ' . "\n"; } } /** * Retrieve the maximum upload file size * * @param array $column description of column in given table * @param integer $biggest_max_file_size biggest max file size for uploading * * @return array an html snippet and $biggest_max_file_size */ function PMA_getMaxUploadSize($column, $biggest_max_file_size) { // find maximum upload size, based on field type /** * @todo with functions this is not so easy, as you can basically * process any data with function like MD5 */ global $max_upload_size; $max_field_sizes = array( 'tinyblob' => '256', 'blob' => '65536', 'mediumblob' => '16777216', 'longblob' => '4294967296'); // yeah, really $this_field_max_size = $max_upload_size; // from PHP max if ($this_field_max_size > $max_field_sizes[$column['pma_type']]) { $this_field_max_size = $max_field_sizes[$column['pma_type']]; } $html_output = PMA_getFormattedMaximumUploadSize($this_field_max_size) . "\n"; // do not generate here the MAX_FILE_SIZE, because we should // put only one in the form to accommodate the biggest field if ($this_field_max_size > $biggest_max_file_size) { $biggest_max_file_size = $this_field_max_size; } return array($html_output, $biggest_max_file_size); } /** * Get HTML for pma no support types * * @param array $column description of column in given table * @param string $default_char_editing default char editing mode which is stroe * in the config.inc.php script * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string * @param integer $tabindex tab index * @param array $special_chars apecial characters * @param integer $tabindex_for_value offset for the values tabindex * @param integer $idindex id index * @param string $text_dir * @param array $special_chars_encoded replaced char if the string starts * with a \r\n pair (0x0d0a) add an extra \n * * @return string an html snippet */ function PMA_getNoSupportTypes($column, $default_char_editing,$backup_field, $column_name_appendix, $unnullify_trigger,$tabindex,$special_chars, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,$data, $extracted_columnspec ) { $fieldsize = PMA_getColumnSize($column, $extracted_columnspec); $html_output = $backup_field . "\n"; if ($column['is_char'] && ($GLOBALS['cfg']['CharEditing'] == 'textarea' || strpos($data, "\n") !== false) ) { $html_output .= "\n"; $GLOBALS['cfg']['CharEditing'] = $default_char_editing; $html_output .= PMA_getTextarea($column, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded); } else { $html_output .= PMA_getHTMLinput($column, $column_name_appendix, $special_chars, $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex); if ($column['Extra'] == 'auto_increment') { $html_output .= ''; } if (substr($column['pma_type'], 0, 9) == 'timestamp') { $html_output .= ''; } if (substr($column['pma_type'], 0, 8) == 'datetime') { $html_output .= ''; } if ($column['True_Type'] == 'bit') { $html_output .= ''; } if ($column['pma_type'] == 'date' || $column['pma_type'] == 'datetime' || substr($column['pma_type'], 0, 9) == 'timestamp' ) { // the _3 suffix points to the date field // the _2 suffix points to the corresponding NULL checkbox // in dateFormat, 'yy' means the year with 4 digits } } return $html_output; } /** * Get the field size * * @param array $column description of column in given table * * @return integer field size */ function PMA_getColumnSize($column, $extracted_columnspec) { if ($column['is_char']) { $fieldsize = $extracted_columnspec['spec_in_brackets']; if ($fieldsize > $GLOBALS['cfg']['MaxSizeForInputField']) { /** * This case happens for CHAR or VARCHAR columns which have * a size larger than the maximum size for input field. */ $GLOBALS['cfg']['CharEditing'] = 'textarea'; } } else { /** * This case happens for example for INT or DATE columns; * in these situations, the value returned in $column['len'] * seems appropriate. */ $fieldsize = $column['len']; } return min(max($fieldsize, $GLOBALS['cfg']['MinSizeForInputField']), $GLOBALS['cfg']['MaxSizeForInputField']); } /** * Get HTML for gis data types * * @param string $current_row row description * @param array $column description of column in given table * * @return string an html snippet */ function PMA_getHTMLforGisDataTypes($current_row, $column) { $data_val = isset($current_row[$column['Field']]) ? $current_row[$column['Field']] : ''; $_url_params = array( 'field' => $column['Field_title'], 'value' => $data_val, ); if ($column['pma_type'] != 'geometry') { $_url_params = $_url_params + array('gis_data[gis_type]' => strtoupper($column['pma_type'])); } $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert')); return '' . PMA_linkOrButton('#', $edit_str, array(), false, false, '_blank') . ''; } /** * get html for continue insertion form * * @param string $table name of the table * @param string $db name of the database * @param array $where_clause_array array of where clauses * @param string $err_url error url * * @return string an html snippet */ function PMA_getContinueInsertionForm($table, $db, $where_clause_array, $err_url) { $html_output = '
' . PMA_generate_common_hidden_inputs($db, $table) . '' . '' . ''; if (isset($_REQUEST['where_clause'])) { foreach ($where_clause_array as $key_id => $where_clause) { $html_output .= ''. "\n"; } } $tmp = '' . "\n"; $html_output .= "\n" . sprintf(__('Continue insertion with %s rows'), $tmp); unset($tmp); $html_output .= '
' . "\n"; return $html_output; } /** * Get action panel * * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * @param boolean $found_unique_key boolean variable for unique key * * @return string an html snippet */ function PMA_getActionsPanel($where_clause, $after_insert, $tabindex, $tabindex_for_value, $found_unique_key ) { $html_output = '
' . '' . '' . '' . '' . '' . ''; $html_output .='' . PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value) . '' . '
' . PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value) . "\n"; $html_output .= '' . '   ' . __('and then') . '   ' . '' . PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_key) . '
' . '
'; return $html_output; } /** * Get a HTML drop down for submit types * * @param array $where_clause where clause * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * * @return string an html snippet */ function PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value) { $html_output = ''; return $html_output; } /** * Get HTML drop down for after insert * * @param array $where_clause where clause * @param string $after_insert insert mode, e.g. new_insert, same_insert * @param string $after_insert a request parameter it can be 'edit_text', 'back' * @param boolean $found_unique_key boolean variable for unique key * * @return string an html snippet */ function PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_key) { $html_output = ''; return $html_output; } /** * get Submit button and Reset button for action panel * * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex * * @return string an html snippet */ function PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value) { return '' . PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere')) . '' . '' . '' . '' . ''; } /** * Get table head and table foot for insert row table * * @param array $url_params url parameters * * @return string an html snippet */ function PMA_getHeadAndFootOfInsertRowTable($url_params) { $html_output = '' . '' . '' . ''; if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) { $html_output .= PMA_showColumnTypesInDataEditView($url_params, true); } if ($GLOBALS['cfg']['ShowFunctionFields']) { $html_output .= PMA_showFunctionFieldsInEditMode($url_params, true); } $html_output .= '' . '' . '' . '' . ' ' . '' . '' . '' . ''; return $html_output; } /** * Prepares the field value and retrieve special chars, backup field and data array * * @param array $current_row a row of the table * @param array $column description of column in given table * @param array $extracted_columnspec associative array containing type, spec_in_brackets * and possibly enum_set_values (another array) * @param boolean $real_null_value whether column value null or not null * * @return array $real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded */ function PMA_getSpecialCharsAndBackupFieldForExistingRow($current_row, $column, $extracted_columnspec, $real_null_value, $gis_data_types, $column_name_appendix) { $special_chars_encoded = ''; // (we are editing) if (is_null($current_row[$column['Field']])) { $real_null_value = true; $current_row[$column['Field']] = ''; $special_chars = ''; $data = $current_row[$column['Field']]; } elseif ($column['True_Type'] == 'bit') { $special_chars = PMA_printable_bit_value( $current_row[$column['Field']], $extracted_columnspec['spec_in_brackets'] ); } elseif (in_array($column['True_Type'], $gis_data_types)) { // Convert gis data to Well Know Text format $current_row[$column['Field']] = PMA_asWKT($current_row[$column['Field']], true); $special_chars = htmlspecialchars($current_row[$column['Field']]); } else { // special binary "characters" if ($column['is_binary'] || ($column['is_blob'] && ! $GLOBALS['cfg']['ProtectBinary'])) { if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $GLOBALS['cfg']['ShowFunctionFields']) { $current_row[$column['Field']] = bin2hex($current_row[$column['Field']]); $column['display_binary_as_hex'] = true; } else { $current_row[$column['Field']] = PMA_replaceBinaryContents($current_row[$column['Field']]); } } // end if $special_chars = htmlspecialchars($current_row[$column['Field']]); //We need to duplicate the first \n or otherwise we will lose //the first newline entered in a VARCHAR or TEXT column $special_chars_encoded = PMA_duplicateFirstNewline($special_chars); $data = $current_row[$column['Field']]; } // end if... else... //when copying row, it is useful to empty auto-increment column to prevent duplicate key error if (isset($_REQUEST['default_action']) && $_REQUEST['default_action'] === 'insert') { if ($column['Key'] === 'PRI' && strpos($column['Extra'], 'auto_increment') !== false) { $data = $special_chars_encoded = $special_chars = null; } } // If a timestamp field value is not included in an update // statement MySQL auto-update it to the current timestamp; // however, things have changed since MySQL 4.1, so // it's better to set a fields_prev in this situation $backup_field = ''; return array($real_null_value, $special_chars_encoded, $special_chars, $data, $backup_field); } /** * display default values * * @param type $column description of column in given table * @param boolean $real_null_value whether column value null or not null * * @return array $real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded */ function PMA_getSpecialCharsAndBackupFieldForInsertingMode($column, $real_null_value) { if (! isset($column['Default'])) { $column['Default'] = ''; $real_null_value = true; $data = ''; } else { $data = $column['Default']; } if ($column['True_Type'] == 'bit') { $special_chars = PMA_convert_bit_default_value($column['Default']); } else { $special_chars = htmlspecialchars($column['Default']); } $backup_field = ''; $special_chars_encoded = PMA_duplicateFirstNewline($special_chars); // this will select the UNHEX function while inserting if (($column['is_binary'] || ($column['is_blob'] && ! $GLOBALS['cfg']['ProtectBinary'])) && (isset($_SESSION['tmp_user_values']['display_binary_as_hex']) && $_SESSION['tmp_user_values']['display_binary_as_hex']) && $GLOBALS['cfg']['ShowFunctionFields'] ) { $column['display_binary_as_hex'] = true; } return array($real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded); } /** * Prepares the update/insert of a row * * @return array $loop_array, $using_key, $is_insert, $is_insertignore */ function PMA_getParamsForUpdateOrInsert() { if (isset($_REQUEST['where_clause'])) { // we were editing something => use the WHERE clause $loop_array = (is_array($_REQUEST['where_clause']) ? $_REQUEST['where_clause'] : array($_REQUEST['where_clause'])); $using_key = true; $is_insert = $_REQUEST['submit_type'] == 'insert' || $_REQUEST['submit_type'] == 'showinsert' || $_REQUEST['submit_type'] == 'insertignore'; $is_insertignore = $_REQUEST['submit_type'] == 'insertignore'; } else { // new row => use indexes $loop_array = array(); foreach ($_REQUEST['fields']['multi_edit'] as $key => $dummy) { $loop_array[] = $key; } $using_key = false; $is_insert = true; $is_insertignore = false; } return array($loop_array, $using_key, $is_insert, $is_insertignore); } /** * check wether insert row mode and if so include tbl_changen script and set global variables. * * @return void */ function PMA_isInsertRow() { if (isset($_REQUEST['insert_rows']) && is_numeric($_REQUEST['insert_rows']) && $_REQUEST['insert_rows'] != $GLOBALS['cfg']['InsertRows'] ) { $GLOBALS['cfg']['InsertRows'] = $_REQUEST['insert_rows']; $GLOBALS['js_include'][] = 'tbl_change.js'; include_once 'libraries/header.inc.php'; include 'tbl_change.php'; exit; } } /** * set $_SESSION for edit_next * * @param string $one_where_clause one where clause from where clauses array * * @return void */ function PMA_setSessionForEditNext($one_where_clause) { $local_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($GLOBALS['table']) . ' WHERE ' . str_replace('` =', '` >', $one_where_clause) . ' LIMIT 1;'; $res = PMA_DBI_query($local_query); $row = PMA_DBI_fetch_row($res); $meta = PMA_DBI_get_fields_meta($res); // must find a unique condition based on unique key, // not a combination of all fields list($unique_condition, $clause_is_unique) = PMA_getUniqueCondition($res, count($meta), $meta, $row, true); if (! empty($unique_condition)) { $_SESSION['edit_next'] = $unique_condition; } unset($unique_condition, $clause_is_unique); } /** * set $goto_include varible for different cases and retrieve like, * if $GLOBALS['goto'] empty, if $goto_include previously not defined * and new_insert, same_insert, same_insert * * @param string $goto_include store some script for include, otherwise it is boolean false * @return string $goto_include */ function PMA_getGotoInclude($goto_include) { if (isset($_REQUEST['after_insert']) && in_array($_REQUEST['after_insert'], array('new_insert', 'same_insert', 'same_insert')) ) { $goto_include = 'tbl_change.php'; } elseif (! empty($GLOBALS['goto'])) { if (! preg_match('@^[a-z_]+\.php$@', $GLOBALS['goto'])) { // this should NOT happen //$GLOBALS['goto'] = false; $goto_include = false; } else { $goto_include = $GLOBALS['goto']; } if ($GLOBALS['goto'] == 'db_sql.php' && strlen($GLOBALS['table'])) { $GLOBALS['table'] = ''; } } if (! $goto_include) { if (! strlen($GLOBALS['table'])) { $goto_include = 'db_sql.php'; } else { $goto_include = 'tbl_sql.php'; } } return $goto_include; } /** * Defines the url to return in case of failure of the query * * @param array $url_params url parameters * @return string error url for query failure */ function PMA_getErrorUrl($url_params) { if (isset($_REQUEST['err_url'])) { return $_REQUEST['err_url']; } else { return 'tbl_change.php' . PMA_generate_common_url($url_params); } } /** * Builds the sql query * * @param boolean $is_insertignore $_REQUEST['submit_type'] == 'insertignore' * @param array $query_fields column names array * @param array $value_sets array of query values * @return string a query */ function PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets) { if ($is_insertignore) { $insert_command = 'INSERT IGNORE '; } else { $insert_command = 'INSERT '; } $query[] = $insert_command . 'INTO ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($GLOBALS['table']) . ' (' . implode(', ', $query_fields) . ') VALUES (' . implode('), (', $value_sets) . ')'; unset($insert_command, $query_fields); return $query; } /** * Executes the sql query and get the result, then move back to the calling page * * @param array $url_params url paramters array * @param string $query built query from PMA_buildSqlQuery() * @return array $url_params, $total_affected_rows, $last_messages * $warning_messages, $error_messages, $return_to_sql_query */ function PMA_executeSqlQuery($url_params, $query) { if (! empty($GLOBALS['sql_query'])) { $url_params['sql_query'] = $GLOBALS['sql_query']; $return_to_sql_query = $GLOBALS['sql_query']; } $GLOBALS['sql_query'] = implode('; ', $query) . ';'; // to ensure that the query is displayed in case of // "insert as new row" and then "insert another new row" $GLOBALS['display_query'] = $GLOBALS['sql_query']; $total_affected_rows = 0; $last_messages = array(); $warning_messages = array(); $error_messages = array(); foreach ($query as $single_query) { if ($_REQUEST['submit_type'] == 'showinsert') { $last_messages[] = PMA_Message::notice(__('Showing SQL query')); continue; } if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) { $result = PMA_DBI_try_query($single_query); } else { $result = PMA_DBI_query($single_query); } if (! $result) { $error_messages[] = PMA_Message::sanitize(PMA_DBI_getError()); } else { // The next line contains a real assignment, it's not a typo if ($tmp = @PMA_DBI_affected_rows()) { $total_affected_rows += $tmp; } unset($tmp); $insert_id = PMA_DBI_insert_id(); if ($insert_id != 0) { // insert_id is id of FIRST record inserted in one insert, so if we // inserted multiple rows, we had to increment this if ($total_affected_rows > 0) { $insert_id = $insert_id + $total_affected_rows - 1; } $last_message = PMA_Message::notice(__('Inserted row id: %1$d')); $last_message->addParam($insert_id); $last_messages[] = $last_message; } PMA_DBI_free_result($result); } $warning_messages = PMA_getWarningMessages(); } unset($result, $single_query, $last_message, $query); return array($url_params, $total_affected_rows, $last_messages, $warning_messages, $error_messages, $return_to_sql_query); } /** * get the warning messages array * * @return array $warning_essages */ function PMA_getWarningMessages() { $warning_essages = array(); foreach (PMA_DBI_get_warnings() as $warning) { $warning_essages[] = PMA_Message::sanitize( $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message'] ); } return $warning_essages; } ?>
' . __('Column') . ''. __('Null') . '' . __('Value') . '
' . '' . '