<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "fromto")
    $fromTo = explode (",", $paramValue);
}

$wd_id = array_pop ($fromTo);
$to    = array_pop ($fromTo);
$from  = array_pop ($fromTo);

$dal = new DAL();
  
for ($i=0; $i<count($fromTo); $i++) {
  $rowid = $fromTo[$i];

  if ($from == "leftmulMultiSelect2" && $to == "rightmulMultiSelect2") {
    $sql = "INSERT INTO etpcountry " .
           "(etproduct_id, country_id) " .
           "VALUES ($rowid, $wd_id) " ;
    $result = $dal->query($sql);
    $refresh = "11";
  }       

  else if ($from == "rightmulMultiSelect2" && $to == "leftmulMultiSelect2") {
//print_r ("$wd_id, $to, $from, $rowid");
    $sql = "DELETE FROM etpcountry " .
           "WHERE id = $rowid ";
    $result = $dal->query($sql);
    $refresh = "11";
  }
    
}

echo json_encode($refresh);

?>

