<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "selid")
    $selid = $paramValue;
  else if ($paramName == "values")
    $values = $paramValue;
}

$dal = new DAL();
$sql = "SELECT  querycriteria, " .
       "CASE WHEN combineidx = 1 THEN combinedquery ELSE query END as query " .
       "FROM reportquery " .
       "WHERE id = $selid LIMIT 1 ";
$report = $dal->query($sql);

$critList = explode (",", $report->querycriteria);
$valuList = explode (",", $values);

$sql = str_replace ($critList, $valuList, $report->query);

$result = $dal->query($sql);

echo json_encode($result);

?>

