/**
 * get the html of the form to add the new column to given table
 *
 * @param integer $num_fields number of columns to add
 * @param string  $db         current database
 * @param string  $table      current table
 * @param array   $columnMeta array containing default values for the fields
 *
 * @return HTML
 */
function PMA_getHtmlForCreateNewColumn($num_fields, $db, $table, $columnMeta = array())
{
    $cfgRelation = PMA_getRelationsParam();
    $content_cells = array();
    $available_mime = array();
    $mime_map = array();
    if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
        $mime_map = PMA_getMIME($db, $table);
        $available_mime = PMA_getAvailableMIMEtypes();
    }
    $comments_map = PMA_getComments($db, $table);
    for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
        $content_cells[$columnNumber] = array('columnNumber' => $columnNumber, 'columnMeta' => $columnMeta, 'type_upper' => '', 'length_values_input_size' => 8, 'length' => '', 'extracted_columnspec' => array(), 'submit_attribute' => null, 'analyzed_sql' => null, 'comments_map' => $comments_map, 'fields_meta' => null, 'is_backup' => true, 'move_columns' => array(), 'cfgRelation' => $cfgRelation, 'available_mime' => isset($available_mime) ? $available_mime : array(), 'mime_map' => $mime_map);
    }
    return PMA\Template::get('columns_definitions/table_fields_definitions')->render(array('is_backup' => true, 'fields_meta' => null, 'mimework' => $cfgRelation['mimework'], 'content_cells' => $content_cells));
}
/**
 * Returns the html for Enable Statistics
 *
 * @param string $url_query Url query
 * @param string $html      html for database list
 *
 * @return string
 */
function PMA_getHtmlForNoticeEnableStatistics($url_query, $html)
{
    $notice = PMA_Message::notice(__('Note: Enabling the database statistics here might cause ' . 'heavy traffic between the web server and the MySQL server.'))->getDisplay();
    $html .= $notice;
    $items = array();
    $items[] = array('content' => '<strong>' . "\n" . __('Enable statistics') . '</strong><br />' . "\n", 'class' => 'li_switch_dbstats', 'url' => array('href' => 'server_databases.php' . $url_query . '&amp;dbstats=1', 'title' => __('Enable statistics')));
    include_once './libraries/Template.class.php';
    $html .= PMA\Template::get('list/unordered')->render(array('items' => $items));
    return $html;
}
/**
 * Shows form which allows to quickly load
 * settings stored in browser's local storage
 *
 * @return string
 */
function PMA_userprefsAutoloadGetHeader()
{
    if (isset($_REQUEST['prefs_autoload']) && $_REQUEST['prefs_autoload'] == 'hide') {
        $_SESSION['userprefs_autoload'] = true;
        return '';
    }
    $script_name = basename(basename($GLOBALS['PMA_PHP_SELF']));
    $return_url = htmlspecialchars($script_name . '?' . http_build_query($_GET, '', '&'));
    return PMA\Template::get('prefs_autoload')->render(array('hiddenInputs' => PMA_URL_getHiddenInputs(), 'return_url' => $return_url));
}
/**
 * Returns HTML for the query details panel
 *
 * @return string html
 */
