Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#795758
Hi all,

We've been having some issues getting an export Report Table trigger to work - followign the example provided on the ProcessMaker wiki. http://wiki.processmaker.com/3.0/Report_Tables

The parameters ($params) of the trigger code are correct, and contain all required data when printed. Additionally, the upload.php file called does work when provided with a stripped down html form - returning data correctly.

The problem seems to be lying within the curl functions. The response of curl_exec all always empty - causing upload.php to stopp
Upload.php's _Files variable is always blank too.

Any Help would be appreciated!

Thanks
#795759
That code is old. I suspect that the problem is this line:
Code: Select all
   'ATTACH_FILE'  => '@' . $csvFilePath
This won't work in PHP 5.5 and later. You need to use:
Code: Select all
   'ATTACH_FILE'  => new CurlFile($csvFilePath)

However, it is much simpler to use the new PMFAddInputDocument() function instead of /services/upload.

Try using this code:
Code: Select all
$InputDocId = '9684354975728fdb12d1f12070508672'; //set to UID of input document

// Function to prepare the value from char fields for export
// by escapeing "" (double quotation marks) by doubling them and
// replacing '\r\n' with a hard return "\n", which occurs in textareas.
// If necessary, the value is enclosed in "..."
function escapeValue($s) {
        $s2 = str_replace('"', '""', $s);
        $s2 = str_replace('\r\n', "\n", $s2);
        if ($s != $s2 or trim($s2) != $s2) {
                $s2 = '"'. $s2 .'"';
        }
        return $s2;
}

if (empty(@@reportTableName)) {
        die("Please select table to export.");
}

$reportTbl = @@reportTableName;
$aFields = executeQuery('DESCRIBE ' . $reportTbl) or
        die("Error: Unable to find table '$reportTbl'.");

$aFieldNames = '';
foreach ($aFields as $aField) {
        $aFieldNames[] = $aField['Field'];
}
$firstLine = implode('; ', $aFieldNames);

$aRows = executeQuery("SELECT * FROM $reportTbl") or
        die("Error: Unable to query table '$reportTbl'.");

$aExportRows = array($firstLine);

foreach ($aRows as $aRow) {
        $aExportLine = array();

        foreach ($aFields as $aField) {
                $val = $aRow[ $aField['Field'] ];
                if (strpos($aField['Type'], "char") !== false) {
                        $val = escapeValue($val);
                }
                $aExportLine[] = $val;
         }

        $aExportRows[] = implode(';', $aExportLine);
}
@@sContents = implode("\n", $aExportRows);
$csvFilePath = tempnam(sys_get_temp_dir(), $reportTbl . '_') . '.csv';
@@csvFilename = basename($csvFilePath);
file_put_contents($csvFilePath, @@sContents);

@@fileId = PMFAddInputDocument($inputDocId, null, 1, 'INPUT', "CSV file for table $reportTbl", 'Add',
   @@APPLICATION, @%INDEX, @@TASK, @@USER_LOGGED, 'file', $csvFilePath);

if (!empty(@@fileId)) {
     $baseUrl = (G::is_https() ? "https://" : "http://") . $_SERVER['SERVER_NAME'] .
        ($_SERVER['SERVER_PORT'] == '80' ? '' : ':'.$_SERVER['SERVER_PORT']) . //comment out if no port
        '/sys' . @@SYS_SYS .'/'. @@SYS_LANG .'/'. @@SYS_SKIN .'/';
     @@csvFileUrl = $baseUrl . 'cases/cases_ShowDocument?a=' . @@fileId . '&v=1';
     unlink($csvFilePath);
}
else {
   //An error should be displayed in @@__ERROR__, but can uncomment the following line for user:
   //die("Error adding file '$csvFilePath' to case.");
}
Let me know if that works for you and I will update the documentation.
#795764
amosbatto wrote:That code is old. I suspect that the problem is this line:
Code: Select all
   'ATTACH_FILE'  => '@' . $csvFilePath
This won't work in PHP 5.5 and later. You need to use:
Code: Select all
   'ATTACH_FILE'  => new CurlFile($csvFilePath) 

