/**
  * Create the code for displaying the phpMyAdmin
  * logo based on configuration settings
  *
  * @return string HTML code for the logo
  */
 private function _logo()
 {
     // display Logo, depending on $GLOBALS['cfg']['NavigationDisplayLogo']
     if (!$GLOBALS['cfg']['NavigationDisplayLogo']) {
         return Template::get('navigation/logo')->render(array('displayLogo' => false));
     }
     $logo = 'phpMyAdmin';
     if (@file_exists($GLOBALS['pmaThemeImage'] . 'logo_left.png')) {
         $logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'logo_left.png" ' . 'alt="' . $logo . '" id="imgpmalogo" />';
     } elseif (@file_exists($GLOBALS['pmaThemeImage'] . 'pma_logo2.png')) {
         $logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo2.png" ' . 'alt="' . $logo . '" id="imgpmalogo" />';
     }
     if (!$GLOBALS['cfg']['NavigationLogoLink']) {
         return Template::get('navigation/logo')->render(array('displayLogo' => true, 'useLogoLink' => false, 'logo' => $logo));
     }
     $useLogoLink = true;
     $linkAttriks = null;
     $logoLink = trim(htmlspecialchars($GLOBALS['cfg']['NavigationLogoLink']));
     // prevent XSS, see PMASA-2013-9
     // if link has protocol, allow only http and https
     if (preg_match('/^[a-z]+:/i', $logoLink) && !preg_match('/^https?:/i', $logoLink)) {
         $logoLink = 'index2.php';
     }
     switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
         case 'new':
             $linkAttriks = 'target="_blank"';
             break;
         case 'main':
             // do not add our parameters for an external link
             $host = parse_url($GLOBALS['cfg']['NavigationLogoLink'], PHP_URL_HOST);
             if (empty($host)) {
                 $logoLink .= PMA_URL_getCommon();
             } else {
                 $linkAttriks = 'target="_blank"';
             }
     }
     return Template::get('navigation/logo')->render(array('displayLogo' => true, 'useLogoLink' => $useLogoLink, 'logoLink' => $logoLink, 'linkAttribs' => $linkAttriks, 'logo' => $logo));
 }