function PMA_getQueryDetails()
{
    return PMA\Template::get('designer/query_details')->render();
}
Esempio n. 5
0
    if (isset($_REQUEST['add_favorite'])) {
        if (!$already_favorite) {
            // Otherwise add to favorite list.
            $favorite_table = $_REQUEST['favorite_table'];
            $fav_instance->add($db, $favorite_table);
        }
    }
    // Handle favorite table list. ----ENDS----
    list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow($i, $odd_row, $table_is_view, $current_table, $browse_table_label, $tracking_icon, $GLOBALS['replication_info']['slave']['status'], $browse_table, $tbl_url_query, $search_table, $db_is_system_schema, $titles, $empty_table, $drop_query, $drop_message, $collation, $formatted_size, $unit, $overhead, isset($create_time) ? $create_time : '', isset($update_time) ? $update_time : '', isset($check_time) ? $check_time : '', $is_show_stats, $ignored, $do, $colspan_for_structure);
    $overall_approx_rows = $overall_approx_rows || $approx_rows;
    $response->addHTML($html_output);
}
// end foreach
// Show Summary
$response->addHTML('</tbody>');
$response->addHTML(PMA\Template::get('structure/body_for_table_summary')->render(array('num_tables' => $num_tables, 'server_slave_status' => $GLOBALS['replication_info']['slave']['status'], 'db_is_system_schema' => $db_is_system_schema, 'sum_entries' => $sum_entries, 'db_collation' => $db_collation, 'is_show_stats' => $is_show_stats, 'sum_size' => $sum_size, 'overhead_size' => $overhead_size, 'create_time_all' => $create_time_all, 'update_time_all' => $update_time_all, 'check_time_all' => $check_time_all, 'approx_rows' => $overall_approx_rows)));
$response->addHTML('</table>');
//check all
$response->addHTML(PMA\Template::get('structure/check_all_tables')->render(array('pmaThemeImage' => $pmaThemeImage, 'text_dir' => $text_dir, 'overhead_check' => $overhead_check, 'db_is_system_schema' => $db_is_system_schema, 'hidden_fields' => $hidden_fields)));
$response->addHTML('</form>');
//end of form
// display again the table list navigator
$response->addHTML(PMA_Util::getListNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']));
$response->addHTML('</div><hr />');
/**
 * Work on the database
 */
/* DATABASE WORK */
/* Printable view of a table */
$response->addHTML(PMA\Template::get('structure/print_view_data_dictionary_link')->render(array('url_query' => $url_query)));
PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);
        if (isset($columnMeta['Field'])) {
            $form_params['field_orig[' . $columnNumber . ']'] = $columnMeta['Field'];
            if (isset($columnMeta['column_status']) && !$columnMeta['column_status']['isEditable']) {
                $form_params['field_name[' . $columnNumber . ']'] = $columnMeta['Field'];
            }
        } else {
            $form_params['field_orig[' . $columnNumber . ']'] = '';
        }
        // old column type
        if (isset($columnMeta['Type'])) {
            // keep in uppercase because the new type will be in uppercase
            $form_params['field_type_orig[' . $columnNumber . ']'] = mb_strtoupper($type);
            if (isset($columnMeta['column_status']) && !$columnMeta['column_status']['isEditable']) {
                $form_params['field_type[' . $columnNumber . ']'] = mb_strtoupper($type);
            }
        } else {
            $form_params['field_type_orig[' . $columnNumber . ']'] = '';
        }
        // old column length
        $form_params['field_length_orig[' . $columnNumber . ']'] = $length;
        // old column default
        $form_params = array_merge($form_params, array("field_default_value_orig[{$columnNumber}]" => Util\get($columnMeta, 'Default', ''), "field_default_type_orig[{$columnNumber}]" => Util\get($columnMeta, 'DefaultType', ''), "field_collation_orig[{$columnNumber}]" => Util\get($columnMeta, 'Collation', ''), "field_attribute_orig[{$columnNumber}]" => trim(Util\get($extracted_columnspec, 'attribute', '')), "field_null_orig[{$columnNumber}]" => Util\get($columnMeta, 'Null', ''), "field_extra_orig[{$columnNumber}]" => Util\get($columnMeta, 'Extra', ''), "field_comments_orig[{$columnNumber}]" => Util\get($columnMeta, 'Comment', '')));
    }
    $content_cells[$columnNumber] = array('columnNumber' => $columnNumber, 'columnMeta' => $columnMeta, 'type_upper' => mb_strtoupper($type), 'length_values_input_size' => $length_values_input_size, 'length' => $length, 'extracted_columnspec' => $extracted_columnspec, 'submit_attribute' => $submit_attribute, 'comments_map' => $comments_map, 'fields_meta' => isset($fields_meta) ? $fields_meta : null, 'is_backup' => $is_backup, 'move_columns' => $move_columns, 'cfgRelation' => $cfgRelation, 'available_mime' => $available_mime, 'mime_map' => isset($mime_map) ? $mime_map : array());
}
// end for
$html = PMA\Template::get('columns_definitions/column_definitions_form')->render(array('is_backup' => $is_backup, 'fields_meta' => isset($fields_meta) ? $fields_meta : null, 'mimework' => $cfgRelation['mimework'], 'action' => $action, 'form_params' => $form_params, 'content_cells' => $content_cells));
unset($form_params);
$response = PMA_Response::getInstance();
$response->getHeader()->getScripts()->addFiles(array('jquery/jquery.uitablefilter.js', 'indexes.js'));
$response->addHTML($html);
Esempio n. 7
0
/**
 * Add or remove favorite tables
 *
 * @param string $db current database
 *
 * @return void
 */
function PMA_addRemoveFavoriteTables($db)
{
    $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
    if (isset($_REQUEST['favorite_tables'])) {
        $favorite_tables = json_decode($_REQUEST['favorite_tables'], true);
    } else {
        $favorite_tables = array();
    }
    // Required to keep each user's preferences separate.
    $user = sha1($GLOBALS['cfg']['Server']['user']);
    // Request for Synchronization of favorite tables.
    if (isset($_REQUEST['sync_favorite_tables'])) {
        PMA_synchronizeFavoriteTables($fav_instance, $user, $favorite_tables);
        exit;
    }
    $changes = true;
    $msg = '';
    $titles = PMA_Util::buildActionTitles();
    $favorite_table = $_REQUEST['favorite_table'];
    $already_favorite = PMA_checkFavoriteTable($db, $favorite_table);
    if (isset($_REQUEST['remove_favorite'])) {
        if ($already_favorite) {
            // If already in favorite list, remove it.
            $fav_instance->remove($db, $favorite_table);
        }
    } elseif (isset($_REQUEST['add_favorite'])) {
        if (!$already_favorite) {
            if (count($fav_instance->getTables()) == $GLOBALS['cfg']['NumFavoriteTables']) {
                $changes = false;
                $msg = '<div class="error"><img src="themes/dot.gif" ' . 'title="" alt="" class="icon ic_s_error" />' . __("Favorite List is full!") . '</div>';
            } else {
                // Otherwise add to favorite list.
                $fav_instance->add($db, $favorite_table);
            }
        }
    }
    $favorite_tables[$user] = $fav_instance->getTables();
    $ajax_response = PMA_Response::getInstance();
    $ajax_response->addJSON('changes', $changes);
    if ($changes) {
        $ajax_response->addJSON('user', $user);
        $ajax_response->addJSON('favorite_tables', json_encode($favorite_tables));
        $ajax_response->addJSON('list', $fav_instance->getHtmlList());
        $ajax_response->addJSON('anchor', PMA\Template::get('structure/favorite_anchor')->render(array('db' => $db, 'current_table' => array('TABLE_NAME' => $favorite_table), 'titles' => $titles)));
    } else {
        $ajax_response->addJSON('message', $msg);
    }
}
Esempio n. 8
0
/**
 * prints out diagnostic info for pma relation feature
 *
 * @param array $cfgRelation Relation configuration
 *
 * @return string
 */
