Handle front end templating
 /**
  * Return HTML for a given Storage Engine
  *
  * @param StorageEngine $engine storage engine
  *
  * @return string
  */
 private function _getHtmlForServerEngine($engine)
 {
     $pageOutput = !empty($_REQUEST['page']) ? $engine->getPage($_REQUEST['page']) : '';
     /**
      * Displays details about a given Storage Engine
      */
     return Template::get('server/engines/engine')->render(array('title' => $engine->getTitle(), 'helpPage' => $engine->getMysqlHelpPage(), 'comment' => $engine->getComment(), 'infoPages' => $engine->getInfoPages(), 'support' => $engine->getSupportInformationMessage(), 'variables' => $engine->getHtmlVariables(), 'pageOutput' => $pageOutput));
 }
 /**
  * Returns the html for plugin Tab.
  *
  * @return string
  */
 private function _getPluginsHtml()
 {
     $html = '<div id="plugins_plugins">';
     $html .= Template::get('server/plugins/section_links')->render(array('plugins' => $this->plugins));
     foreach ($this->plugins as $plugin_type => $plugin_list) {
         $html .= Template::get('server/plugins/section')->render(array('plugin_type' => $plugin_type, 'plugin_list' => $plugin_list));
     }
     $html .= '</div>';
     return $html;
 }
 /**
  * Returns the tracking icon if the table is tracked
  *
  * @param string $table table name
  *
  * @return string HTML for tracking icon
  */
 protected function getTrackingIcon($table)
 {
     $tracking_icon = '';
     if (Tracker::isActive()) {
         $is_tracked = Tracker::isTracked($GLOBALS["db"], $table);
         if ($is_tracked || Tracker::getVersion($GLOBALS["db"], $table) > 0) {
             $tracking_icon = Template::get('database/structure/tracking_icon')->render(array('url_query' => $this->_url_query, 'truename' => $table, 'is_tracked' => $is_tracked));
         }
     }
     return $tracking_icon;
 }
 /**
  * Returns HTML code for the language selector
  *
  * @param boolean $use_fieldset whether to use fieldset for selection
  * @param boolean $show_doc     whether to show documentation links
  *
  * @return string
  *
  * @access  public
  */
 public function getSelectorDisplay($use_fieldset = false, $show_doc = true)
 {
     $_form_params = array('db' => $GLOBALS['db'], 'table' => $GLOBALS['table']);
     // For non-English, display "Language" with emphasis because it's
     // not a proper word in the current language; we show it to help
     // people recognize the dialog
     $language_title = __('Language') . (__('Language') != 'Language' ? ' - <em>Language</em>' : '');
     if ($show_doc) {
         $language_title .= Util::showDocu('faq', 'faq7-2');
     }
     $available_languages = $this->sortedLanguages();
     return Template::get('select_lang')->render(array('language_title' => $language_title, 'use_fieldset' => $use_fieldset, 'available_languages' => $available_languages, '_form_params' => $_form_params));
 }
/**
 * 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();
        $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 = 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 " . Util::backquote($dbname), null, 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 = Template::get('privileges/privileges_summary')->render($data);
    return $html_output;
}
 /**
  * Prints Html for Server Variables Items
  *
  * @param array $serverVars        global variables
  * @param array $serverVarsSession session variables
  *
  * @return string
  */
 private function _getHtmlForServerVariablesItems($serverVars, $serverVarsSession)
 {
     // list of static (i.e. non-editable) system variables
     $static_variables = $this->_getStaticSystemVariables();
     $output = '';
     foreach ($serverVars as $name => $value) {
         $has_session_value = isset($serverVarsSession[$name]) && $serverVarsSession[$name] != $value;
         $row_class = $has_session_value ? ' diffSession' : '';
         $docLink = isset($this->variable_doc_links[$name]) ? $this->variable_doc_links[$name] : null;
         list($formattedValue, $isHtmlFormatted) = $this->_formatVariable($name, $value);
         $output .= Template::get('server/variables/variable_row')->render(array('rowClass' => $row_class, 'editable' => !in_array(strtolower($name), $static_variables), 'docLink' => $docLink, 'name' => $name, 'value' => $formattedValue, 'isSuperuser' => $this->dbi->isSuperuser(), 'isHtmlFormatted' => $isHtmlFormatted));
         if ($has_session_value) {
             list($formattedValue, $isHtmlFormatted) = $this->_formatVariable($name, $serverVarsSession[$name]);
             $output .= Template::get('server/variables/session_variable_row')->render(array('rowClass' => $row_class, 'value' => $formattedValue, 'isHtmlFormatted' => $isHtmlFormatted));
         }
     }
     return $output;
 }
