2 /* vim: set expandtab sw=4 ts=4 sts=4: */
9 require_once 'libraries/common.inc.php';
11 $response = PMA_Response
::getInstance();
12 $header = $response->getHeader();
13 $scripts = $header->getScripts();
14 $scripts->addFile('server_variables.js');
17 * Does the common work
19 require 'libraries/server_common.inc.php';
22 * Required to display documentation links
24 require 'libraries/server_variables_doc.php';
30 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
31 $response = PMA_Response
::getInstance();
33 if (isset($_REQUEST['type'])) {
34 if ($_REQUEST['type'] === 'getval') {
35 // Send with correct charset
36 header('Content-Type: text/html; charset=UTF-8');
37 $varValue = PMA_DBI_fetch_single_row(
38 'SHOW GLOBAL VARIABLES WHERE Variable_name="'
39 . PMA_Util
::sqlAddSlashes($_REQUEST['varName']) . '";',
42 if (isset($VARIABLE_DOC_LINKS[$_REQUEST['varName']][3])
43 && $VARIABLE_DOC_LINKS[$_REQUEST['varName']][3] == 'byte'
48 ' ', PMA_Util
::formatByteDown($varValue[1], 3, 3)
57 } else if ($_REQUEST['type'] === 'setval') {
58 $value = $_REQUEST['varValue'];
60 if (isset($VARIABLE_DOC_LINKS[$_REQUEST['varName']][3])
61 && $VARIABLE_DOC_LINKS[$_REQUEST['varName']][3] == 'byte'
63 '/^\s*(\d+(\.\d+)?)\s*(mb|kb|mib|kib|gb|gib)\s*$/i',
76 $value = floatval($matches[1]) * PMA_Util
::pow(
78 $exp[strtolower($matches[3])]
81 $value = PMA_Util
::sqlAddSlashes($value);
84 if (! is_numeric($value)) {
85 $value="'" . $value . "'";
88 if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName'])
90 'SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value
93 // Some values are rounded down etc.
94 $varValue = PMA_DBI_fetch_single_row(
95 'SHOW GLOBAL VARIABLES WHERE Variable_name="'
96 . PMA_Util
::sqlAddSlashes($_REQUEST['varName'])
101 formatVariable($_REQUEST['varName'], $varValue[1])
104 $response->isSuccess(false);
107 __('Setting variable failed')
116 * Displays the sub-page heading
118 $output = '<h2>' . PMA_Util
::getImage('s_vars.png')
119 . '' . __('Server variables and settings') . "\n"
120 . PMA_Util
::showMySQLDocu(
121 'server_system_variables', 'server_system_variables'
128 $url = htmlspecialchars('server_variables.php?' . PMA_generate_common_url());
129 $output .= '<a style="display: none;" href="#" class="editLink">';
130 $output .= PMA_Util
::getIcon('b_edit.png', __('Edit')) . '</a>';
131 $output .= '<a style="display: none;" href="' . $url . '" class="ajax saveLink">';
132 $output .= PMA_Util
::getIcon('b_save.png', __('Save')) . '</a> ';
133 $output .= '<a style="display: none;" href="#" class="cancelLink">';
134 $output .= PMA_Util
::getIcon('b_close.png', __('Cancel')) . '</a> ';
135 $output .= PMA_Util
::getImage(
139 'style' => 'display:none',
145 * Sends the queries and buffers the results
147 $serverVarsSession = PMA_DBI_fetch_result('SHOW SESSION VARIABLES;', 0, 1);
148 $serverVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES;', 0, 1);
154 $value = ! empty($_REQUEST['filter']) ?
htmlspecialchars($_REQUEST['filter']) : '';
155 $output .= '<fieldset id="tableFilter">'
156 . '<legend>' . __('Filters') . '</legend>'
157 . '<div class="formelement">'
158 . '<label for="filterText">' . __('Containing the word:') . '</label>'
159 . '<input name="filterText" type="text" id="filterText"'
160 . ' style="vertical-align: baseline;" value="' . $value . '" />'
164 $output .= '<div id="serverVariables" class="data filteredData noclick">'
165 . '<div class="var-header var-row">'
166 . '<div class="var-name">' . __('Variable') . '</div>'
167 . '<div class="var-value valueHeader">'
168 . __('Session value') . ' / ' . __('Global value')
170 . '<div style="clear:both"></div>'
174 foreach ($serverVars as $name => $value) {
175 $has_session_value = isset($serverVarsSession[$name])
176 && $serverVarsSession[$name] != $value;
177 $row_class = ($odd_row ?
' odd' : ' even')
178 . ($has_session_value ?
' diffSession' : '');
180 $output .= '<div class="var-row' . $row_class . '">'
181 . '<div class="var-name">';
183 // To display variable documentation link
184 if (isset($VARIABLE_DOC_LINKS[$name])) {
185 $output .= '<span title="' . htmlspecialchars(str_replace('_', ' ', $name)) . '">';
186 $output .= PMA_Util
::showMySQLDocu(
187 $VARIABLE_DOC_LINKS[$name][1],
188 $VARIABLE_DOC_LINKS[$name][1],
190 $VARIABLE_DOC_LINKS[$name][2] . '_' . $VARIABLE_DOC_LINKS[$name][0],
193 $output .= htmlspecialchars(str_replace('_', ' ', $name));
195 $output .= '</span>';
197 $output .= htmlspecialchars(str_replace('_', ' ', $name));
200 . '<div class="var-value value' . (PMA_isSuperuser() ?
' editable' : '') . '"> '
201 . formatVariable($name, $value)
203 . '<div style="clear:both"></div>'
206 if ($has_session_value) {
207 $output .= '<div class="var-row' . ($odd_row ?
' odd' : ' even') . '">'
208 . '<div class="var-name session">(' . __('Session value') . ')</div>'
209 . '<div class="var-value value"> ' . formatVariable($name, $serverVarsSession[$name]) . '</div>'
210 . '<div style="clear:both"></div>'
214 $odd_row = ! $odd_row;
218 $response->addHtml($output);
223 * @param string $name variable name
224 * @param numeric $value variable value
226 * @return formatted string
228 function formatVariable($name, $value)
230 global $VARIABLE_DOC_LINKS;
232 if (is_numeric($value)) {
233 if (isset($VARIABLE_DOC_LINKS[$name][3])
234 && $VARIABLE_DOC_LINKS[$name][3]=='byte'
236 return '<abbr title="'
237 . PMA_Util
::formatNumber($value, 0) . '">'
238 . implode(' ', PMA_Util
::formatByteDown($value, 3, 3))
241 return PMA_Util
::formatNumber($value, 0);
244 return htmlspecialchars($value);