Translated using Weblate (Indonesian)
[phpmyadmin.git] / server_variables.php
blobd1d6b9169c4f982922648333d89da3de0d011c64
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Server variables
6 * @package PhpMyAdmin
7 */
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');
16 /**
17 * Does the common work
19 require 'libraries/server_common.inc.php';
21 /**
22 * Required to display documentation links
24 require 'libraries/server_variables_doc.php';
26 /**
27 * Ajax request
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']) . '";',
40 'NUM'
42 if (isset($VARIABLE_DOC_LINKS[$_REQUEST['varName']][3])
43 && $VARIABLE_DOC_LINKS[$_REQUEST['varName']][3] == 'byte'
44 ) {
45 $response->addJSON(
46 'message',
47 implode(
48 ' ', PMA_Util::formatByteDown($varValue[1], 3, 3)
51 } else {
52 $response->addJSON(
53 'message',
54 $varValue[1]
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'
62 && preg_match(
63 '/^\s*(\d+(\.\d+)?)\s*(mb|kb|mib|kib|gb|gib)\s*$/i',
64 $value,
65 $matches
67 ) {
68 $exp = array(
69 'kb' => 1,
70 'kib' => 1,
71 'mb' => 2,
72 'mib' => 2,
73 'gb' => 3,
74 'gib' => 3
76 $value = floatval($matches[1]) * PMA_Util::pow(
77 1024,
78 $exp[strtolower($matches[3])]
80 } else {
81 $value = PMA_Util::sqlAddSlashes($value);
84 if (! is_numeric($value)) {
85 $value="'" . $value . "'";
88 if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName'])
89 && PMA_DBI_query(
90 'SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value
92 ) {
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'])
97 . '";', 'NUM'
99 $response->addJSON(
100 'variable',
101 formatVariable($_REQUEST['varName'], $varValue[1])
103 } else {
104 $response->isSuccess(false);
105 $response->addJSON(
106 'error',
107 __('Setting variable failed')
111 exit;
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'
123 . '</h2>' . "\n";
126 * Link templates
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(
136 'b_help.png',
137 __('Documentation'),
138 array(
139 'style' => 'display:none',
140 'id' => 'docImage'
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);
152 * Displays the page
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 . '" />'
161 . '</div>'
162 . '</fieldset>';
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')
169 . '</div>'
170 . '<div style="clear:both"></div>'
171 . '</div>';
173 $odd_row = true;
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],
189 false,
190 $VARIABLE_DOC_LINKS[$name][2] . '_' . $VARIABLE_DOC_LINKS[$name][0],
191 true
193 $output .= htmlspecialchars(str_replace('_', ' ', $name));
194 $output .= '</a>';
195 $output .= '</span>';
196 } else {
197 $output .= htmlspecialchars(str_replace('_', ' ', $name));
199 $output .= '</div>'
200 . '<div class="var-value value' . (PMA_isSuperuser() ? ' editable' : '') . '">&nbsp;'
201 . formatVariable($name, $value)
202 . '</div>'
203 . '<div style="clear:both"></div>'
204 . '</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">&nbsp;' . formatVariable($name, $serverVarsSession[$name]) . '</div>'
210 . '<div style="clear:both"></div>'
211 . '</div>';
214 $odd_row = ! $odd_row;
216 $output .= '</div>';
218 $response->addHtml($output);
221 * Format Variable
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))
239 . '</abbr>';
240 } else {
241 return PMA_Util::formatNumber($value, 0);
244 return htmlspecialchars($value);