Example #7
0
/**
 * Creates a list of items containing the relevant
 * information and some action links.
 *
 * @param string $type  One of ['routine'|'trigger'|'event']
 * @param array  $items An array of items
 *
 * @return string HTML code of the list of items
 */
function PMA_RTE_getList($type, $items)
{
    global $table;
    /**
     * Conditional classes switch the list on or off
     */
    $class1 = 'hide';
    $class2 = '';
    if (!$items) {
        $class1 = '';
        $class2 = ' hide';
    }
    /**
     * Generate output
     */
    $retval = "<!-- LIST OF " . PMA_RTE_getWord('docu') . " START -->\n";
    $retval .= '<form id="rteListForm" class="ajax" action="';
    switch ($type) {
        case 'routine':
            $retval .= 'db_routines.php';
            break;
        case 'trigger':
            if (!empty($table)) {
                $retval .= 'tbl_triggers.php';
            } else {
                $retval .= 'db_triggers.php';
            }
            break;
        case 'event':
            $retval .= 'db_events.php';
            break;
        default:
            break;
    }
    $retval .= '">';
    $retval .= URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
    $retval .= "<fieldset>\n";
    $retval .= "    <legend>\n";
    $retval .= "        " . PMA_RTE_getWord('title') . "\n";
    $retval .= "        " . PMA\libraries\Util::showMySQLDocu(PMA_RTE_getWord('docu')) . "\n";
    $retval .= "    </legend>\n";
    $retval .= "    <div class='{$class1}' id='nothing2display'>\n";
    $retval .= "      " . PMA_RTE_getWord('nothing') . "\n";
    $retval .= "    </div>\n";
    $retval .= "    <table class='data{$class2}'>\n";
    $retval .= "        <!-- TABLE HEADERS -->\n";
    $retval .= "        <tr>\n";
    // th cells with a colspan need corresponding td cells, according to W3C
    switch ($type) {
        case 'routine':
            $retval .= "            <th></th>\n";
            $retval .= "            <th>" . __('Name') . "</th>\n";
            $retval .= "            <th colspan='4'>" . __('Action') . "</th>\n";
            $retval .= "            <th>" . __('Type') . "</th>\n";
            $retval .= "            <th>" . __('Returns') . "</th>\n";
            $retval .= "        </tr>\n";
            $retval .= "        <tr style='display: none'>\n";
            // see comment above
            for ($i = 0; $i < 7; $i++) {
                $retval .= "            <td></td>\n";
            }
            break;
        case 'trigger':
            $retval .= "            <th></th>\n";
            $retval .= "            <th>" . __('Name') . "</th>\n";
            if (empty($table)) {
                $retval .= "            <th>" . __('Table') . "</th>\n";
            }
            $retval .= "            <th colspan='3'>" . __('Action') . "</th>\n";
            $retval .= "            <th>" . __('Time') . "</th>\n";
            $retval .= "            <th>" . __('Event') . "</th>\n";
            $retval .= "        </tr>\n";
            $retval .= "        <tr style='display: none'>\n";
            // see comment above
            for ($i = 0; $i < (empty($table) ? 7 : 6); $i++) {
                $retval .= "            <td></td>\n";
            }
            break;
        case 'event':
            $retval .= "            <th></th>\n";
            $retval .= "            <th>" . __('Name') . "</th>\n";
            $retval .= "            <th>" . __('Status') . "</th>\n";
            $retval .= "            <th colspan='3'>" . __('Action') . "</th>\n";
            $retval .= "            <th>" . __('Type') . "</th>\n";
            $retval .= "        </tr>\n";
            $retval .= "        <tr style='display: none'>\n";
            // see comment above
            for ($i = 0; $i < 6; $i++) {
                $retval .= "            <td></td>\n";
            }
            break;
        default:
            break;
    }
    $retval .= "        </tr>\n";
    $retval .= "        <!-- TABLE DATA -->\n";
    $count = 0;
    foreach ($items as $item) {
        $rowclass = $count % 2 == 0 ? 'odd' : 'even';
        if ($GLOBALS['is_ajax_request'] && empty($_REQUEST['ajax_page_request'])) {
            $rowclass .= ' ajaxInsert hide';
        }
        // Get each row from the correct function
        switch ($type) {
            case 'routine':
                $retval .= PMA_RTN_getRowForList($item, $rowclass);
                break;
            case 'trigger':
                $retval .= PMA_TRI_getRowForList($item, $rowclass);
                break;
            case 'event':
                $retval .= PMA_EVN_getRowForList($item, $rowclass);
                break;
            default:
                break;
        }
        $count++;
    }
    $retval .= "    </table>\n";
    if (count($items)) {
        $retval .= '<div class="withSelected">';
        $retval .= Template::get('select_all')->render(array('pmaThemeImage' => $GLOBALS['pmaThemeImage'], 'text_dir' => $GLOBALS['text_dir'], 'formName' => 'rteListForm'));
        $retval .= PMA\libraries\Util::getButtonOrImage('submit_mult', 'mult_submit', __('Export'), 'b_export.png', 'export');
        $retval .= PMA\libraries\Util::getButtonOrImage('submit_mult', 'mult_submit', __('Drop'), 'b_drop.png', 'drop');
        $retval .= '</div>';
    }
    $retval .= "</fieldset>\n";
    $retval .= "</form>\n";
    $retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n";
    return $retval;
}
 /**
  * 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->setRequestStatus(false);
         $this->response->addHTML(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'] = 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'] = Util::getScriptNameForOption($this->cfg['DefaultTabDatabase'], 'database');
         $url_params['back'] = 'sql.php';
         include 'libraries/db_common.inc.php';
     } else {
         $url_params['goto'] = 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->setRequestStatus(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)));
 }
 /**
  * Returns the html for server Character Sets and Collations.
  *
  * @param array $mysqlCharsets      Mysql Charsets list
  * @param array $mysqlCollations    Mysql Collations list
  * @param array $mysqlCharsetsDesc  Charsets descriptions
  * @param array $mysqlDftCollations Default Collations list
  *
  * @return string
  */
 function _getHtmlForCharsets($mysqlCharsets, $mysqlCollations, $mysqlCharsetsDesc, $mysqlDftCollations)
 {
     return Template::get('server/collations/charsets')->render(array('mysqlCharsets' => $mysqlCharsets, 'mysqlCollations' => $mysqlCollations, 'mysqlCharsetsDesc' => $mysqlCharsetsDesc, 'mysqlDftCollations' => $mysqlDftCollations));
 }
