<?php

require '../config.php';
dol_include_once('/query/class/query.class.php');
dol_include_once('/query/class/dashboard.class.php');
$PDOdb = new TPDOdb();
$get = GETPOST('get');
$put = GETPOST('put');
switch ($get) {
    case 'tables':
        $query = new TQuery();
        $query->load($PDOdb, GETPOST('id'));
        __out(TQuery::getTables($query->pdodb), 'json');
        break;
    case 'fields':
        $query = new TQuery();
        $query->load($PDOdb, GETPOST('id'));
        __out(TQuery::getFields($query->pdodb, GETPOST('table')), 'json');
        break;
    default:
        break;
}
switch ($put) {
    case 'query':
        $query = new TQuery();
        $query->load($PDOdb, GETPOST('id'));
        $query->set_values($_REQUEST);
        $query->THide = GETPOST('THide');
        $query->TOperator = GETPOST('TOperator');
        $query->TGroup = GETPOST('TGroup');
        $query->TFunction = GETPOST('TFunction');