function PMA_getRelationsParamDiagnostic($cfgRelation)
{
    $retval = '<br>';
    $messages = array();
    $messages['error'] = '<font color="red"><strong>' . __('not OK') . '</strong></font>';
    $messages['ok'] = '<font color="green"><strong>' . _pgettext('Correctly working', 'OK') . '</strong></font>';
    $messages['enabled'] = '<font color="green">' . __('Enabled') . '</font>';
    $messages['disabled'] = '<font color="red">' . __('Disabled') . '</font>';
    if (empty($cfgRelation['db'])) {
        $retval .= __('Configuration of pmadb… ') . $messages['error'] . PMA_Util::showDocu('setup', 'linked-tables') . '<br />' . "\n" . __('General relation features') . ' <font color="green">' . __('Disabled') . '</font>' . "\n";
        if ($GLOBALS['cfg']['ZeroConf']) {
            if (empty($GLOBALS['db'])) {
                $retval .= PMA_getHtmlFixPMATables(true, true);
            } else {
                $retval .= PMA_getHtmlFixPMATables(true);
            }
        }
    } else {
        $retval .= '<table>' . "\n";
        if (!$cfgRelation['allworks'] && $GLOBALS['cfg']['ZeroConf'] && PMA_arePmadbTablesDefined()) {
            $retval .= PMA_getHtmlFixPMATables(false);
            $retval .= '<br />';
        }
        $retval .= PMA_getDiagMessageForParameter('pmadb', $cfgRelation['db'], $messages, 'pmadb');
        $retval .= PMA_getDiagMessageForParameter('relation', isset($cfgRelation['relation']), $messages, 'relation');
        $retval .= PMA_getDiagMessageForFeature(__('General relation features'), 'relwork', $messages);
        $retval .= PMA_getDiagMessageForParameter('table_info', isset($cfgRelation['table_info']), $messages, 'table_info');
        $retval .= PMA_getDiagMessageForFeature(__('Display Features'), 'displaywork', $messages);
        $retval .= PMA_getDiagMessageForParameter('table_coords', isset($cfgRelation['table_coords']), $messages, 'table_coords');
        $retval .= PMA_getDiagMessageForParameter('pdf_pages', isset($cfgRelation['pdf_pages']), $messages, 'pdf_pages');
        $retval .= PMA_getDiagMessageForFeature(__('Designer and creation of PDFs'), 'pdfwork', $messages);
        $retval .= PMA_getDiagMessageForParameter('column_info', isset($cfgRelation['column_info']), $messages, 'column_info');
        $retval .= PMA_getDiagMessageForFeature(__('Displaying Column Comments'), 'commwork', $messages, false);
        $retval .= PMA_getDiagMessageForFeature(__('Browser transformation'), 'mimework', $messages);
        if ($cfgRelation['commwork'] && !$cfgRelation['mimework']) {
            $retval .= '<tr><td colspan=2 class="left error">';
            $retval .= __('Please see the documentation on how to' . ' update your column_info table. ');
            $retval .= PMA_Util::showDocu('config', 'cfg_Servers_column_info');
            $retval .= '</td></tr>';
        }
        $retval .= PMA_getDiagMessageForParameter('bookmarktable', isset($cfgRelation['bookmark']), $messages, 'bookmark');
        $retval .= PMA_getDiagMessageForFeature(__('Bookmarked SQL query'), 'bookmarkwork', $messages);
        $retval .= PMA_getDiagMessageForParameter('history', isset($cfgRelation['history']), $messages, 'history');
        $retval .= PMA_getDiagMessageForFeature(__('SQL history'), 'historywork', $messages);
        $retval .= PMA_getDiagMessageForParameter('recent', isset($cfgRelation['recent']), $messages, 'recent');
        $retval .= PMA_getDiagMessageForFeature(__('Persistent recently used tables'), 'recentwork', $messages);
        $retval .= PMA_getDiagMessageForParameter('favorite', isset($cfgRelation['favorite']), $messages, 'favorite');
        $retval .= PMA_getDiagMessageForFeature(__('Persistent favorite tables'), 'favoritework', $messages);
        $retval .= PMA_getDiagMessageForParameter('table_uiprefs', isset($cfgRelation['table_uiprefs']), $messages, 'table_uiprefs');
        $retval .= PMA_getDiagMessageForFeature(__('Persistent tables\' UI preferences'), 'uiprefswork', $messages);
        $retval .= PMA_getDiagMessageForParameter('tracking', isset($cfgRelation['tracking']), $messages, 'tracking');
        $retval .= PMA_getDiagMessageForFeature(__('Tracking'), 'trackingwork', $messages);
        $retval .= PMA_getDiagMessageForParameter('userconfig', isset($cfgRelation['userconfig']), $messages, 'userconfig');
        $retval .= PMA_getDiagMessageForFeature(__('User preferences'), 'userconfigwork', $messages);
        $retval .= PMA_getDiagMessageForParameter('users', isset($cfgRelation['users']), $messages, 'users');
        $retval .= PMA_getDiagMessageForParameter('usergroups', isset($cfgRelation['usergroups']), $messages, 'usergroups');
        $retval .= PMA_getDiagMessageForFeature(__('Configurable menus'), 'menuswork', $messages);
        $retval .= PMA_getDiagMessageForParameter('navigationhiding', isset($cfgRelation['navigationhiding']), $messages, 'navigationhiding');
        $retval .= PMA_getDiagMessageForFeature(__('Hide/show navigation items'), 'navwork', $messages);
        $retval .= PMA_getDiagMessageForParameter('savedsearches', isset($cfgRelation['savedsearches']), $messages, 'savedsearches');
        $retval .= PMA_getDiagMessageForFeature(__('Saving Query-By-Example searches'), 'savedsearcheswork', $messages);
        $retval .= PMA_getDiagMessageForParameter('central_columns', isset($cfgRelation['central_columns']), $messages, 'central_columns');
        $retval .= PMA_getDiagMessageForFeature(__('Managing Central list of columns'), 'centralcolumnswork', $messages);
        $retval .= PMA_getDiagMessageForParameter('designer_settings', isset($cfgRelation['designer_settings']), $messages, 'designer_settings');
        $retval .= PMA_getDiagMessageForFeature(__('Remembering Designer Settings'), 'designersettingswork', $messages);
        $retval .= PMA_getDiagMessageForParameter('export_templates', isset($cfgRelation['export_templates']), $messages, 'export_templates');
        $retval .= PMA_getDiagMessageForFeature(__('Saving export templates'), 'exporttemplateswork', $messages);
        $retval .= '</table>' . "\n";
        if (!$cfgRelation['allworks']) {
            $retval .= '<p>' . __('Quick steps to set up advanced features:') . '</p>';
            $items = array();
            $items[] = sprintf(__('Create the needed tables with the ' . '<code>%screate_tables.sql</code>.'), htmlspecialchars(SQL_DIR)) . ' ' . PMA_Util::showDocu('setup', 'linked-tables');
            $items[] = __('Create a pma user and give access to these tables.') . ' ' . PMA_Util::showDocu('config', 'cfg_Servers_controluser');
            $items[] = __('Enable advanced features in configuration file ' . '(<code>config.inc.php</code>), for example by ' . 'starting from <code>config.sample.inc.php</code>.') . ' ' . PMA_Util::showDocu('setup', 'quick-install');
            $items[] = __('Re-login to phpMyAdmin to load the updated configuration file.');
            include_once './libraries/Template.class.php';
            $retval .= PMA\Template::get('list/unordered')->render(array('items' => $items));
        }
    }
    return $retval;
}
/**
 * prints list item for main page
 *
 * @param string $name            displayed text
 * @param string $listId          id, used for css styles
 * @param string $url             make item as link with $url as target
 * @param string $mysql_help_page display a link to MySQL's manual
 * @param string $target          special target for $url
 * @param string $a_id            id for the anchor,
 *                                used for jQuery to hook in functions
 * @param string $class           class for the li element
 * @param string $a_class         class for the anchor element
 *
 * @return void
 */