Example #10
0
 /**
  * Prepare option fields block
  *
  * @return  string  $options_html   html content
  *
  * @access  private
  *
  * @see     _getTableHeaders()
  */
 private function _getOptionsBlock()
 {
     $options_html = '';
     $options_html .= '<form method="post" action="sql.php" ' . 'name="displayOptionsForm"';
     $options_html .= ' class="ajax print_ignore" ';
     $options_html .= '>';
     $url_params = array('db' => $this->__get('db'), 'table' => $this->__get('table'), 'sql_query' => $this->__get('sql_query'), 'goto' => $this->__get('goto'), 'display_options_form' => 1);
     $options_html .= URL::getHiddenInputs($url_params) . '<br />' . Util::getDivForSliderEffect('', __('Options')) . '<fieldset>';
     $options_html .= '<div class="formelement">';
     $choices = array('P' => __('Partial texts'), 'F' => __('Full texts'));
     // pftext means "partial or full texts" (done to reduce line lengths)
     $options_html .= Util::getRadioFields('pftext', $choices, $_SESSION['tmpval']['pftext'], true, true, '', 'pftext_' . $this->__get('unique_id')) . '</div>';
     if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
         $options_html .= '<div class="formelement">';
         $choices = array('K' => __('Relational key'), 'D' => __('Display column for relations'));
         $options_html .= Util::getRadioFields('relational_display', $choices, $_SESSION['tmpval']['relational_display'], true, true, '', 'relational_display_' . $this->__get('unique_id')) . '</div>';
     }
     $options_html .= '<div class="formelement">' . Template::get('checkbox')->render(array('html_field_name' => 'display_binary', 'label' => __('Show binary contents'), 'checked' => !empty($_SESSION['tmpval']['display_binary']), 'onclick' => false, 'html_field_id' => 'display_binary_' . $this->__get('unique_id'))) . '<br />' . Template::get('checkbox')->render(array('html_field_name' => 'display_blob', 'label' => __('Show BLOB contents'), 'checked' => !empty($_SESSION['tmpval']['display_blob']), 'onclick' => false, 'html_field_id' => 'display_blob_' . $this->__get('unique_id'))) . '</div>';
     // I would have preferred to name this "display_transformation".
     // This is the only way I found to be able to keep this setting sticky
     // per SQL query, and at the same time have a default that displays
     // the transformations.
     $options_html .= '<div class="formelement">' . Template::get('checkbox')->render(array('html_field_name' => 'hide_transformation', 'label' => __('Hide browser transformation'), 'checked' => !empty($_SESSION['tmpval']['hide_transformation']), 'onclick' => false, 'html_field_id' => 'hide_transformation_' . $this->__get('unique_id'))) . '</div>';
     $options_html .= '<div class="formelement">';
     $choices = array('GEOM' => __('Geometry'), 'WKT' => __('Well Known Text'), 'WKB' => __('Well Known Binary'));
     $options_html .= Util::getRadioFields('geoOption', $choices, $_SESSION['tmpval']['geoOption'], true, true, '', 'geoOption_' . $this->__get('unique_id'));
     $options_html .= '</div>';
     $options_html .= '<div class="clearfloat"></div>' . '</fieldset>';
     $options_html .= '<fieldset class="tblFooters">' . '<input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . '</div>' . '</form>';
     return $options_html;
 }
                $partition['node_group'] = '';
            }
            if ($subpartition_count > 1 && $partitionDetails['can_have_subpartitions'] == true) {
                // Has subpartitions
                $partition['subpartition_count'] = $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, $subpartition_count);
                for ($j = 0; $j < $subpartition_count; $j++) {
                    if (!isset($subpartitions[$j])) {
                        // Newly added subpartition
                        $subpartitions[$j] = array('name' => $partition['name'] . '_s' . $j, 'engine' => '', 'comment' => '', 'data_directory' => '', 'index_directory' => '', 'max_rows' => '', 'min_rows' => '', 'tablespace' => '', 'node_group' => '');
                    }
                    $subpartition =& $subpartitions[$j];
                    $subpartition['prefix'] = 'partitions[' . $i . ']' . '[subpartitions][' . $j . ']';
                }
            } else {
                // No subpartitions
                unset($partition['subpartitions']);
                unset($partition['subpartition_count']);
            }
        }
        $partitionDetails['partitions'] = $partitions;
    }
}
echo Template::get('columns_definitions/partitions')->render(array('partitionDetails' => $partitionDetails));
 /**
  * Returns the html for all binary log items.
  *
  * @param resource $result         MySQL Query result
  * @param bool     $dontlimitchars Whether limit chars
  *
  * @return string
  */
 private function _getAllLogItemInfo($result, $dontlimitchars)
 {
     $html = "";
     $odd_row = true;
     while ($value = $this->dbi->fetchAssoc($result)) {
         $html .= Template::get('server/binlog/log_row')->render(array('odd_row' => $odd_row, 'value' => $value, 'dontlimitchars' => $dontlimitchars));
         $odd_row = !$odd_row;
     }
     return $html;
 }
