/**
  * Test for PMA_getCentralColumnsFromTable with $allFields = true
  *
  * @return void
  */
 public function testPMAGetCentralColumnsFromTableWithAllFields()
 {
     $db = 'PMA_db';
     $table = 'PMA_table';
     $GLOBALS['dbi']->expects($this->at(3))->method('fetchResult')->with("SELECT * FROM `pma_central_columns` " . "WHERE db_name = 'PMA_db' AND col_name IN ('id','col1','col2');", null, null, $GLOBALS['controllink'])->will($this->returnValue(array_slice($this->_columnData, 0, 2)));
     $this->assertEquals(array_slice($this->_modifiedColumnData, 0, 2), PMA_getCentralColumnsFromTable($db, $table, true));
 }
$response->addHTML($tablestructure);
$response->addHTML(PMA_getHtmlForTableStructureHeader($db_is_system_schema, $tbl_is_view));
$response->addHTML('<tbody>');
// table body
// prepare comments
$comments_map = array();
$mime_map = array();
if ($GLOBALS['cfg']['ShowPropertyComments']) {
    include_once 'libraries/transformations.lib.php';
    $comments_map = PMA_getComments($db, $table);
    if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
        $mime_map = PMA_getMIME($db, $table, true);
    }
}
require_once 'libraries/central_columns.lib.php';
$central_list = PMA_getCentralColumnsFromTable($db, $table);
$rownum = 0;
$columns_list = array();
$save_row = array();
$odd_row = true;
foreach ($fields as $row) {
    $save_row[] = $row;
    $rownum++;
    $columns_list[] = $row['Field'];
    $type = $row['Type'];
    $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
    if ('set' == $extracted_columnspec['type'] || 'enum' == $extracted_columnspec['type']) {
        $type_nowrap = '';
    } else {
        $type_nowrap = ' class="nowrap"';
    }
 /**
  * Displays the table structure ('show table' works correct since 3.23.03)
  *
  * @param array           $cfgRelation               current relation parameters
  * @param array           $columns_with_unique_index Columns with unique index
  * @param mixed           $url_params                Contains an associative
  *                                                   array with url params
  * @param PMA_Index|false $primary_index             primary index or false if
  *                                                   no one exists
  * @param array           $fields                    Fields
  * @param array           $columns_with_index        Columns with index
  * @param array           $create_table_fields       Fields of the table.
  *
  * @return string
  */
 protected function displayStructure($cfgRelation, $columns_with_unique_index, $url_params, $primary_index, $fields, $columns_with_index, $create_table_fields)
 {
     /* TABLE INFORMATION */
     $HideStructureActions = '';
     if ($GLOBALS['cfg']['HideStructureActions'] === true) {
         $HideStructureActions .= ' HideStructureActions';
     }
     // prepare comments
     $comments_map = array();
     $mime_map = array();
     if ($GLOBALS['cfg']['ShowPropertyComments']) {
         include_once 'libraries/transformations.lib.php';
         $comments_map = PMA_getComments($this->db, $this->table);
         if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
             $mime_map = PMA_getMIME($this->db, $this->table, true);
         }
     }
     include_once 'libraries/central_columns.lib.php';
     $central_list = PMA_getCentralColumnsFromTable($this->db, $this->table);
     $columns_list = array();
     $titles = array('Change' => PMA_Util::getIcon('b_edit.png', __('Change')), 'Drop' => PMA_Util::getIcon('b_drop.png', __('Drop')), 'NoDrop' => PMA_Util::getIcon('b_drop.png', __('Drop')), 'Primary' => PMA_Util::getIcon('b_primary.png', __('Primary')), 'Index' => PMA_Util::getIcon('b_index.png', __('Index')), 'Unique' => PMA_Util::getIcon('b_unique.png', __('Unique')), 'Spatial' => PMA_Util::getIcon('b_spatial.png', __('Spatial')), 'IdxFulltext' => PMA_Util::getIcon('b_ftext.png', __('Fulltext')), 'NoPrimary' => PMA_Util::getIcon('bd_primary.png', __('Primary')), 'NoIndex' => PMA_Util::getIcon('bd_index.png', __('Index')), 'NoUnique' => PMA_Util::getIcon('bd_unique.png', __('Unique')), 'NoSpatial' => PMA_Util::getIcon('bd_spatial.png', __('Spatial')), 'NoIdxFulltext' => PMA_Util::getIcon('bd_ftext.png', __('Fulltext')), 'DistinctValues' => PMA_Util::getIcon('b_browse.png', __('Distinct values')));
     /**
      * Work on the table
      */
     if ($this->_tbl_is_view) {
         $item = $this->dbi->fetchSingleRow(sprintf("SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`,\n                      `SECURITY_TYPE`\n                    FROM `INFORMATION_SCHEMA`.`VIEWS`\n                    WHERE TABLE_SCHEMA='%s'\n                    AND TABLE_NAME='%s';", PMA_Util::sqlAddSlashes($this->db), PMA_Util::sqlAddSlashes($this->table)));
         $createView = $this->dbi->getTable($this->db, $this->table)->showCreate();
         // get algorithm from $createView of the form
         // CREATE ALGORITHM=<ALGORITHM> DE...
         $parts = explode(" ", substr($createView, 17));
         $item['ALGORITHM'] = $parts[0];
         $view = array('operation' => 'alter', 'definer' => $item['DEFINER'], 'sql_security' => $item['SECURITY_TYPE'], 'name' => $this->table, 'as' => $item['VIEW_DEFINITION'], 'with' => $item['CHECK_OPTION'], 'algorithm' => $item['ALGORITHM']);
         $edit_view_url = 'view_create.php' . PMA_URL_getCommon($url_params) . '&amp;' . implode('&amp;', array_map(function ($key, $val) {
             return 'view[' . urlencode($key) . ']=' . urlencode($val);
         }, array_keys($view), $view));
     }
     /**
      * Displays Space usage and row statistics
      */
     // BEGIN - Calc Table Space
     // Get valid statistics whatever is the table type
     if ($GLOBALS['cfg']['ShowStats']) {
         //get table stats in HTML format
         $tablestats = $this->getTableStats();
         //returning the response in JSON format to be used by Ajax
         $this->response->addJSON('tableStat', $tablestats);
     }
     // END - Calc Table Space
     return Template::get('table/structure/display_structure')->render(array('HideStructureActions' => $HideStructureActions, 'db' => $this->db, 'table' => $this->table, 'db_is_system_schema' => $this->_db_is_system_schema, 'tbl_is_view' => $this->_tbl_is_view, 'mime_map' => $mime_map, 'url_query' => $this->_url_query, 'titles' => $titles, 'tbl_storage_engine' => $this->_tbl_storage_engine, 'primary' => $primary_index, 'columns_with_unique_index' => $columns_with_unique_index, 'edit_view_url' => isset($edit_view_url) ? $edit_view_url : null, 'columns_list' => $columns_list, 'tablestats' => isset($tablestats) ? $tablestats : null, 'fields' => $fields, 'columns_with_index' => $columns_with_index, 'central_list' => $central_list, 'create_table_fields' => $create_table_fields));
 }
