<!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_math.php
 * 
 * Primer poziva API funkcije 'math' koja izvrsava osnovne matematicke operacije. 
 *  
 */
 

include_once 'infoapi/infoapi.php';

$m_function = getPostValue ('function', 'add');
$m_param1 = getPostValue ('param1', 6, 'float');
$m_param2 = getPostValue ('param2', 12, 'float');


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

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


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

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

$mQueryEnvelope->data->function = $m_function;
$mQueryEnvelope->data->param1 = $m_param1;
$mQueryEnvelope->data->param2 = $m_param2;

$mQuery = $mQueryEnvelope;
$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
  }

}
?>

<hr />

<?php
if (!$m_error) {
  $m_result = $mResponse->data->value;
} else {
  $m_result = 'ERR';
}  //  if (!$m_error) 
?>

<form id="form1" name="form1" method="post" action="">
<input name="param1" type="text" value="<?php echo $m_param1; ?>" size="4" maxlength="4" />
<input name="param2" type="text" value="<?php echo $m_param2; ?>" size="4" maxlength="4" />
<select name="function">
  <option value="add" <?php echo ($m_function=='add' ? 'selected="selected"' : ''); ?>>+</option>
  <option value="sub" <?php echo ($m_function=='sub' ? 'selected="selected"' : ''); ?>>-</option>
  <option value="div" <?php echo ($m_function=='div' ? 'selected="selected"' : ''); ?>>/</option>
  <option value="mul" <?php echo ($m_function=='mul' ? 'selected="selected"' : ''); ?>>*</option>
</select>
<input name="submit" type="submit" value="=" />
<input name="result" type="text" value="<?php echo $m_result; ?>" size="4" maxlength="4" disabled="disabled" />
</form>

<hr />


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

</body>
</html>