/**
 * Get HTML for display the users overview
 * (if less than 50 users, display them immediately)
 *
 * @param array  $result        ran sql query
 * @param array  $db_rights     user's database rights array
 * @param string $pmaThemeImage a image source link
 * @param string $text_dir      text directory
 *
 * @return string HTML snippet
 */
function PMA_getUsersOverview($result, $db_rights, $pmaThemeImage, $text_dir)
{
    while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
        $row['privs'] = PMA_extractPrivInfo($row, true);
        $db_rights[$row['User']][$row['Host']] = $row;
    }
    @$GLOBALS['dbi']->freeResult($result);
    $user_group_count = 0;
    if ($GLOBALS['cfgRelation']['menuswork']) {
        $user_group_count = PMA_getUserGroupCount();
    }
    $html_output = '<form name="usersForm" id="usersForm" action="server_privileges.php" ' . 'method="post">' . "\n" . URL::getHiddenInputs('', '') . '<table id="tableuserrights" class="data">' . "\n" . '<thead>' . "\n" . '<tr><th></th>' . "\n" . '<th>' . __('User name') . '</th>' . "\n" . '<th>' . __('Host name') . '</th>' . "\n" . '<th>' . __('Password') . '</th>' . "\n" . '<th>' . __('Global privileges') . ' ' . Util::showHint(__('Note: MySQL privilege names are expressed in English.')) . '</th>' . "\n";
    if ($GLOBALS['cfgRelation']['menuswork']) {
        $html_output .= '<th>' . __('User group') . '</th>' . "\n";
    }
    $html_output .= '<th>' . __('Grant') . '</th>' . "\n" . '<th colspan="' . ($user_group_count > 0 ? '3' : '2') . '">' . __('Action') . '</th>' . "\n" . '</tr>' . "\n" . '</thead>' . "\n";
    $html_output .= '<tbody>' . "\n";
    $html_output .= PMA_getHtmlTableBodyForUserRights($db_rights);
    $html_output .= '</tbody>' . '</table>' . "\n";
    $html_output .= '<div class="floatleft">' . Template::get('select_all')->render(array('pmaThemeImage' => $pmaThemeImage, 'text_dir' => $text_dir, 'formName' => 'usersForm')) . "\n";
    $html_output .= Util::getButtonOrImage('submit_mult', 'mult_submit', __('Export'), 'b_tblexport.png', 'export');
    $html_output .= '<input type="hidden" name="initial" ' . 'value="' . (isset($_GET['initial']) ? htmlspecialchars($_GET['initial']) : '') . '" />';
    $html_output .= '</div>' . '<div class="clear_both" style="clear:both"></div>';
    // add/delete user fieldset
    $html_output .= PMA_getFieldsetForAddDeleteUser();
    $html_output .= '</form>' . "\n";
    return $html_output;
}
 /**
  * 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)->getStatusInfo(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) = Util::formatByteDown($this->_showtable['Data_length'], $max_digits, $decimals);
     if ($mergetable == false) {
         list($index_size, $index_unit) = 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) = Util::formatByteDown($this->_showtable['Data_free'], $max_digits, $decimals);
         list($effect_size, $effect_unit) = Util::formatByteDown($this->_showtable['Data_length'] + $this->_showtable['Index_length'] - $this->_showtable['Data_free'], $max_digits, $decimals);
     } else {
         list($effect_size, $effect_unit) = Util::formatByteDown($this->_showtable['Data_length'] + $this->_showtable['Index_length'], $max_digits, $decimals);
     }
     list($tot_size, $tot_unit) = 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) = 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));
 }
 /**
  * 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']) && 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)->getStatusInfo('ENGINE');
     $this->response->addHTML(Template::get('table/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 DatabaseInterface::QUERY_STORE with $this->dbi->numRows()
     // in mysqli
     $columns = $this->dbi->getColumns($this->db, $this->table);
     // common form
     $this->response->addHTML(Template::get('table/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 (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(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 = GISVisualization::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'));
     // 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(array_merge($this->url_params, array('saveToFile' => true, 'session_max_rows' => $rows, 'pos' => $pos)));
     $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('svg'), 'drawOl' => $this->visualization->asOl()));
     $this->response->addHTML($html);
 }
 /**
  * Add or remove favorite tables
  *
  * @return void
  */
 public function addRemoveFavoriteTablesAction()
 {
     $fav_instance = 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 = 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))));
 }
