<!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 za SPEKTAR 
 *  
 */
 

include_once 'infoapi/infoapi.php';



  // korisnicko ime
  $m_username = "info";

  // lozinka
  $m_password = "demo";


$miapiHandler = new iapiHandler;
$miapiHandler->APIServerURL = SERVER_URL;

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


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

$mQueryEnvelope = new iapiQueryEnvelope ($mAPIFunctionName);
$mQueryEnvelope->username = $m_username;
$mQueryEnvelope->password = $m_password;

$mQuery = $mQueryEnvelope;
$mQuery->data->fields = 'id_art, stanje, cena, def_mp_marza, pdv_stopa_art';
$m_filter = new iapiFilter ('NE', 'cena', 0);
$mQuery->data->filter = $m_filter;
$mQuery->data->order = 'id_art';
$mQuery->data->result_database_format = 'SQLITE';
$mQuery->data->sif_firme_cond = '';
$mQuery->data->sif_obj_cond = '0101';


$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('spektar_data.db', 'w');
    fwrite($m_output_file, $mdatabasedata);
    fclose($m_output_file);

    echo 'data stored to spektar_data.db';
    
}
?>
<hr />

<?php include_once 'inc_sysinfo.php'; ?>

</body>
</html>