<?php
$function = $_REQUEST["f"];
if($function == "getProductImages"){
  $arrList = explode("\n",$_REQUEST["skuList"]);
  //var_dump($arrList);
  getProductImages($arrList);
}elseif($function == "getNumbers"){
  getNumbers($_REQUEST);
}
function getProductImages($arrList){
  $items = [];
  foreach($arrList as $key => $value){
    if($value === ""){
      array_push($items, "");
    }elseif($value === "*"){
        $currItem = new stdClass();
        $currItem->SKU = "";
        $currItem->Description = "";
        $currItem->ImageURL = "/img/Logo_1000.png";
      array_push($items, $currItem);
    }else{
      $item = new Item("%","%", $value);
      if($item->SKU){
        $currItem = new stdClass();
        $currItem->SKU = $item->SKU;
        $currItem->Description = $item->Description;
        $currItem->Notes = $item->Notes;
        $currItem->ImageURL = $item->getImage(true);
        array_push($items, $currItem);
      // var_dump($item->SKU);
      }
    }
    
    
   
  }
  header("Content-Type: application/json");
    $return = new stdClass();
    $return->Items = $items;
    echo json_encode($return);
}
function getNumbers($data){
  $items = "";
  global $con;
  $line = $data["line"];
  $group = $data["group"];
 
  $query = "SELECT SKU FROM INVENTORY WHERE `Line` LIKE '$line' AND `Group` LIKE '$group' AND `Active` = 1 AND IF(Qty>0,1,IF(Discontinued = 1,0,1)) ORDER BY SKU";
  //var_dump($query);
  $result = mysqli_query($con, $query);
  while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
    $items .= $row['SKU'] . "\n";
  }
  
    
   
  
  echo $items;
}
 ?>
