<!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_getattachment.php
 * 
 * Primer poziva API funkcije 'attachments' koja vraca priloge i upotreba priloga koji su dobijeni kao rezultat poziva. 
 *  
 */

// ukljuci INFO API biblioteku
include_once 'infoapi/infoapi.php';

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

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


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

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

// izvrsi funkciju
$mResponse = $miapiHandler->Execute($mQuery);

//echo "<pre>";
//print_r ($mResponse);
//echo "</pre>";

if (isset ($mResponse->data->attachments)) {
    foreach ($mResponse->data->attachments->items as $mItem) {
?>
<p>Attachment '<?php echo $mItem->id; ?>' (<?php echo $mItem->type; ?>):<br />
<?php
        switch (strtoupper($mItem->type)) {
            case 'STRING':
                echo $mItem->content;
                break;

            case 'GIF':
            case 'JPG':
            case 'JPEG':
            case 'PNG':
                $mContents = base64_decode ($mItem->content);
                file_put_contents ($mItem->file_name, $mContents);
                echo '<img src="' . $mItem->file_name . '">';
                break;
                
            default:
                echo $mItem->content;
        }
?>
</p>
<?php        
    }    
}

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

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

<hr />

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

</body>
</html>