function PMA_printListItem($name, $listId = null, $url = null, $mysql_help_page = null, $target = null, $a_id = null, $class = null, $a_class = null)
{
    echo PMA\Template::get('list/item')->render(array('content' => $name, 'id' => $listId, 'class' => $class, 'url' => array('href' => $url, 'target' => $target, 'id' => $a_id, 'class' => $a_class), 'mysql_help_page' => $mysql_help_page));
}
Esempio n. 10
0
 /**
  * Test for render
  *
  * @return void
  */
 public function testDynamicRender()
 {
     $this->assertEquals('value', PMA\Template::get('test/echo')->render(array('variable' => 'value')));
 }
$response->addHTML('</tbody></table>');
$response->addHTML(PMA\Template::get('structure/check_all_table_column')->render(array('pmaThemeImage' => $pmaThemeImage, 'text_dir' => $text_dir, 'tbl_is_view' => $tbl_is_view, 'db_is_system_schema' => $db_is_system_schema, 'tbl_storage_engine' => $tbl_storage_engine)));
$response->addHTML('</form><hr class="print_ignore"/>');
$response->addHTML(PMA\Template::get('structure/move_columns_dialog')->render());
/**
 * Work on the table
 */
$response->addHTML('<div id="structure-action-links">');
if ($tbl_is_view) {
    $response->addHTML(PMA_getHtmlForEditView($url_params));
}
$response->addHTML(PMA\Template::get('structure/optional_action_links')->render(array('url_query' => $url_query, 'tbl_is_view' => $tbl_is_view, 'db_is_system_schema' => $db_is_system_schema)));
$response->addHTML('</div>');
if (!$tbl_is_view && !$db_is_system_schema) {
    $response->addHTML('<br />');
    $response->addHTML(PMA\Template::get('structure/add_column')->render(array('columns_list' => $columns_list)));
}
/**
 * Displays indexes
 */
if (!$tbl_is_view && !$db_is_system_schema && 'ARCHIVE' != $tbl_storage_engine) {
    //return the list of index
    $response->addJSON('indexes_list', PMA_Index::getHtmlForIndexes($GLOBALS['table'], $GLOBALS['db']));
    $response->addHTML(PMA_getHtmlForDisplayIndexes());
}
/**
 * Displays Space usage and row statistics
 */
