/** * Creates a fieldset for adding a new item, if the user has the privileges. * * @param string $docu String used to create a link to the MySQL docs * @param string $priv Privilege to check for adding a new item * @param string $name MySQL name of the item * * @return string An HTML snippet with the link to add a new item */ function PMA_RTE_getFooterLinks($docu, $priv, $name) { global $db, $url_query, $ajax_class; $icon = 'b_' . strtolower($name) . '_add.png'; $retval = ""; $retval .= "<!-- ADD " . $name . " FORM START -->\n"; $retval .= "<fieldset class='left'>\n"; $retval .= "<legend>" . _pgettext('Create new procedure', 'New') . "</legend>\n"; $retval .= " <div class='wrap'>\n"; if (PMA_Util::currentUserHasPrivilege($priv, $db)) { $retval .= " <a {$ajax_class['add']} "; $retval .= "href='db_" . strtolower($name) . "s.php"; $retval .= "?{$url_query}&add_item=1' onclick='\$.datepicker.initialized = false;'>"; $retval .= PMA_Util::getIcon($icon); $retval .= PMA_RTE_getWord('add') . "</a>\n"; } else { $retval .= " " . PMA_Util::getIcon($icon); $retval .= PMA_RTE_getWord('no_create') . "\n"; } $retval .= " " . PMA_Util::showMySQLDocu($docu) . "\n"; $retval .= " </div>\n"; $retval .= "</fieldset>\n"; $retval .= "<!-- ADD " . $name . " FORM END -->\n\n"; return $retval; }
/** * Returns the html content for the query statistics * * @param PMA_ServerStatusData $ServerStatusData Server status data * * @return string */ function PMA_getHtmlForQueryStatistics($ServerStatusData) { $retval = ''; $hour_factor = 3600 / $ServerStatusData->status['Uptime']; $used_queries = $ServerStatusData->used_queries; $total_queries = array_sum($used_queries); $retval .= '<h3 id="serverstatusqueries">'; /* l10n: Questions is the name of a MySQL Status variable */ $retval .= sprintf(__('Questions since startup: %s'), PMA_Util::formatNumber($total_queries, 0)); $retval .= ' '; $retval .= PMA_Util::showMySQLDocu('server-status-variables', false, 'statvar_Questions'); $retval .= '<br />'; $retval .= '<span>'; $retval .= 'ø ' . __('per hour:') . ' '; $retval .= PMA_Util::formatNumber($total_queries * $hour_factor, 0); $retval .= '<br />'; $retval .= 'ø ' . __('per minute:') . ' '; $retval .= PMA_Util::formatNumber($total_queries * 60 / $ServerStatusData->status['Uptime'], 0); $retval .= '<br />'; if ($total_queries / $ServerStatusData->status['Uptime'] >= 1) { $retval .= 'ø ' . __('per second:') . ' '; $retval .= PMA_Util::formatNumber($total_queries / $ServerStatusData->status['Uptime'], 0); } $retval .= '</span>'; $retval .= '</h3>'; $retval .= PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData); return $retval; }
/** * setup HTML for a given Storage Engine * * @return string */ function PMA_getHtmlForSpecifiedServerEngines() { /** * Displays details about a given Storage Engine */ $html = ''; $engine_plugin = PMA_StorageEngine::getEngine($_REQUEST['engine']); $html .= '<h2>' . "\n" . PMA_Util::getImage('b_engine.png') . ' ' . htmlspecialchars($engine_plugin->getTitle()) . "\n" . ' ' . PMA_Util::showMySQLDocu($engine_plugin->getMysqlHelpPage()) . "\n" . '</h2>' . "\n\n"; $html .= '<p>' . "\n" . ' <em>' . "\n" . ' ' . htmlspecialchars($engine_plugin->getComment()) . "\n" . ' </em>' . "\n" . '</p>' . "\n\n"; $infoPages = $engine_plugin->getInfoPages(); if (!empty($infoPages) && is_array($infoPages)) { $html .= '<p>' . "\n" . ' <strong>[</strong>' . "\n"; if (empty($_REQUEST['page'])) { $html .= ' <strong>' . __('Variables') . '</strong>' . "\n"; } else { $html .= ' <a href="server_engines.php' . PMA_URL_getCommon(array('engine' => $_REQUEST['engine'])) . '">' . __('Variables') . '</a>' . "\n"; } foreach ($infoPages as $current => $label) { $html .= ' <strong>|</strong>' . "\n"; if (isset($_REQUEST['page']) && $_REQUEST['page'] == $current) { $html .= ' <strong>' . $label . '</strong>' . "\n"; } else { $html .= ' <a href="server_engines.php' . PMA_URL_getCommon(array('engine' => $_REQUEST['engine'], 'page' => $current)) . '">' . htmlspecialchars($label) . '</a>' . "\n"; } } unset($current, $label); $html .= ' <strong>]</strong>' . "\n" . '</p>' . "\n\n"; } unset($infoPages, $page_output); if (!empty($_REQUEST['page'])) { $page_output = $engine_plugin->getPage($_REQUEST['page']); } if (!empty($page_output)) { $html .= $page_output; } else { $html .= '<p> ' . $engine_plugin->getSupportInformationMessage() . "\n" . '</p>' . "\n" . $engine_plugin->getHtmlVariables(); } return $html; }
/** * Get HTML for the Change password dialog * * @param string $mode where is the function being called? * values : 'change_pw' or 'edit_other' * @param string $username username * @param string $hostname hostname * * @return string html snippet */ function PMA_getHtmlForChangePassword($mode, $username, $hostname) { /** * autocomplete feature of IE kills the "onchange" event handler and it * must be replaced by the "onpropertychange" one in this case */ $chg_evt_handler = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7 ? 'onpropertychange' : 'onchange'; $is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php'; $html = '<form method="post" id="change_password_form" ' . 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" ' . 'name="chgPassword" ' . 'class="' . ($is_privileges ? 'submenu-item' : '') . '">'; $html .= PMA_URL_getHiddenInputs(); if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) { $html .= '<input type="hidden" name="username" ' . 'value="' . htmlspecialchars($username) . '" />' . '<input type="hidden" name="hostname" ' . 'value="' . htmlspecialchars($hostname) . '" />'; } $html .= '<fieldset id="fieldset_change_password">' . '<legend' . ($is_privileges ? ' data-submenu-label="' . __('Change password') . '"' : '') . '>' . __('Change password') . '</legend>' . '<table class="data noclick">' . '<tr class="odd">' . '<td colspan="2">' . '<input type="radio" name="nopass" value="1" id="nopass_1" ' . 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; ' . 'this.checked = true" />' . '<label for="nopass_1">' . __('No Password') . '</label>' . '</td>' . '</tr>' . '<tr class="even vmiddle">' . '<td>' . '<input type="radio" name="nopass" value="0" id="nopass_0" ' . 'onclick="document.getElementById(\'text_pma_pw\').focus();" ' . 'checked="checked" />' . '<label for="nopass_0">' . __('Password:'******' </label>' . '</td>' . '<td>' . '<input type="password" name="pma_pw" id="text_pma_pw" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . ' ' . __('Re-type:') . ' ' . '<input type="password" name="pma_pw2" id="text_pma_pw2" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . '</td>' . '</tr>'; $serverType = PMA_Util::getServerType(); $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin('change', $username, $hostname); $is_superuser = $GLOBALS['dbi']->isSuperuser(); if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50507 || $serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200) { // Provide this option only for 5.7.6+ // OR for privileged users in 5.5.7+ if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706 || $is_superuser && $mode == 'edit_other') { $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown($username, $hostname, $orig_auth_plugin, 'change_pw', 'new'); $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td><td>'; $html .= $auth_plugin_dropdown; $html .= '</td></tr>' . '<tr id="tr_element_before_generate_password"></tr>' . '</table>'; $html .= '<div ' . ($orig_auth_plugin != 'sha256_password' ? 'style="display:none"' : '') . ' id="ssl_reqd_warning_cp">' . PMA_Message::notice(__('This method requires using an \'<i>SSL connection</i>\' ' . 'or an \'<i>unencrypted connection that encrypts the password ' . 'using RSA</i>\'; while connecting to the server.') . PMA_Util::showMySQLDocu('sha256-authentication-plugin'))->getDisplay() . '</div>'; } else { $html .= '<tr id="tr_element_before_generate_password"></tr>' . '</table>'; } } else { $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown($username, $hostname, $orig_auth_plugin, 'change_pw', 'old'); $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td><td>'; $html .= $auth_plugin_dropdown . '</td></tr>' . '<tr id="tr_element_before_generate_password"></tr>' . '</table>'; } $html .= '</fieldset>' . '<fieldset id="fieldset_change_password_footer" class="tblFooters">' . '<input type="hidden" name="change_pw" value="1" />' . '<input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . '</form>'; return $html; }
/** * Get HTML for the Change password dialog * * @param string $username username * @param string $hostname hostname * * @return string html snippet */ function PMA_getHtmlForChangePassword($username, $hostname) { /** * autocomplete feature of IE kills the "onchange" event handler and it * must be replaced by the "onpropertychange" one in this case */ $chg_evt_handler = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7 ? 'onpropertychange' : 'onchange'; $is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php'; $html = '<form method="post" id="change_password_form" ' . 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" ' . 'name="chgPassword" ' . 'class="' . ($is_privileges ? 'submenu-item' : '') . '">'; $html .= PMA_URL_getHiddenInputs(); if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) { $html .= '<input type="hidden" name="username" ' . 'value="' . htmlspecialchars($username) . '" />' . '<input type="hidden" name="hostname" ' . 'value="' . htmlspecialchars($hostname) . '" />'; } $html .= '<fieldset id="fieldset_change_password">' . '<legend' . ($is_privileges ? ' data-submenu-label="' . __('Change password') . '"' : '') . '>' . __('Change password') . '</legend>' . '<table class="data noclick">' . '<tr class="odd">' . '<td colspan="2">' . '<input type="radio" name="nopass" value="1" id="nopass_1" ' . 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; ' . 'this.checked = true" />' . '<label for="nopass_1">' . __('No Password') . '</label>' . '</td>' . '</tr>' . '<tr class="even vmiddle">' . '<td>' . '<input type="radio" name="nopass" value="0" id="nopass_0" ' . 'onclick="document.getElementById(\'text_pma_pw\').focus();" ' . 'checked="checked" />' . '<label for="nopass_0">' . __('Password:'******' </label>' . '</td>' . '<td>' . '<input type="password" name="pma_pw" id="text_pma_pw" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . ' ' . __('Re-type:') . ' ' . '<input type="password" name="pma_pw2" id="text_pma_pw2" size="10" ' . 'class="textfield"' . $chg_evt_handler . '="nopass[1].checked = true" />' . '</td>' . '</tr>'; $default_auth_plugin = PMA_getCurrentAuthenticationPlugin('change', $username, $hostname); // See http://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-5.html if (PMA_MYSQL_INT_VERSION >= 50705) { $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_mysql_native" ' . 'value="mysql_native_password"'; if ($default_auth_plugin == 'mysql_native_password') { $html .= '" checked="checked"'; } $html .= ' />' . '<label for="radio_pw_hash_mysql_native">' . __('MySQL native password') . '</label>' . '</td>' . '</tr>' . '<tr id="tr_element_before_generate_password">' . '<td> </td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_sha256" ' . 'value="sha256_password"'; if ($default_auth_plugin == 'sha256_password') { $html .= '" checked="checked"'; } $html .= ' />' . '<label for="radio_pw_hash_sha256">' . __('SHA256 password') . '</label>' . '</td>' . '</tr>'; } elseif (PMA_MYSQL_INT_VERSION >= 50606) { $html .= '<tr class="vmiddle" id="tr_element_before_generate_password">' . '<td>' . __('Password Hashing:') . '</td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_new" ' . 'value="' . $default_auth_plugin . '" checked="checked" />' . '<label for="radio_pw_hash_new">' . $default_auth_plugin . '</label>' . '</td>' . '</tr>'; } else { $html .= '<tr class="vmiddle">' . '<td>' . __('Password Hashing:') . '</td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_new" ' . 'value="mysql_native_password" checked="checked" />' . '<label for="radio_pw_hash_new">mysql_native_password</label>' . '</td>' . '</tr>' . '<tr id="tr_element_before_generate_password" >' . '<td> </td>' . '<td>' . '<input type="radio" name="pw_hash" id="radio_pw_hash_old" ' . 'value="old" />' . '<label for="radio_pw_hash_old">' . __('MySQL 4.0 compatible') . '</label>' . '</td>' . '</tr>'; } $html .= '</table>'; $html .= '<div ' . ($default_auth_plugin != 'sha256_password' ? 'style="display:none"' : '') . ' id="ssl_reqd_warning">' . PMA_Message::notice(__('This method requires using an \'<i>SSL connection</i>\' ' . 'or an \'<i>unencrypted connection that encrypts the password ' . 'using RSA</i>\'; while connecting to the server.') . PMA_Util::showMySQLDocu('sha256-authentication-plugin'))->getDisplay() . '</div>'; $html .= '</fieldset>' . '<fieldset id="fieldset_change_password_footer" class="tblFooters">' . '<input type="hidden" name="change_pw" value="1" />' . '<input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . '</form>'; return $html; }
/** * Provides the main search form's html * * @return string HTML for selection form */ public function getSelectionForm() { $html_output = '<a id="db_search"></a>'; $html_output .= '<form id="db_search_form"' . ' class="ajax"' . ' method="post" action="db_search.php" name="db_search">'; $html_output .= PMA_URL_getHiddenInputs($GLOBALS['db']); $html_output .= '<fieldset>'; // set legend caption $html_output .= '<legend>' . __('Search in database') . '</legend>'; $html_output .= '<table class="formlayout">'; // inputbox for search phrase $html_output .= '<tr>'; $html_output .= '<td>' . __('Words or values to search for (wildcard: "%"):') . '</td>'; $html_output .= '<td><input type="text"' . ' name="criteriaSearchString" size="60"' . ' value="' . htmlspecialchars($this->_criteriaSearchString) . '" />'; $html_output .= '</td>'; $html_output .= '</tr>'; // choices for types of search $html_output .= '<tr>'; $html_output .= '<td class="right vtop">' . __('Find:') . '</td>'; $html_output .= '<td>'; $choices = array('1' => __('at least one of the words') . PMA_Util::showHint(__('Words are separated by a space character (" ").')), '2' => __('all words') . PMA_Util::showHint(__('Words are separated by a space character (" ").')), '3' => __('the exact phrase'), '4' => __('as regular expression') . ' ' . PMA_Util::showMySQLDocu('Regexp')); // 4th parameter set to true to add line breaks // 5th parameter set to false to avoid htmlspecialchars() escaping // in the label since we have some HTML in some labels $html_output .= PMA_Util::getRadioFields('criteriaSearchType', $choices, $this->_criteriaSearchType, true, false); $html_output .= '</td></tr>'; // displays table names as select options $html_output .= '<tr>'; $html_output .= '<td class="right vtop">' . __('Inside tables:') . '</td>'; $html_output .= '<td rowspan="2">'; $html_output .= '<select name="criteriaTables[]" size="6"' . ' multiple="multiple">'; foreach ($this->_tables_names_only as $each_table) { if (in_array($each_table, $this->_criteriaTables)) { $is_selected = ' selected="selected"'; } else { $is_selected = ''; } $html_output .= '<option value="' . htmlspecialchars($each_table) . '"' . $is_selected . '>' . str_replace(' ', ' ', htmlspecialchars($each_table)) . '</option>'; } // end for $html_output .= '</select>'; $html_output .= '</td></tr>'; // Displays 'select all' and 'unselect all' links $alter_select = '<a href="#" ' . 'onclick="setSelectOptions(\'db_search\',' . ' \'criteriaTables[]\', true); return false;">' . __('Select All') . '</a> / '; $alter_select .= '<a href="#" ' . 'onclick="setSelectOptions(\'db_search\',' . ' \'criteriaTables[]\', false); return false;">' . __('Unselect All') . '</a>'; $html_output .= '<tr><td class="right vbottom">' . $alter_select . '</td></tr>'; // Inputbox for column name entry $html_output .= '<tr>'; $html_output .= '<td class="right">' . __('Inside column:') . '</td>'; $html_output .= '<td><input type="text" name="criteriaColumnName" size="60"' . 'value="' . (!empty($this->_criteriaColumnName) ? htmlspecialchars($this->_criteriaColumnName) : '') . '" /></td>'; $html_output .= '</tr>'; $html_output .= '</table>'; $html_output .= '</fieldset>'; $html_output .= '<fieldset class="tblFooters">'; $html_output .= '<input type="submit" name="submit_search" value="' . __('Go') . '" id="buttonGo" />'; $html_output .= '</fieldset>'; $html_output .= '</form>'; $html_output .= '<div id="togglesearchformdiv">' . '<a id="togglesearchformlink"></a></div>'; return $html_output; }
/** * Get the HTML for the profiling table and accompanying chart if profiling is set. * Otherwise returns null * * @param string $url_query url query * @param string $db current database * @param array $profiling_results array containing the profiling info * * @return string $profiling_table html for the profiling table and chart */ function PMA_getHtmlForProfilingChart($url_query, $db, $profiling_results) { if (isset($profiling_results)) { $pma_token = $_SESSION[' PMA_token ']; $url_query = isset($url_query) ? $url_query : PMA_URL_getCommon(array('db' => $db)); $profiling_table = ''; $profiling_table .= '<fieldset><legend>' . __('Profiling') . '</legend>' . "\n"; $profiling_table .= '<div style="float: left;">'; $profiling_table .= '<h3>' . __('Detailed profile') . '</h3>'; $profiling_table .= '<table id="profiletable"><thead>' . "\n"; $profiling_table .= ' <tr>' . "\n"; $profiling_table .= ' <th>' . __('Order') . '<div class="sorticon"></div></th>' . "\n"; $profiling_table .= ' <th>' . __('State') . PMA_Util::showMySQLDocu('general-thread-states') . '<div class="sorticon"></div></th>' . "\n"; $profiling_table .= ' <th>' . __('Time') . '<div class="sorticon"></div></th>' . "\n"; $profiling_table .= ' </tr></thead><tbody>' . "\n"; list($detailed_table, $chart_json, $profiling_stats) = PMA_analyzeAndGetTableHtmlForProfilingResults($profiling_results); $profiling_table .= $detailed_table; $profiling_table .= '</tbody></table>' . "\n"; $profiling_table .= '</div>'; $profiling_table .= '<div style="float: left; margin-left:10px;">'; $profiling_table .= '<h3>' . __('Summary by state') . '</h3>'; $profiling_table .= '<table id="profilesummarytable"><thead>' . "\n"; $profiling_table .= ' <tr>' . "\n"; $profiling_table .= ' <th>' . __('State') . PMA_Util::showMySQLDocu('general-thread-states') . '<div class="sorticon"></div></th>' . "\n"; $profiling_table .= ' <th>' . __('Total Time') . '<div class="sorticon"></div></th>' . "\n"; $profiling_table .= ' <th>' . __('% Time') . '<div class="sorticon"></div></th>' . "\n"; $profiling_table .= ' <th>' . __('Calls') . '<div class="sorticon"></div></th>' . "\n"; $profiling_table .= ' <th>' . __('ø Time') . '<div class="sorticon"></div></th>' . "\n"; $profiling_table .= ' </tr></thead><tbody>' . "\n"; $profiling_table .= PMA_getTableHtmlForProfilingSummaryByState($profiling_stats); $profiling_table .= '</tbody></table>' . "\n"; $profiling_table .= <<<EOT <script type="text/javascript"> pma_token = '{$pma_token}'; url_query = '{$url_query}'; </script> EOT; $profiling_table .= "</div>"; $profiling_table .= "<div class='clearfloat'></div>"; //require_once 'libraries/chart.lib.php'; $profiling_table .= '<div id="profilingChartData" style="display:none;">'; $profiling_table .= json_encode($chart_json); $profiling_table .= '</div>'; $profiling_table .= '<div id="profilingchart" style="display:none;">'; $profiling_table .= '</div>'; $profiling_table .= '<script type="text/javascript">'; $profiling_table .= "AJAX.registerOnload('sql.js', function () {"; $profiling_table .= 'makeProfilingChart();'; $profiling_table .= 'initProfilingTables();'; $profiling_table .= '});'; $profiling_table .= '</script>'; $profiling_table .= '</fieldset>' . "\n"; } else { $profiling_table = null; } return $profiling_table; }
/** * Define some data and links needed on the client side * * @param PMA_ServerStatusData $ServerStatusData Server status data * * @return string */ function PMA_getHtmlForClientSideDataAndLinks($ServerStatusData) { /** * Define some data needed on the client side */ $input = '<input type="hidden" name="%s" value="%s" />'; $form = '<form id="js_data" class="hide">'; $form .= sprintf($input, 'server_time', microtime(true) * 1000); $form .= sprintf($input, 'server_os', PHP_OS); $form .= sprintf($input, 'is_superuser', $GLOBALS['dbi']->isSuperuser()); $form .= sprintf($input, 'server_db_isLocal', $ServerStatusData->db_isLocal); $form .= '</form>'; /** * Define some links used on client side */ $links = '<div id="profiling_docu" class="hide">'; $links .= PMA_Util::showMySQLDocu('general-thread-states'); $links .= '</div>'; $links .= '<div id="explain_docu" class="hide">'; $links .= PMA_Util::showMySQLDocu('explain-output'); $links .= '</div>'; return $form . $links; }
/** * Get HTML snippet for display user overview page * * @param string $pmaThemeImage a image source link * @param string $text_dir text directory * * @return string $html_output */ function PMA_getHtmlForUserOverview($pmaThemeImage, $text_dir) { $html_output = '<h2>' . "\n" . PMA_Util::getIcon('b_usrlist.png') . __('User accounts overview') . "\n" . '</h2>' . "\n"; $password_column = 'Password'; if (PMA_Util::getServerType() == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706) { $password_column = 'authentication_string'; } // $sql_query is for the initial-filtered, // $sql_query_all is for counting the total no. of users $sql_query = $sql_query_all = 'SELECT *,' . " IF(`" . $password_column . "` = _latin1 '', 'N', 'Y') AS 'Password'" . ' FROM `mysql`.`user`'; $sql_query .= isset($_REQUEST['initial']) ? PMA_rangeOfUsers($_REQUEST['initial']) : ''; $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; $sql_query_all .= ' ;'; $res = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DatabaseInterface::QUERY_STORE); $res_all = $GLOBALS['dbi']->tryQuery($sql_query_all, null, PMA_DatabaseInterface::QUERY_STORE); if (!$res) { // the query failed! This may have two reasons: // - the user does not have enough privileges // - the privilege tables use a structure of an earlier version. // so let's try a more simple query $GLOBALS['dbi']->freeResult($res); $GLOBALS['dbi']->freeResult($res_all); $sql_query = 'SELECT * FROM `mysql`.`user`'; $res = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DatabaseInterface::QUERY_STORE); if (!$res) { $html_output .= PMA_getHtmlForViewUsersError(); $html_output .= PMA_getAddUserHtmlFieldset(); } else { // This message is hardcoded because I will replace it by // a automatic repair feature soon. $raw = 'Your privilege table structure seems to be older than' . ' this MySQL version!<br />' . 'Please run the <code>mysql_upgrade</code> command' . '(<code>mysql_fix_privilege_tables</code> on older systems)' . ' that should be included in your MySQL server distribution' . ' to solve this problem!'; $html_output .= PMA_Message::rawError($raw)->getDisplay(); } $GLOBALS['dbi']->freeResult($res); } else { $db_rights = PMA_getDbRightsForUserOverview(); // for all initials, even non A-Z $array_initials = array(); foreach ($db_rights as $right) { foreach ($right as $account) { if (empty($account['User']) && $account['Host'] == 'localhost') { $html_output .= PMA_Message::notice(__('A user account allowing any user from localhost to ' . 'connect is present. This will prevent other users ' . 'from connecting if the host part of their account ' . 'allows a connection from any (%) host.') . PMA_Util::showMySQLDocu('problems-connecting'))->getDisplay(); break 2; } } } /** * Displays the initials * Also not necessary if there is less than 20 privileges */ if ($GLOBALS['dbi']->numRows($res_all) > 20) { $html_output .= PMA_getHtmlForInitials($array_initials); } /** * Display the user overview * (if less than 50 users, display them immediately) */ if (isset($_REQUEST['initial']) || isset($_REQUEST['showall']) || $GLOBALS['dbi']->numRows($res) < 50) { $html_output .= PMA_getUsersOverview($res, $db_rights, $pmaThemeImage, $text_dir); } else { $html_output .= PMA_getAddUserHtmlFieldset(); } // end if (display overview) if (!$GLOBALS['is_ajax_request'] || !empty($_REQUEST['ajax_page_request'])) { if (isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv']) { $flushnote = new PMA_Message(__('Note: phpMyAdmin gets the users\' privileges directly ' . 'from MySQL\'s privilege tables. The content of these ' . 'tables may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'you should %sreload the privileges%s before you continue.'), PMA_Message::NOTICE); $flushLink = '<a href="server_privileges.php' . PMA_URL_getCommon(array('flush_privileges' => 1)) . '" id="reload_privileges_anchor">'; $flushnote->addParam($flushLink, false); $flushnote->addParam('</a>', false); } else { $flushnote = new PMA_Message(__('Note: phpMyAdmin gets the users\' privileges directly ' . 'from MySQL\'s privilege tables. The content of these ' . 'tables may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'the privileges have to be reloaded but currently, you ' . 'don\'t have the RELOAD privilege.') . PMA_Util::showMySQLDocu('privileges-provided', false, 'priv_reload'), PMA_Message::NOTICE); } $html_output .= $flushnote->getDisplay(); } } return $html_output; }
/** * Test for PMA_getHtmlForSqlQueryFormInsert * * @return void */ public function testPMAGetHtmlForSqlQueryFormInsert() { //Call the test function $query = "select * from PMA"; $html = PMA_getHtmlForSqlQueryFormInsert($query); //validate 1: query $this->assertContains(htmlspecialchars($query), $html); //validate 2: enable auto select text in textarea $auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"'; $this->assertContains($auto_sel, $html); //validate 3: showMySQLDocu $this->assertContains(PMA_Util::showMySQLDocu('SELECT'), $html); //validate 4: $fields_list $this->assertContains('<input type="button" value="DELETE" id="delete"', $html); $this->assertContains('<input type="button" value="UPDATE" id="update"', $html); $this->assertContains('<input type="button" value="INSERT" id="insert"', $html); $this->assertContains('<input type="button" value="SELECT" id="select"', $html); $this->assertContains('<input type="button" value="SELECT *" id="selectall"', $html); //validate 5: Clear button $this->assertContains('<input type="button" value="DELETE" id="delete"', $html); $this->assertContains(__('Clear'), $html); }
/** * 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 .= "<fieldset>\n"; $retval .= " <legend>\n"; $retval .= " " . PMA_RTE_getWord('title') . "\n"; $retval .= " " . PMA_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>" . __('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>" . __('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>" . __('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"; $retval .= "</fieldset>\n"; $retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n"; return $retval; }
/** * Creates the code for displaying the links * at the top of the navigation panel * * @return string HTML code for the links */ private function _links() { // always iconic $showIcon = true; $showText = false; $retval = '<!-- LINKS START -->'; $retval .= '<div id="navipanellinks">'; $retval .= $this->_getLink('index.php?' . PMA_URL_getCommon(), $showText, __('Home'), $showIcon, 'b_home.png'); // if we have chosen server if ($GLOBALS['server'] != 0) { // Logout for advanced authentication if ($GLOBALS['cfg']['Server']['auth_type'] != 'config') { $link = 'index.php?' . $GLOBALS['url_query']; $link .= '&old_usr='******'PHP_AUTH_USER']); $retval .= $this->_getLink($link, $showText, __('Log out'), $showIcon, 's_loggoff.png', '', true); } $link = 'querywindow.php?'; $link .= PMA_URL_getCommon($GLOBALS['db'], $GLOBALS['table']); $link .= '&no_js=true'; $retval .= $this->_getLink($link, $showText, __('Query window'), $showIcon, 'b_selboard.png', 'pma_open_querywindow', true); } $retval .= $this->_getLink(PMA_Util::getDocuLink('index'), $showText, __('phpMyAdmin documentation'), $showIcon, 'b_docs.png', '', false, 'documentation'); if ($showIcon) { $retval .= PMA_Util::showMySQLDocu('', true); } if ($showText) { // PMA_showMySQLDocu always spits out an icon, // we just replace it with some perl regexp. $link = preg_replace('/<img[^>]+>/i', __('Documentation'), PMA_Util::showMySQLDocu('', true)); $retval .= $link; $retval .= '<br />'; } $retval .= $this->_getLink('#', $showText, __('Reload navigation panel'), $showIcon, 's_reload.png', 'pma_navigation_reload'); $retval .= '</div>'; $retval .= '<!-- LINKS ENDS -->'; return $retval; }
/** * Returns single option in a list element * * @param string $section name of config section in * $GLOBALS['cfg'][$section] for plugin * @param string $plugin_name unique plugin name * @param array &$propertyGroup options property main group instance * @param boolean $is_subgroup if this group is a subgroup * * @return string table row with option */ function PMA_pluginGetOneOption($section, $plugin_name, &$propertyGroup, $is_subgroup = false) { $ret = "\n"; if (!$is_subgroup) { // for subgroup headers if (strpos(get_class($propertyGroup), "PropertyItem")) { $properties = [$propertyGroup]; } else { // for main groups $ret .= '<div class="export_sub_options" id="' . $plugin_name . '_' . $propertyGroup->getName() . '">'; if (method_exists($propertyGroup, 'getText')) { $text = $propertyGroup->getText(); } if ($text != null) { $ret .= '<h4>' . PMA_getString($text) . '</h4>'; } $ret .= '<ul>'; } } if (!isset($properties)) { $not_subgroup_header = true; if (method_exists($propertyGroup, 'getProperties')) { $properties = $propertyGroup->getProperties(); } } if (isset($properties)) { foreach ($properties as $propertyItem) { $property_class = get_class($propertyItem); // if the property is a subgroup, we deal with it recursively if (strpos($property_class, "Subgroup")) { // for subgroups // each subgroup can have a header, which may also be a form element $subgroup_header = $propertyItem->getSubgroupHeader(); if (isset($subgroup_header)) { $ret .= PMA_pluginGetOneOption($section, $plugin_name, $subgroup_header); } $ret .= '<li class="subgroup"><ul'; if (isset($subgroup_header)) { $ret .= ' id="ul_' . $subgroup_header->getName() . '">'; } else { $ret .= '>'; } $ret .= PMA_pluginGetOneOption($section, $plugin_name, $propertyItem, true); } else { // single property item switch ($property_class) { case "BoolPropertyItem": $ret .= '<li>' . "\n"; $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $propertyItem->getName() . '"' . ' value="something" id="checkbox_' . $plugin_name . '_' . $propertyItem->getName() . '"' . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $propertyItem->getName()); if ($propertyItem->getForce() != null) { // Same code is also few lines lower, update both if needed $ret .= ' onclick="if (!this.checked && ' . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' . $propertyItem->getForce() . '\') ' . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' . $propertyItem->getForce() . '\').checked)) ' . 'return false; else return true;"'; } $ret .= ' />'; $ret .= '<label for="checkbox_' . $plugin_name . '_' . $propertyItem->getName() . '">' . PMA_getString($propertyItem->getText()) . '</label>'; break; case "DocPropertyItem": echo "DocPropertyItem"; break; case "HiddenPropertyItem": $ret .= '<li><input type="hidden" name="' . $plugin_name . '_' . $propertyItem->getName() . '"' . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $propertyItem->getName()) . '"' . ' /></li>'; break; case "MessageOnlyPropertyItem": $ret .= '<li>' . "\n"; $ret .= '<p>' . PMA_getString($propertyItem->getText()) . '</p>'; break; case "RadioPropertyItem": $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $propertyItem->getName()); foreach ($propertyItem->getValues() as $key => $val) { $ret .= '<li><input type="radio" name="' . $plugin_name . '_' . $propertyItem->getName() . '" value="' . $key . '" id="radio_' . $plugin_name . '_' . $propertyItem->getName() . '_' . $key . '"'; if ($key == $default) { $ret .= ' checked="checked"'; } $ret .= ' />' . '<label for="radio_' . $plugin_name . '_' . $propertyItem->getName() . '_' . $key . '">' . PMA_getString($val) . '</label></li>'; } break; case "SelectPropertyItem": $ret .= '<li>' . "\n"; $ret .= '<label for="select_' . $plugin_name . '_' . $propertyItem->getName() . '" class="desc">' . PMA_getString($propertyItem->getText()) . '</label>'; $ret .= '<select name="' . $plugin_name . '_' . $propertyItem->getName() . '"' . ' id="select_' . $plugin_name . '_' . $propertyItem->getName() . '">'; $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $propertyItem->getName()); foreach ($propertyItem->getValues() as $key => $val) { $ret .= '<option value="' . $key . '"'; if ($key == $default) { $ret .= ' selected="selected"'; } $ret .= '>' . PMA_getString($val) . '</option>'; } $ret .= '</select>'; break; case "TextPropertyItem": $ret .= '<li>' . "\n"; $ret .= '<label for="text_' . $plugin_name . '_' . $propertyItem->getName() . '" class="desc">' . PMA_getString($propertyItem->getText()) . '</label>'; $ret .= '<input type="text" name="' . $plugin_name . '_' . $propertyItem->getName() . '"' . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $propertyItem->getName()) . '"' . ' id="text_' . $plugin_name . '_' . $propertyItem->getName() . '"' . ($propertyItem->getSize() != null ? ' size="' . $propertyItem->getSize() . '"' : '') . ($propertyItem->getLen() != null ? ' maxlength="' . $propertyItem->getLen() . '"' : '') . ' />'; break; default: } } } } if ($is_subgroup) { // end subgroup $ret .= '</ul></li>'; } else { // end main group if (!empty($not_subgroup_header)) { $ret .= '</ul></div>'; } } if (method_exists($propertyGroup, "getDoc")) { $doc = $propertyGroup->getDoc(); if ($doc != null) { if (count($doc) == 3) { $ret .= PMA_Util::showMySQLDocu($doc[0], $doc[1], false, $doc[2]); } elseif (count($doc) == 1) { $ret .= PMA_Util::showDocu('faq', $doc[0]); } else { $ret .= PMA_Util::showMySQLDocu($doc[0], $doc[1]); } } } // Close the list element after $doc link is displayed if (isset($property_class)) { if ($property_class == 'BoolPropertyItem' || $property_class == 'MessageOnlyPropertyItem' || $property_class == 'SelectPropertyItem' || $property_class == 'TextPropertyItem') { $ret .= '</li>'; } } $ret .= "\n"; return $ret; }
/** * Prints Html for Server Variables Items * * @param Array $variable_doc_links documentation links * @param Array $serverVars global variables * @param Array $serverVarsSession session variables * * @return string */ function PMA_getHtmlForServerVariablesItems($variable_doc_links, $serverVars, $serverVarsSession) { // list of static system variables $static_variables = PMA_getStaticSystemVariables(); $output = '<tbody>'; $odd_row = true; foreach ($serverVars as $name => $value) { $has_session_value = isset($serverVarsSession[$name]) && $serverVarsSession[$name] != $value; $row_class = ($odd_row ? ' odd' : ' even') . ($has_session_value ? ' diffSession' : ''); $output .= '<tr class="var-row' . $row_class . '">'; $output .= '<td class="var-action">'; // Edit Link active only for Dynamic System variables if (!in_array(strtolower($name), $static_variables)) { $output .= '<a href="#" class="editLink">' . PMA_Util::getIcon('b_edit.png', __('Edit')) . '</a>'; } else { $output .= '<span title="' . __('This is a read-only variable and can not be edited') . '" class="read_only_var" >' . PMA_Util::getIcon('bd_edit.png', __('Edit')) . '</span>'; } $output .= '</td>'; $output .= '<td class="var-name">'; // To display variable documentation link if (isset($variable_doc_links[$name])) { $output .= '<span title="' . htmlspecialchars(str_replace('_', ' ', $name)) . '">'; $output .= PMA_Util::showMySQLDocu($variable_doc_links[$name][1], false, $variable_doc_links[$name][2] . '_' . $variable_doc_links[$name][0], true); $output .= htmlspecialchars(str_replace('_', ' ', $name)); $output .= '</a>'; $output .= '</span>'; } else { $output .= htmlspecialchars(str_replace('_', ' ', $name)); } $output .= '</td>'; $output .= '<td class="var-value value' . ($GLOBALS['dbi']->isSuperuser() ? ' editable' : '') . '"> ' . PMA_formatVariable($name, $value, $variable_doc_links) . '</td>' . '</tr>'; if ($has_session_value) { $output .= '<tr class="var-row' . ($odd_row ? ' odd' : ' even') . '">' . '<td class="var-action"></td>' . '<td class="var-name session">(' . __('Session value') . ')</td>' . '<td class="var-value value"> ' . PMA_formatVariable($name, $serverVarsSession[$name], $variable_doc_links) . '</td>' . '</tr>'; } $odd_row = !$odd_row; } $output .= '</tbody>'; return $output; }
/** * Returns single option in a list element * * @param string $section name of config section in * $GLOBALS['cfg'][$section] for plugin * @param string $plugin_name unique plugin name * @param array &$propertyGroup options property main group instance * @param boolean $is_subgroup if this group is a subgroup * * @return string table row with option */ function PMA_pluginGetOneOption($section, $plugin_name, &$propertyGroup, $is_subgroup = false) { $ret = "\n"; if (!$is_subgroup) { // for subgroup headers if (mb_strpos(get_class($propertyGroup), "PropertyItem")) { $properties = array($propertyGroup); } else { // for main groups $ret .= '<div class="export_sub_options" id="' . $plugin_name . '_' . $propertyGroup->getName() . '">'; if (method_exists($propertyGroup, 'getText')) { $text = $propertyGroup->getText(); } if ($text != null) { $ret .= '<h4>' . PMA_getString($text) . '</h4>'; } $ret .= '<ul>'; } } if (!isset($properties)) { $not_subgroup_header = true; if (method_exists($propertyGroup, 'getProperties')) { $properties = $propertyGroup->getProperties(); } } if (isset($properties)) { /** @var OptionsPropertySubgroup $propertyItem */ foreach ($properties as $propertyItem) { $property_class = get_class($propertyItem); // if the property is a subgroup, we deal with it recursively if (mb_strpos($property_class, "Subgroup")) { // for subgroups // each subgroup can have a header, which may also be a form element /** @var OptionsPropertyItem $subgroup_header */ $subgroup_header = $propertyItem->getSubgroupHeader(); if (isset($subgroup_header)) { $ret .= PMA_pluginGetOneOption($section, $plugin_name, $subgroup_header); } $ret .= '<li class="subgroup"><ul'; if (isset($subgroup_header)) { $ret .= ' id="ul_' . $subgroup_header->getName() . '">'; } else { $ret .= '>'; } $ret .= PMA_pluginGetOneOption($section, $plugin_name, $propertyItem, true); continue; } // single property item $ret .= PMA_getHtmlForProperty($section, $plugin_name, $propertyItem); } } if ($is_subgroup) { // end subgroup $ret .= '</ul></li>'; } else { // end main group if (!empty($not_subgroup_header)) { $ret .= '</ul></div>'; } } if (method_exists($propertyGroup, "getDoc")) { $doc = $propertyGroup->getDoc(); if ($doc != null) { if (count($doc) == 3) { $ret .= PMA_Util::showMySQLDocu($doc[1], false, $doc[2]); } elseif (count($doc) == 1) { $ret .= PMA_Util::showDocu('faq', $doc[0]); } else { $ret .= PMA_Util::showMySQLDocu($doc[1]); } } } // Close the list element after $doc link is displayed if (isset($property_class)) { if ($property_class == 'BoolPropertyItem' || $property_class == 'MessageOnlyPropertyItem' || $property_class == 'SelectPropertyItem' || $property_class == 'TextPropertyItem') { $ret .= '</li>'; } } $ret .= "\n"; return $ret; }
/** * Function to get html for displaying the index form * * @param array $fields fields * @param PMA_Index $index index * @param array $form_params form parameters * @param int $add_fields number of fields in the form * * @return string */ function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields) { $html = ""; $html .= '<form action="tbl_indexes.php" method="post" name="index_frm" id="' . 'index_frm" class="ajax"' . 'onsubmit="if (typeof(this.elements[\'index[Key_name]\'].disabled) !=' . ' \'undefined\') {' . 'this.elements[\'index[Key_name]\'].disabled = false}">'; $html .= PMA_URL_getHiddenInputs($form_params); $html .= '<fieldset id="index_edit_fields">'; $html .= '<div class="index_info">'; $html .= '<div>' . '<div class="label">' . '<strong>' . '<label for="input_index_name">' . __('Index name:') . PMA_Util::showHint(PMA_Message::notice(__('"PRIMARY" <b>must</b> be the name of' . ' and <b>only of</b> a primary key!'))) . '</label>' . '</strong>' . '</div>' . '<input type="text" name="index[Key_name]" id="input_index_name"' . ' size="25"' . 'value="' . htmlspecialchars($index->getName()) . '"' . 'onfocus="this.select()" />' . '</div>'; $html .= '<div>' . '<div class="label">' . '<strong>' . '<label for="input_index_comment">' . __('Comment:') . '</label>' . '</strong>' . '</div>' . '<input type="text" name="index[Index_comment]" ' . 'id="input_index_comment" size="30"' . 'value="' . htmlspecialchars($index->getComment()) . '"' . 'onfocus="this.select()" />' . '</div>'; $html .= '<div>' . '<div class="label">' . '<strong>' . '<label for="select_index_type">' . __('Index type:') . PMA_Util::showMySQLDocu('ALTER_TABLE') . '</label>' . '</strong>' . '</div>' . '<select name="index[Index_type]" id="select_index_type" ' . (isset($_REQUEST['create_edit_table']) ? 'disabled="disabled"' : '') . '>' . $index->generateIndexSelector() . '</select>' . '</div>'; $html .= '<div class="clearfloat"></div>'; $html .= '</div>'; $html .= '<table id="index_columns">'; $html .= '<thead>' . '<tr>' . '<th>' . __('Column') . '</th>' . '<th>' . __('Size') . '</th>' . '</tr>' . '</thead>'; $odd_row = true; $spatial_types = array('geometry', 'point', 'linestring', 'polygon', 'multipoint', 'multilinestring', 'multipolygon', 'geomtrycollection'); $html .= '<tbody>'; /* @var $column PMA_Index_Column */ foreach ($index->getColumns() as $column) { $html .= '<tr class="'; $html .= $odd_row ? 'odd' : 'even'; $html .= 'noclick">'; $html .= '<td><span class="drag_icon" title="' . __('Drag to reorder') . '"' . '></span>'; $html .= '<select name="index[columns][names][]">'; $html .= '<option value="">-- ' . __('Ignore') . ' --</option>'; foreach ($fields as $field_name => $field_type) { if (($index->getType() != 'FULLTEXT' || preg_match('/(char|text)/i', $field_type)) && ($index->getType() != 'SPATIAL' || in_array($field_type, $spatial_types))) { $html .= '<option value="' . htmlspecialchars($field_name) . '"' . ($field_name == $column->getName() ? ' selected="selected"' : '') . '>' . htmlspecialchars($field_name) . ' [' . htmlspecialchars($field_type) . ']' . '</option>' . "\n"; } } // end foreach $fields $html .= '</select>'; $html .= '</td>'; $html .= '<td>'; $html .= '<input type="text" size="5" onfocus="this.select()"' . 'name="index[columns][sub_parts][]" value="'; if ($index->getType() != 'SPATIAL') { $html .= $column->getSubPart(); } $html .= '"/>'; $html .= '</td>'; $html .= '</tr>'; $odd_row = !$odd_row; } // end foreach $edited_index_info['Sequences'] for ($i = 0; $i < $add_fields; $i++) { $html .= '<tr class="'; $html .= $odd_row ? 'odd' : 'even'; $html .= 'noclick">'; $html .= '<td><span class="drag_icon" title="' . __('Drag to reorder') . '"' . '></span>'; $html .= '<select name="index[columns][names][]">'; $html .= '<option value="">-- ' . __('Ignore') . ' --</option>'; $j = 0; foreach ($fields as $field_name => $field_type) { if (isset($_REQUEST['create_edit_table'])) { $col_index = $field_type[1]; $field_type = $field_type[0]; } $html .= '<option value="' . htmlspecialchars(isset($col_index) ? $col_index : $field_name) . '" ' . ($j++ == $i ? 'selected="selected"' : '') . '>' . htmlspecialchars($field_name) . ' [' . htmlspecialchars($field_type) . ']' . '</option>' . "\n"; } // end foreach $fields $html .= '</select>'; $html .= '</td>'; $html .= '<td>' . '<input type="text" size="5" onfocus="this.select()"' . 'name="index[columns][sub_parts][]" value="" />' . '</td>'; $html .= '</tr>'; $odd_row = !$odd_row; } // end foreach $edited_index_info['Sequences'] $html .= '</tbody>'; $html .= '</table>'; $html .= '</fieldset>'; $html .= '<fieldset class="tblFooters">'; $btn_value = sprintf(__('Add %s column(s) to index'), 1); $html .= '<div class="slider"></div>'; $html .= '<div class="add_fields">'; $html .= '<input type="submit" value="' . $btn_value . '" />'; $html .= '</div>'; $html .= '</fieldset>'; $html .= '</form>'; return $html; }
/** * Get HTML links for 'Print view', 'Relation view', 'Propose table structure', * 'Track table' and 'Move columns' * * @param string $url_query url query * @param boolean $tbl_is_view whether table is view or not * @param boolean $db_is_system_schema whether db is information schema or not * @param string $tbl_storage_engine table storage engine * @param array $cfgRelation current relation parameters * * @return string $html_output */ function PMA_getHtmlForOptionalActionLinks($url_query, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $cfgRelation) { $html_output = '<a href="tbl_printview.php?' . $url_query . '" target="print_view">' . PMA_Util::getIcon('b_print.png', __('Print view'), true) . '</a>'; if (!$tbl_is_view && !$db_is_system_schema) { // if internal relations are available, or foreign keys are supported // ($tbl_storage_engine comes from libraries/tbl_info.inc.php if ($cfgRelation['relwork'] || PMA_Util::isForeignKeySupported($tbl_storage_engine)) { $html_output .= '<a href="tbl_relation.php?' . $url_query . '">' . PMA_Util::getIcon('b_relations.png', __('Relation view'), true) . '</a>'; } if (!PMA_DRIZZLE) { $html_output .= '<a href="sql.php?' . $url_query . '&session_max_rows=all&sql_query=' . urlencode('SELECT * FROM ' . PMA_Util::backquote($GLOBALS['table']) . ' PROCEDURE ANALYSE()') . '">' . PMA_Util::getIcon('b_tblanalyse.png', __('Propose table structure'), true) . '</a>'; $html_output .= PMA_Util::showMySQLDocu('procedure_analyse') . "\n"; } if (PMA_Tracker::isActive()) { $html_output .= '<a href="tbl_tracking.php?' . $url_query . '">' . PMA_Util::getIcon('eye.png', __('Track table'), true) . '</a>'; } $html_output .= '<a href="#" id="move_columns_anchor">' . PMA_Util::getIcon('b_move.png', __('Move columns'), true) . '</a>'; } return $html_output; }
/** * Function to get header cells * * @param bool $is_backup whether backup or not * @param array|null $columnMeta column meta data * @param bool $mimework whether mimework or not * @param string $db current database * @param string $table current table * * @return array */ function PMA_getHeaderCells($is_backup, $columnMeta, $mimework, $db, $table) { $header_cells = array(); $header_cells[] = __('Name'); $header_cells[] = __('Type') . PMA_Util::showMySQLDocu('data-types'); $header_cells[] = __('Length/Values') . PMA_Util::showHint(__('If column type is "enum" or "set", please enter the values using' . ' this format: \'a\',\'b\',\'c\'…<br />If you ever need to put' . ' a backslash ("\\") or a single quote ("\'") amongst those' . ' values, precede it with a backslash (for example \'\\\\xyz\'' . ' or \'a\\\'b\').')); $header_cells[] = __('Default') . PMA_Util::showHint(__('For default values, please enter just a single value,' . ' without backslash escaping or quotes, using this format: a')); $header_cells[] = __('Collation'); $header_cells[] = __('Attributes'); $header_cells[] = __('Null'); // We could remove this 'if' and let the key information be shown and // editable. However, for this to work, structure.lib.php must be modified // to use the key fields, as tbl_addfield does. if (!$is_backup) { $header_cells[] = __('Index'); } $header_cells[] = '<abbr title="AUTO_INCREMENT">A_I</abbr>'; $header_cells[] = __('Comments'); if (isset($columnMeta)) { $header_cells[] = __('Move column'); } if ($mimework && $GLOBALS['cfg']['BrowseMIME']) { $header_cells[] = __('MIME type'); $header_link = '<a href="transformation_overview.php?' . PMA_URL_getCommon($db, $table) . '#%s" title="' . __('List of available transformations and their options') . '" target="_blank">%s</a>'; $transformations_hint = PMA_Util::showHint(__('Please enter the values for transformation options using this' . ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put' . ' a backslash ("\\") or a single quote ("\'") amongst those' . ' values, precede it with a backslash (for example \'\\\\xyz\'' . ' or \'a\\\'b\').')); $header_cells[] = sprintf($header_link, 'transformation', __('Browser display transformation')); $header_cells[] = __('Browser display transformation options') . $transformations_hint; $header_cells[] = sprintf($header_link, 'input_transformation', __('Input transformation')); $header_cells[] = __('Input transformation options') . $transformations_hint; } return $header_cells; }
/** * Get initial values for Sql Query Form Insert * * @param string $query query to display in the textarea * * @return array ($legend, $query, $columns_list) * * @usedby PMA_getHtmlForSqlQueryFormInsert() */ function PMA_initQueryForm($query) { $columns_list = array(); if (!mb_strlen($GLOBALS['db'])) { // prepare for server related $legend = sprintf(__('Run SQL query/queries on server %s'), '"' . htmlspecialchars(!empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '"'); } elseif (!mb_strlen($GLOBALS['table'])) { // prepare for db related $db = $GLOBALS['db']; // if you want navigation: $tmp_db_link = '<a href="' . PMA_Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . PMA_URL_getCommon(array('db' => $db)) . '"'; $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'); } } else { $db = $GLOBALS['db']; // Get the list and number of fields // we do a try_query here, because we could be in the query window, // trying to synchronize and the table has not yet been created $columns_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], null, true); $tmp_db_link = '<a href="' . PMA_Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database') . PMA_URL_getCommon(array('db' => $db)) . '"'; $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryTable'], 'backquote'); } } $legend .= ': ' . PMA_Util::showMySQLDocu('SELECT'); return array($legend, $query, $columns_list); }
/** * 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 .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']); $retval .= "<fieldset>\n"; $retval .= " <legend>\n"; $retval .= " " . PMA_RTE_getWord('title') . "\n"; $retval .= " " . PMA_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 .= PMA_Util::getWithSelected($GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], 'rteListForm'); $retval .= PMA_Util::getButtonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', __('Export'), 'b_export.png', 'export'); $retval .= PMA_Util::getButtonOrImage('submit_mult', 'mult_submit', 'submit_mult_drop', __('Drop'), 'b_drop.png', 'drop'); $retval .= '</div>'; } $retval .= "</fieldset>\n"; $retval .= "</form>\n"; $retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n"; 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 '<li id="' . $listId . '"'; if (null !== $class) { echo ' class="' . $class . '"'; } echo '>'; if (null !== $url) { echo '<a href="' . $url . '"'; if (null !== $target) { echo ' target="' . $target . '"'; } if (null != $a_id) { echo ' id="' . $a_id . '"'; } if (null != $a_class) { echo ' class="' . $a_class . '"'; } echo '>'; } echo $name; if (null !== $url) { echo '</a>' . "\n"; } if (null !== $mysql_help_page) { echo PMA_Util::showMySQLDocu($mysql_help_page); } echo '</li>'; }
/** * Function to handle foreign key updates * * @param array $destination_foreign_db destination foreign database * @param array $multi_edit_columns_name multi edit column names * @param array $destination_foreign_table destination foreign table * @param array $destination_foreign_column destination foreign column * @param array $options_array options array * @param string $table current table * @param array $existrel_foreign db, table, column * * @return array */ public function updateForeignKeys($destination_foreign_db, $multi_edit_columns_name, $destination_foreign_table, $destination_foreign_column, $options_array, $table, $existrel_foreign) { $html_output = ''; $preview_sql_data = ''; $display_query = ''; $seen_error = false; foreach ($destination_foreign_db as $master_field_md5 => $foreign_db) { $create = false; $drop = false; // Map the fieldname's md5 back to its real name $master_field = $multi_edit_columns_name[$master_field_md5]; $foreign_table = $destination_foreign_table[$master_field_md5]; $foreign_field = $destination_foreign_column[$master_field_md5]; if (isset($existrel_foreign[$master_field_md5]['ref_db_name'])) { $ref_db_name = $existrel_foreign[$master_field_md5]['ref_db_name']; } else { $ref_db_name = $GLOBALS['db']; } $empty_fields = false; foreach ($master_field as $key => $one_field) { if (!empty($one_field) && empty($foreign_field[$key]) || empty($one_field) && !empty($foreign_field[$key])) { $empty_fields = true; } if (empty($one_field) && empty($foreign_field[$key])) { unset($master_field[$key]); unset($foreign_field[$key]); } } if (!empty($foreign_db) && !empty($foreign_table) && !$empty_fields) { if (isset($existrel_foreign[$master_field_md5])) { $constraint_name = $existrel_foreign[$master_field_md5]['constraint']; $on_delete = !empty($existrel_foreign[$master_field_md5]['on_delete']) ? $existrel_foreign[$master_field_md5]['on_delete'] : 'RESTRICT'; $on_update = !empty($existrel_foreign[$master_field_md5]['on_update']) ? $existrel_foreign[$master_field_md5]['on_update'] : 'RESTRICT'; if ($ref_db_name != $foreign_db || $existrel_foreign[$master_field_md5]['ref_table_name'] != $foreign_table || $existrel_foreign[$master_field_md5]['ref_index_list'] != $foreign_field || $existrel_foreign[$master_field_md5]['index_list'] != $master_field || $_REQUEST['constraint_name'][$master_field_md5] != $constraint_name || $_REQUEST['on_delete'][$master_field_md5] != $on_delete || $_REQUEST['on_update'][$master_field_md5] != $on_update) { // another foreign key is already defined for this field // or an option has been changed for ON DELETE or ON UPDATE $drop = true; $create = true; } // end if... else.... } else { // no key defined for this field(s) $create = true; } } elseif (isset($existrel_foreign[$master_field_md5])) { $drop = true; } // end if... else.... $tmp_error_drop = false; if ($drop) { $drop_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' DROP FOREIGN KEY ' . PMA_Util::backquote($existrel_foreign[$master_field_md5]['constraint']) . ';'; if (!isset($_REQUEST['preview_sql'])) { $display_query .= $drop_query . "\n"; $this->_dbi->tryQuery($drop_query); $tmp_error_drop = $this->_dbi->getError(); if (!empty($tmp_error_drop)) { $seen_error = true; $html_output .= PMA_Util::mysqlDie($tmp_error_drop, $drop_query, false, '', false); continue; } } else { $preview_sql_data .= $drop_query . "\n"; } } $tmp_error_create = false; if (!$create) { continue; } $create_query = $this->_getSQLToCreateForeignKey($table, $master_field, $foreign_db, $foreign_table, $foreign_field, $_REQUEST['constraint_name'][$master_field_md5], $options_array[$_REQUEST['on_delete'][$master_field_md5]], $options_array[$_REQUEST['on_update'][$master_field_md5]]); if (!isset($_REQUEST['preview_sql'])) { $display_query .= $create_query . "\n"; $this->_dbi->tryQuery($create_query); $tmp_error_create = $this->_dbi->getError(); if (!empty($tmp_error_create)) { $seen_error = true; if (substr($tmp_error_create, 1, 4) == '1005') { $message = PMA_Message::error(__('Error creating foreign key on %1$s (check data ' . 'types)')); $message->addParam(implode(', ', $master_field)); $html_output .= $message->getDisplay(); } else { $html_output .= PMA_Util::mysqlDie($tmp_error_create, $create_query, false, '', false); } $html_output .= PMA_Util::showMySQLDocu('InnoDB_foreign_key_constraints') . "\n"; } } else { $preview_sql_data .= $create_query . "\n"; } // this is an alteration and the old constraint has been dropped // without creation of a new one if ($drop && $create && empty($tmp_error_drop) && !empty($tmp_error_create)) { // a rollback may be better here $sql_query_recreate = '# Restoring the dropped constraint...' . "\n"; $sql_query_recreate .= $this->_getSQLToCreateForeignKey($table, $master_field, $existrel_foreign[$master_field_md5]['ref_db_name'], $existrel_foreign[$master_field_md5]['ref_table_name'], $existrel_foreign[$master_field_md5]['ref_index_list'], $existrel_foreign[$master_field_md5]['constraint'], $options_array[$existrel_foreign[$master_field_md5]['on_delete']], $options_array[$existrel_foreign[$master_field_md5]['on_update']]); if (!isset($_REQUEST['preview_sql'])) { $display_query .= $sql_query_recreate . "\n"; $this->_dbi->tryQuery($sql_query_recreate); } else { $preview_sql_data .= $sql_query_recreate; } } } // end foreach return array($html_output, $preview_sql_data, $display_query, $seen_error); }
/** * return HTML for Sql Query Form Insert * * @param string $query query to display in the textarea * @param string $delimiter default delimiter to use * * @return string * * @usedby PMA_getHtmlForSqlQueryForm() */ function PMA_getHtmlForSqlQueryFormInsert($query = '', $delimiter = ';') { // enable auto select text in textarea if ($GLOBALS['cfg']['TextareaAutoSelect']) { $auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"'; } else { $auto_sel = ''; } $locking = ''; $height = $GLOBALS['cfg']['TextareaRows'] * 2; $table = ''; $db = ''; $fields_list = array(); if (!mb_strlen($GLOBALS['db'])) { // prepare for server related $legend = sprintf(__('Run SQL query/queries on server %s'), '"' . htmlspecialchars(!empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '"'); } elseif (!mb_strlen($GLOBALS['table'])) { // prepare for db related $db = $GLOBALS['db']; // if you want navigation: $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . PMA_URL_getCommon(array('db' => $db)) . '"'; $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; // else use // $tmp_db_link = htmlspecialchars($db); $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'); } } else { $table = $GLOBALS['table']; $db = $GLOBALS['db']; // Get the list and number of fields // we do a try_query here, because we could be in the query window, // trying to synchronize and the table has not yet been created $fields_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], null, true); $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . PMA_URL_getCommon(array('db' => $db)) . '"'; $tmp_db_link .= '>' . htmlspecialchars($db) . '</a>'; // else use // $tmp_db_link = htmlspecialchars($db); $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link); if (empty($query)) { $query = PMA_Util::expandUserString($GLOBALS['cfg']['DefaultQueryTable'], 'backquote'); } } $legend .= ': ' . PMA_Util::showMySQLDocu('SELECT'); if (count($fields_list)) { $sqlquerycontainer_id = 'sqlquerycontainer'; } else { $sqlquerycontainer_id = 'sqlquerycontainerfull'; } $html = '<a id="querybox"></a>' . '<div id="queryboxcontainer">' . '<fieldset id="queryboxf">'; $html .= '<legend>' . $legend . '</legend>'; $html .= '<div id="queryfieldscontainer">'; $html .= '<div id="' . $sqlquerycontainer_id . '">' . '<textarea tabindex="100" name="sql_query" id="sqlquery"' . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"' . ' rows="' . $height . '"' . ' dir="' . $GLOBALS['text_dir'] . '"' . $auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>'; // Add buttons to generate query easily for // select all, single select, insert, update and delete if (count($fields_list)) { $html .= '<input type="button" value="SELECT *" id="selectall"' . ' class="button sqlbutton" />'; $html .= '<input type="button" value="SELECT" id="select"' . ' class="button sqlbutton" />'; $html .= '<input type="button" value="INSERT" id="insert"' . ' class="button sqlbutton" />'; $html .= '<input type="button" value="UPDATE" id="update"' . ' class="button sqlbutton" />'; $html .= '<input type="button" value="DELETE" id="delete"' . ' class="button sqlbutton" />'; } $html .= '<input type="button" value="' . __('Clear') . '" id="clear"' . ' class="button sqlbutton" />'; $html .= '</div>' . "\n"; if (count($fields_list)) { $html .= '<div id="tablefieldscontainer">' . '<label>' . __('Columns') . '</label>' . '<select id="tablefields" name="dummy" ' . 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" ' . 'multiple="multiple" ondblclick="insertValueQuery()">'; foreach ($fields_list as $field) { $html .= '<option value="' . PMA_Util::backquote(htmlspecialchars($field['Field'])) . '"'; if (isset($field['Field']) && mb_strlen($field['Field']) && isset($field['Comment'])) { $html .= ' title="' . htmlspecialchars($field['Comment']) . '"'; } $html .= '>' . htmlspecialchars($field['Field']) . '</option>' . "\n"; } $html .= '</select>' . '<div id="tablefieldinsertbuttoncontainer">'; if (PMA_Util::showIcons('ActionLinksMode')) { $html .= '<input type="button" class="button" name="insert"' . ' value="<<" onclick="insertValueQuery()"' . ' title="' . __('Insert') . '" />'; } else { $html .= '<input type="button" class="button" name="insert"' . ' value="' . __('Insert') . '"' . ' onclick="insertValueQuery()" />'; } $html .= '</div>' . "\n" . '</div>' . "\n"; } $html .= '<div class="clearfloat"></div>' . "\n"; $html .= '</div>' . "\n"; $cfgBookmark = PMA_Bookmark_getParams(); if ($cfgBookmark) { $html .= '<div id="bookmarkoptions">'; $html .= '<div class="formelement">'; $html .= '<label for="bkm_label">' . __('Bookmark this SQL query:') . '</label>'; $html .= '<input type="text" name="bkm_label" id="bkm_label"' . ' tabindex="110" value="" />'; $html .= '</div>'; $html .= '<div class="formelement">'; $html .= '<input type="checkbox" name="bkm_all_users" tabindex="111"' . ' id="id_bkm_all_users" value="true" />'; $html .= '<label for="id_bkm_all_users">' . __('Let every user access this bookmark') . '</label>'; $html .= '</div>'; $html .= '<div class="formelement">'; $html .= '<input type="checkbox" name="bkm_replace" tabindex="112"' . ' id="id_bkm_replace" value="true" />'; $html .= '<label for="id_bkm_replace">' . __('Replace existing bookmark of same name') . '</label>'; $html .= '</div>'; $html .= '</div>'; } $html .= '<div class="clearfloat"></div>' . "\n"; $html .= '</fieldset>' . "\n" . '</div>' . "\n"; $html .= '<fieldset id="queryboxfooter" class="tblFooters">' . "\n"; $html .= '<div class="formelement">' . "\n"; $html .= '</div>' . "\n"; $html .= '<div class="formelement">' . "\n"; $html .= '<label for="id_sql_delimiter">[ ' . __('Delimiter') . '</label>' . "\n"; $html .= '<input type="text" name="sql_delimiter" tabindex="131" size="3" ' . 'value="' . $delimiter . '" ' . 'id="id_sql_delimiter" /> ]'; $html .= '<input type="checkbox" name="show_query" value="1" ' . 'id="checkbox_show_query" tabindex="132" checked="checked" />' . '<label for="checkbox_show_query">' . __('Show this query here again') . '</label>'; $html .= '<input type="checkbox" name="retain_query_box" value="1" ' . 'id="retain_query_box" tabindex="133" ' . ($GLOBALS['cfg']['RetainQueryBox'] === false ? '' : ' checked="checked"') . ' />' . '<label for="retain_query_box">' . __('Retain query box') . '</label>'; $html .= '<input type="checkbox" name="rollback_query" value="1" ' . 'id="rollback_query" tabindex="134" />' . '<label for="rollback_query">' . __('Rollback when finished') . '</label>'; $html .= '</div>' . "\n"; $html .= '<input type="submit" id="button_submit_query" name="SQL"'; $html .= ' tabindex="200" value="' . __('Go') . '" />' . "\n"; $html .= '<div class="clearfloat"></div>' . "\n"; $html .= '</fieldset>' . "\n"; return $html; }
/** * Formats SQL queries to html * * @param array $arr The SQL queries * @param string $mode mode of printing * @param integer $start_token starting token * @param integer $number_of_tokens number of tokens to format, -1 = all * * @return string The formatted SQL queries * * @access public */ function PMA_SQP_formatHtml($arr, $mode = 'color', $start_token = 0, $number_of_tokens = -1) { global $PMA_SQPdata_operators_docs, $PMA_SQPdata_functions_docs; //DEBUG echo 'in Format<pre>'; print_r($arr); echo '</pre>'; // then check for an array if (!is_array($arr)) { return htmlspecialchars($arr); } // first check for the SQL parser having hit an error if (PMA_SQP_isError()) { return htmlspecialchars($arr['raw']); } // else do it properly switch ($mode) { case 'color': $str = '<span class="syntax">'; $html_line_break = '<br />'; $docu = true; break; case 'query_only': $str = ''; $html_line_break = "\n"; $docu = false; break; case 'text': $str = ''; $html_line_break = '<br />'; $docu = true; break; } // end switch // inner_sql is a span that exists for all cases, except query_only // of $cfg['SQP']['fmtType'] to make possible a replacement // for inline editing if ($mode != 'query_only') { $str .= '<span class="inner_sql">'; } $close_docu_link = false; $indent = 0; $bracketlevel = 0; $functionlevel = 0; $infunction = false; $space_punct_listsep = ' '; $space_punct_listsep_function_name = ' '; // $space_alpha_reserved_word = '<br />'."\n"; $space_alpha_reserved_word = ' '; $keywords_with_brackets_1before = array('INDEX' => 1, 'KEY' => 1, 'ON' => 1, 'USING' => 1); $keywords_with_brackets_2before = array('IGNORE' => 1, 'INDEX' => 1, 'INTO' => 1, 'KEY' => 1, 'PRIMARY' => 1, 'PROCEDURE' => 1, 'REFERENCES' => 1, 'UNIQUE' => 1, 'USE' => 1); // These reserved words do NOT get a newline placed near them. $keywords_no_newline = array('AS' => 1, 'ASC' => 1, 'DESC' => 1, 'DISTINCT' => 1, 'DUPLICATE' => 1, 'HOUR' => 1, 'INTERVAL' => 1, 'IS' => 1, 'LIKE' => 1, 'NOT' => 1, 'NULL' => 1, 'ON' => 1, 'REGEXP' => 1); // These reserved words introduce a privilege list $keywords_priv_list = array('GRANT' => 1, 'REVOKE' => 1); if ($number_of_tokens == -1) { $number_of_tokens = $arr['len']; } $typearr = array(); if ($number_of_tokens >= 0) { $typearr[0] = ''; $typearr[1] = ''; $typearr[2] = ''; $typearr[3] = $arr[$start_token]['type']; } $in_priv_list = false; for ($i = $start_token; $i < $number_of_tokens; $i++) { // DEBUG echo "Loop format <strong>" . $arr[$i]['data'] // . "</strong> " . $arr[$i]['type'] . "<br />"; $before = ''; $after = ''; // array_shift($typearr); /* 0 prev2 1 prev 2 current 3 next */ if ($i + 1 < $number_of_tokens) { $typearr[4] = $arr[$i + 1]['type']; } else { $typearr[4] = ''; } for ($j = 0; $j < 4; $j++) { $typearr[$j] = $typearr[$j + 1]; } switch ($typearr[2]) { case 'alpha_bitfield_constant_introducer': $before = ' '; $after = ''; break; case 'white_newline': $before = ''; break; case 'punct_bracket_open_round': $bracketlevel++; $infunction = false; $keyword_brackets_2before = isset($keywords_with_brackets_2before[strtoupper($arr[$i - 2]['data'])]); $keyword_brackets_1before = isset($keywords_with_brackets_1before[strtoupper($arr[$i - 1]['data'])]); // Make sure this array is sorted! if ($typearr[1] == 'alpha_functionName' || $typearr[1] == 'alpha_columnType' || $typearr[1] == 'punct' || $typearr[3] == 'digit_integer' || $typearr[3] == 'digit_hex' || $typearr[3] == 'digit_float' || $typearr[0] == 'alpha_reservedWord' && $keyword_brackets_2before || $typearr[1] == 'alpha_reservedWord' && $keyword_brackets_1before) { $functionlevel++; $infunction = true; $after .= ' '; } else { $indent++; if ($mode != 'query_only') { $after .= '<div class="syntax_indent' . $indent . '">'; } else { $after .= ' '; } } break; case 'alpha_identifier': if ($typearr[1] == 'punct_qualifier' || $typearr[3] == 'punct_qualifier') { $after = ''; $before = ''; } // for example SELECT 1 somealias if ($typearr[1] == 'digit_integer') { $before = ' '; } if ($typearr[3] == 'alpha_columnType' || $typearr[3] == 'alpha_identifier') { $after .= ' '; } break; case 'punct_user': case 'punct_qualifier': $before = ''; $after = ''; break; case 'punct_listsep': if ($infunction == true) { $after .= $space_punct_listsep_function_name; } else { $after .= $space_punct_listsep; } break; case 'punct_queryend': if ($typearr[3] != 'comment_mysql' && $typearr[3] != 'comment_ansi' && $typearr[3] != 'comment_c') { $after .= $html_line_break; $after .= $html_line_break; } $space_punct_listsep = ' '; $space_punct_listsep_function_name = ' '; $space_alpha_reserved_word = ' '; $in_priv_list = false; break; case 'comment_mysql': case 'comment_ansi': $after .= $html_line_break; break; case 'punct': $before .= ' '; if ($docu && isset($PMA_SQPdata_operators_docs[$arr[$i]['data']]) && ($arr[$i]['data'] != '*' || in_array($arr[$i]['type'], array('digit_integer', 'digit_float', 'digit_hex')))) { $before .= PMA_Util::showMySQLDocu('functions', $PMA_SQPdata_operators_docs[$arr[$i]['data']]['link'], false, $PMA_SQPdata_operators_docs[$arr[$i]['data']]['anchor'], true); $after .= '</a>'; } // workaround for // select * from mytable limit 0,-1 // (a side effect of this workaround is that // select 20 - 9 // becomes // select 20 -9 // ) if ($typearr[3] != 'digit_integer') { $after .= ' '; } break; case 'punct_bracket_close_round': // only close bracket level when it was opened before if ($bracketlevel > 0) { $bracketlevel--; if ($infunction == true) { $functionlevel--; $after .= ' '; $before .= ' '; } else { $indent--; $before .= $mode != 'query_only' ? '</div>' : ' '; } $infunction = $functionlevel > 0 ? true : false; } break; case 'alpha_columnType': if ($docu) { switch ($arr[$i]['data']) { case 'tinyint': case 'smallint': case 'mediumint': case 'int': case 'bigint': case 'decimal': case 'float': case 'double': case 'real': case 'bit': case 'boolean': case 'serial': $before .= PMA_Util::showMySQLDocu('data-types', 'numeric-types', false, '', true); $after = '</a>' . $after; break; case 'date': case 'datetime': case 'timestamp': case 'time': case 'year': $before .= PMA_Util::showMySQLDocu('data-types', 'date-and-time-types', false, '', true); $after = '</a>' . $after; break; case 'char': case 'varchar': case 'tinytext': case 'text': case 'mediumtext': case 'longtext': case 'binary': case 'varbinary': case 'tinyblob': case 'mediumblob': case 'blob': case 'longblob': case 'enum': case 'set': $before .= PMA_Util::showMySQLDocu('data-types', 'string-types', false, '', true); $after = '</a>' . $after; break; } } if ($typearr[3] == 'alpha_columnAttrib') { $after .= ' '; } if ($typearr[1] == 'alpha_columnType') { $before .= ' '; } break; case 'alpha_columnAttrib': // ALTER TABLE tbl_name AUTO_INCREMENT = 1 // COLLATE LATIN1_GENERAL_CI DEFAULT if ($typearr[1] == 'alpha_identifier' || $typearr[1] == 'alpha_charset') { $before .= ' '; } if ($typearr[3] == 'alpha_columnAttrib' || $typearr[3] == 'quote_single' || $typearr[3] == 'digit_integer') { $after .= ' '; } // workaround for // AUTO_INCREMENT = 31DEFAULT_CHARSET = utf-8 if ($typearr[2] == 'alpha_columnAttrib' && $typearr[3] == 'alpha_reservedWord') { $before .= ' '; } // workaround for // select * from mysql.user where binary user="******" // binary is marked as alpha_columnAttrib // but should be marked as a reserved word if (strtoupper($arr[$i]['data']) == 'BINARY' && $typearr[3] == 'alpha_identifier') { $after .= ' '; } break; case 'alpha_functionName': $funcname = strtoupper($arr[$i]['data']); if ($docu && isset($PMA_SQPdata_functions_docs[$funcname])) { $before .= PMA_Util::showMySQLDocu('functions', $PMA_SQPdata_functions_docs[$funcname]['link'], false, $PMA_SQPdata_functions_docs[$funcname]['anchor'], true); $after .= '</a>'; } break; case 'alpha_reservedWord': // do not uppercase the reserved word if we are calling // this function in query_only mode, because we need // the original query (otherwise we get problems with // semi-reserved words like "storage" which is legal // as an identifier name) if ($mode != 'query_only') { $arr[$i]['data'] = strtoupper($arr[$i]['data']); } if (($typearr[1] != 'alpha_reservedWord' || $typearr[1] == 'alpha_reservedWord' && isset($keywords_no_newline[strtoupper($arr[$i - 1]['data'])])) && $typearr[1] != 'punct_level_plus' && !isset($keywords_no_newline[$arr[$i]['data']])) { // do not put a space before the first token, because // we use a lot of pattern matching checking for the // first reserved word at beginning of query // so do not put a newline before // // also we must not be inside a privilege list if ($i > 0) { // the alpha_identifier exception is there to // catch cases like // GRANT SELECT ON mydb.mytable TO myuser@localhost // (else, we get mydb.mytableTO) // // the quote_single exception is there to // catch cases like // GRANT ... TO 'marc'@'domain.com' IDENTIFIED... /** * @todo fix all cases and find why this happens */ if (!$in_priv_list || $typearr[1] == 'alpha_identifier' || $typearr[1] == 'quote_single' || $typearr[1] == 'white_newline') { $before .= $space_alpha_reserved_word; } } else { // on first keyword, check if it introduces a // privilege list if (isset($keywords_priv_list[$arr[$i]['data']])) { $in_priv_list = true; } } } else { $before .= ' '; } switch ($arr[$i]['data']) { case 'CREATE': case 'ALTER': case 'DROP': case 'RENAME': case 'TRUNCATE': case 'ANALYZE': case 'ANALYSE': case 'OPTIMIZE': if ($docu) { switch ($arr[$i + 1]['data']) { case 'EVENT': case 'TABLE': case 'TABLESPACE': case 'FUNCTION': case 'INDEX': case 'PROCEDURE': case 'TRIGGER': case 'SERVER': case 'DATABASE': case 'VIEW': $before .= PMA_Util::showMySQLDocu('SQL-Syntax', $arr[$i]['data'] . '_' . $arr[$i + 1]['data'], false, '', true); $close_docu_link = true; break; } if ($arr[$i + 1]['data'] == 'LOGFILE' && $arr[$i + 2]['data'] == 'GROUP') { $before .= PMA_Util::showMySQLDocu('SQL-Syntax', $arr[$i]['data'] . '_LOGFILE_GROUP', false, '', true); $close_docu_link = true; } } if (!$in_priv_list) { $space_punct_listsep = $html_line_break; $space_alpha_reserved_word = ' '; } break; case 'EVENT': case 'TABLESPACE': case 'TABLE': case 'FUNCTION': case 'INDEX': case 'PROCEDURE': case 'SERVER': case 'TRIGGER': case 'DATABASE': case 'VIEW': case 'GROUP': if ($close_docu_link) { $after = '</a>' . $after; $close_docu_link = false; } break; case 'SET': if ($docu && ($i == 0 || $arr[$i - 1]['data'] != 'CHARACTER')) { $before .= PMA_Util::showMySQLDocu('SQL-Syntax', $arr[$i]['data'], false, '', true); $after = '</a>' . $after; } if (!$in_priv_list) { $space_punct_listsep = $html_line_break; $space_alpha_reserved_word = ' '; } break; case 'EXPLAIN': case 'DESCRIBE': case 'DELETE': case 'SHOW': case 'UPDATE': if ($docu) { $before .= PMA_Util::showMySQLDocu('SQL-Syntax', $arr[$i]['data'], false, '', true); $after = '</a>' . $after; } if (!$in_priv_list) { $space_punct_listsep = $html_line_break; $space_alpha_reserved_word = ' '; } break; case 'INSERT': case 'REPLACE': if ($docu) { $before .= PMA_Util::showMySQLDocu('SQL-Syntax', $arr[$i]['data'], false, '', true); $after = '</a>' . $after; } if (!$in_priv_list) { $space_punct_listsep = $html_line_break; $space_alpha_reserved_word = $html_line_break; } break; case 'VALUES': $space_punct_listsep = ' '; $space_alpha_reserved_word = $html_line_break; break; case 'SELECT': if ($docu) { $before .= PMA_Util::showMySQLDocu('SQL-Syntax', 'SELECT', false, '', true); $after = '</a>' . $after; } $space_punct_listsep = ' '; $space_alpha_reserved_word = $html_line_break; break; case 'CALL': case 'DO': case 'HANDLER': if ($docu) { $before .= PMA_Util::showMySQLDocu('SQL-Syntax', $arr[$i]['data'], false, '', true); $after = '</a>' . $after; } break; default: if ($close_docu_link && in_array($arr[$i]['data'], array('LIKE', 'NOT', 'IN', 'REGEXP', 'NULL'))) { $after .= '</a>'; $close_docu_link = false; } else { if ($docu && isset($PMA_SQPdata_functions_docs[$arr[$i]['data']])) { /* Handle multi word statements first */ if (isset($typearr[4]) && $typearr[4] == 'alpha_reservedWord' && $typearr[3] == 'alpha_reservedWord' && isset($PMA_SQPdata_functions_docs[strtoupper($arr[$i]['data'] . '_' . $arr[$i + 1]['data'] . '_' . $arr[$i + 2]['data'])])) { $tempname = strtoupper($arr[$i]['data'] . '_' . $arr[$i + 1]['data'] . '_' . $arr[$i + 2]['data']); $before .= PMA_Util::showMySQLDocu('functions', $PMA_SQPdata_functions_docs[$tempname]['link'], false, $PMA_SQPdata_functions_docs[$tempname]['anchor'], true); $close_docu_link = true; } else { if (isset($typearr[3]) && $typearr[3] == 'alpha_reservedWord' && isset($PMA_SQPdata_functions_docs[strtoupper($arr[$i]['data'] . '_' . $arr[$i + 1]['data'])])) { $tempname = strtoupper($arr[$i]['data'] . '_' . $arr[$i + 1]['data']); $before .= PMA_Util::showMySQLDocu('functions', $PMA_SQPdata_functions_docs[$tempname]['link'], false, $PMA_SQPdata_functions_docs[$tempname]['anchor'], true); $close_docu_link = true; } else { $before .= PMA_Util::showMySQLDocu('functions', $PMA_SQPdata_functions_docs[$arr[$i]['data']]['link'], false, $PMA_SQPdata_functions_docs[$arr[$i]['data']]['anchor'], true); $after .= '</a>'; } } } } break; } // end switch ($arr[$i]['data']) $after .= ' '; break; case 'digit_integer': case 'digit_float': case 'digit_hex': /** * @todo could there be other types preceding a digit? */ if ($typearr[1] == 'alpha_reservedWord') { $after .= ' '; } if ($infunction && $typearr[3] == 'punct_bracket_close_round') { $after .= ' '; } if ($typearr[1] == 'alpha_columnAttrib') { $before .= ' '; } break; case 'alpha_variable': $after = ' '; break; case 'quote_double': case 'quote_single': // workaround: for the query // REVOKE SELECT ON `base2\_db`.* FROM 'user'@'%' // the @ is incorrectly marked as alpha_variable // in the parser, and here, the '%' gets a blank before, // which is a syntax error if ($typearr[1] != 'punct_user' && $typearr[1] != 'alpha_bitfield_constant_introducer') { $before .= ' '; } if ($infunction && $typearr[3] == 'punct_bracket_close_round') { $after .= ' '; } break; case 'quote_backtick': // here we check for punct_user to handle correctly // DEFINER = `username`@`%` // where @ is the punct_user and `%` is the quote_backtick if ($typearr[3] != 'punct_qualifier' && $typearr[3] != 'alpha_variable' && $typearr[3] != 'punct_user') { $after .= ' '; } if ($typearr[1] != 'punct_qualifier' && $typearr[1] != 'alpha_variable' && $typearr[1] != 'punct_user') { $before .= ' '; } break; default: break; } // end switch ($typearr[2]) /* if ($typearr[3] != 'punct_qualifier') { $after .= ' '; } $after .= "\n"; */ $str .= $before; if ($mode == 'color') { $str .= PMA_SQP_formatHTML_colorize($arr[$i]); } elseif ($mode == 'text') { $str .= htmlspecialchars($arr[$i]['data']); } else { $str .= $arr[$i]['data']; } $str .= $after; } // end for // close unclosed indent levels while ($indent > 0) { $indent--; $str .= $mode != 'query_only' ? '</div>' : ' '; } /* End possibly unclosed documentation link */ if ($close_docu_link) { $str .= '</a>'; $close_docu_link = false; } if ($mode != 'query_only') { // close inner_sql span $str .= '</span>'; } if ($mode == 'color') { // close syntax span $str .= '</span>'; } return $str; }
/** * Generates formatted HTML for extra search options in table search form * * @return string the generated HTML */ private function _getOptions() { $html_output = ''; $html_output .= PMA_Util::getDivForSliderEffect('searchoptions', __('Options')); /** * Displays columns select list for selecting distinct columns in the search */ $html_output .= '<fieldset id="fieldset_select_fields">' . '<legend>' . __('Select columns (at least one):') . '</legend>' . '<select name="columnsToDisplay[]"' . ' size="' . min(count($this->_columnNames), 10) . '"' . ' multiple="multiple">'; // Displays the list of the fields foreach ($this->_columnNames as $each_field) { $html_output .= ' ' . '<option value="' . htmlspecialchars($each_field) . '"' . ' selected="selected">' . htmlspecialchars($each_field) . '</option>' . "\n"; } // end for $html_output .= '</select>' . '<input type="checkbox" name="distinct" value="DISTINCT"' . ' id="oDistinct" />' . '<label for="oDistinct">DISTINCT</label></fieldset>'; /** * Displays input box for custom 'Where' clause to be used in the search */ $html_output .= '<fieldset id="fieldset_search_conditions">' . '<legend>' . '<em>' . __('Or') . '</em> ' . __('Add search conditions (body of the "where" clause):') . '</legend>'; $html_output .= PMA_Util::showMySQLDocu('Functions'); $html_output .= '<input type="text" name="customWhereClause"' . ' class="textfield" size="64" />'; $html_output .= '</fieldset>'; /** * Displays option of changing default number of rows displayed per page */ $html_output .= '<fieldset id="fieldset_limit_rows">' . '<legend>' . __('Number of rows per page') . '</legend>' . '<input type="number" name="session_max_rows" required="required" ' . 'min="1" ' . 'value="' . $GLOBALS['cfg']['MaxRows'] . '" class="textfield" />' . '</fieldset>'; /** * Displays option for ordering search results * by a column value (Asc or Desc) */ $html_output .= '<fieldset id="fieldset_display_order">' . '<legend>' . __('Display order:') . '</legend>' . '<select name="orderByColumn"><option value="--nil--"></option>'; foreach ($this->_columnNames as $each_field) { $html_output .= ' ' . '<option value="' . htmlspecialchars($each_field) . '">' . htmlspecialchars($each_field) . '</option>' . "\n"; } // end for $html_output .= '</select>'; $choices = array('ASC' => __('Ascending'), 'DESC' => __('Descending')); $html_output .= PMA_Util::getRadioFields('order', $choices, 'ASC', false, true, "formelement"); unset($choices); $html_output .= '</fieldset><br style="clear: both;"/></div>'; return $html_output; }
/** * Displays the sub-page heading */ $doc_link = PMA_Util::showMySQLDocu('server_system_variables'); $response->addHtml(PMA_getHtmlForSubPageHeader('variables', $doc_link)); /** * Sends the queries and buffers the results */ $serverVarsResult = $GLOBALS['dbi']->tryQuery('SHOW SESSION VARIABLES;'); if ($serverVarsResult !== false) { $serverVarsSession = array(); while ($arr = $GLOBALS['dbi']->fetchRow($serverVarsResult)) { $serverVarsSession[$arr[0]] = $arr[1]; } $GLOBALS['dbi']->freeResult($serverVarsResult); $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1); /** * Link templates */ $response->addHtml(PMA_getHtmlForLinkTemplates()); /** * Displays the page */ $response->addHtml(PMA_getHtmlForServerVariables($variable_doc_links, $serverVars, $serverVarsSession)); } else { /** * Display the error message */ $response->addHTML(PMA_Message::error(sprintf(__('Not enough privilege to view server variables and settings. %s'), PMA_Util::showMySQLDocu('server-system-variables', false, 'sysvar_show_compatibility_56')))->getDisplay()); } exit;
/** * Get HTML snippet for partition maintenance * * @param array $partition_names array of partition names for a specific db/table * @param array $url_params url parameters * * @return string $html_output */ function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params) { $choices = array('ANALYZE' => __('Analyze'), 'CHECK' => __('Check'), 'OPTIMIZE' => __('Optimize'), 'REBUILD' => __('Rebuild'), 'REPAIR' => __('Repair'), 'TRUNCATE' => __('Truncate')); $partition_method = PMA_Partition::getPartitionMethod($GLOBALS['db'], $GLOBALS['table']); // add COALESCE or DROP option to choices array depeding on Partition method if ($partition_method == 'RANGE' || $partition_method == 'LIST') { $choices['DROP'] = __('Drop'); } else { $choices['COALESCE'] = __('Coalesce'); } $html_output = '<div class="operations_half_width">' . '<form id="partitionsForm" class="ajax" ' . 'method="post" action="tbl_operations.php" >' . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']) . '<fieldset>' . '<legend>' . __('Partition maintenance') . PMA_Util::showMySQLDocu('partitioning_maintenance') . '</legend>'; $html_select = '<select id="partition_name" name="partition_name[]"' . ' multiple="multiple" required="required">' . "\n"; $first = true; foreach ($partition_names as $one_partition) { $one_partition = htmlspecialchars($one_partition); $html_select .= '<option value="' . $one_partition . '"'; if ($first) { $html_select .= ' selected="selected"'; $first = false; } $html_select .= '>' . $one_partition . '</option>' . "\n"; } $html_select .= '</select>' . "\n"; $html_output .= sprintf(__('Partition %s'), $html_select); $html_output .= '<div class="clearfloat" />'; $html_output .= PMA_Util::getRadioFields('partition_operation', $choices, 'ANALYZE', false, true, 'floatleft'); $this_url_params = array_merge($url_params, array('sql_query' => 'ALTER TABLE ' . PMA_Util::backquote($GLOBALS['table']) . ' REMOVE PARTITIONING;')); $html_output .= '<div class="clearfloat" /><br />'; $html_output .= '<a href="sql.php' . PMA_URL_getCommon($this_url_params) . '">' . __('Remove partitioning') . '</a>'; $html_output .= '</fieldset>' . '<fieldset class="tblFooters">' . '<input type="hidden" name="submit_partition" value="1">' . '<input type="submit" value="' . __('Go') . '" />' . '</fieldset>' . '</form>' . '</div>'; return $html_output; }
/** * Prints Html for Server Variables Items * * @param Array $variable_doc_links documentation links * * @return string */ function PMA_getHtmlForServerVariablesItems($variable_doc_links) { /** * Sends the queries and buffers the results */ $serverVarsSession = $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1); $serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1); $output = ''; $odd_row = true; foreach ($serverVars as $name => $value) { $has_session_value = isset($serverVarsSession[$name]) && $serverVarsSession[$name] != $value; $row_class = ($odd_row ? ' odd' : ' even') . ($has_session_value ? ' diffSession' : ''); $output .= '<div class="var-row' . $row_class . '">' . '<div class="var-name">'; // To display variable documentation link if (isset($variable_doc_links[$name])) { $output .= '<span title="' . htmlspecialchars(str_replace('_', ' ', $name)) . '">'; $output .= PMA_Util::showMySQLDocu($variable_doc_links[$name][1], false, $variable_doc_links[$name][2] . '_' . $variable_doc_links[$name][0], true); $output .= htmlspecialchars(str_replace('_', ' ', $name)); $output .= '</a>'; $output .= '</span>'; } else { $output .= htmlspecialchars(str_replace('_', ' ', $name)); } $output .= '</div>' . '<div class="var-value value' . ($GLOBALS['dbi']->isSuperuser() ? ' editable' : '') . '"> ' . PMA_formatVariable($name, $value, $variable_doc_links) . '</div>' . '<div style="clear:both"></div>' . '</div>'; if ($has_session_value) { $output .= '<div class="var-row' . ($odd_row ? ' odd' : ' even') . '">' . '<div class="var-name session">(' . __('Session value') . ')</div>' . '<div class="var-value value"> ' . PMA_formatVariable($name, $serverVarsSession[$name], $variable_doc_links) . '</div>' . '<div style="clear:both"></div>' . '</div>'; } $odd_row = !$odd_row; } return $output; }
/** * Function to handle update for a foreign key * * @param array $multi_edit_columns_name multu edit columns name * @param string $master_field_md5 master field md5 * @param string $destination_foreign_table destination foreign table * @param string $destination_foreign_column destination foreign column * @param array $options_array options array * @param array $existrel_foreign db, table, column * @param string $table current table * @param bool &$seen_error whether seen error * @param string &$display_query display query * @param string $foreign_db foreign database * * @return string */ function PMA_handleUpdateForForeignKey($multi_edit_columns_name, $master_field_md5, $destination_foreign_table, $destination_foreign_column, $options_array, $existrel_foreign, $table, &$seen_error, &$display_query, $foreign_db) { $html_output = ''; $create = false; $drop = false; // Map the fieldname's md5 back to its real name $master_field = $multi_edit_columns_name[$master_field_md5]; $foreign_table = $destination_foreign_table[$master_field_md5]; $foreign_field = $destination_foreign_column[$master_field_md5]; if (!empty($foreign_db) && !empty($foreign_table) && !empty($foreign_field)) { if (isset($existrel_foreign[$master_field])) { $constraint_name = $existrel_foreign[$master_field]['constraint']; $on_delete = !empty($existrel_foreign[$master_field]['on_delete']) ? $existrel_foreign[$master_field]['on_delete'] : 'RESTRICT'; $on_update = !empty($existrel_foreign[$master_field]['on_update']) ? $existrel_foreign[$master_field]['on_update'] : 'RESTRICT'; } if (!isset($existrel_foreign[$master_field])) { // no key defined for this field $create = true; } elseif ($existrel_foreign[$master_field]['foreign_db'] != $foreign_db || $existrel_foreign[$master_field]['foreign_table'] != $foreign_table || $existrel_foreign[$master_field]['foreign_field'] != $foreign_field || $_REQUEST['constraint_name'][$master_field_md5] != $constraint_name || $_REQUEST['on_delete'][$master_field_md5] != $on_delete || $_REQUEST['on_update'][$master_field_md5] != $on_update) { // another foreign key is already defined for this field // or an option has been changed for ON DELETE or ON UPDATE $drop = true; $create = true; } // end if... else.... } elseif (isset($existrel_foreign[$master_field])) { $drop = true; } // end if... else.... $tmp_error_drop = false; if ($drop) { $drop_query = PMA_getSQLToDropForeignKey($table, $existrel_foreign[$master_field]['constraint']); $display_query .= $drop_query . "\n"; $GLOBALS['dbi']->tryQuery($drop_query); $tmp_error_drop = $GLOBALS['dbi']->getError(); if (!empty($tmp_error_drop)) { $seen_error = true; $html_output .= PMA_Util::mysqlDie($tmp_error_drop, $drop_query, false, '', false); return $html_output; } } $tmp_error_create = false; if ($create) { $create_query = PMA_getSQLToCreateForeignKey($table, $master_field, $foreign_db, $foreign_table, $foreign_field, $_REQUEST['constraint_name'][$master_field_md5], $options_array[$_REQUEST['on_delete'][$master_field_md5]], $options_array[$_REQUEST['on_update'][$master_field_md5]]); $display_query .= $create_query . "\n"; $GLOBALS['dbi']->tryQuery($create_query); $tmp_error_create = $GLOBALS['dbi']->getError(); if (!empty($tmp_error_create)) { $seen_error = true; if (substr($tmp_error_create, 1, 4) == '1005') { $message = PMA_Message::error(__('Error creating foreign key on %1$s (check data types)')); $message->addParam($master_field); $html_output .= $message->getDisplay(); } else { $html_output .= PMA_Util::mysqlDie($tmp_error_create, $create_query, false, '', false); } $html_output .= PMA_Util::showMySQLDocu('InnoDB_foreign_key_constraints') . "\n"; } // this is an alteration and the old constraint has been dropped // without creation of a new one if ($drop && $create && empty($tmp_error_drop) && !empty($tmp_error_create)) { // a rollback may be better here $sql_query_recreate = '# Restoring the dropped constraint...' . "\n"; $sql_query_recreate .= PMA_getSQLToCreateForeignKey($table, $master_field, $existrel_foreign[$master_field]['foreign_db'], $existrel_foreign[$master_field]['foreign_table'], $existrel_foreign[$master_field]['foreign_field'], $existrel_foreign[$master_field]['constraint'], $options_array[$existrel_foreign[$master_field]['on_delete']], $options_array[$existrel_foreign[$master_field]['on_update']]); $display_query .= $sql_query_recreate . "\n"; $GLOBALS['dbi']->tryQuery($sql_query_recreate); } } return $html_output; }
/** * Get HTML links for 'Print view', 'Relation view', 'Propose table structure', * 'Track table' and 'Move columns' * * @param string $url_query url query * @param boolean $tbl_is_view whether table is view or not * @param boolean $db_is_system_schema whether db is information schema or not * * @return string $html_output */ function PMA_getHtmlForOptionalActionLinks($url_query, $tbl_is_view, $db_is_system_schema) { $html_output = '<a href="tbl_printview.php' . $url_query . '" target="print_view">' . PMA_Util::getIcon('b_print.png', __('Print view'), true) . '</a>'; if (!$tbl_is_view && !$db_is_system_schema) { if (!PMA_DRIZZLE) { $html_output .= '<a href="sql.php' . $url_query . '&session_max_rows=all&sql_query=' . urlencode('SELECT * FROM ' . PMA_Util::backquote($GLOBALS['table']) . ' PROCEDURE ANALYSE()') . '">' . PMA_Util::getIcon('b_tblanalyse.png', __('Propose table structure'), true) . '</a>'; $html_output .= PMA_Util::showMySQLDocu('procedure_analyse') . "\n"; } if (PMA_Tracker::isActive()) { $html_output .= '<a href="tbl_tracking.php' . $url_query . '">' . PMA_Util::getIcon('eye.png', __('Track table'), true) . '</a>'; } $html_output .= '<a href="#" id="move_columns_anchor">' . PMA_Util::getIcon('b_move.png', __('Move columns'), true) . '</a>'; $html_output .= '<a href="normalization.php' . $url_query . '">' . PMA_Util::getIcon('normalize.png', __('Improve table structure'), true) . '</a>'; } if ($tbl_is_view && !$db_is_system_schema) { if (PMA_Tracker::isActive()) { $html_output .= '<a href="tbl_tracking.php' . $url_query . '">' . PMA_Util::getIcon('eye.png', __('Track view'), true) . '</a>'; } } return $html_output; }