<?php
include 'db.php';
if(isset($_POST['typ']) and $_POST['typ']=='eko_kl') {
  $konto = $_POST['konto'];
  $x=''; 
  $w=array();
  for($i=0; $i<4; $i++){ 
    $x .= $konto[$i];
    $w[$i] = " konto='$x' ";
  }                         
  $sql = 'select konto, opis from proracun_finplan where '.implode('or',$w). 'order by konto'; 
  $stmt = $dbh->prepare($sql);
  $stmt->execute();    
  $out = $stmt->fetchAll(PDO::FETCH_ASSOC);
  echo $out = json_encode($out);  
  die();
}
if(isset($_POST['typ']) and $_POST['typ']=='fun_kl') { 
  $konto = $_POST['konto'];
  $x=$konto[0]; 
  $w=array();
  for($i=1; $i<4; $i++){ 
    $x .= $konto[$i];
    $w[$i] = " sif_klf='$x' ";
  }                         
  $sql = 'select sif_klf konto, naziv_duzi opis from proracun_rpmklf where '.implode('or',$w). 'order by konto'; 
  $stmt = $dbh->prepare($sql);
  $stmt->execute();    
  $out = $stmt->fetchAll(PDO::FETCH_ASSOC);
  echo $out = json_encode($out);
}