// BEGIN - Calc Table Space
// Get valid statistics whatever is the table type
if ($cfg['ShowStats']) {
Esempio n. 12
0
 /**
  * Returns HTML for previewing strings found and their replacements
  *
  * @param int     $columnIndex index of the column
  * @param string  $find        string to find in the column
  * @param string  $replaceWith string to replace with
  * @param boolean $useRegex    to use Regex replace or not
  * @param string  $charSet     character set of the connection
  *
  * @return string HTML for previewing strings found and their replacements
  */
 function getReplacePreview($columnIndex, $find, $replaceWith, $useRegex, $charSet)
 {
     $column = $this->_columnNames[$columnIndex];
     if ($useRegex) {
         $result = $this->_getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet);
     } else {
         $sql_query = "SELECT " . PMA_Util::backquote($column) . "," . " REPLACE(" . PMA_Util::backquote($column) . ", '" . $find . "', '" . $replaceWith . "')," . " COUNT(*)" . " FROM " . PMA_Util::backquote($this->_db) . "." . PMA_Util::backquote($this->_table) . " WHERE " . PMA_Util::backquote($column) . " LIKE '%" . $find . "%' COLLATE " . $charSet . "_bin";
         // here we
         // change the collation of the 2nd operand to a case sensitive
         // binary collation to make sure that the comparison
         // is case sensitive
         $sql_query .= " GROUP BY " . PMA_Util::backquote($column) . " ORDER BY " . PMA_Util::backquote($column) . " ASC";
         $result = $GLOBALS['dbi']->fetchResult($sql_query, 0);
     }
     return PMA\Template::get('table/replace_preview')->render(array('db' => $this->_db, 'table' => $this->_table, 'columnIndex' => $columnIndex, 'find' => $find, 'replaceWith' => $replaceWith, 'useRegex' => $useRegex, 'result' => $result));
 }
Esempio n. 13
0
        $add_fields = count($_REQUEST['index']['columns']['names']) - $index->getColumnCount();
    }
    if (isset($_REQUEST['add_fields'])) {
        $add_fields += $_REQUEST['added_fields'];
    }
} elseif (isset($_REQUEST['create_index'])) {
    $add_fields = $_REQUEST['added_fields'];
}
// end preparing form values
// Get fields and stores their name/type
if (isset($_REQUEST['create_edit_table'])) {
    $fields = json_decode($_REQUEST['columns'], true);
    $index_params = array('Non_unique' => $_REQUEST['index']['Index_choice'] == 'UNIQUE' ? '0' : '1');
    $index->set($index_params);
    $add_fields = count($fields);
} else {
    $fields = $GLOBALS['dbi']->getTable($db, $table)->getNameAndTypeOfTheColumns();
}
$form_params = array('db' => $db, 'table' => $table);
if (isset($_REQUEST['create_index'])) {
    $form_params['create_index'] = 1;
} elseif (isset($_REQUEST['old_index'])) {
    $form_params['old_index'] = $_REQUEST['old_index'];
} elseif (isset($_REQUEST['index'])) {
    $form_params['old_index'] = $_REQUEST['index'];
}
$response = PMA_Response::getInstance();
$response->addHTML(PMA\Template::get('index_form')->render(array('fields' => $fields, 'index' => $index, 'form_params' => $form_params, 'add_fields' => $add_fields)));
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('indexes.js');
            }
            if (PMA_isValid($_REQUEST['subpartition_count'], 'numeric') && $_REQUEST['subpartition_count'] > 1 && $partitionDetails['can_have_subpartitions'] == true) {
                // Has subpartitions
                $partition['subpartition_count'] = $_REQUEST['subpartition_count'];
                if (!isset($partition['subpartitions'])) {
                    $partition['subpartitions'] = array();
                }
                $subpartitions =& $partition['subpartitions'];
                // Remove details of the additional subpartitions
                // when number of subpartitions have been reduced
                array_splice($subpartitions, $_REQUEST['subpartition_count']);
                for ($j = 0; $j < $_REQUEST['subpartition_count']; $j++) {
                    if (!isset($subpartitions[$j])) {
                        // Newly added subpartition
                        $subpartitions[$j] = array('engine' => '', 'comment' => '', 'data_directory' => '', 'index_directory' => '', 'max_rows' => '', 'min_rows' => '', 'tablespace' => '', 'node_group' => '');
                    }
                    $subpartition =& $subpartitions[$j];
                    $subpartition['name'] = 'p' . $i . 's' . $j;
                    $subpartition['prefix'] = 'partitions[' . $i . ']' . '[subpartitions][' . $j . ']';
                }
            } else {
                // No subpartitions
                unset($partition['subpartitions']);
                unset($partition['subpartition_count']);
            }
        }
        $partitionDetails['partitions'] = $partitions;
    }
}
echo PMA\Template::get('columns_definitions/partitions')->render(array('partitionDetails' => $partitionDetails));
Esempio n. 15
0
/**
 * Displays JavaScript code
 *
 * @param array $js_array lines of javascript code
 *
 * @return string
 */
function PMA_displayJavascript($js_array)
{
    if (empty($js_array)) {
        return null;
    }
    include_once './libraries/Template.class.php';
    return PMA\Template::get('javascript/display')->render(array('js_array' => $js_array));
}
Esempio n. 16
0
}
// end if
// If we did an update, refresh our data
if (isset($_POST['destination_db']) && $cfgRelation['relwork']) {
    $existrel = PMA_getForeigners($db, $table, '', 'internal');
}
if (isset($_POST['destination_foreign_db']) && PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
    $existrel_foreign = PMA_getForeigners($db, $table, '', 'foreign');
}
if ($cfgRelation['displaywork']) {
    $disp = PMA_getDisplayField($db, $table);
}
// display secondary level tabs if necessary
$engine = PMA_Table::sGetStatusInfo($db, $table, 'ENGINE');
$response->addHTML(PMA_getStructureSecondaryTabs($engine));
$response->addHTML('<div id="structure_content">');
/**
 * Dialog
 */
