function processRequest($matches) { // Verify that the request type is acceptable. if (!is_null($this->requestTypeWhiteList)) { $requestIsAcceptable = false; foreach ($this->requestTypeWhiteList as $requestType) { if ($_SERVER['REQUEST_METHOD'] == $requestType) { $requestIsAcceptable = true; break; } } if (!$requestIsAcceptable) { throw new Exception("The request type is not acceptable."); } } $imagingServiceUri = PccConfig::getImagingService() . $_SERVER['PATH_INFO']; // Add only the white-listed query parameters to the outgoing request. $queryParameters = ""; if (!is_null($this->queryParameterWhiteList)) { foreach ($this->queryParameterWhiteList as $key) { $data = $_GET[$key]; if (!is_null($data)) { if (!empty($queryParameters)) { $queryParameters .= "&"; } $queryParameters .= $key . '=' . urlencode($data); } } } if (!empty($queryParameters)) { $imagingServiceUri .= '?' . $queryParameters; } // Add only the white-listed request header items to the outgoing request. $headerList = ''; $body = ''; if (!is_null($this->requestHeaderWhiteList)) { foreach ($this->requestHeaderWhiteList as $key) { $data = $_SERVER[$key]; if (!is_null($data)) { $headerList = "{$headerList}{$key}: {$data}\r\n"; } } } $acsApiKey = PccConfig::getApiKey(); $headerList = "{$headerList}Acs-Api-Key: {$acsApiKey}\r\n"; if ($_SERVER['REQUEST_METHOD'] == 'POST' || $_SERVER['REQUEST_METHOD'] == 'PUT') { $body = @file_get_contents('php://input'); } $options = array('http' => array('method' => $_SERVER['REQUEST_METHOD'], 'header' => $headerList, 'content' => $body)); $context = stream_context_create($options); $result = file_get_contents($imagingServiceUri, false, $context); // Retrieve HTTP status code list($version, $status_code, $msg) = explode(' ', $http_response_header[0], 3); // Add only the white-listed response header items to the response (plus the status code) if ($status_code == 0) { // The imaging service currently returns 0 status sometimes. $status_code = 200; } header("{$version} {$status_code} {$msg}"); if (!is_null($this->responseHeaderWhiteList)) { foreach ($this->responseHeaderWhiteList as $key) { foreach ($http_response_header as $value) { if (preg_match("/^{$key}:/i", $value)) { // Successful match header($value, TRUE); } } } } // Return the body of the response only if it did not fail. if ($status_code == 200) { echo $result; } }
function listMarkupJson($matches) { $annotationFiles = array('annotationFiles' => array()); header("Content-Type: application/json"); $viewingSessionId = $_GET['DocumentID']; // Call PCCIS $url = PccConfig::getImagingService() . "/ViewingSession/" . urlencode($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); if ($result === 0 || !$response->externalId || !strlen($response->externalId)) { header("HTTP/1.1 500 Internal Server Error"); } else { $path2Save = PccConfig::getMarkupsPath(); $i = 1; $fileList = glob($path2Save . '*.xml'); foreach ($fileList as $file) { if (stristr($file, $response->externalId . '_' . $response->attachmentIndex) == TRUE) { $nameParts = explode('.', array_pop(explode('_', basename($file)))); $name = substr($nameParts[0], 1); $annotationFiles['annotationFiles'][] = array('annotationLabel' => $name, 'annotationName' => basename($file), 'ID' => (string) $i++); } } } echo json_encode($annotationFiles); flush(); }
} } else { // If there was no 'document' parameter, but a 'viewingSessionId' // value exists, there is viewing session already so we don't // need to do anything else. This case is true when viewing attachments // of email message document types (.EML and .MSG). $viewingSessionId = stripslashes($_GET['viewingSessionId']); if (!empty($viewingSessionId)) { // Request properties about the viewing session from PCCIS. // The properties will include an identifier of the source document // from which the attachment was obtained. The name of the attachment // is also available. These values are used to just to provide // contextual information to the user. // GET http://localhost:18681/PCCIS/V1/ViewingSession/u{Viewing Session ID} // $url = PccConfig::getImagingService() . "/ViewingSession/u" . urlencode($viewingSessionId); $result = file_get_contents($url); $response = json_decode($result); $document = $response->origin->sourceDocument . ":{" . $response->attachmentDisplayName . "}"; } else { echo 'You must include the name of a document in the URL.<br/>'; $link = $_SERVER['PHP_SELF'] . '?document=sample.doc'; echo 'For example, click on this link: <a href="' . $link . '">' . $link . '</a>'; return; } } ?> <!DOCTYPE html> <html> <head id="Head1" runat="server"> <meta charset="utf-8"/>
fclose($fileHandle); $options = array('http' => array('method' => 'PUT', 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n", 'content' => $fileContents)); // Upload File to PCCIS. // PUT http://localhost:18681/PCCIS/V1/ViewingSessions/u{Viewing Session ID}/SourceFile?FileExtension={File Extension} // Note the "u" prefixed to the Viewing Session ID. This is required when providing // an unencoded Viewing Session ID, which is what PCCIS returns from the initial POST. // $url = PccConfig::getImagingService() . "/ViewingSession/u{$viewingSessionId}/SourceFile?FileExtension={$extension}"; $context = stream_context_create($options); file_get_contents($url, false, $context); $data = array('viewer' => 'HTML5'); $options = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n", 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'content' => json_encode($data))); // Start Viewing Session in PCCIS. // POST http://localhost:18681/PCCIS/V1/ViewingSessions/u{Viewing Session ID}/Notification/SessionStarted // $url = PccConfig::getImagingService() . "/ViewingSession/u{$viewingSessionId}/Notification/SessionStarted"; $context = stream_context_create($options); file_get_contents($url, false, $context); } else { $url = PccConfig::getImagingService() . "/ViewingSession/u{$viewingSessionId}/Notification/SessionStopped"; $data = array('endUserMessage' => "Document not found: {$documentQueryParameter}", 'httpStatus' => 504); $options = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n", 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'content' => json_encode($data))); $context = stream_context_create($options); file_get_contents($url, false, $context); } $data = array('viewingSessionId' => $viewingSessionId); echo json_encode($data); } else { $data = array('error' => 'document parameter is required'); echo json_encode($data); }