Integrating new class Util\HttpStream for export mehods, bpmn and old projects.

This commit is contained in:
Erik Amaru Ortiz
2014-03-05 20:15:53 -04:00
parent 6f385257ea
commit 611073ab90
2 changed files with 111 additions and 79 deletions

View File

@@ -22,84 +22,112 @@
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
$httpStream = new \ProcessMaker\Util\IO\HttpStream();
$outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP;
if (\BpmnProject::exists($_GET["pro_uid"])) {
$exporter = new ProcessMaker\Exporter\XmlExporter($_GET["pro_uid"]);
$version = ProcessMaker\Util\Common::getLastVersion($outputDir . $exporter->getProjectName() ."-*.pmx") + 1;
$outputFilename = sprintf("%s-%s.%s", $exporter->getProjectName(), $version, "pmx");
$exporter->saveExport($outputDir . $outputFilename);
$httpStream->setHeader("Content-Type" , "application/pmx");
} else {
$oProcess = new Processes();
$proFields = $oProcess->serializeProcess($_GET["pro_uid"]);
$result = $oProcess->saveSerializedProcess($proFields);
$outputFilename = $outputDir . $result["FILENAME"];
rename($outputFilename . "tpm", $outputFilename);
}
$httpStream->loadFromFile($outputFilename);
$httpStream->send();
// ************* DEPRECATED (it will be removed soon) *********************************
//G::LoadThirdParty( 'pear/json', 'class.json' );
try {
function myTruncate ($chain, $limit, $break = '.', $pad = '...')
{
if (strlen( $chain ) <= $limit) {
return $chain;
}
$breakpoint = strpos( $chain, $break, $limit );
if (false !== $breakpoint) {
$len = strlen( $chain ) - 1;
if ($breakpoint < $len) {
$chain = substr( $chain, 0, $breakpoint ) . $pad;
}
}
return $chain;
}
function addTitlle ($Category, $Id, $Lang)
{
require_once 'classes/model/Content.php';
$content = new Content();
$value = $content->load( $Category, '', $Id, $Lang );
return $value;
}
//$oJSON = new Services_JSON();
$stdObj = Bootstrap::json_decode( $_POST['data'] );
if (isset( $stdObj->pro_uid ))
$sProUid = $stdObj->pro_uid;
else
throw (new Exception( G::LoadTranslation('ID_PROCESS_UID_NOT_DEFINED') ));
/* Includes */
G::LoadClass( 'processes' );
$oProcess = new Processes();
$proFields = $oProcess->serializeProcess( $sProUid );
$Fields = $oProcess->saveSerializedProcess( $proFields );
$pathLength = strlen( PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP );
$length = strlen( $Fields['PRO_TITLE'] ) + $pathLength;
foreach ($Fields as $key => $value) {
if ($key == 'PRO_TITLE') {
$Fields[$key] = myTruncate( $value, 65, ' ', '...' );
}
if ($key == 'FILENAME') {
$Fields[$key] = myTruncate( $value, 60, '_', '...pm' );
}
if (($length) >= 250) {
if ($key == 'FILENAME_LINK') {
list ($file, $rest) = explode( 'p=', $value );
list ($filenameLink, $rest) = explode( '&', $rest );
$Fields[$key] = myTruncate( $filenameLink, 250 - $pathLength, '_', '' );
$Fields[$key] = $file . "p=" . $Fields[$key] . '&' . $rest;
}
}
}
/* Render page */
if (isset( $_REQUEST["processMap"] ) && $_REQUEST["processMap"] == 1) {
$G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent( "xmlform", "xmlform", "processes/processes_Export", "", $Fields );
G::RenderPage( "publish", "raw" );
} else {
$xmlFrm = new XmlForm();
$xmlFrm->home = PATH_XMLFORM . "processes" . PATH_SEP;
$xmlFrm->parseFile( "processes_Export.xml", SYS_LANG, true );
$Fields["xmlFrmFieldLabel"] = array ("title" => $xmlFrm->fields["TITLE"]->label,"proTitle" => $xmlFrm->fields["PRO_TITLE"]->label,"proDescription" => $xmlFrm->fields["PRO_DESCRIPTION"]->label,"size" => $xmlFrm->fields["SIZE"]->label,"fileName" => $xmlFrm->fields["FILENAME_LABEL"]->label
);
echo G::json_encode( $Fields );
}
} catch (Exception $e) {
$G_PUBLISH = new Publisher();
$aMessage['MESSAGE'] = $e->getMessage();
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
G::RenderPage( 'publish', 'raw' );
}
//try {
//
// function myTruncate ($chain, $limit, $break = '.', $pad = '...')
// {
// if (strlen( $chain ) <= $limit) {
// return $chain;
// }
// $breakpoint = strpos( $chain, $break, $limit );
// if (false !== $breakpoint) {
// $len = strlen( $chain ) - 1;
// if ($breakpoint < $len) {
// $chain = substr( $chain, 0, $breakpoint ) . $pad;
// }
// }
// return $chain;
// }
//
// function addTitlle ($Category, $Id, $Lang)
// {
// require_once 'classes/model/Content.php';
// $content = new Content();
// $value = $content->load( $Category, '', $Id, $Lang );
// return $value;
// }
//
// //$oJSON = new Services_JSON();
// $stdObj = Bootstrap::json_decode( $_POST['data'] );
// if (isset( $stdObj->pro_uid ))
// $sProUid = $stdObj->pro_uid;
// else
// throw (new Exception( G::LoadTranslation('ID_PROCESS_UID_NOT_DEFINED') ));
//
// /* Includes */
// G::LoadClass( 'processes' );
// $oProcess = new Processes();
// $proFields = $oProcess->serializeProcess( $sProUid );
// $Fields = $oProcess->saveSerializedProcess( $proFields );
// $pathLength = strlen( PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP );
// $length = strlen( $Fields['PRO_TITLE'] ) + $pathLength;
//
// foreach ($Fields as $key => $value) {
// if ($key == 'PRO_TITLE') {
// $Fields[$key] = myTruncate( $value, 65, ' ', '...' );
// }
// if ($key == 'FILENAME') {
// $Fields[$key] = myTruncate( $value, 60, '_', '...pm' );
// }
// if (($length) >= 250) {
// if ($key == 'FILENAME_LINK') {
// list ($file, $rest) = explode( 'p=', $value );
// list ($filenameLink, $rest) = explode( '&', $rest );
// $Fields[$key] = myTruncate( $filenameLink, 250 - $pathLength, '_', '' );
// $Fields[$key] = $file . "p=" . $Fields[$key] . '&' . $rest;
// }
// }
// }
//
// /* Render page */
// if (isset( $_REQUEST["processMap"] ) && $_REQUEST["processMap"] == 1) {
// $G_PUBLISH = new Publisher();
// $G_PUBLISH->AddContent( "xmlform", "xmlform", "processes/processes_Export", "", $Fields );
//
// G::RenderPage( "publish", "raw" );
// } else {
// $xmlFrm = new XmlForm();
// $xmlFrm->home = PATH_XMLFORM . "processes" . PATH_SEP;
// $xmlFrm->parseFile( "processes_Export.xml", SYS_LANG, true );
//
// $Fields["xmlFrmFieldLabel"] = array ("title" => $xmlFrm->fields["TITLE"]->label,"proTitle" => $xmlFrm->fields["PRO_TITLE"]->label,"proDescription" => $xmlFrm->fields["PRO_DESCRIPTION"]->label,"size" => $xmlFrm->fields["SIZE"]->label,"fileName" => $xmlFrm->fields["FILENAME_LABEL"]->label
// );
//
// echo G::json_encode( $Fields );
// }
//} catch (Exception $e) {
// $G_PUBLISH = new Publisher();
// $aMessage['MESSAGE'] = $e->getMessage();
// $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
// G::RenderPage( 'publish', 'raw' );
//}

View File

@@ -695,6 +695,10 @@ function exportProcess() {
var record = processesGrid.getSelectionModel().getSelections();
if(record.length == 1) {
window.location = "../processes/processes_Export?pro_uid=" + record[0].get("PRO_UID");
return;
var myMask = new Ext.LoadMask(Ext.getBody(), {msg: _("ID_LOADING")});
myMask.show();