<!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_sendtable.php
 * 
 * Primer poziva API funkcije 'sendtable' kojoj se salje tabela a ona vraca broj slogova u tabeli. 
 *  
 */
 
include_once 'infoapi/infoapi.php';

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

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

$mQueryEnvelope = new iapiQueryEnvelope ($mAPIFunctionName);
$mQueryEnvelope->username = USERNAME;
$mQueryEnvelope->password = PASSWORD;

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

$mQuery = $mQueryEnvelope;

$mQueryEnvelope->data->result_database_format = 'PLAIN_OBJ';
//$mQueryEnvelope->data->result_database_format = 'SQLITE';

$mQueryEnvelope->data->br_dokum = "0012";

// tekuci datum 
$mQueryEnvelope->data->datum = new DateTime('2017-01-01');

// datum valute je sedam dana kasnije
$mQueryEnvelope->data->valuta = new DateTime('2017-01-08');

$mQueryEnvelope->data->fields = "*";
$mQueryEnvelope->data->komitent = "0000";
$mQueryEnvelope->data->objekat = "0101";

$mDb= new PDO('sqlite:stavke.db');
$mDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$mData = $mDb->query('SELECT * FROM stavke');

$mQuery->data->AddTableReference ('stavke', $mData);

$mQueryEnvelope->data->database_format = 'PLAIN_OBJ';
//$mQueryEnvelope->data->database_format = 'SQLITE';

$miapiHandler->SaveRequestJSONToFile = true;

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

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

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

</body>
</html>