<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="sr-RS">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php

/*
 * Demo: demo_spektar.php
 * 
 * Primer poziva API funkcije GETARTIKLI (cenovnik)
 *  
 */
 

include_once 'infoapi/infoapi.php';

$miapiHandler = new iapiHandler;
$miapiHandler->APIServerURL = SERVER_URL; // definisano u apitest/config.php

$miapiHandler->DebugLevel = DEBUG_LEVEL;
$miapiHandler->DebugSections = DEBUG_SECTIONS;


// naziv API funkcije koja se poziva
$mAPIFunctionName = 'GETARTIKLILIST';

$mQueryEnvelope = new iapiQueryEnvelope ($mAPIFunctionName);
$mQueryEnvelope->username = USERNAME; // definisano u apitest/config.php
$mQueryEnvelope->password = PASSWORD; // definisano u apitest/config.php

$mQuery = $mQueryEnvelope;

// moze se navesti lista polja koja treba vratiti u rezultatu
//$mQuery->data->fields = 'id_art, stanje, cena, def_mp_mar, pdv_st_art';

// po potrebi se može podesiti filter nad podacima
//$m_filter = new iapiFilter ('NE', 'cena', 0);   // artikli koji imaju cenu
//$m_filter = new iapiFilter ('GT', 'stanje', 0); // artikli kojih ima na stanju
//$mQuery->data->filter = $m_filter;

$mQuery->data->order = 'id_art';
$mQuery->data->result_database_format = 'SQLITE';

$mResponse  = $miapiHandler->Execute($mQuery);

$m_error = false;

if ($mResponse->error_state !='ok') {
  $m_error = true;
?>
Greska: <?php echo $mResponse->error_state; ?> - <?php echo $mResponse->error_message; ?>
<?php
} else {

  if ($mResponse->data->error_state !='ok') {
    $m_error = true;
?>
Greska: <?php echo $mResponse->data->error_state; ?> - <?php echo $mResponse->data->error_message; ?>
<?php
  }

}

if (!$m_error) {
   
    $mdatabasedata = base64_decode ($mResponse->data->databaseattachment);

    $m_output_file = fopen('artikli.db', 'w');
    fwrite($m_output_file, $mdatabasedata);
    fclose($m_output_file);

    echo 'data stored to artikli.db';
    
}
?>
<hr />
<?php include_once 'inc_sysinfo.php'; ?>
</body>
</html>