// Now find out the columns of our $table
// need to use PMA_DatabaseInterface::QUERY_STORE with $GLOBALS['dbi']->numRows()
// in mysqli
$columns = $GLOBALS['dbi']->getColumns($db, $table);
// common form
$html_output .= PMA\Template::get('tbl_relation/common_form')->render(array('db' => $db, 'table' => $table, 'columns' => $columns, 'cfgRelation' => $cfgRelation, 'tbl_storage_engine' => $tbl_storage_engine, 'existrel' => isset($existrel) ? $existrel : array(), 'existrel_foreign' => isset($existrel_foreign) ? $existrel_foreign['foreign_keys_data'] : array(), 'options_array' => $options_array));
if (PMA_Util::isForeignKeySupported($tbl_storage_engine)) {
    $html_output .= PMA_getHtmlForDisplayIndexes();
}
// Render HTML output
$response->addHTML($html_output);
$response->addHTML('</div>');
Esempio n. 17
0
 case 'check_tbl':
 case 'optimize_tbl':
 case 'repair_tbl':
 case 'analyze_tbl':
 case 'checksum_tbl':
     $query_type = $submit_mult;
     unset($submit_mult);
     $mult_btn = __('Yes');
     break;
 case 'export':
     unset($submit_mult);
     include 'db_export.php';
     exit;
     break;
 case 'show_create':
     $show_create = PMA\Template::get('structure/show_create')->render(array('db' => $GLOBALS['db'], 'db_objects' => $selected));
     // Send response to client.
     $response = PMA_Response::getInstance();
     $response->addJSON('message', $show_create);
     exit;
 case 'sync_unique_columns_central_list':
     include_once 'libraries/central_columns.lib.php';
     $centralColsError = PMA_syncUniqueColumns($selected);
     break;
 case 'delete_unique_columns_central_list':
     include_once 'libraries/central_columns.lib.php';
     $centralColsError = PMA_deleteColumnsFromList($selected);
     break;
 case 'make_consistent_with_central_list':
     include_once 'libraries/central_columns.lib.php';
     $centralColsError = PMA_makeConsistentWithList($GLOBALS['db'], $selected);
}
// build user preferences menu
$form_param = isset($_GET['form']) ? $_GET['form'] : null;
if (!isset($forms[$form_param])) {
    $forms_keys = array_keys($forms);
    $form_param = array_shift($forms_keys);
}
$tabs_icons = array('Features' => 'b_tblops.png', 'Sql_queries' => 'b_sql.png', 'Navi_panel' => 'b_select.png', 'Main_panel' => 'b_props.png', 'Import' => 'b_import.png', 'Export' => 'b_export.png');
require_once './libraries/Template.class.php';
$content = PMA_Util::getHtmlTab(array('link' => 'prefs_manage.php', 'text' => __('Manage your settings'))) . "\n";
$script_name = basename($GLOBALS['PMA_PHP_SELF']);
foreach (array_keys($forms) as $formset) {
    $tab = array('link' => 'prefs_forms.php', 'text' => PMA_lang('Form_' . $formset), 'icon' => $tabs_icons[$formset], 'active' => $script_name == 'prefs_forms.php' && $formset == $form_param);
    $content .= PMA_Util::getHtmlTab($tab, array('form' => $formset)) . "\n";
}
echo PMA\Template::get('list/unordered')->render(array('id' => 'topmenu2', 'class' => 'user_prefs_tabs', 'content' => $content));
echo '<div class="clearfloat"></div>';
// show "configuration saved" message and reload navigation panel if needed
if (!empty($_GET['saved'])) {
    PMA_Message::rawSuccess(__('Configuration has been saved.'))->display();
}
/* debug code
$arr = $cf->getConfigArray();
$arr2 = array();
foreach ($arr as $k => $v) {
    $arr2[] = "<b>$k</b> " . var_export($v, true);
}
$arr2 = implode(', ', $arr2);
$arr2 .= '<br />Blacklist: ' . (empty($cfg['UserprefsDisallow'])
        ? '<i>empty</i>'
        : implode(', ', $cfg['UserprefsDisallow']));
/**
 * build html for adding a new user defined column to central list
 *
 * @param string $db current database
 *
 * @return html of the form to let user add a new user defined column to the list
 */