Example #18
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' => intval($_REQUEST['unlim_num_rows']),
                    'rows' => $rows,
                    'sql_query' => $sql_query,
                )
            );
    }
Example #19
0
 /**
  * Renders the console
  *
  * @access public
  * @return string
  */
 public function getDisplay()
 {
     if (!$this->_isAjax && $this->_isEnabled) {
         $cfgBookmark = Bookmark::getParams();
         $image = Util::getImage('console.png', __('SQL Query Console'));
         $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
         $bookmarkContent = static::getBookmarkContent();
         return Template::get('console/display')->render(array('cfgBookmark' => $cfgBookmark, 'image' => $image, '_sql_history' => $_sql_history, 'bookmarkContent' => $bookmarkContent));
     }
     return '';
 }
Example #20
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;
    }
    return Template::get('javascript/display')->render(array('js_array' => $js_array));
}
 /**
  * Returns the html for Enable Statistics
  *
  * @return string
  */
 private function _getHtmlForNoticeEnableStatistics()
 {
     $html = '';
     $notice = 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' . $GLOBALS['url_query'] . '&amp;dbstats=1', 'title' => __('Enable statistics')));
     $html .= Template::get('list/unordered')->render(array('items' => $items));
     return $html;
 }
 /**
  * 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' => 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/search/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/search/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' => true));
     return array('type' => $type, 'collation' => $collation, 'func' => $func, 'value' => $value);
 }
/**
 * Get HTML for display Add userfieldset
 *
 * @param string $db    the database
 * @param string $table the table name
 *
 * @return string html output
 */