However, it is much simpler to use the new PMFAddInputDocument() function instead of /services/upload.

Thanks for the reply @amosbatto

Using the PMFAddInputDocument() function you suggest, a different error occurs; with row not existing.

I will continue to investigate - just wanted to let you know what the result was.

Thanks
Attachments
chrome_2017-10-02_15-31-54.png
chrome_2017-10-02_15-31-54.png (38.88 KiB) Viewed 3350 times
#795767
The problem is the variable is defined as $InputDocId, but used as $inputDocId (wrong case) when passed to PMFAddInputDocument().

Try this code:
Code: Select all
$inputDocId = '9684354975728fdb12d1f12070508672'; //set to UID of input document

// Function to prepare the value from char fields for export
// by escapeing "" (double quotation marks) by doubling them and
// replacing '\r\n' with a hard return "\n", which occurs in textareas.
// If necessary, the value is enclosed in "..."
function escapeValue($s) {
        $s2 = str_replace('"', '""', $s);
        $s2 = str_replace('\r\n', "\n", $s2);
        if ($s != $s2 or trim($s2) != $s2) {
                $s2 = '"'. $s2 .'"';
        }
        return $s2;
}

if (empty(@@reportTableName)) {
        die("Please select table to export.");
}

$reportTbl = @@reportTableName;
$aFields = executeQuery('DESCRIBE ' . $reportTbl) or
        die("Error: Unable to find table '$reportTbl'.");

$aFieldNames = '';
foreach ($aFields as $aField) {
        $aFieldNames[] = $aField['Field'];
}
$firstLine = implode('; ', $aFieldNames);

$aRows = executeQuery("SELECT * FROM $reportTbl") or
        die("Error: Unable to query table '$reportTbl'.");

$aExportRows = array($firstLine);

foreach ($aRows as $aRow) {
        $aExportLine = array();

        foreach ($aFields as $aField) {
                $val = $aRow[ $aField['Field'] ];
                if (strpos($aField['Type'], "char") !== false) {
                        $val = escapeValue($val);
                }
                $aExportLine[] = $val;
         }

        $aExportRows[] = implode(';', $aExportLine);
}
@@sContents = implode("\n", $aExportRows);
$csvFilePath = tempnam(sys_get_temp_dir(), $reportTbl) . '.csv';
@@csvFilePath = $csvFilePath;
@@csvFilename = basename($csvFilePath);
file_put_contents($csvFilePath, @@sContents);

@@fileId = PMFAddInputDocument($inputDocId, null, 1, 'INPUT', "CSV file for table $reportTbl", 'Add',
   @@APPLICATION, @%INDEX, @@TASK, @@USER_LOGGED, 'file', $csvFilePath);

if (!empty(@@fileId)) {
     $baseUrl = (G::is_https() ? "https://" : "http://") . $_SERVER['SERVER_NAME'] .
        ($_SERVER['SERVER_PORT'] == '80' ? '' : ':'.$_SERVER['SERVER_PORT']) . //comment out if no port
        '/sys' . @@SYS_SYS .'/'. @@SYS_LANG .'/'. @@SYS_SKIN .'/';
     @@csvFileUrl = $baseUrl . 'cases/cases_ShowDocument?a=' . @@fileId . '&v=1';
     unlink($csvFilePath);
}
else {
   //An error should be displayed in @@__ERROR__, but can uncomment the following line for user:
   //die("Error adding file '$csvFilePath' to case.");
}
Here is the updated process that you can download and test:
(33.09 KiB) Downloaded 267 times
#795771
amosbatto wrote:The problem is the variable is defined as $InputDocId, but used as $inputDocId (wrong case) when passed to PMFAddInputDocument().
Thanks again @amosbatto

I updated this, modified the implodes and string replaces for CSV export and it is now working as expected.

Your help is appreciated.

Updating the doc would be a great idea.

Thanks,

Daniel
Most Demanding OST to PST Converter

If you are looking for the most demanding and one […]

Interested in launching your NFT marketplace platf[…]

When you buy Klonopin online from Xanaxgeneric.com[…]

Are you looking to buy Xanax online? Xanax is a me[…]