function PMA_getHTMLforAddNewColumn($db)
{
    $addNewColumn = '<div id="add_col_div"><a href="#">' . '<span>+</span> ' . __('Add new column') . '</a>' . '<form id="add_new" style="min-width:100%;display:none" ' . 'method="post" action="db_central_columns.php">' . PMA_URL_getHiddenInputs($db) . '<input type="hidden" name="add_new_column" value="add_new_column">' . '<table>';
    $addNewColumn .= PMA_getCentralColumnsTableHeader();
    $addNewColumn .= '<tr>' . '<td></td>' . '<td name="col_name" class="nowrap">' . PMA\Template::get('columns_definitions/column_name')->render(array('columnNumber' => 0, 'ci' => 0, 'ci_offset' => 0, 'columnMeta' => array(), 'cfgRelation' => array('centralcolumnswork' => false))) . '</td>' . '<td name = "col_type" class="nowrap">' . PMA\Template::get('columns_definitions/column_type')->render(array('columnNumber' => 0, 'ci' => 1, 'ci_offset' => 0, 'type_upper' => '', 'columnMeta' => array())) . '</td>' . '<td class="nowrap" name="col_length">' . PMA\Template::get('columns_definitions/column_length')->render(array('columnNumber' => 0, 'ci' => 2, 'ci_offset' => 0, 'length_values_input_size' => 8, 'length_to_display' => '')) . '</td>' . '<td class="nowrap" name="col_default">' . PMA\Template::get('columns_definitions/column_default')->render(array('columnNumber' => 0, 'ci' => 3, 'ci_offset' => 0, 'type_upper' => '', 'columnMeta' => array())) . '</td>' . '<td name="collation" class="nowrap">' . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'field_collation[0]', 'field_0_4', null, false) . '</td>' . '<td class="nowrap" name="col_attribute">' . PMA\Template::get('columns_definitions/column_attribute')->render(array('columnNumber' => 0, 'ci' => 5, 'ci_offset' => 0, 'extracted_columnspec' => array(), 'columnMeta' => array(), 'submit_attribute' => false)) . '</td>' . '<td class="nowrap" name="col_isNull">' . PMA\Template::get('columns_definitions/column_null')->render(array('columnNumber' => 0, 'ci' => 6, 'ci_offset' => 0, 'columnMeta' => array())) . '</td>' . '<td class="nowrap" name="col_extra">' . PMA\Template::get('columns_definitions/column_extra')->render(array('columnNumber' => 0, 'ci' => 7, 'ci_offset' => 0, 'columnMeta' => array())) . '</td>' . ' <td>' . '<input id="add_column_save" type="submit" ' . ' value="Save"/></td>' . '</tr>';
    $addNewColumn .= '</table></form></div>';
    return $addNewColumn;
}
/**
 * generates the error report form to collect user description and preview the
 * report before being sent
 *
 * @return String the form
 */
function PMA_getErrorReportForm()
{
    $datas = array('report_data' => PMA_getPrettyReportData(), 'hidden_inputs' => PMA_URL_getHiddenInputs(), 'hidden_fields' => null);
    $reportData = PMA_getReportData();
    if (!empty($reportData)) {
        $datas['hidden_fields'] = PMA_getHiddenFields($reportData);
    }
    include_once './libraries/Template.class.php';
    return PMA\Template::get('error/report_form')->render($datas);
}
/**
 * Returns the html for create table.
 *
 * @param string $db database name
 *
 * @return string
 */
function PMA_getHtmlForCreateTable($db)
{
    return PMA\Template::get('database/create_table')->render(array('db' => $db));
}
Esempio n. 22
0
/**
 * Send HTTP header, taking IIS limits into account (600 seems ok)
 *
 * @param string $uri         the header to send
 * @param bool   $use_refresh whether to use Refresh: header when running on IIS
 *
 * @return boolean  always true
 */
function PMA_sendHeaderLocation($uri, $use_refresh = false)
{
    if (PMA_IS_IIS && mb_strlen($uri) > 600) {
        include_once './libraries/js_escape.lib.php';
        PMA_Response::getInstance()->disable();
        include_once './libraries/Template.class.php';
        echo PMA\Template::get('header_location')->render(array('uri' => $uri));
        return;
    }
    if (SID) {
        if (mb_strpos($uri, '?') === false) {
            header('Location: ' . $uri . '?' . SID);
        } else {
            $separator = PMA_URL_getArgSeparator();
            header('Location: ' . $uri . $separator . SID);
        }
        return;
    }
    session_write_close();
    if (headers_sent()) {
        if (function_exists('debug_print_backtrace')) {
            echo '<pre>';
            debug_print_backtrace();
            echo '</pre>';
        }
        trigger_error('PMA_sendHeaderLocation called when headers are already sent!', E_USER_ERROR);
    }
    // bug #1523784: IE6 does not like 'Refresh: 0', it
    // results in a blank page
    // but we need it when coming from the cookie login panel)
    if (PMA_IS_IIS && $use_refresh) {
        header('Refresh: 0; ' . $uri);
    } else {
        header('Location: ' . $uri);
    }
}
/**
 * Get a HTML table for display user's tabel specific or database specific rights
 *
 * @param string $username username
 * @param string $hostname host name
 * @param string $type     database, table or routine
 * @param string $dbname   database name
 *
 * @return array $html_output
 */
