/** * retrieves table column info * * @return array table column nfo */ function get_tab_info() { PMA_DBI_select_db($GLOBALS['db']); $tab_column = array(); for ($i = 0, $cnt = count($GLOBALS['PMD']["TABLE_NAME"]); $i < $cnt; $i++) { $fields_rs = PMA_DBI_query(PMA_DBI_get_columns_sql($GLOBALS['db'], $GLOBALS['PMD']["TABLE_NAME_SMALL"][$i], null, true), null, PMA_DBI_QUERY_STORE); $j = 0; while ($row = PMA_DBI_fetch_assoc($fields_rs)) { $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_ID'][$j] = $j; $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_NAME'][$j] = $row['Field']; $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['TYPE'][$j] = $row['Type']; $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['NULLABLE'][$j] = $row['Null']; $j++; } } return $tab_column; }
/** * Returns all column names in given table * * @param string $database name of database * @param string $table name of table to retrieve columns from * @param mixed $link mysql link resource * * @return null|array */ function PMA_DBI_get_column_names($database, $table, $link = null) { $sql = PMA_DBI_get_columns_sql($database, $table); // We only need the 'Field' column which contains the table's column names $fields = array_keys(PMA_DBI_fetch_result($sql, 'Field', null, $link)); if (!is_array($fields) || count($fields) == 0) { return null; } return $fields; }
$dropdown .= ' selected="selected"'; } $dropdown .= '>' . $value . '</option>'; } $dropdown = '<select>' . $dropdown . '</select>'; $extra_data['dropdown'] = $dropdown; PMA_ajaxResponse(null, true, $extra_data); } /** * Find possible values for set fields during grid edit. */ if (isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) { $field_info_query = PMA_DBI_get_columns_sql($db, $table, $_REQUEST['column']); $field_info_result = PMA_DBI_fetch_result($field_info_query, null, null, null, PMA_DBI_QUERY_STORE); $selected_values = explode(',', $_REQUEST['curr_value']); $search = array('set', '(', ')', "'"); $values = explode(',', str_replace($search, '', $field_info_result[0]['Type'])); $select = ''; foreach ($values as $value) { $select .= '<option value="' . htmlspecialchars($value) . '"'; if (in_array($value, $selected_values, true)) { $select .= ' selected="selected"'; } $select .= '>' . $value . '</option>';
/** * Defines the relation parameters for the current user * just a copy of the functions used for relations ;-) * but added some stuff to check what will work * * @access protected * @return array the relation parameters for the current user */ function PMA__getRelationsParam() { $cfgRelation = array(); $cfgRelation['relwork'] = false; $cfgRelation['displaywork'] = false; $cfgRelation['bookmarkwork'] = false; $cfgRelation['pdfwork'] = false; $cfgRelation['commwork'] = false; $cfgRelation['mimework'] = false; $cfgRelation['historywork'] = false; $cfgRelation['recentwork'] = false; $cfgRelation['uiprefswork'] = false; $cfgRelation['trackingwork'] = false; $cfgRelation['designerwork'] = false; $cfgRelation['userconfigwork'] = false; $cfgRelation['allworks'] = false; $cfgRelation['user'] = null; $cfgRelation['db'] = null; if ($GLOBALS['server'] == 0 || empty($GLOBALS['cfg']['Server']['pmadb']) || !PMA_DBI_select_db($GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink'])) { // No server selected -> no bookmark table // we return the array with the falses in it, // to avoid some 'Unitialized string offset' errors later $GLOBALS['cfg']['Server']['pmadb'] = false; return $cfgRelation; } $cfgRelation['user'] = $GLOBALS['cfg']['Server']['user']; $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb']; // Now I just check if all tables that i need are present so I can for // example enable relations but not pdf... // I was thinking of checking if they have all required columns but I // fear it might be too slow $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($GLOBALS['cfg']['Server']['pmadb']); $tab_rs = PMA_query_as_controluser($tab_query, false, PMA_DBI_QUERY_STORE); if (!$tab_rs) { // query failed ... ? //$GLOBALS['cfg']['Server']['pmadb'] = false; return $cfgRelation; } while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) { if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) { $cfgRelation['bookmark'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) { $cfgRelation['relation'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_info']) { $cfgRelation['table_info'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) { $cfgRelation['table_coords'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['designer_coords']) { $cfgRelation['designer_coords'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['column_info']) { $cfgRelation['column_info'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) { $cfgRelation['pdf_pages'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) { $cfgRelation['history'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) { $cfgRelation['recent'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) { $cfgRelation['table_uiprefs'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) { $cfgRelation['tracking'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { $cfgRelation['userconfig'] = $curr_table[0]; } } // end while PMA_DBI_free_result($tab_rs); if (isset($cfgRelation['relation'])) { $cfgRelation['relwork'] = true; if (isset($cfgRelation['table_info'])) { $cfgRelation['displaywork'] = true; } } if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { $cfgRelation['pdfwork'] = true; } if (isset($cfgRelation['column_info'])) { $cfgRelation['commwork'] = true; if ($GLOBALS['cfg']['Server']['verbose_check']) { $mime_query = PMA_DBI_get_columns_sql($cfgRelation['db'], $cfgRelation['column_info']); $mime_rs = PMA_query_as_controluser($mime_query, false); $mime_field_mimetype = false; $mime_field_transformation = false; $mime_field_transformation_options = false; while ($curr_mime_field = @PMA_DBI_fetch_row($mime_rs)) { if ($curr_mime_field[0] == 'mimetype') { $mime_field_mimetype = true; } elseif ($curr_mime_field[0] == 'transformation') { $mime_field_transformation = true; } elseif ($curr_mime_field[0] == 'transformation_options') { $mime_field_transformation_options = true; } } PMA_DBI_free_result($mime_rs); if ($mime_field_mimetype && $mime_field_transformation && $mime_field_transformation_options) { $cfgRelation['mimework'] = true; } } else { $cfgRelation['mimework'] = true; } } if (isset($cfgRelation['history'])) { $cfgRelation['historywork'] = true; } if (isset($cfgRelation['recent'])) { $cfgRelation['recentwork'] = true; } if (isset($cfgRelation['table_uiprefs'])) { $cfgRelation['uiprefswork'] = true; } if (isset($cfgRelation['tracking'])) { $cfgRelation['trackingwork'] = true; } if (isset($cfgRelation['userconfig'])) { $cfgRelation['userconfigwork'] = true; } // we do not absolutely need that the internal relations or the PDF // schema feature be activated if (isset($cfgRelation['designer_coords'])) { $cfgRelation['designerwork'] = true; } if (isset($cfgRelation['bookmark'])) { $cfgRelation['bookmarkwork'] = true; } if ($cfgRelation['relwork'] && $cfgRelation['displaywork'] && $cfgRelation['pdfwork'] && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfgRelation['historywork'] && $cfgRelation['recentwork'] && $cfgRelation['uiprefswork'] && $cfgRelation['trackingwork'] && $cfgRelation['userconfigwork'] && $cfgRelation['bookmarkwork'] && $cfgRelation['designerwork']) { $cfgRelation['allworks'] = true; } return $cfgRelation; }
/** * Returns descriptions of columns in given table (all or given by $column) * * @param string $database name of database * @param string $table name of table to retrieve columns from * @param string $column name of column, null to show all columns * @param boolean $full whether to return full info or only column names * @param mixed $link mysql link resource * * @return false|array array indexed by column names or, * if $column is given, flat array description */ function PMA_DBI_get_columns($database, $table, $column = null, $full = false, $link = null) { $sql = PMA_DBI_get_columns_sql($database, $table, $column, $full); $fields = PMA_DBI_fetch_result($sql, 'Field', null, $link); if (!is_array($fields) || count($fields) == 0) { return null; } if (PMA_DRIZZLE) { // fix Key column, it's much simpler in PHP than in SQL $has_pk = false; $has_pk_candidates = false; foreach ($fields as $f) { if ($f['Key'] == 'PRI') { $has_pk = true; break; } else { if ($f['Null'] == 'NO' && ($f['Key'] == 'MUL' || $f['Key'] == 'UNI')) { $has_pk_candidates = true; } } } if (!$has_pk && $has_pk_candidates) { // check whether we can promote some unique index to PRI $sql = "\n SELECT i.index_name, p.column_name\n FROM data_dictionary.indexes i\n JOIN data_dictionary.index_parts p USING (table_schema, table_name)\n WHERE i.table_schema = '" . PMA_sqlAddSlashes($database) . "'\n AND i.table_name = '" . PMA_sqlAddSlashes($table) . "'\n AND i.is_unique\n AND NOT i.is_nullable"; $fs = PMA_DBI_fetch_result($sql, 'index_name', null, $link); $fs = $fs ? array_shift($fs) : array(); foreach ($fs as $f) { $fields[$f]['Key'] = 'PRI'; } } } return $column != null ? array_shift($fields) : $fields; }