function PMA_getAddUserHtmlFieldset($db = '', $table = '')
{
    if (!$GLOBALS['is_createuser']) {
        return '';
    }
    $rel_params = array();
    $url_params = array('adduser' => 1);
    if (!empty($db)) {
        $url_params['dbname'] = $rel_params['checkprivsdb'] = $db;
    }
    if (!empty($table)) {
        $url_params['tablename'] = $rel_params['checkprivstable'] = $table;
    }
    return Template::get('privileges/add_user_fieldset')->render(array('url_params' => $url_params, 'rel_params' => $rel_params));
}
 /**
  * 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 (!Sanitize::checkLink($logoLink, true)) {
         $logoLink = 'index.php';
     }
     switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
         case 'new':
             $linkAttriks = 'target="_blank" rel="noopener noreferrer"';
             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 .= URL::getCommon();
             } else {
                 $linkAttriks = 'target="_blank" rel="noopener noreferrer"';
             }
     }
     return Template::get('navigation/logo')->render(array('displayLogo' => true, 'useLogoLink' => $useLogoLink, 'logoLink' => $logoLink, 'linkAttribs' => $linkAttriks, 'logo' => $logo));
 }
 /**
  * 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'])) {
         $this->response->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 = Message::success(__('Table %1$s has been altered successfully.'));
             $message->addParam($this->table);
             $this->response->addJSON('message', Util::getMessage($message, $sql_query, 'success'));
             $this->response->addJSON('index_table', Index::getHtmlForIndexes($this->table, $this->db));
         } else {
             include 'tbl_structure.php';
         }
     } else {
         $this->response->setRequestStatus(false);
         $this->response->addJSON('message', $error);
     }
 }