function openDocumentPropeties($path, $propertiesSchema = '*')
{
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://172.17.42.1:8080/nuxeo/site/automation');
    $session = $client->getSession('Administrator', 'Administrator');
    $answer = $session->newRequest("Document.Query")->set('params', 'query', "SELECT * FROM Document WHERE ecm:path = '" . $path . "'")->setSchema($propertiesSchema)->sendRequest();
    $documentsArray = $answer->getDocumentList();
    $value = sizeof($documentsArray);
    echo '<table>';
    echo '<tr><TH>uid</TH><TH>Path</TH>
		<TH>Type</TH><TH>State</TH><TH>Title</TH><TH>Property 1</TH>
		<TH>Property 2</TH><TH>Download as PDF</TH>';
    for ($test = 0; $test < $value; $test++) {
        echo '<tr>';
        echo '<td> ' . current($documentsArray)->getUid() . '</td>';
        echo '<td> ' . current($documentsArray)->getPath() . '</td>';
        echo '<td> ' . current($documentsArray)->getType() . '</td>';
        echo '<td> ' . current($documentsArray)->getState() . '</td>';
        echo '<td> ' . current($documentsArray)->getTitle() . '</td>';
        echo '<td> ' . current($documentsArray)->getProperty('dc:description') . '</td>';
        echo '<td> ' . current($documentsArray)->getProperty('dc:creator') . '</td>';
        echo '<td><form id="test" action="../samples/B5bis.php" method="post" >';
        echo '<input type="hidden" name="data" value="' . current($documentsArray)->getPath() . '"/>';
        echo '<input type="submit" value="download"/>';
        echo '</form></td></tr>';
        next($documentsArray);
    }
    echo '</table>';
}
function DateSearch($date)
{
    $utilities = new \Nuxeo\Automation\Client\NuxeoUtilities();
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://localhost:8080/nuxeo/site/automation');
    $session = $client->getSession('Administrator', 'Administrator');
    $answer = $session->newRequest("Document.Query")->set('params', 'query', "SELECT * FROM Document WHERE dc:created >= DATE '" . $utilities->dateConverterPhpToNuxeo($date) . "'")->sendRequest();
    $documentsArray = $answer->getDocumentList();
    $value = sizeof($documentsArray);
    echo '<table>';
    echo '<tr><TH>uid</TH><TH>Path</TH>
		<TH>Type</TH><TH>State</TH><TH>Title</TH><TH>Download as PDF</TH>';
    for ($test = 0; $test < $value; $test++) {
        echo '<tr>';
        echo '<td> ' . current($documentsArray)->getUid() . '</td>';
        echo '<td> ' . current($documentsArray)->getPath() . '</td>';
        echo '<td> ' . current($documentsArray)->getType() . '</td>';
        echo '<td> ' . current($documentsArray)->getState() . '</td>';
        echo '<td> ' . current($documentsArray)->getTitle() . '</td>';
        echo '<td><form id="test" action="../tests/B5bis.php" method="post" >';
        echo '<input type="hidden" name="data" value="' . current($documentsArray)->getPath() . '"/>';
        echo '<input type="submit" value="download"/>';
        echo '</form></td></tr>';
        next($documentsArray);
    }
    echo '</table>';
}
/**
 *
 * AttachBlob function
 *
 * @param String $blob contains the path of the blob to load as an attachment
 * @param String $filePath contains the path of the folder where the fille holding the blob will be created
 * @param String $blobtype contains the type of the blob (given by the $_FILES['blobPath']['type'])
 */
function attachBlob($blob = '../test.txt', $filePath = '/default-domain/workspaces/document', $blobtype = 'application/binary')
{
    //only works on LINUX / MAC
    // We get the name of the file to use it for the name of the document
    $ename = explode("/", $blob);
    $filename = end($ename);
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://localhost:8080/nuxeo/site/automation');
    $session = $client->getSession('Administrator', 'Administrator');
    $properties = "dc:title=" . $filename;
    //We create the document that will hold the file
    $answer = $session->newRequest("Document.Create")->set('input', 'doc:' . $filePath)->set('params', 'type', 'File')->set('params', 'name', end($ename))->set('params', 'properties', $properties)->sendRequest();
    //We upload the file
    $answer = $session->newRequest("Blob.Attach")->set('params', 'document', $answer->getDocument(0)->getPath())->loadBlob($blob, $blobtype)->sendRequest();
}
function GetBlob($path = '/default-domain/workspaces/jkjkj/test2.rtf', $blobtype = 'application/binary')
{
    $eurl = explode("/", $path);
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://localhost:8080/nuxeo/site/automation');
    $session = $client->GetSession('Administrator', 'Administrator');
    $answer = $session->NewRequest("Blob.Get")->Set('input', 'doc: ' . $path)->SendRequest();
    if (!isset($answer) or $answer == false) {
        echo '$answer is not set';
    } else {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' . end($eurl) . '.pdf');
        readfile('tempstream');
    }
}
/**
 *
 * getFileContent function
 * function used to download the blob of a file, converted into a PDF file
 * @param String $path contains the path of th file holding the blob
 */
function getFileContent($path = '/default-domain/workspaces/jkjkj/teezeareate.1304515647395')
{
    $eurl = explode("/", $path);
    $temp = str_replace(" ", "", end($eurl));
    $client = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient('http://localhost:8080/nuxeo/site/automation');
    $session = $client->getSession('Administrator', 'Administrator');
    $answer = $session->newRequest("Blob.Get")->set('input', 'doc:' . $path)->sendRequest();
    if (!isset($answer) or $answer == false) {
        echo '$answer is not set';
    } else {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' . $temp . '.pdf');
        readfile('tempstream');
    }
}
 /**
  * @return \Nuxeo\Automation\Client\NuxeoSession
  */
 protected function getClient()
 {
     if (null === $this->client_instance) {
         $repo_url = get_option('nx_repository_url');
         $repo_username = get_option('nx_username');
         $repo_password = get_option('nx_password');
         $nxclient = new \Nuxeo\Automation\Client\NuxeoPhpAutomationClient($repo_url . '/site/automation');
         $this->client_instance = $nxclient->getSession($repo_username, $repo_password);
         /*
          * Workaround for self-signed certificates
          * WARNING: this is highly not recommended
          */
         //      $guzzleClientProperty = (new ReflectionObject($this->client_instance))->getProperty('client');
         //      $guzzleClientProperty->setAccessible(true);
         //
         //      /** @var \Guzzle\Http\Client $guzzleClient */
         //      $guzzleClient = $guzzleClientProperty->getValue($this->client_instance);
         //      $guzzleClient->setSslVerification(false);
     }
     return $this->client_instance;
 }