Translated using Weblate (Estonian)
[phpmyadmin.git] / ajax.php
blobbf1d46873e564464ba838589a6086bea9af26b31
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Generic AJAX endpoint for getting information about database
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Response;
11 use PhpMyAdmin\Util;
12 use PhpMyAdmin\Core;
14 if (! defined('ROOT_PATH')) {
15 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
18 $_GET['ajax_request'] = 'true';
20 require_once ROOT_PATH . 'libraries/common.inc.php';
22 $response = Response::getInstance();
23 $response->setAjax(true);
25 if (empty($_POST['type'])) {
26 Core::fatalError(__('Bad type!'));
29 switch ($_POST['type']) {
30 case 'list-databases':
31 $response->addJSON('databases', $GLOBALS['dblist']->databases);
32 break;
33 case 'list-tables':
34 Util::checkParameters(['db'], true);
35 $response->addJSON('tables', $GLOBALS['dbi']->getTables($_POST['db']));
36 break;
37 case 'list-columns':
38 Util::checkParameters(['db', 'table'], true);
39 $response->addJSON('columns', $GLOBALS['dbi']->getColumnNames($_POST['db'], $_POST['table']));
40 break;
41 case 'config-get':
42 Util::checkParameters(['key'], true);
43 $response->addJSON('value', $GLOBALS['PMA_Config']->get($_POST['key']));
44 break;
45 case 'config-set':
46 Util::checkParameters(['key', 'value'], true);
47 $result = $GLOBALS['PMA_Config']->setUserValue(null, $_POST['key'], json_decode($_POST['value']));
48 if ($result !== true) {
49 $response = Response::getInstance();
50 $response->setRequestStatus(false);
51 $response->addJSON('message', $result);
53 break;
54 default:
55 Core::fatalError(__('Bad type!'));