function PMA_getHtmlForAllTableSpecificRights($username, $hostname, $type, $dbname = '')
{
    $uiData = array('database' => array('formId' => 'database_specific_priv', 'subMenuLabel' => __('Database'), 'legend' => __('Database-specific privileges'), 'typeLabel' => __('Database')), 'table' => array('formId' => 'table_specific_priv', 'subMenuLabel' => __('Table'), 'legend' => __('Table-specific privileges'), 'typeLabel' => __('Table')), 'routine' => array('formId' => 'routine_specific_priv', 'subMenuLabel' => __('Routine'), 'legend' => __('Routine-specific privileges'), 'typeLabel' => __('Routine')));
    /**
     * no db name given, so we want all privs for the given user
     * db name was given, so we want all user specific rights for this db
     */
    $db_rights = PMA_getUserSpecificRights($username, $hostname, $type, $dbname);
    ksort($db_rights);
    $foundRows = array();
    $privileges = array();
    foreach ($db_rights as $row) {
        $onePrivilege = array();
        $paramDbName = '';
        $paramTableName = '';
        $paramRoutineName = '';
        if ($type == 'database') {
            $name = $row['Db'];
            $onePrivilege['grant'] = $row['Grant_priv'] == 'Y';
            $onePrivilege['tablePrivs'] = !empty($row['Table_priv']) || !empty($row['Column_priv']);
            $onePrivilege['privileges'] = join(',', PMA_extractPrivInfo($row, true));
            $paramDbName = $row['Db'];
        } elseif ($type == 'table') {
            $name = $row['Table_name'];
            $onePrivilege['grant'] = in_array('Grant', explode(',', $row['Table_priv']));
            $onePrivilege['columnPrivs'] = !empty($row['Column_priv']);
            $onePrivilege['privileges'] = join(',', PMA_extractPrivInfo($row, true));
            $paramDbName = $dbname;
            $paramTableName = $row['Table_name'];
        } else {
            // routine
            $name = $row['Routine_name'];
            $onePrivilege['grant'] = in_array('Grant', explode(',', $row['Proc_priv']));
            $privs = array('Alter_routine_priv' => 'N', 'Execute_priv' => 'N', 'Grant_priv' => 'N');
            foreach (explode(',', $row['Proc_priv']) as $priv) {
                if ($priv == 'Alter Routine') {
                    $privs['Alter_routine_priv'] = 'Y';
                } else {
                    $privs[$priv . '_priv'] = 'Y';
                }
            }
            $onePrivilege['privileges'] = join(',', PMA_extractPrivInfo($privs, true));
            $paramDbName = $dbname;
            $paramRoutineName = $row['Routine_name'];
        }
        $foundRows[] = $name;
        $onePrivilege['name'] = $name;
        $onePrivilege['editLink'] = '';
        if ($GLOBALS['is_grantuser']) {
            $onePrivilege['editLink'] = PMA_getUserLink('edit', $username, $hostname, $paramDbName, $paramTableName, $paramRoutineName);
        }
        $onePrivilege['revokeLink'] = '';
        if ($type != 'database' || !empty($row['can_delete'])) {
            $onePrivilege['revokeLink'] = PMA_getUserLink('revoke', $username, $hostname, $paramDbName, $paramTableName, $paramRoutineName);
        }
        $privileges[] = $onePrivilege;
    }
    $data = $uiData[$type];
    $data['privileges'] = $privileges;
    $data['userName'] = $username;
    $data['hostName'] = $hostname;
    $data['database'] = $dbname;
    $data['type'] = $type;
    if ($type == 'database') {
        // we already have the list of databases from libraries/common.inc.php
        // via $pma = new PMA;
        $pred_db_array = $GLOBALS['pma']->databases;
        $databases_to_skip = array('information_schema', 'performance_schema');
        $databases = array();
        if (!empty($pred_db_array)) {
            foreach ($pred_db_array as $current_db) {
                if (in_array($current_db, $databases_to_skip)) {
                    continue;
                }
                $current_db_escaped = PMA_Util::escapeMysqlWildcards($current_db);
                // cannot use array_diff() once, outside of the loop,
                // because the list of databases has special characters
                // already escaped in $foundRows,
                // contrary to the output of SHOW DATABASES
                if (!in_array($current_db_escaped, $foundRows)) {
                    $databases[] = $current_db;
                }
            }
        }
        $data['databases'] = $databases;
    } elseif ($type == 'table') {
        $result = @$GLOBALS['dbi']->tryQuery("SHOW TABLES FROM " . PMA_Util::backquote($dbname), null, PMA_DatabaseInterface::QUERY_STORE);
        $tables = array();
        if ($result) {
            while ($row = $GLOBALS['dbi']->fetchRow($result)) {
                if (!in_array($row[0], $foundRows)) {
                    $tables[] = $row[0];
                }
            }
            $GLOBALS['dbi']->freeResult($result);
        }
        $data['tables'] = $tables;
    } else {
        // routine
        $routineData = $GLOBALS['dbi']->getRoutines($dbname);
        $routines = array();
        foreach ($routineData as $routine) {
            if (!in_array($routine['name'], $foundRows)) {
                $routines[] = $routine['name'];
            }
        }
        $data['routines'] = $routines;
    }
    $html_output = PMA\Template::get('privileges/privileges_summary')->render($data);
    return $html_output;
}
$scripts = $header->getScripts();
$scripts->addFile('openlayers/OpenLayers.js');
$scripts->addFile('jquery/jquery.svg.js');
$scripts->addFile('tbl_gis_visualization.js');
$scripts->addFile('OpenStreetMap.js');
// If all the rows contain SRID, use OpenStreetMaps on the initial loading.
if (!isset($_REQUEST['displayVisualization'])) {
    $visualization = PMA_GIS_Visualization::get($sql_query, $visualizationSettings, $rows, $pos);
    if ($visualization->hasSrid()) {
        unset($visualizationSettings['choice']);
    }
    $visualizationSettings['choice'] = 'useBaseLayer';
}
$svgSupport = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8 ? false : true;
$format = $svgSupport ? 'svg' : 'png';
$visualization = PMA_GIS_Visualization::get($sql_query, $visualizationSettings, $rows, $pos);
if ($visualizationSettings != null) {
    foreach ($visualization->getSettings() as $setting => $val) {
        if (!isset($visualizationSettings[$setting])) {
            $visualizationSettings[$setting] = $val;
        }
    }
}
$result = $visualization->toImage($format);
/**
 * Displays the page
 */
$url_params['sql_query'] = $sql_query;
$downloadUrl = 'tbl_gis_visualization.php' . PMA_URL_getCommon($url_params) . '&saveToFile=true';
$html = PMA\Template::get('gis_visualization/gis_visualization')->render(array('url_params' => $url_params, 'downloadUrl' => $downloadUrl, 'labelCandidates' => $labelCandidates, 'spatialCandidates' => $spatialCandidates, 'visualizationSettings' => $visualizationSettings, 'sql_query' => $sql_query, 'visualization' => $result, 'svgSupport' => $svgSupport, 'drawOl' => $visualization->asOl()));
$response->addHTML($html);