Completing UI integration for new Export methods and fixing some details

This commit is contained in:
Erik Amaru Ortiz
2014-03-06 12:39:16 -04:00
parent 9dbc0796ea
commit f1cb7170d8
4 changed files with 60 additions and 52 deletions

View File

@@ -21,16 +21,33 @@
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
//add more security, and catch any error or exception
$sFileName = $_GET['p'] . '.pm';
$file = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName . 'tpm';
$filex = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName;
if (file_exists( $file )) {
rename( $file, $filex );
if (! isset($_GET["file_hash"])) {
throw new Exception("Invalid Request, param 'file_hash' was not sent.");
}
$realPath = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName;
G::streamFile( $realPath, true );
$httpStream = new \ProcessMaker\Util\IO\HttpStream();
$outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP;
$filename = base64_decode($_GET["file_hash"]);
$fileExtension = pathinfo($outputDir . $filename, PATHINFO_EXTENSION);
if (! file_exists($outputDir . $filename)) {
throw new Exception("Error, couldn't find request file: $filename");
}
$httpStream->loadFromFile($outputDir . $filename);
$httpStream->setHeader("Content-Type", "application/$fileExtension");
$httpStream->send();
// ************* DEPRECATED (it will be removed soon) *********************************
//add more security, and catch any error or exception
//$sFileName = $_GET['p'] . '.pm';
//$file = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName . 'tpm';
//$filex = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName;
//
//if (file_exists( $file )) {
// rename( $file, $filex );
//}
//
//$realPath = PATH_DOCUMENT . 'output' . PATH_SEP . $sFileName;
//G::streamFile( $realPath, true );

View File

@@ -22,30 +22,33 @@
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
$httpStream = new \ProcessMaker\Util\IO\HttpStream();
$response = new StdClass();
$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"]);
try {
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);
$version = ProcessMaker\Util\Common::getLastVersion($outputDir . $exporter->getProjectName() . "-*.pmx") + 1;
$outputFilename = sprintf("%s-%s.%s", $exporter->getProjectName(), $version, "pmx");
$exporter->saveExport($outputDir . $outputFilename);
} else {
$oProcess = new Processes();
$proFields = $oProcess->serializeProcess($_GET["pro_uid"]);
$result = $oProcess->saveSerializedProcess($proFields);
$outputFilename = $result["FILENAME"];
$httpStream->setHeader("Content-Type" , "application/pmx");
rename($outputDir . $outputFilename . "tpm", $outputDir . $outputFilename);
}
} else {
$oProcess = new Processes();
$proFields = $oProcess->serializeProcess($_GET["pro_uid"]);
$result = $oProcess->saveSerializedProcess($proFields);
$outputFilename = $outputDir . $result["FILENAME"];
rename($outputFilename . "tpm", $outputFilename);
$response->file_hash = base64_encode($outputFilename);
$response->success = true;
} catch (Exception $e) {
$response->message = $e->getMessage();
$response->success = false;
}
$httpStream->loadFromFile($outputFilename);
$httpStream->send();
echo json_encode($response);
// ************* DEPRECATED (it will be removed soon) *********************************

View File

@@ -151,6 +151,7 @@ class HttpStream
/**
* @param string $filename file to stream
* @throws \Exception
*/
public function loadFromFile($filename)
{

View File

@@ -695,37 +695,24 @@ 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")});
var proUid = record[0].get("PRO_UID");
myMask.show();
///////
var proUid = record[0].get("PRO_UID");
var proTitle = record[0].get("PRO_TITLE");
var titleLength = 60;
title = (titleLength - proTitle.length >= 0)? proTitle : proTitle.substring(0, (titleLength - 1) + 1) + "...";
///////
Ext.Ajax.request({
url: "../processes/processes_Ajax",
method: "POST",
params: {
"action": "process_Export",
"data": "{\"pro_uid\": \"" + proUid + "\"}",
"processMap": 0
},
success: function (response, opts) {
url: "../processes/processes_Export",
method: "GET",
params: {"pro_uid": proUid},
success: function (response) {
var result = JSON.parse(response.responseText);
myMask.hide();
var dataResponse = eval("(" + response.responseText + ")"); //json
var url = window.location.href;
window.location = url.substring(0, url.lastIndexOf("/") + 1) + dataResponse.FILENAME_LINK;
if (result.success) {
window.location = "../processes/processes_DownloadFile?file_hash=" + result.file_hash;
} else {
Ext.Msg.show({title: "", msg: result.message, icon: Ext.MessageBox.ERROR, buttons: Ext.MessageBox.OK});
}
},
failure: function (response, opts) {