I don't use proprietary technologies like SharePoint, but I found this PHP library for uploading files to SharePoint:
https://www.example-code.com/phpExt/sha ... d_file.asp
You might want to use this library if just needing to access lists in SharePoint:
https://github.com/thybag/PHP-SharePoint-Lists-API
Using the first example, I imagine that your trigger code in ProcessMaker would be something like this:
Code: Select all//set to the path where you placed the file on the ProcessMaker server:
//Note: if you don't have access to the server, then upload this file as a Public File in a process
require_once("/opt/chilkat/chilkat_9_5_0.php");
$g = new G();
function uploadToSharepoint($filePath, $dirOnSharepoint, $url) {
$http = new CkHttp();
// If SharePoint Windows classic authentication is used, then set the
// Login, Password, LoginDomain, and NtlmAuth properties.
$http->put_Login('SHAREPOINT_USERNAME');
$http->put_Password('SHAREPOINT_PASSWORD');
$http->put_LoginDomain('SHAREPOINT_NTLM_DOMAIN');
$http->put_NtlmAuth(true);
$resp = $http->PostXml('https://SHAREPOINT_HTTPS_DOMAIN/_api/contextinfo','','utf-8');
if ($http->get_LastMethodSuccess() != true) {
throw new Exception($http->lastErrorText());
}
if ($resp->get_StatusCode() != 200) {
throw new Exception( 'Error status code: '. $resp->get_StatusCode() .
'Response body:'. $resp->bodyStr());
}
$xml = new CkXml();
$xml->LoadXml($resp->bodyStr());
$req = new CkHttpRequest();
$req->put_HttpVerb('POST');
$req->put_Path("/_api/web/GetFolderByServerRelativeUrl('$dirOnSharepoint')/Files/add(url='$url',overwrite=true)");
$req->StreamBodyFromFile( $filePath );
// Add the X-RequestDigest header field.
$req->AddHeader('X-RequestDigest', $xml->getChildContent('d:FormDigestValue'));
// Do the upload using https (TLS). Port 443 is the default port for https.
$bUseTls = true;
// resp is a CkHttpResponse
$resp = $http->SynchronousRequest('SHAREPOINT_HTTPS_DOMAIN', 443, $bUseTls, $req);
if ($http->get_LastMethodSuccess() != true) {
throw new Exception( $http->lastErrorText() );
}
if ($resp->get_StatusCode() != 200) {
$xml = new CkXml();
$xml->LoadXml($resp->bodyStr());
throw new Exception('Failed status code: ' . $resp->get_StatusCode() ."\n". $xml->getXml();
}
}
$caseId = @@APPLICATION;
$sql = "SELECT AD.*, U.USR_FIRSTNAME, U.USR_LASTNAME, U.USR_USERNAME
FROM APP_DOCUMENT AD
LEFT JOIN USERS U ON AD.USR_UID=U.USR_UID
WHERE AD.APP_UID='$caseId' AND AD.APP_DOC_STATUS='ACTIVE' ";
$aFiles = executeQuery($sql);
foreach ($aFiles as $aFile) {
$resp = $http->PostXml('https://SHAREPOINT_HTTPS_DOMAIN/_api/contextinfo','','utf-8');
if ($http->get_LastMethodSuccess() != true) {
throw new Exception($http->lastErrorText());
}
if ($resp->get_StatusCode() != 200) {
throw new Exception( 'Response status code = ' . $resp->get_StatusCode() ."\n".
'Response body:' ."\n". $resp->bodyStr() );
}
if ($aFile['APP_DOC_TYE'] == 'OUTPUT') {
$filename = $aFile['APP_DOC_FILENAME'].'_'.$aFile['DOC_VERSION'];
$realFilename = $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'];
$od = new OutputDocument();
$aDocInfo = $od->Load( $aFile['DOC_UID'] );
if ($aDocInfo["OUT_DOC_GENERATE"] == 'PDF' or $aDocInfo["OUT_DOC_GENERATE"] == 'BOTH') {
$path = PATH_DOCUMENT. $g->getPathFromUID($caseId) .PATH_SEP. "outdocs" .PATH_SEP. $realFilename .'.pdf';
//set the directory to the case number on the sharepoint server:
uploadToSharepoint($path, @@APP_NUMBER, @@APP_NUMBER .'_'. $filename .'.pdf');
}
if ($aDocInfo["OUT_DOC_GENERATE"] == 'DOC' or $aDocInfo["OUT_DOC_GENERATE"] == 'BOTH') {
$path = PATH_DOCUMENT. $g->getPathFromUID($caseId) .PATH_SEP. "outdocs" .PATH_SEP. $realFilename .'.doc';
//set the directory to the case number on the sharepoint server:
uploadToSharepoint($path, @@APP_NUMBER, @@APP_NUMBER .'_'. $filename .'.doc');
}
}
else { //an Input Document or attached file:
$filename = $aFile['APP_DOC_FILENAME'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$realFilename = $aFile['APP_DOC_UID'] .'_'. $aFile['DOC_VERSION'];
$path = PATH_DOCUMENT. $g->getPathFromUID($caseId) .PATH_SEP. $realFilename .'.'. $ext;
//set the directory to the case number on the sharepoint server:
uploadToSharepoint($path, @@APP_NUMBER, @@APP_NUMBER .'_'. $filename);
}
}
}
You will probably have to debug it to get it to work, since I don't have SharePoint to test it, but this code should get you started. This code doesn't check whether the users uploaded files with the same name to the case, so you will also need to add code to check for that if you need it.