From 60dc1f8c7af8ff3e4ad4e05c173abe54347861ed Mon Sep 17 00:00:00 2001 From: Julio Cesar Laura Date: Tue, 25 Sep 2012 13:22:23 -0400 Subject: [PATCH] BUG 6216 Impossible to get input document in tracker SOLVED - Incorrect business logic to get the file to download - Fix the business logic to get the file --- .../methods/tracker/tracker_ShowDocument.php | 73 +++++++++++++------ 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/workflow/engine/methods/tracker/tracker_ShowDocument.php b/workflow/engine/methods/tracker/tracker_ShowDocument.php index bd8a17540..838ba00a3 100755 --- a/workflow/engine/methods/tracker/tracker_ShowDocument.php +++ b/workflow/engine/methods/tracker/tracker_ShowDocument.php @@ -1,6 +1,6 @@ - */ -if (!isset($_SESSION['PROCESS'])) { - G::header('location: login'); -} - -require_once 'classes/model/AppDocumentPeer.php'; +require_once ( "classes/model/AppDocumentPeer.php" ); $oAppDocument = new AppDocument(); -$oAppDocument->Fields = $oAppDocument->load($_GET['a']); +if(!isset($_GET['v'])){//Load last version of the document + $docVersion=$oAppDocument->getLastAppDocVersion($_GET['a']); +}else{ + $docVersion=$_GET['v']; +} +$oAppDocument->Fields = $oAppDocument->load($_GET['a'],$docVersion); $sAppDocUid = $oAppDocument->getAppDocUid(); -$info = pathinfo($oAppDocument->getAppDocFilename()); $iDocVersion = $oAppDocument->getDocVersion(); +$info = pathinfo( $oAppDocument->getAppDocFilename() ); $ext = $info['extension']; -$realPath = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/' . $sAppDocUid .'_'.$iDocVersion . '.' . $ext; -if (!file_exists($realPath)) { - $realPath = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/' . $sAppDocUid . '.' . $ext; -} -if (!file_exists($realPath)) { - G::streamFile($realPath, true, $oAppDocument->Fields['APP_DOC_FILENAME']); +if (isset($_GET['b'])) { + if ($_GET['b'] == '0') { + $bDownload = false; + } + else { + $bDownload = true; + } } else { - die("'" . $oAppDocument->Fields['APP_DOC_FILENAME'] . "' " . G::LoadTranslation('ID_ERROR_STREAMING_FILE')); -} \ No newline at end of file + $bDownload = true; +} + + +$realPath = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/' . $sAppDocUid .'_'.$iDocVersion . '.' . $ext ; +$realPath1 = PATH_DOCUMENT . $oAppDocument->Fields['APP_UID'] . '/' . $sAppDocUid . '.' . $ext ; +$sw_file_exists=false; +if(file_exists($realPath)){ + $sw_file_exists=true; +}elseif(file_exists($realPath1)){ + $sw_file_exists=true; + $realPath=$realPath1; +} + +if(!$sw_file_exists){ + $error_message="'".$oAppDocument->Fields['APP_DOC_FILENAME']. "' ".G::LoadTranslation('ID_ERROR_STREAMING_FILE'); + if((isset($_POST['request']))&&($_POST['request']==true)){ + $res ['success'] = 'failure'; + $res ['message'] = $error_message; + print G::json_encode ( $res ); + }else{ + G::SendMessageText($error_message, "ERROR"); + $backUrlObj=explode("sys".SYS_SYS,$_SERVER['HTTP_REFERER']); + G::header("location: "."/sys".SYS_SYS.$backUrlObj[1]); + die; + } + +}else{ + if((isset($_POST['request']))&&($_POST['request']==true)){ + $res ['success'] = 'success'; + $res ['message'] = $oAppDocument->Fields['APP_DOC_FILENAME']; + print G::json_encode ( $res ); + }else{ + G::streamFile ( $realPath, $bDownload, $oAppDocument->Fields['APP_DOC_FILENAME'] ); + } +}