Example #1
0
function documentArt()
{
    header("Cache-Control: no-cache, must-revalidate");
    //HTTP 1.1
    header("Pragma: no-cache");
    //HTTP 1.0
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    // Date in the past
    $viewingSessionId = urldecode($_GET['DocumentID']);
    $annotationID = $_GET['AnnotationID'];
    // Call PCCIS
    // DocumentID query parameter already includes the "u" prefix so no need to add here
    $url = PccConfig::getImagingService() . "/ViewingSession/{$viewingSessionId}";
    $acsApiKey = PccConfig::getApiKey();
    $options = array('http' => array('method' => 'GET', 'header' => "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n"));
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $response = json_decode($result);
    // make sure target directory exists
    $targetDir = PccConfig::getMarkupsPath();
    $annotationFileName = PccConfig::getMarkupsPath() . $response->externalId . "_" . $response->attachmentIndex . "_" . $annotationID . ".xml";
    if (file_exists($targetDir) === false) {
        @mkdir($targetDir, 0777, true);
    }
    if (!PccConfig::isFileSafeToOpen($annotationFileName)) {
        header('HTTP/1.0 403 Forbidden');
        return;
    }
    $ok = true;
    if ($_SERVER['REQUEST_METHOD'] == "POST") {
        header("Status: 200 OK");
        $data = @file_get_contents('php://input');
        if ($data === false) {
            $ok = false;
        }
        $res = file_put_contents($annotationFileName, $data);
        if ($res === false) {
            $ok = false;
        }
    } else {
        header("Status: 200 OK");
        header('Content-type: application/xml');
        if (file_exists($annotationFileName) === true) {
            $data = file_get_contents($annotationFileName);
            if ($data === false) {
                $ok = false;
            }
            echo $data;
        }
    }
    if ($ok === false) {
        header("Status: 500 Internal Server Error");
        header('Content-type: text/plain');
    }
}
if (!empty($documentQueryParameter)) {
    if (strstr($documentQueryParameter, "http://") || strstr($documentQueryParameter, "https://")) {
        $document = $documentQueryParameter;
        $originalDocumentName = $documentQueryParameter;
    } else {
        $filename = basename($documentQueryParameter);
        $folder = dirname($documentQueryParameter);
        if ($folder == ".") {
            $folder = PccConfig::getDocumentsPath();
        } else {
            $folder = $folder . "/";
        }
        $document = Utils::combine($folder, $filename);
    }
    $extension = pathinfo($document, PATHINFO_EXTENSION);
    $correctPath = PccConfig::isFileSafeToOpen($document);
    if (!$correctPath) {
        header('HTTP/1.0 403 Forbidden');
        echo '<h1>403 Forbidden</h1>';
        return;
    }
    $acsApiKey = PccConfig::getApiKey();
    // Set viewing session properties using JSON.
    $data = array('externalId' => Utils::getHashString($document), 'tenantId' => 'My User ID', 'origin' => array('ipAddress' => $_SERVER['REMOTE_ADDR'], 'hostName' => $_SERVER['REMOTE_HOST'], 'sourceDocument' => $document), 'render' => array('flash' => array('optimizationLevel' => 1), 'html5' => array('alwaysUseRaster' => false)));
    $options = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n" . "Accusoft-Affinity-Hint: {$document}\r\n", 'content' => json_encode($data)));
    // Request a new viewing session from PCCIS.
    //   POST http://localhost:18681/PCCIS/V1/ViewingSession
    //
    $url = PccConfig::getImagingService() . "/ViewingSession";
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);