<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "selectid")
    $co_id = $paramValue;
  else if ($paramName == "column")
    $column = $paramValue;
}

$dal = new DAL();

if ($column == "left") {
  $sql = "SELECT EP.id, EP.name AS text " .
         "FROM etproduct EP " .
         "LEFT JOIN etpcountry EC ON (EC.etproduct_id = EP.id) " .
         "WHERE EC.id IS NULL " .
         "ORDER BY text " ;
  $result = $dal->query($sql);
}

else if ($column == "right") {
  $sql = "SELECT EC.id, EP.name AS text " .
         "FROM etproduct EP, etpcountry EC " .
         "WHERE EC.etproduct_id = EP.id AND EC.country_id = $co_id " .
         "ORDER BY text " ;
  $result = $dal->query($sql);
}

echo json_encode($result);

?>

