Translated using Weblate (Lithuanian)
[phpmyadmin.git] / ajax.php
blob9e02080b39d8338cd5044f4979bc49cccc97f170
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\Controllers\AjaxController;
11 use PhpMyAdmin\Core;
12 use PhpMyAdmin\DatabaseInterface;
13 use PhpMyAdmin\Response;
14 use PhpMyAdmin\Util;
16 if (! defined('ROOT_PATH')) {
17 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
20 $_GET['ajax_request'] = 'true';
22 require_once ROOT_PATH . 'libraries/common.inc.php';
24 /** @var Response $response */
25 $response = $containerBuilder->get(Response::class);
26 $response->setAjax(true);
28 /** @var DatabaseInterface $dbi */
29 $dbi = $containerBuilder->get(DatabaseInterface::class);
31 /** @var AjaxController $controller */
32 $controller = $containerBuilder->get(AjaxController::class);
34 if (empty($_POST['type'])) {
35 Core::fatalError(__('Bad type!'));
38 switch ($_POST['type']) {
39 case 'list-databases':
40 $response->addJSON($controller->databases());
41 break;
42 case 'list-tables':
43 Util::checkParameters(['db'], true);
44 $response->addJSON($controller->tables([
45 'db' => $_POST['db'],
46 ]));
47 break;
48 case 'list-columns':
49 Util::checkParameters(['db', 'table'], true);
50 $response->addJSON($controller->columns([
51 'db' => $_POST['db'],
52 'table' => $_POST['table'],
53 ]));
54 break;
55 case 'config-get':
56 Util::checkParameters(['key'], true);
57 $response->addJSON($controller->getConfig([
58 'key' => $_POST['key'],
59 ]));
60 break;
61 case 'config-set':
62 Util::checkParameters(['key', 'value'], true);
63 $result = $controller->setConfig([
64 'key' => $_POST['key'],
65 'value' => $_POST['value'],
66 ]);
67 if ($result !== true) {
68 $response->setRequestStatus(false);
69 $response->addJSON('message', $result);
71 break;
72 default:
73 Core::fatalError(__('Bad type!'));