/**
 * build dropdown select html to select column in selected table,
 * include only columns which are not already in central list
 *
 * @param string $db           current database to which selected table belongs
 * @param string $selected_tbl selected table
 *
 * @return string html to select column
 */
function PMA_getHTMLforColumnDropdown($db, $selected_tbl)
{
    $existing_cols = PMA_getCentralColumnsFromTable($db, $selected_tbl);
    $GLOBALS['dbi']->selectDb($db, $GLOBALS['userlink']);
    $columns = (array) $GLOBALS['dbi']->getColumnNames($db, $selected_tbl, $GLOBALS['userlink']);
    $selectColHtml = "";
    foreach ($columns as $column) {
        if (!in_array($column, $existing_cols)) {
            $selectColHtml .= '<option value="' . htmlspecialchars($column) . '">' . htmlspecialchars($column) . '</option>';
        }
    }
    return $selectColHtml;
}
 /**
  * Test for PMA_getCentralColumnsFromTable
  *
  * @return void
  */
 public function testPMAGetCentralColumnsFromTable()
 {
     $db = 'PMA_db';
     $table = 'PMA_table';
     $this->assertEquals(array("id", "col1"), PMA_getCentralColumnsFromTable($db, $table));
     $this->assertEquals(array("id", "col1"), PMA_getCentralColumnsFromTable($db, $table, true));
 }