Example #2
0
 /**
  * Function to get html for the start row and number of rows panel
  *
  * @param string $sql_query sql query
  *
  * @return string html
  */
 public static function getStartAndNumberOfRowsPanel($sql_query)
 {
     $pos = isset($_REQUEST['pos']) ? $_REQUEST['pos'] : $_SESSION['tmpval']['pos'];
     if (isset($_REQUEST['session_max_rows'])) {
         $rows = $_REQUEST['session_max_rows'];
     } else {
         if ($_SESSION['tmpval']['max_rows'] != 'all') {
             $rows = $_SESSION['tmpval']['max_rows'];
         } else {
             $rows = $GLOBALS['cfg']['MaxRows'];
         }
     }
     return Template::get('startAndNumberOfRowsPanel')->render(array('pos' => $pos, 'unlim_num_rows' => $_REQUEST['unlim_num_rows'], 'rows' => $rows, 'sql_query' => $sql_query));
 }
 /**
  * Add or remove favorite tables
  *
  * @return void
  */
 public function addRemoveFavoriteTablesAction()
 {
     $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'])) {
         $this->synchronizeFavoriteTables($fav_instance, $user, $favorite_tables);
         return;
     }
     $changes = true;
     $titles = PMA_Util::buildActionTitles();
     $favorite_table = $_REQUEST['favorite_table'];
     $already_favorite = $this->checkFavoriteTable($favorite_table);
     if (isset($_REQUEST['remove_favorite'])) {
         if ($already_favorite) {
             // If already in favorite list, remove it.
             $fav_instance->remove($this->db, $favorite_table);
             $already_favorite = false;
             // for favorite_anchor template
         }
     } elseif (isset($_REQUEST['add_favorite'])) {
         if (!$already_favorite) {
             $nbTables = count($fav_instance->getTables());
             if ($nbTables == $GLOBALS['cfg']['NumFavoriteTables']) {
                 $changes = false;
             } else {
                 // Otherwise add to favorite list.
                 $fav_instance->add($this->db, $favorite_table);
                 $already_favorite = true;
                 // for favorite_anchor template
             }
         }
     }
     $favorite_tables[$user] = $fav_instance->getTables();
     $this->response->addJSON('changes', $changes);
     if (!$changes) {
         $this->response->addJSON('message', Template::get('components/error_message')->render(array('msg' => __("Favorite List is full!"))));
         return;
     }
     $this->response->addJSON(array('user' => $user, 'favorite_tables' => json_encode($favorite_tables), 'list' => $fav_instance->getHtmlList(), 'anchor' => Template::get('database/structure/favorite_anchor')->render(array('db' => $this->db, 'current_table' => array('TABLE_NAME' => $favorite_table), 'titles' => $titles, 'already_favorite' => $already_favorite))));
 }
 /**
  * Execute the query and return the result
  *
  * @return void
  */
 public function indexAction()
 {
     if (isset($_REQUEST['ajax_request']) && isset($_REQUEST['pos']) && isset($_REQUEST['session_max_rows'])) {
         $this->ajaxAction();
         return;
     }
     // Throw error if no sql query is set
     if (!isset($this->sql_query) || $this->sql_query == '') {
         $this->response->isSuccess(false);
         $this->response->addHTML(PMA_Message::error(__('No SQL query was set to fetch data.')));
         return;
     }
     $this->response->getHeader()->getScripts()->addFiles(array('chart.js', 'tbl_chart.js', 'jqplot/jquery.jqplot.js', 'jqplot/plugins/jqplot.barRenderer.js', 'jqplot/plugins/jqplot.canvasAxisLabelRenderer.js', 'jqplot/plugins/jqplot.canvasTextRenderer.js', 'jqplot/plugins/jqplot.categoryAxisRenderer.js', 'jqplot/plugins/jqplot.dateAxisRenderer.js', 'jqplot/plugins/jqplot.pointLabels.js', 'jqplot/plugins/jqplot.pieRenderer.js', 'jqplot/plugins/jqplot.highlighter.js'));
     /**
      * Extract values for common work
      * @todo Extract common files
      */
     $db =& $this->db;
     $table =& $this->table;
     /**
      * Runs common work
      */
     if (mb_strlen($this->table)) {
         $url_params['goto'] = PMA_Util::getScriptNameForOption($this->cfg['DefaultTabTable'], 'table');
         $url_params['back'] = 'tbl_sql.php';
         include 'libraries/tbl_common.inc.php';
         include 'libraries/tbl_info.inc.php';
     } elseif (mb_strlen($this->db)) {
         $url_params['goto'] = PMA_Util::getScriptNameForOption($this->cfg['DefaultTabDatabase'], 'database');
         $url_params['back'] = 'sql.php';
         include 'libraries/db_common.inc.php';
         list($tables, $num_tables, $total_num_tables, $sub_part, $is_show_stats, $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos) = PMA_Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
     } else {
         $url_params['goto'] = PMA_Util::getScriptNameForOption($this->cfg['DefaultTabServer'], 'server');
         $url_params['back'] = 'sql.php';
         include 'libraries/server_common.inc.php';
     }
     $data = array();
     $result = $this->dbi->tryQuery($this->sql_query);
     $fields_meta = $this->dbi->getFieldsMeta($result);
     while ($row = $this->dbi->fetchAssoc($result)) {
         $data[] = $row;
     }
     $keys = array_keys($data[0]);
     $numeric_types = array('int', 'real');
     $numeric_column_count = 0;
     foreach ($keys as $idx => $key) {
         if (in_array($fields_meta[$idx]->type, $numeric_types)) {
             $numeric_column_count++;
         }
     }
     if ($numeric_column_count == 0) {
         $this->response->isSuccess(false);
         $this->response->addJSON('message', __('No numeric columns present in the table to plot.'));
         return;
     }
     $url_params['db'] = $this->db;
     $url_params['reload'] = 1;
     /**
      * Displays the page
      */
     $this->response->addHTML(Template::get('table/chart/tbl_chart')->render(array('url_query' => $this->url_query, 'url_params' => $url_params, 'keys' => $keys, 'fields_meta' => $fields_meta, 'numeric_types' => $numeric_types, 'numeric_column_count' => $numeric_column_count, 'sql_query' => $this->sql_query)));
 }
 /**
  * Index
  *
  * @return void
  */
 public function indexAction()
 {
     // Send table of column names to populate corresponding dropdowns depending
     // on the current selection
     if (isset($_REQUEST['getDropdownValues']) && $_REQUEST['getDropdownValues'] === 'true') {
         // if both db and table are selected
         if (isset($_REQUEST['foreignTable'])) {
             $this->getDropdownValueForTableAction();
         } else {
             // if only the db is selected
             $this->getDropdownValueForDbAction();
         }
         return;
     }
     $this->response->getHeader()->getScripts()->addFiles(array('tbl_relation.js', 'indexes.js'));
     // Gets tables information
     include_once 'libraries/tbl_info.inc.php';
     // updates for Internal relations
     if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) {
         $this->updateForInternalRelationAction();
     }
     // updates for foreign keys
     if (isset($_POST['destination_foreign_db'])) {
         $this->updateForForeignKeysAction();
     }
     // Updates for display field
     if ($this->cfgRelation['displaywork'] && isset($_POST['display_field'])) {
         $this->updateForDisplayField();
     }
     // If we did an update, refresh our data
     if (isset($_POST['destination_db']) && $this->cfgRelation['relwork']) {
         $this->existrel = PMA_getForeigners($this->db, $this->table, '', 'internal');
     }
     if (isset($_POST['destination_foreign_db']) && PMA_Util::isForeignKeySupported($this->tbl_storage_engine)) {
         $this->existrel_foreign = PMA_getForeigners($this->db, $this->table, '', 'foreign');
     }
     if ($this->cfgRelation['displaywork']) {
         $this->disp = PMA_getDisplayField($this->db, $this->table);
     }
     // display secondary level tabs if necessary
     $engine = $this->dbi->getTable($this->db, $this->table)->sGetStatusInfo('ENGINE');
     $this->response->addHTML(Template::get('structure/secondary_tabs')->render(array('url_params' => array('db' => $GLOBALS['db'], 'table' => $GLOBALS['table']), 'engine' => $engine)));
     $this->response->addHTML('<div id="structure_content">');
     /**
      * Dialog
      */
     // Now find out the columns of our $table
     // need to use PMA_DatabaseInterface::QUERY_STORE with $this->dbi->numRows()
     // in mysqli
     $columns = $this->dbi->getColumns($this->db, $this->table);
     // common form
     $this->response->addHTML(Template::get('tbl_relation/common_form')->render(array('db' => $this->db, 'table' => $this->table, 'columns' => $columns, 'cfgRelation' => $this->cfgRelation, 'tbl_storage_engine' => $this->tbl_storage_engine, 'existrel' => isset($this->existrel) ? $this->existrel : array(), 'existrel_foreign' => isset($this->existrel_foreign) ? $this->existrel_foreign['foreign_keys_data'] : array(), 'options_array' => $this->options_array)));
     if (PMA_Util::isForeignKeySupported($this->tbl_storage_engine)) {
         $this->response->addHTML(PMA_getHtmlForDisplayIndexes());
     }
     $this->response->addHTML('</div>');
 }
 /**
  * Index
  *
  * @return void
  */
 public function indexAction()
 {
     // Throw error if no sql query is set
     if (!isset($this->sql_query) || $this->sql_query == '') {
         $this->response->setRequestStatus(false);
         $this->response->addHTML(PMA_Message::error(__('No SQL query was set to fetch data.')));
         return;
     }
     // Execute the query and return the result
     $result = $this->dbi->tryQuery($this->sql_query);
     // Get the meta data of results
     $meta = $this->dbi->getFieldsMeta($result);
     // Find the candidate fields for label column and spatial column
     $labelCandidates = array();
     $spatialCandidates = array();
     foreach ($meta as $column_meta) {
         if ($column_meta->type == 'geometry') {
             $spatialCandidates[] = $column_meta->name;
         } else {
             $labelCandidates[] = $column_meta->name;
         }
     }
     // Get settings if any posted
     if (PMA_isValid($_REQUEST['visualizationSettings'], 'array')) {
         $this->visualizationSettings = $_REQUEST['visualizationSettings'];
     }
     if (!isset($this->visualizationSettings['labelColumn']) && isset($labelCandidates[0])) {
         $this->visualizationSettings['labelColumn'] = '';
     }
     // If spatial column is not set, use first geometric column as spatial column
     if (!isset($this->visualizationSettings['spatialColumn'])) {
         $this->visualizationSettings['spatialColumn'] = $spatialCandidates[0];
     }
     // Convert geometric columns from bytes to text.
     $pos = isset($_REQUEST['pos']) ? $_REQUEST['pos'] : $_SESSION['tmpval']['pos'];
     if (isset($_REQUEST['session_max_rows'])) {
         $rows = $_REQUEST['session_max_rows'];
     } else {
         if ($_SESSION['tmpval']['max_rows'] != 'all') {
             $rows = $_SESSION['tmpval']['max_rows'];
         } else {
             $rows = $GLOBALS['cfg']['MaxRows'];
         }
     }
     $this->visualization = PMA_GIS_Visualization::get($this->sql_query, $this->visualizationSettings, $rows, $pos);
     if (isset($_REQUEST['saveToFile'])) {
         $this->saveToFileAction();
         return;
     }
     $this->response->getHeader()->getScripts()->addFiles(array('openlayers/OpenLayers.js', 'jquery/jquery.svg.js', 'tbl_gis_visualization.js', 'OpenStreetMap.js'));
     // If all the rows contain SRID, use OpenStreetMaps on the initial loading.
     if (!isset($_REQUEST['displayVisualization'])) {
         if ($this->visualization->hasSrid()) {
             $this->visualizationSettings['choice'] = 'useBaseLayer';
         } else {
             unset($this->visualizationSettings['choice']);
         }
     }
     $this->visualization->setUserSpecifiedSettings($this->visualizationSettings);
     if ($this->visualizationSettings != null) {
         foreach ($this->visualization->getSettings() as $setting => $val) {
             if (!isset($this->visualizationSettings[$setting])) {
                 $this->visualizationSettings[$setting] = $val;
             }
         }
     }
     /**
      * Displays the page
      */
     $this->url_params['sql_query'] = $this->sql_query;
     $downloadUrl = 'tbl_gis_visualization.php' . PMA_URL_getCommon($this->url_params) . '&saveToFile=true';
     $svgSupport = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER <= 8 ? false : true;
     $html = Template::get('table/gis_visualization/gis_visualization')->render(array('url_params' => $this->url_params, 'downloadUrl' => $downloadUrl, 'labelCandidates' => $labelCandidates, 'spatialCandidates' => $spatialCandidates, 'visualizationSettings' => $this->visualizationSettings, 'sql_query' => $this->sql_query, 'visualization' => $this->visualization->toImage($svgSupport ? 'svg' : 'png'), 'svgSupport' => $svgSupport, 'drawOl' => $this->visualization->asOl()));
     $this->response->addHTML($html);
 }
 /**
  * Get HTML snippet for display table statistics
  *
  * @return string $html_output
  */
 protected function getTableStats()
 {
     if (empty($this->_showtable)) {
         $this->_showtable = $this->dbi->getTable($this->db, $this->table)->sGetStatusInfo(null, true);
     }
     if (empty($this->_showtable['Data_length'])) {
         $this->_showtable['Data_length'] = 0;
     }
     if (empty($this->_showtable['Index_length'])) {
         $this->_showtable['Index_length'] = 0;
     }
     $is_innodb = isset($this->_showtable['Type']) && $this->_showtable['Type'] == 'InnoDB';
     $mergetable = $this->table_obj->isMerge();
     // this is to display for example 261.2 MiB instead of 268k KiB
     $max_digits = 3;
     $decimals = 1;
     list($data_size, $data_unit) = PMA_Util::formatByteDown($this->_showtable['Data_length'], $max_digits, $decimals);
     if ($mergetable == false) {
         list($index_size, $index_unit) = PMA_Util::formatByteDown($this->_showtable['Index_length'], $max_digits, $decimals);
     }
     // InnoDB returns a huge value in Data_free, do not use it
     if (!$is_innodb && isset($this->_showtable['Data_free']) && $this->_showtable['Data_free'] > 0) {
         list($free_size, $free_unit) = PMA_Util::formatByteDown($this->_showtable['Data_free'], $max_digits, $decimals);
         list($effect_size, $effect_unit) = PMA_Util::formatByteDown($this->_showtable['Data_length'] + $this->_showtable['Index_length'] - $this->_showtable['Data_free'], $max_digits, $decimals);
     } else {
         list($effect_size, $effect_unit) = PMA_Util::formatByteDown($this->_showtable['Data_length'] + $this->_showtable['Index_length'], $max_digits, $decimals);
     }
     list($tot_size, $tot_unit) = PMA_Util::formatByteDown($this->_showtable['Data_length'] + $this->_showtable['Index_length'], $max_digits, $decimals);
     if ($this->_table_info_num_rows > 0) {
         list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($this->_showtable['Data_length'] + $this->_showtable['Index_length']) / $this->_showtable['Rows'], 6, 1);
     } else {
         $avg_size = $avg_unit = '';
     }
     return Template::get('table/structure/display_table_stats')->render(array('showtable' => $this->_showtable, 'table_info_num_rows' => $this->_table_info_num_rows, 'tbl_is_view' => $this->_tbl_is_view, 'db_is_system_schema' => $this->_db_is_system_schema, 'tbl_storage_engine' => $this->_tbl_storage_engine, 'url_query' => $this->_url_query, 'tbl_collation' => $this->_tbl_collation, 'is_innodb' => $is_innodb, 'mergetable' => $mergetable, 'avg_size' => isset($avg_size) ? $avg_size : null, 'avg_unit' => isset($avg_unit) ? $avg_unit : null, 'data_size' => $data_size, 'data_unit' => $data_unit, 'index_size' => isset($index_size) ? $index_size : null, 'index_unit' => isset($index_unit) ? $index_unit : null, 'free_size' => isset($free_size) ? $free_size : null, 'free_unit' => isset($free_unit) ? $free_unit : null, 'effect_size' => $effect_size, 'effect_unit' => $effect_unit, 'tot_size' => $tot_size, 'tot_unit' => $tot_unit));
 }
 /**
  * Provides a column's type, collation, operators list, and criteria value
  * to display in table search form
  *
  * @param integer $search_index Row number in table search form
  * @param integer $column_index Column index in ColumnNames array
  *
  * @return array Array containing column's properties
  */
 public function getColumnProperties($search_index, $column_index)
 {
     $selected_operator = isset($_POST['criteriaColumnOperators']) ? $_POST['criteriaColumnOperators'][$search_index] : '';
     $entered_value = isset($_POST['criteriaValues']) ? $_POST['criteriaValues'] : '';
     $titles = array('Browse' => PMA_Util::getIcon('b_browse.png', __('Browse foreign values')));
     //Gets column's type and collation
     $type = $this->_columnTypes[$column_index];
     $collation = $this->_columnCollations[$column_index];
     //Gets column's comparison operators depending on column type
     $func = Template::get('table/column_comparison_operators')->render(array('search_index' => $search_index, 'columnTypes' => $this->_columnTypes, 'column_index' => $column_index, 'columnNullFlags' => $this->_columnNullFlags, 'selected_operator' => $selected_operator));
     //Gets link to browse foreign data(if any) and criteria inputbox
     $foreignData = PMA_getForeignData($this->_foreigners, $this->_columnNames[$column_index], false, '', '');
     $value = Template::get('table/input_box')->render(array('str' => '', 'column_type' => (string) $type, 'column_id' => 'fieldID_', 'in_zoom_search_edit' => false, '_foreigners' => $this->_foreigners, 'column_name' => $this->_columnNames[$column_index], 'foreignData' => $foreignData, 'table' => $this->table, 'column_index' => $search_index, 'foreignMaxLimit' => $GLOBALS['cfg']['ForeignKeyMaxLimit'], 'criteriaValues' => $entered_value, 'db' => $this->db, 'titles' => $titles, 'in_fbs' => false));
     return array('type' => $type, 'collation' => $collation, 'func' => $func, 'value' => $value);
 }
 /**
  * Process the data from the edit/create index form,
  * run the query to build the new index
  * and moves back to "tbl_sql.php"
  *
  * @return void
  */
 public function doSaveDataAction()
 {
     $error = false;
     $sql_query = $this->dbi->getTable($this->db, $this->table)->getSqlQueryForIndexCreateOrEdit($this->index, $error);
     // If there is a request for SQL previewing.
     if (isset($_REQUEST['preview_sql'])) {
         PMA_Response::getInstance()->addJSON('sql_data', Template::get('preview_sql')->render(array('query_data' => $sql_query)));
     } elseif (!$error) {
         $this->dbi->query($sql_query);
         if ($GLOBALS['is_ajax_request'] == true) {
             $message = PMA_Message::success(__('Table %1$s has been altered successfully.'));
             $message->addParam($this->table);
             $response = PMA_Response::getInstance();
             $response->addJSON('message', PMA_Util::getMessage($message, $sql_query, 'success'));
             $response->addJSON('index_table', PMA_Index::getHtmlForIndexes($this->table, $this->db));
         } else {
             include 'tbl_structure.php';
         }
     } else {
         $response = PMA_Response::getInstance();
         $response->isSuccess(false);
         $response->addJSON('message', $error);
     }
 }
Example #10
0
$data = array();
$result = $GLOBALS['dbi']->tryQuery($sql_query);
$fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
    $data[] = $row;
}
$keys = array_keys($data[0]);
$numeric_types = array('int', 'real');
$numeric_column_count = 0;
foreach ($keys as $idx => $key) {
    if (in_array($fields_meta[$idx]->type, $numeric_types)) {
        $numeric_column_count++;
    }
}
if ($numeric_column_count == 0) {
    $response->isSuccess(false);
    $response->addJSON('message', __('No numeric columns present in the table to plot.'));
    exit;
}
// get settings if any posted
$chartSettings = array();
if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
    $chartSettings = $_REQUEST['chartSettings'];
}
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
/**
 * Displays the page
 */
$response->addHTML(Template::get('tbl_chart')->render(array('url_query' => $url_query, 'url_params' => $url_params, 'keys' => $keys, 'fields_meta' => $fields_meta, 'numeric_types' => $numeric_types, 'numeric_column_count' => $numeric_column_count, 'sql_query' => $sql_query)));